diff --git a/CoqOfRust/blacklist.txt b/CoqOfRust/blacklist.txt index 6e830bf59..5139e5429 100644 --- a/CoqOfRust/blacklist.txt +++ b/CoqOfRust/blacklist.txt @@ -22,4 +22,10 @@ move_sui/links/ move_sui/simulations/move_bytecode_verifier_meter/lib.v # Because it does not change much right now and takes a long time to compile move_sui/proofs -move_sui/simulations \ No newline at end of file +move_sui/simulations +# Plonky3 related files that does not pass +plonky3/commit/src/adapters/extension_mmcs.v +plonky3/merkle-tree/src/hiding_mmcs.v +plonky3/merkle-tree/src/mmcs.v +plonky3/monty-31/src/monty_31.v +plonky3/poseidon2/src/external.v \ No newline at end of file diff --git a/CoqOfRust/plonky3/air/links/air.v b/CoqOfRust/plonky3/air/links/air.v new file mode 100644 index 000000000..3803f267d --- /dev/null +++ b/CoqOfRust/plonky3/air/links/air.v @@ -0,0 +1,95 @@ +Require Import CoqOfRust.CoqOfRust. +Require Import CoqOfRust.links.M. +Require Import plonky3.air.air. + +(* pub trait AirBuilder: Sized { *) +Module AirBuilder. +(* + type F: Field; + + type Expr: Algebra + Algebra; + + type Var: Into + + Copy + + Send + + Sync + + Add + + Add + + Add + + Sub + + Sub + + Sub + + Mul + + Mul + + Mul; + + type M: Matrix; + + fn main(&self) -> Self::M; + + fn is_first_row(&self) -> Self::Expr; + fn is_last_row(&self) -> Self::Expr; + fn is_transition(&self) -> Self::Expr { + self.is_transition_window(2) + } + fn is_transition_window(&self, size: usize) -> Self::Expr; + + fn when>(&mut self, condition: I) -> FilteredAirBuilder<'_, Self> { + FilteredAirBuilder { + inner: self, + condition: condition.into(), + } + } + + fn when_ne, I2: Into>( + &mut self, + x: I1, + y: I2, + ) -> FilteredAirBuilder<'_, Self> { + self.when(x.into() - y.into()) + } + + fn when_first_row(&mut self) -> FilteredAirBuilder<'_, Self> { + self.when(self.is_first_row()) + } + + fn when_last_row(&mut self) -> FilteredAirBuilder<'_, Self> { + self.when(self.is_last_row()) + } + + fn when_transition(&mut self) -> FilteredAirBuilder<'_, Self> { + self.when(self.is_transition()) + } + + fn when_transition_window(&mut self, size: usize) -> FilteredAirBuilder<'_, Self> { + self.when(self.is_transition_window(size)) + } + + fn assert_zero>(&mut self, x: I); + + fn assert_zeros>(&mut self, array: [I; N]) { + for elem in array { + self.assert_zero(elem); + } + } + + fn assert_bools>(&mut self, array: [I; N]) { + let zero_array = array.map(|x| x.into().bool_check()); + self.assert_zeros(zero_array); + } + + fn assert_one>(&mut self, x: I) { + self.assert_zero(x.into() - Self::Expr::ONE); + } + + fn assert_eq, I2: Into>(&mut self, x: I1, y: I2) { + self.assert_zero(x.into() - y.into()); + } + + fn assert_bool>(&mut self, x: I) { + self.assert_zero(x.into().bool_check()); + } +*) + Class Run (Self : Set) `{Link Self} : Set := { + }. +End AirBuilder. \ No newline at end of file diff --git a/CoqOfRust/plonky3/baby-bear/src/aarch64_neon/mod.rs b/CoqOfRust/plonky3/baby-bear/src/aarch64_neon/mod.rs new file mode 100644 index 000000000..d47a7ccc5 --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/aarch64_neon/mod.rs @@ -0,0 +1,4 @@ +mod packing; +mod poseidon2; + +pub use packing::*; diff --git a/CoqOfRust/plonky3/baby-bear/src/aarch64_neon/packing.rs b/CoqOfRust/plonky3/baby-bear/src/aarch64_neon/packing.rs new file mode 100644 index 000000000..163e25581 --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/aarch64_neon/packing.rs @@ -0,0 +1,36 @@ +use core::arch::aarch64::{int32x4_t, uint32x4_t}; +use core::mem::transmute; + +use p3_monty_31::{MontyParametersNeon, PackedMontyField31Neon}; + +use crate::BabyBearParameters; + +const WIDTH: usize = 4; + +impl MontyParametersNeon for BabyBearParameters { + // SAFETY: This is a valid packed representation of P. + const PACKED_P: uint32x4_t = unsafe { transmute::<[u32; WIDTH], _>([0x78000001; WIDTH]) }; + // This MU is the same 0x88000001 as elsewhere, just interpreted as an `i32`. + // SAFETY: This is a valid packed representation of MU. + const PACKED_MU: int32x4_t = unsafe { transmute::<[i32; WIDTH], _>([-0x77ffffff; WIDTH]) }; +} + +pub type PackedBabyBearNeon = PackedMontyField31Neon; + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::WIDTH; + use crate::BabyBear; + + const SPECIAL_VALS: [BabyBear; WIDTH] = + BabyBear::new_array([0x00000000, 0x00000001, 0x00000002, 0x78000000]); + + test_packed_field!( + crate::PackedBabyBearNeon, + &[crate::PackedBabyBearNeon::ZERO], + &[crate::PackedBabyBearNeon::ONE], + p3_monty_31::PackedMontyField31Neon::(super::SPECIAL_VALS) + ); +} diff --git a/CoqOfRust/plonky3/baby-bear/src/aarch64_neon/poseidon2.rs b/CoqOfRust/plonky3/baby-bear/src/aarch64_neon/poseidon2.rs new file mode 100644 index 000000000..9d8b4094d --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/aarch64_neon/poseidon2.rs @@ -0,0 +1,59 @@ +//! Eventually this will hold a vectorized Neon implementation of Poseidon2 for PackedBabyBearNeon +//! Currently this is essentially a placeholder to allow compilation and testing on Neon devices. +//! +//! Converting the AVX2/AVX512 code across to Neon is on the TODO list. + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use crate::{BabyBear, PackedBabyBearNeon, Poseidon2BabyBear}; + + type F = BabyBear; + type Perm16 = Poseidon2BabyBear<16>; + type Perm24 = Poseidon2BabyBear<24>; + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_neon_poseidon2_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm16::new_from_rng_128(&mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut neon_input = input.map(Into::::into); + poseidon2.permute_mut(&mut neon_input); + + let neon_output = neon_input.map(|x| x.0[0]); + + assert_eq!(neon_output, expected); + } + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_neon_poseidon2_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm24::new_from_rng_128(&mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut neon_input = input.map(Into::::into); + poseidon2.permute_mut(&mut neon_input); + + let neon_output = neon_input.map(|x| x.0[0]); + + assert_eq!(neon_output, expected); + } +} diff --git a/CoqOfRust/plonky3/baby-bear/src/baby_bear.rs b/CoqOfRust/plonky3/baby-bear/src/baby_bear.rs new file mode 100644 index 000000000..4a1420b8b --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/baby_bear.rs @@ -0,0 +1,240 @@ +use p3_field::exponentiation::exp_1725656503; +use p3_field::{Field, PrimeCharacteristicRing}; +use p3_monty_31::{ + BarrettParameters, BinomialExtensionData, FieldParameters, MontyField31, MontyParameters, + PackedMontyParameters, RelativelyPrimePower, TwoAdicData, +}; + +/// The prime field `2^31 - 2^27 + 1`, a.k.a. the Baby Bear field. +pub type BabyBear = MontyField31; + +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialEq)] +pub struct BabyBearParameters; + +impl MontyParameters for BabyBearParameters { + /// The Baby Bear prime: 2^31 - 2^27 + 1. + /// This is the unique 31-bit prime with the highest possible 2 adicity (27). + const PRIME: u32 = 0x78000001; + + const MONTY_BITS: u32 = 32; + const MONTY_MU: u32 = 0x88000001; +} + +impl PackedMontyParameters for BabyBearParameters {} + +impl BarrettParameters for BabyBearParameters {} + +impl FieldParameters for BabyBearParameters { + const MONTY_GEN: BabyBear = BabyBear::new(31); + + fn try_inverse(p1: F) -> Option { + if p1.is_zero() { + return None; + } + + // From Fermat's little theorem, in a prime field `F_p`, the inverse of `a` is `a^(p-2)`. + // Here p-2 = 2013265919 = 1110111111111111111111111111111_2. + // Uses 30 Squares + 7 Multiplications => 37 Operations total. + + let p100000000 = p1.exp_power_of_2(8); + let p100000001 = p100000000 * p1; + let p10000000000000000 = p100000000.exp_power_of_2(8); + let p10000000100000001 = p10000000000000000 * p100000001; + let p10000000100000001000 = p10000000100000001.exp_power_of_2(3); + let p1000000010000000100000000 = p10000000100000001000.exp_power_of_2(5); + let p1000000010000000100000001 = p1000000010000000100000000 * p1; + let p1000010010000100100001001 = p1000000010000000100000001 * p10000000100000001000; + let p10000000100000001000000010 = p1000000010000000100000001.square(); + let p11000010110000101100001011 = p10000000100000001000000010 * p1000010010000100100001001; + let p100000001000000010000000100 = p10000000100000001000000010.square(); + let p111000011110000111100001111 = + p100000001000000010000000100 * p11000010110000101100001011; + let p1110000111100001111000011110000 = p111000011110000111100001111.exp_power_of_2(4); + let p1110111111111111111111111111111 = + p1110000111100001111000011110000 * p111000011110000111100001111; + + Some(p1110111111111111111111111111111) + } +} + +impl RelativelyPrimePower<7> for BabyBearParameters { + /// In the field `BabyBear`, `a^{1/7}` is equal to a^{1725656503}. + /// + /// This follows from the calculation `7 * 1725656503 = 6*(2^31 - 2^27) + 1 = 1 mod (p - 1)`. + fn exp_root_d(val: R) -> R { + exp_1725656503(val) + } +} + +impl TwoAdicData for BabyBearParameters { + const TWO_ADICITY: usize = 27; + + type ArrayLike = &'static [BabyBear]; + + const TWO_ADIC_GENERATORS: Self::ArrayLike = &BabyBear::new_array([ + 0x1, 0x78000000, 0x67055c21, 0x5ee99486, 0xbb4c4e4, 0x2d4cc4da, 0x669d6090, 0x17b56c64, + 0x67456167, 0x688442f9, 0x145e952d, 0x4fe61226, 0x4c734715, 0x11c33e2a, 0x62c3d2b1, + 0x77cad399, 0x54c131f4, 0x4cabd6a6, 0x5cf5713f, 0x3e9430e8, 0xba067a3, 0x18adc27d, + 0x21fd55bc, 0x4b859b3d, 0x3bd57996, 0x4483d85a, 0x3a26eef8, 0x1a427a41, + ]); + + const ROOTS_8: Self::ArrayLike = &BabyBear::new_array([0x1, 0x5ee99486, 0x67055c21, 0xc9ea3ba]); + const INV_ROOTS_8: Self::ArrayLike = + &BabyBear::new_array([0x1, 0x6b615c47, 0x10faa3e0, 0x19166b7b]); + + const ROOTS_16: Self::ArrayLike = &BabyBear::new_array([ + 0x1, 0xbb4c4e4, 0x5ee99486, 0x4b49e08, 0x67055c21, 0x5376917a, 0xc9ea3ba, 0x563112a7, + ]); + const INV_ROOTS_16: Self::ArrayLike = &BabyBear::new_array([ + 0x1, 0x21ceed5a, 0x6b615c47, 0x24896e87, 0x10faa3e0, 0x734b61f9, 0x19166b7b, 0x6c4b3b1d, + ]); +} + +impl BinomialExtensionData<4> for BabyBearParameters { + const W: BabyBear = BabyBear::new(11); + const DTH_ROOT: BabyBear = BabyBear::new(1728404513); + const EXT_GENERATOR: [BabyBear; 4] = BabyBear::new_array([8, 1, 0, 0]); + const EXT_TWO_ADICITY: usize = 29; + + type ArrayLike = [[BabyBear; 4]; 2]; + const TWO_ADIC_EXTENSION_GENERATORS: Self::ArrayLike = + BabyBear::new_2d_array([[0, 0, 1996171314, 0], [0, 0, 0, 124907976]]); +} + +impl BinomialExtensionData<5> for BabyBearParameters { + const W: BabyBear = BabyBear::new(2); + const DTH_ROOT: BabyBear = BabyBear::new(815036133); + const EXT_GENERATOR: [BabyBear; 5] = BabyBear::new_array([8, 1, 0, 0, 0]); + const EXT_TWO_ADICITY: usize = 27; + + type ArrayLike = [[BabyBear; 5]; 0]; + const TWO_ADIC_EXTENSION_GENERATORS: Self::ArrayLike = []; +} + +#[cfg(test)] +mod tests { + use core::array; + + use num_bigint::BigUint; + use p3_field::extension::BinomialExtensionField; + use p3_field::{InjectiveMonomial, PermutationMonomial, PrimeField64, TwoAdicField}; + use p3_field_testing::{ + test_field, test_field_dft, test_prime_field, test_prime_field_32, test_prime_field_64, + test_two_adic_field, + }; + + use super::*; + + type F = BabyBear; + type EF = BinomialExtensionField; + + #[test] + fn test_baby_bear_two_adicity_generators() { + let base = BabyBear::from_u32(0x1a427a41); + for bits in 0..=BabyBear::TWO_ADICITY { + assert_eq!( + BabyBear::two_adic_generator(bits), + base.exp_power_of_2(BabyBear::TWO_ADICITY - bits) + ); + } + } + + #[test] + fn test_to_babybear_array() { + let range_array: [u32; 32] = array::from_fn(|i| i as u32); + assert_eq!( + BabyBear::new_array(range_array), + range_array.map(F::from_u32) + ) + } + + #[test] + fn test_baby_bear() { + let f = F::from_u32(100); + assert_eq!(f.as_canonical_u64(), 100); + + let f_1 = F::ONE; + let f_2 = F::TWO; + let f_p_minus_1 = F::NEG_ONE; + let f_p_minus_2 = F::NEG_ONE + F::NEG_ONE; + let m1 = F::from_u32(0x34167c58); + let m2 = F::from_u32(0x61f3207b); + let expected_prod = F::from_u32(0x1b5c8046); + assert_eq!(m1 * m2, expected_prod); + + assert_eq!(m1.injective_exp_n().injective_exp_root_n(), m1); + assert_eq!(m2.injective_exp_n().injective_exp_root_n(), m2); + assert_eq!(F::TWO.injective_exp_n().injective_exp_root_n(), F::TWO); + + let f_serialized = serde_json::to_string(&f).unwrap(); + let f_deserialized: F = serde_json::from_str(&f_serialized).unwrap(); + assert_eq!(f, f_deserialized); + + let f_1_serialized = serde_json::to_string(&f_1).unwrap(); + let f_1_deserialized: F = serde_json::from_str(&f_1_serialized).unwrap(); + let f_1_serialized_again = serde_json::to_string(&f_1_deserialized).unwrap(); + let f_1_deserialized_again: F = serde_json::from_str(&f_1_serialized_again).unwrap(); + assert_eq!(f_1, f_1_deserialized); + assert_eq!(f_1, f_1_deserialized_again); + + let f_2_serialized = serde_json::to_string(&f_2).unwrap(); + let f_2_deserialized: F = serde_json::from_str(&f_2_serialized).unwrap(); + assert_eq!(f_2, f_2_deserialized); + + let f_p_minus_1_serialized = serde_json::to_string(&f_p_minus_1).unwrap(); + let f_p_minus_1_deserialized: F = serde_json::from_str(&f_p_minus_1_serialized).unwrap(); + assert_eq!(f_p_minus_1, f_p_minus_1_deserialized); + + let f_p_minus_2_serialized = serde_json::to_string(&f_p_minus_2).unwrap(); + let f_p_minus_2_deserialized: F = serde_json::from_str(&f_p_minus_2_serialized).unwrap(); + assert_eq!(f_p_minus_2, f_p_minus_2_deserialized); + + let m1_serialized = serde_json::to_string(&m1).unwrap(); + let m1_deserialized: F = serde_json::from_str(&m1_serialized).unwrap(); + assert_eq!(m1, m1_deserialized); + + let m2_serialized = serde_json::to_string(&m2).unwrap(); + let m2_deserialized: F = serde_json::from_str(&m2_serialized).unwrap(); + assert_eq!(m2, m2_deserialized); + } + + // MontyField31's have no redundant representations. + const ZEROS: [BabyBear; 1] = [BabyBear::ZERO]; + const ONES: [BabyBear; 1] = [BabyBear::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 3] { + [ + (BigUint::from(2u8), 27), + (BigUint::from(3u8), 1), + (BigUint::from(5u8), 1), + ] + } + + test_field!( + crate::BabyBear, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + test_two_adic_field!(crate::BabyBear); + + test_field_dft!(radix2dit, crate::BabyBear, super::EF, p3_dft::Radix2Dit<_>); + test_field_dft!(bowers, crate::BabyBear, super::EF, p3_dft::Radix2Bowers); + test_field_dft!( + parallel, + crate::BabyBear, + super::EF, + p3_dft::Radix2DitParallel::<_> + ); + test_field_dft!( + recur_dft, + crate::BabyBear, + super::EF, + p3_monty_31::dft::RecursiveDft<_> + ); + test_prime_field!(crate::BabyBear); + test_prime_field_64!(crate::BabyBear); + test_prime_field_32!(crate::BabyBear); +} diff --git a/CoqOfRust/plonky3/baby-bear/src/baby_bear.v b/CoqOfRust/plonky3/baby-bear/src/baby_bear.v new file mode 100644 index 000000000..67c5e2afa --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/baby_bear.v @@ -0,0 +1,1311 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module baby_bear. + Axiom BabyBear : + (Ty.path "p3_baby_bear::baby_bear::BabyBear") = + (Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]). + + (* StructTuple + { + name := "BabyBearParameters"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_marker_Copy_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_core_clone_Clone_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_core_default_Default_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic (Value.StructTuple "p3_baby_bear::baby_bear::BabyBearParameters" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_core_fmt_Debug_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "BabyBearParameters" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_core_cmp_Eq_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_core_hash_Hash_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + Value.Tuple [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_core_marker_StructuralPartialEq_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_core_cmp_PartialEq_p3_baby_bear_baby_bear_BabyBearParameters_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + Value.Bool true)) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_p3_baby_bear_baby_bear_BabyBearParameters_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_p3_monty_31_data_traits_MontyParameters_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* const PRIME: u32 = 0x78000001; *) + (* Ty.path "u32" *) + Definition value_PRIME (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U32 2013265921 |))). + + (* const MONTY_BITS: u32 = 32; *) + (* Ty.path "u32" *) + Definition value_MONTY_BITS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U32 32 |))). + + (* const MONTY_MU: u32 = 0x88000001; *) + (* Ty.path "u32" *) + Definition value_MONTY_MU (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U32 2281701377 |))). + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::MontyParameters" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_PRIME", InstanceField.Method value_PRIME); + ("value_MONTY_BITS", InstanceField.Method value_MONTY_BITS); + ("value_MONTY_MU", InstanceField.Method value_MONTY_MU) + ]. + End Impl_p3_monty_31_data_traits_MontyParameters_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_p3_monty_31_data_traits_PackedMontyParameters_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::PackedMontyParameters" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_monty_31_data_traits_PackedMontyParameters_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_p3_monty_31_data_traits_BarrettParameters_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::BarrettParameters" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_monty_31_data_traits_BarrettParameters_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_p3_monty_31_data_traits_FieldParameters_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* const MONTY_GEN: BabyBear = BabyBear::new(31); *) + (* Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] *) + Definition value_MONTY_GEN (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 31 ] + |) + |))). + + (* + fn try_inverse(p1: F) -> Option { + if p1.is_zero() { + return None; + } + + // From Fermat's little theorem, in a prime field `F_p`, the inverse of `a` is `a^(p-2)`. + // Here p-2 = 2013265919 = 1110111111111111111111111111111_2. + // Uses 30 Squares + 7 Multiplications => 37 Operations total. + + let p100000000 = p1.exp_power_of_2(8); + let p100000001 = p100000000 * p1; + let p10000000000000000 = p100000000.exp_power_of_2(8); + let p10000000100000001 = p10000000000000000 * p100000001; + let p10000000100000001000 = p10000000100000001.exp_power_of_2(3); + let p1000000010000000100000000 = p10000000100000001000.exp_power_of_2(5); + let p1000000010000000100000001 = p1000000010000000100000000 * p1; + let p1000010010000100100001001 = p1000000010000000100000001 * p10000000100000001000; + let p10000000100000001000000010 = p1000000010000000100000001.square(); + let p11000010110000101100001011 = p10000000100000001000000010 * p1000010010000100100001001; + let p100000001000000010000000100 = p10000000100000001000000010.square(); + let p111000011110000111100001111 = + p100000001000000010000000100 * p11000010110000101100001011; + let p1110000111100001111000011110000 = p111000011110000111100001111.exp_power_of_2(4); + let p1110111111111111111111111111111 = + p1110000111100001111000011110000 * p111000011110000111100001111; + + Some(p1110111111111111111111111111111) + } + *) + Definition try_inverse (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ p1 ] => + ltac:(M.monadic + (let p1 := M.alloc (| p1 |) in + M.catch_return (Ty.apply (Ty.path "core::option::Option") [] [ F ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1 |) ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| Value.StructTuple "core::option::Option::None" [] |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ p100000000 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1 |); Value.Integer IntegerKind.Usize 8 ] + |) + |) in + let~ p100000001 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p100000000 |); M.read (| p1 |) ] + |) + |) in + let~ p10000000000000000 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p100000000 |); + Value.Integer IntegerKind.Usize 8 + ] + |) + |) in + let~ p10000000100000001 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p10000000000000000 |); M.read (| p100000001 |) ] + |) + |) in + let~ p10000000100000001000 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p10000000100000001 |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ p1000000010000000100000000 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p10000000100000001000 |); + Value.Integer IntegerKind.Usize 5 + ] + |) + |) in + let~ p1000000010000000100000001 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p1000000010000000100000000 |); M.read (| p1 |) ] + |) + |) in + let~ p1000010010000100100001001 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p1000000010000000100000001 |); M.read (| p10000000100000001000 |) + ] + |) + |) in + let~ p10000000100000001000000010 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1000000010000000100000001 |) ] + |) + |) in + let~ p11000010110000101100001011 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| p10000000100000001000000010 |); + M.read (| p1000010010000100100001001 |) + ] + |) + |) in + let~ p100000001000000010000000100 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p10000000100000001000000010 |) ] + |) + |) in + let~ p111000011110000111100001111 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| p100000001000000010000000100 |); + M.read (| p11000010110000101100001011 |) + ] + |) + |) in + let~ p1110000111100001111000011110000 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p111000011110000111100001111 |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) in + let~ p1110111111111111111111111111111 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| p1110000111100001111000011110000 |); + M.read (| p111000011110000111100001111 |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.read (| p1110111111111111111111111111111 |) ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::FieldParameters" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_MONTY_GEN", InstanceField.Method value_MONTY_GEN); + ("try_inverse", InstanceField.Method try_inverse) + ]. + End Impl_p3_monty_31_data_traits_FieldParameters_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_p3_monty_31_data_traits_RelativelyPrimePower_U64_7_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* + fn exp_root_d(val: R) -> R { + exp_1725656503(val) + } + *) + Definition exp_root_d (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ val ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + M.call_closure (| + R, + M.get_function (| "p3_field::exponentiation::exp_1725656503", [], [ R ] |), + [ M.read (| val |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::RelativelyPrimePower" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.U64 7 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("exp_root_d", InstanceField.Method exp_root_d) ]. + End Impl_p3_monty_31_data_traits_RelativelyPrimePower_U64_7_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_p3_monty_31_data_traits_TwoAdicData_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* const TWO_ADICITY: usize = 27; *) + (* Ty.path "usize" *) + Definition value_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 27 |))). + + (* type ArrayLike = &'static [BabyBear]; *) + Definition _ArrayLike : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ]. + + (* + const TWO_ADIC_GENERATORS: Self::ArrayLike = &BabyBear::new_array([ + 0x1, 0x78000000, 0x67055c21, 0x5ee99486, 0xbb4c4e4, 0x2d4cc4da, 0x669d6090, 0x17b56c64, + 0x67456167, 0x688442f9, 0x145e952d, 0x4fe61226, 0x4c734715, 0x11c33e2a, 0x62c3d2b1, + 0x77cad399, 0x54c131f4, 0x4cabd6a6, 0x5cf5713f, 0x3e9430e8, 0xba067a3, 0x18adc27d, + 0x21fd55bc, 0x4b859b3d, 0x3bd57996, 0x4483d85a, 0x3a26eef8, 0x1a427a41, + ]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + (Ty.path "p3_baby_bear::baby_bear::BabyBearParameters") + "ArrayLike" *) + Definition value_TWO_ADIC_GENERATORS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 28 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 28 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 2013265920; + Value.Integer IntegerKind.U32 1728404513; + Value.Integer IntegerKind.U32 1592366214; + Value.Integer IntegerKind.U32 196396260; + Value.Integer IntegerKind.U32 760005850; + Value.Integer IntegerKind.U32 1721589904; + Value.Integer IntegerKind.U32 397765732; + Value.Integer IntegerKind.U32 1732600167; + Value.Integer IntegerKind.U32 1753498361; + Value.Integer IntegerKind.U32 341742893; + Value.Integer IntegerKind.U32 1340477990; + Value.Integer IntegerKind.U32 1282623253; + Value.Integer IntegerKind.U32 298008106; + Value.Integer IntegerKind.U32 1657000625; + Value.Integer IntegerKind.U32 2009781145; + Value.Integer IntegerKind.U32 1421947380; + Value.Integer IntegerKind.U32 1286330022; + Value.Integer IntegerKind.U32 1559589183; + Value.Integer IntegerKind.U32 1049899240; + Value.Integer IntegerKind.U32 195061667; + Value.Integer IntegerKind.U32 414040701; + Value.Integer IntegerKind.U32 570250684; + Value.Integer IntegerKind.U32 1267047229; + Value.Integer IntegerKind.U32 1003846038; + Value.Integer IntegerKind.U32 1149491290; + Value.Integer IntegerKind.U32 975630072; + Value.Integer IntegerKind.U32 440564289 + ] + ] + |) + |) + |) + |) + |)) + |))). + + (* const ROOTS_8: Self::ArrayLike = &BabyBear::new_array([0x1, 0x5ee99486, 0x67055c21, 0xc9ea3ba]); *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + (Ty.path "p3_baby_bear::baby_bear::BabyBearParameters") + "ArrayLike" *) + Definition value_ROOTS_8 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 1592366214; + Value.Integer IntegerKind.U32 1728404513; + Value.Integer IntegerKind.U32 211723194 + ] + ] + |) + |) + |) + |) + |)) + |))). + + (* + const INV_ROOTS_8: Self::ArrayLike = + &BabyBear::new_array([0x1, 0x6b615c47, 0x10faa3e0, 0x19166b7b]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + (Ty.path "p3_baby_bear::baby_bear::BabyBearParameters") + "ArrayLike" *) + Definition value_INV_ROOTS_8 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 1801542727; + Value.Integer IntegerKind.U32 284861408; + Value.Integer IntegerKind.U32 420899707 + ] + ] + |) + |) + |) + |) + |)) + |))). + + (* + const ROOTS_16: Self::ArrayLike = &BabyBear::new_array([ + 0x1, 0xbb4c4e4, 0x5ee99486, 0x4b49e08, 0x67055c21, 0x5376917a, 0xc9ea3ba, 0x563112a7, + ]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + (Ty.path "p3_baby_bear::baby_bear::BabyBearParameters") + "ArrayLike" *) + Definition value_ROOTS_16 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 196396260; + Value.Integer IntegerKind.U32 1592366214; + Value.Integer IntegerKind.U32 78945800; + Value.Integer IntegerKind.U32 1728404513; + Value.Integer IntegerKind.U32 1400279418; + Value.Integer IntegerKind.U32 211723194; + Value.Integer IntegerKind.U32 1446056615 + ] + ] + |) + |) + |) + |) + |)) + |))). + + (* + const INV_ROOTS_16: Self::ArrayLike = &BabyBear::new_array([ + 0x1, 0x21ceed5a, 0x6b615c47, 0x24896e87, 0x10faa3e0, 0x734b61f9, 0x19166b7b, 0x6c4b3b1d, + ]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + (Ty.path "p3_baby_bear::baby_bear::BabyBearParameters") + "ArrayLike" *) + Definition value_INV_ROOTS_16 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 567209306; + Value.Integer IntegerKind.U32 1801542727; + Value.Integer IntegerKind.U32 612986503; + Value.Integer IntegerKind.U32 284861408; + Value.Integer IntegerKind.U32 1934320121; + Value.Integer IntegerKind.U32 420899707; + Value.Integer IntegerKind.U32 1816869661 + ] + ] + |) + |) + |) + |) + |)) + |))). + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::TwoAdicData" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_TWO_ADICITY", InstanceField.Method value_TWO_ADICITY); + ("ArrayLike", InstanceField.Ty _ArrayLike); + ("value_TWO_ADIC_GENERATORS", InstanceField.Method value_TWO_ADIC_GENERATORS); + ("value_ROOTS_8", InstanceField.Method value_ROOTS_8); + ("value_INV_ROOTS_8", InstanceField.Method value_INV_ROOTS_8); + ("value_ROOTS_16", InstanceField.Method value_ROOTS_16); + ("value_INV_ROOTS_16", InstanceField.Method value_INV_ROOTS_16) + ]. + End Impl_p3_monty_31_data_traits_TwoAdicData_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_p3_monty_31_data_traits_BinomialExtensionData_Usize_4_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* const W: BabyBear = BabyBear::new(11); *) + (* Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] *) + Definition value_W (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 11 ] + |) + |))). + + (* const DTH_ROOT: BabyBear = BabyBear::new(1728404513); *) + (* Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] *) + Definition value_DTH_ROOT (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 1728404513 ] + |) + |))). + + (* const EXT_GENERATOR: [BabyBear; 4] = BabyBear::new_array([8, 1, 0, 0]); *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] *) + Definition value_EXT_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 8; + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 0 + ] + ] + |) + |))). + + (* const EXT_TWO_ADICITY: usize = 29; *) + (* Ty.path "usize" *) + Definition value_EXT_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 29 |))). + + (* type ArrayLike = [[BabyBear; 4]; 2]; *) + Definition _ArrayLike : Ty.t := + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ]. + + (* + const TWO_ADIC_EXTENSION_GENERATORS: Self::ArrayLike = + BabyBear::new_2d_array([[0, 0, 1996171314, 0], [0, 0, 0, 124907976]]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::BinomialExtensionData" + [ Value.Integer IntegerKind.Usize 4 ] + [] + (Ty.path "p3_baby_bear::baby_bear::BabyBearParameters") + "ArrayLike" *) + Definition value_TWO_ADIC_EXTENSION_GENERATORS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_2d_array", + [ Value.Integer IntegerKind.Usize 4; Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + Value.Array + [ + Value.Array + [ + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 1996171314; + Value.Integer IntegerKind.U32 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 124907976 + ] + ] + ] + |) + |))). + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::BinomialExtensionData" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 4 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_W", InstanceField.Method value_W); + ("value_DTH_ROOT", InstanceField.Method value_DTH_ROOT); + ("value_EXT_GENERATOR", InstanceField.Method value_EXT_GENERATOR); + ("value_EXT_TWO_ADICITY", InstanceField.Method value_EXT_TWO_ADICITY); + ("ArrayLike", InstanceField.Ty _ArrayLike); + ("value_TWO_ADIC_EXTENSION_GENERATORS", + InstanceField.Method value_TWO_ADIC_EXTENSION_GENERATORS) + ]. + End Impl_p3_monty_31_data_traits_BinomialExtensionData_Usize_4_for_p3_baby_bear_baby_bear_BabyBearParameters. + + Module Impl_p3_monty_31_data_traits_BinomialExtensionData_Usize_5_for_p3_baby_bear_baby_bear_BabyBearParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::baby_bear::BabyBearParameters". + + (* const W: BabyBear = BabyBear::new(2); *) + (* Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] *) + Definition value_W (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 2 ] + |) + |))). + + (* const DTH_ROOT: BabyBear = BabyBear::new(815036133); *) + (* Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] *) + Definition value_DTH_ROOT (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 815036133 ] + |) + |))). + + (* const EXT_GENERATOR: [BabyBear; 5] = BabyBear::new_array([8, 1, 0, 0, 0]); *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] *) + Definition value_EXT_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 5 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 8; + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 0 + ] + ] + |) + |))). + + (* const EXT_TWO_ADICITY: usize = 27; *) + (* Ty.path "usize" *) + Definition value_EXT_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 27 |))). + + (* type ArrayLike = [[BabyBear; 5]; 0]; *) + Definition _ArrayLike : Ty.t := + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ]. + + (* const TWO_ADIC_EXTENSION_GENERATORS: Self::ArrayLike = []; *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::BinomialExtensionData" + [ Value.Integer IntegerKind.Usize 5 ] + [] + (Ty.path "p3_baby_bear::baby_bear::BabyBearParameters") + "ArrayLike" *) + Definition value_TWO_ADIC_EXTENSION_GENERATORS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic (M.alloc (| Value.Array [] |))). + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::BinomialExtensionData" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 5 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_W", InstanceField.Method value_W); + ("value_DTH_ROOT", InstanceField.Method value_DTH_ROOT); + ("value_EXT_GENERATOR", InstanceField.Method value_EXT_GENERATOR); + ("value_EXT_TWO_ADICITY", InstanceField.Method value_EXT_TWO_ADICITY); + ("ArrayLike", InstanceField.Ty _ArrayLike); + ("value_TWO_ADIC_EXTENSION_GENERATORS", + InstanceField.Method value_TWO_ADIC_EXTENSION_GENERATORS) + ]. + End Impl_p3_monty_31_data_traits_BinomialExtensionData_Usize_5_for_p3_baby_bear_baby_bear_BabyBearParameters. +End baby_bear. diff --git a/CoqOfRust/plonky3/baby-bear/src/extension.rs b/CoqOfRust/plonky3/baby-bear/src/extension.rs new file mode 100644 index 000000000..5e1386c7e --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/extension.rs @@ -0,0 +1,94 @@ +#[cfg(test)] +mod test_quartic_extension { + use alloc::format; + + use num_bigint::BigUint; + use p3_field::extension::BinomialExtensionField; + use p3_field::{BasedVectorSpace, PrimeCharacteristicRing}; + use p3_field_testing::{test_field, test_two_adic_extension_field}; + + use crate::BabyBear; + + type F = BabyBear; + type EF = BinomialExtensionField; + + // MontyField31's have no redundant representations. + const ZEROS: [EF; 1] = [EF::ZERO]; + const ONES: [EF; 1] = [EF::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P^4 - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 8] { + [ + (BigUint::from(2u8), 29), + (BigUint::from(3u8), 1), + (BigUint::from(5u8), 1), + (BigUint::from(31u8), 1), + (BigUint::from(97u8), 1), + (BigUint::from(12241u16), 1), + (BigUint::from(32472031u32), 1), + (BigUint::from(1706804017873u64), 1), + ] + } + + test_field!( + super::EF, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + test_two_adic_extension_field!(super::F, super::EF); + + #[test] + fn display() { + assert_eq!(format!("{}", EF::ZERO), "0"); + assert_eq!(format!("{}", EF::ONE), "1"); + assert_eq!(format!("{}", EF::TWO), "2"); + + assert_eq!( + format!( + "{}", + EF::from_basis_coefficients_slice(&[F::TWO, F::ONE, F::ZERO, F::TWO]).unwrap() + ), + "2 + X + 2 X^3" + ); + } +} + +#[cfg(test)] +mod test_quintic_extension { + use num_bigint::BigUint; + use p3_field::PrimeCharacteristicRing; + use p3_field::extension::BinomialExtensionField; + use p3_field_testing::{test_field, test_two_adic_extension_field}; + + use crate::BabyBear; + + type F = BabyBear; + type EF = BinomialExtensionField; + + // MontyField31's have no redundant representations. + const ZEROS: [EF; 1] = [EF::ZERO]; + const ONES: [EF; 1] = [EF::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P^5 - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 6] { + [ + (BigUint::from(2u8), 27), + (BigUint::from(3u8), 1), + (BigUint::from(5u8), 2), + (BigUint::from(26321u16), 1), + (BigUint::from(1081891u32), 1), + (BigUint::from(115384818561587951104978331u128), 1), + ] + } + + test_field!( + super::EF, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + test_two_adic_extension_field!(super::F, super::EF); +} diff --git a/CoqOfRust/plonky3/baby-bear/src/lib.rs b/CoqOfRust/plonky3/baby-bear/src/lib.rs new file mode 100644 index 000000000..dd39ee0ee --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/lib.rs @@ -0,0 +1,51 @@ +#![no_std] +#![cfg_attr( + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), + feature(stdarch_x86_avx512) +)] + +extern crate alloc; + +mod baby_bear; +mod extension; +mod mds; +mod poseidon2; + +pub use baby_bear::*; +pub use mds::*; +pub use poseidon2::*; + +#[cfg(all(target_arch = "aarch64", target_feature = "neon"))] +mod aarch64_neon; +#[cfg(all(target_arch = "aarch64", target_feature = "neon"))] +pub use aarch64_neon::*; + +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +mod x86_64_avx2; +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +pub use x86_64_avx2::*; + +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +mod x86_64_avx512; +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +pub use x86_64_avx512::*; diff --git a/CoqOfRust/plonky3/baby-bear/src/mds.rs b/CoqOfRust/plonky3/baby-bear/src/mds.rs new file mode 100644 index 000000000..685c85888 --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/mds.rs @@ -0,0 +1,198 @@ +//! MDS matrices over the BabyBear field, and permutations defined by them. +//! +//! NB: Not all sizes have fast implementations of their permutations. +//! Supported sizes: 8, 12, 16, 24, 32, 64. +//! Sizes 8 and 12 are from Plonky2, size 16 was found as part of concurrent +//! work by Angus Gruen and Hamish Ivey-Law. Other sizes are from Ulrich Haböck's +//! database. + +use p3_mds::util::first_row_to_first_col; +use p3_monty_31::{MDSUtils, MdsMatrixMontyField31}; + +#[derive(Clone, Default)] +pub struct MDSBabyBearData; + +impl MDSUtils for MDSBabyBearData { + const MATRIX_CIRC_MDS_8_COL: [i64; 8] = first_row_to_first_col(&[7, 1, 3, 8, 8, 3, 4, 9]); + const MATRIX_CIRC_MDS_12_COL: [i64; 12] = + first_row_to_first_col(&[1, 1, 2, 1, 8, 9, 10, 7, 5, 9, 4, 10]); + const MATRIX_CIRC_MDS_16_COL: [i64; 16] = + first_row_to_first_col(&[1, 1, 51, 1, 11, 17, 2, 1, 101, 63, 15, 2, 67, 22, 13, 3]); + const MATRIX_CIRC_MDS_24_COL: [i64; 24] = first_row_to_first_col(&[ + 0x2D0AAAAB, 0x64850517, 0x17F5551D, 0x04ECBEB5, 0x6D91A8D5, 0x60703026, 0x18D6F3CA, + 0x729601A7, 0x77CDA9E2, 0x3C0F5038, 0x26D52A61, 0x0360405D, 0x68FC71C8, 0x2495A71D, + 0x5D57AFC2, 0x1689DD98, 0x3C2C3DBE, 0x0C23DC41, 0x0524C7F2, 0x6BE4DF69, 0x0A6E572C, + 0x5C7790FA, 0x17E118F6, 0x0878A07F, + ]); + const MATRIX_CIRC_MDS_32_COL: [i64; 32] = first_row_to_first_col(&[ + 0x0BC00000, 0x2BED8F81, 0x337E0652, 0x4C4535D1, 0x4AF2DC32, 0x2DB4050F, 0x676A7CE3, + 0x3A06B68E, 0x5E95C1B1, 0x2C5F54A0, 0x2332F13D, 0x58E757F1, 0x3AA6DCCE, 0x607EE630, + 0x4ED57FF0, 0x6E08555B, 0x4C155556, 0x587FD0CE, 0x462F1551, 0x032A43CC, 0x5E2E43EA, + 0x71609B02, 0x0ED97E45, 0x562CA7E9, 0x2CB70B1D, 0x4E941E23, 0x174A61C1, 0x117A9426, + 0x73562137, 0x54596086, 0x487C560B, 0x68A4ACAB, + ]); + const MATRIX_CIRC_MDS_64_COL: [i64; 64] = first_row_to_first_col(&[ + 0x39577778, 0x0072F4E1, 0x0B1B8404, 0x041E9C88, 0x32D22F9F, 0x4E4BF946, 0x20C7B6D7, + 0x0587C267, 0x55877229, 0x4D186EC4, 0x4A19FD23, 0x1A64A20F, 0x2965CA4D, 0x16D98A5A, + 0x471E544A, 0x193D5C8B, 0x6E66DF0C, 0x28BF1F16, 0x26DB0BC8, 0x5B06CDDB, 0x100DCCA2, + 0x65C268AD, 0x199F09E7, 0x36BA04BE, 0x06C393F2, 0x51B06DFD, 0x6951B0C4, 0x6683A4C2, + 0x3B53D11B, 0x26E5134C, 0x45A5F1C5, 0x6F4D2433, 0x3CE2D82E, 0x36309A7D, 0x3DD9B459, + 0x68051E4C, 0x5C3AA720, 0x11640517, 0x0634D995, 0x1B0F6406, 0x72A18430, 0x26513CC5, + 0x67C0B93C, 0x548AB4A3, 0x6395D20D, 0x3E5DBC41, 0x332AF630, 0x3C5DDCB3, 0x0AA95792, + 0x66EB5492, 0x3F78DDDC, 0x5AC41627, 0x16CD5124, 0x3564DA96, 0x461867C9, 0x157B4E11, + 0x1AA486C8, 0x0C5095A9, 0x3833C0C6, 0x008FEBA5, 0x52ECBE2E, 0x1D178A67, 0x58B3C04B, + 0x6E95CB51, + ]); +} + +pub type MdsMatrixBabyBear = MdsMatrixMontyField31; + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + + use super::MdsMatrixBabyBear; + use crate::BabyBear; + + #[test] + fn babybear8() { + let input: [BabyBear; 8] = BabyBear::new_array([ + 391474477, 1174409341, 666967492, 1852498830, 1801235316, 820595865, 585587525, + 1348326858, + ]); + + let mds_matrix_baby_bear: MdsMatrixBabyBear = Default::default(); + + let output = mds_matrix_baby_bear.permute(input); + + let expected: [BabyBear; 8] = BabyBear::new_array([ + 1752937716, 1801468855, 1102954394, 284747746, 1636355768, 205443234, 1235359747, + 1159982032, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn babybear12() { + let input: [BabyBear; 12] = BabyBear::new_array([ + 918423259, 673549090, 364157140, 9832898, 493922569, 1171855651, 246075034, 1542167926, + 1787615541, 1696819900, 1884530130, 422386768, + ]); + + let mds_matrix_baby_bear: MdsMatrixBabyBear = Default::default(); + + let output = mds_matrix_baby_bear.permute(input); + + let expected: [BabyBear; 12] = BabyBear::new_array([ + 1631062293, 890348490, 1304705406, 1888740923, 845648570, 717048224, 1082440815, + 914769887, 1872991191, 1366539339, 1805116914, 1998032485, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn babybear16() { + let input: [BabyBear; 16] = BabyBear::new_array([ + 1983708094, 1477844074, 1638775686, 98517138, 70746308, 968700066, 275567720, + 1359144511, 960499489, 1215199187, 474302783, 79320256, 1923147803, 1197733438, + 1638511323, 303948902, + ]); + + let mds_matrix_baby_bear: MdsMatrixBabyBear = Default::default(); + + let output = mds_matrix_baby_bear.permute(input); + + let expected: [BabyBear; 16] = BabyBear::new_array([ + 1497569692, 1038070871, 669165859, 456905446, 1116763366, 1267622262, 1985953057, + 1060497461, 704264985, 306103349, 1271339089, 1551541970, 1796459417, 889229849, + 1731972538, 439594789, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn babybear24() { + let input: [BabyBear; 24] = BabyBear::new_array([ + 1307148929, 1603957607, 1515498600, 1412393512, 785287979, 988718522, 1750345556, + 853137995, 534387281, 930390055, 1600030977, 903985158, 1141020507, 636889442, + 966037834, 1778991639, 1440427266, 1379431959, 853403277, 959593575, 733455867, + 908584009, 817124993, 418826476, + ]); + + let mds_matrix_baby_bear: MdsMatrixBabyBear = Default::default(); + + let output = mds_matrix_baby_bear.permute(input); + + let expected: [BabyBear; 24] = BabyBear::new_array([ + 1537871777, 1626055274, 1705000179, 1426678258, 1688760658, 1347225494, 1291221794, + 1224656589, 1791446853, 1978133881, 1820380039, 1366829700, 27479566, 409595531, + 1223347944, 1752750033, 594548873, 1447473111, 1385412872, 1111945102, 1366585917, + 138866947, 1326436332, 656898133, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn babybear32() { + let input: [BabyBear; 32] = BabyBear::new_array([ + 1346087634, 1511946000, 1883470964, 54906057, 233060279, 5304922, 1881494193, + 743728289, 404047361, 1148556479, 144976634, 1726343008, 29659471, 1350407160, + 1636652429, 385978955, 327649601, 1248138459, 1255358242, 84164877, 1005571393, + 1713215328, 72913800, 1683904606, 904763213, 316800515, 656395998, 788184609, + 1824512025, 1177399063, 1358745087, 444151496, + ]); + + let mds_matrix_baby_bear: MdsMatrixBabyBear = Default::default(); + + let output = mds_matrix_baby_bear.permute(input); + + let expected: [BabyBear; 32] = BabyBear::new_array([ + 1359576919, 1657405784, 1031581836, 212090105, 699048671, 877916349, 205627787, + 1211567750, 210807569, 1696391051, 558468987, 161148427, 304343518, 76611896, + 532792005, 1963649139, 1283500358, 250848292, 1109842541, 2007388683, 433801252, + 1189712914, 626158024, 1436409738, 456315160, 1836818120, 1645024941, 925447491, + 1599571860, 1055439714, 353537136, 379644130, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn babybear64() { + let input: [BabyBear; 64] = BabyBear::new_array([ + 1931358930, 1322576114, 1658000717, 134388215, 1517892791, 1486447670, 93570662, + 898466034, 1576905917, 283824713, 1433559150, 1730678909, 155340881, 1978472263, + 1980644590, 1814040165, 654743892, 849954227, 323176597, 146970735, 252703735, + 1856579399, 162749290, 986745196, 352038183, 1239527508, 828473247, 1184743572, + 1017249065, 36804843, 1378131210, 1286724687, 596095979, 1916924908, 528946791, + 397247884, 23477278, 299412064, 415288430, 935825754, 1218003667, 1954592289, + 1594612673, 664096455, 958392778, 497208288, 1544504580, 1829423324, 956111902, + 458327015, 1736664598, 430977734, 599887171, 1100074154, 1197653896, 427838651, + 466509871, 1236918100, 940670246, 1421951147, 255557957, 1374188100, 315300068, + 623354170, + ]); + + let mds_matrix_baby_bear: MdsMatrixBabyBear = Default::default(); + + let output = mds_matrix_baby_bear.permute(input); + + let expected: [BabyBear; 64] = BabyBear::new_array([ + 442300274, 756862170, 167612495, 1103336044, 546496433, 1211822920, 329094196, + 1334376959, 944085937, 977350947, 1445060130, 918469957, 800346119, 1957918170, + 739098112, 1862817833, 1831589884, 1673860978, 698081523, 1128978338, 387929536, + 1106772486, 1367460469, 1911237185, 362669171, 819949894, 1801786287, 1943505026, + 586738185, 996076080, 1641277705, 1680239311, 1005815192, 63087470, 593010310, + 364673774, 543368618, 1576179136, 47618763, 1990080335, 1608655220, 499504830, + 861863262, 765074289, 139277832, 1139970138, 1510286607, 244269525, 43042067, + 119733624, 1314663255, 893295811, 1444902994, 914930267, 1675139862, 1148717487, + 1601328192, 534383401, 296215929, 1924587380, 1336639141, 34897994, 2005302060, + 1780337352, + ]); + + assert_eq!(output, expected); + } +} diff --git a/CoqOfRust/plonky3/baby-bear/src/mds.v b/CoqOfRust/plonky3/baby-bear/src/mds.v new file mode 100644 index 000000000..8216df66a --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/mds.v @@ -0,0 +1,474 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module mds. + (* StructTuple + { + name := "MDSBabyBearData"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_clone_Clone_for_p3_baby_bear_mds_MDSBabyBearData. + Definition Self : Ty.t := Ty.path "p3_baby_bear::mds::MDSBabyBearData". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_baby_bear::mds::MDSBabyBearData" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_baby_bear_mds_MDSBabyBearData. + + Module Impl_core_default_Default_for_p3_baby_bear_mds_MDSBabyBearData. + Definition Self : Ty.t := Ty.path "p3_baby_bear::mds::MDSBabyBearData". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => ltac:(M.monadic (Value.StructTuple "p3_baby_bear::mds::MDSBabyBearData" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_baby_bear_mds_MDSBabyBearData. + + Module Impl_p3_monty_31_mds_MDSUtils_for_p3_baby_bear_mds_MDSBabyBearData. + Definition Self : Ty.t := Ty.path "p3_baby_bear::mds::MDSBabyBearData". + + (* const MATRIX_CIRC_MDS_8_COL: [i64; 8] = first_row_to_first_col(&[7, 1, 3, 8, 8, 3, 4, 9]); *) + (* Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "i64" ] *) + Definition value_MATRIX_CIRC_MDS_8_COL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "i64" ], + M.get_function (| + "p3_mds::util::first_row_to_first_col", + [ Value.Integer IntegerKind.Usize 8 ], + [ Ty.path "i64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 7; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 3; + Value.Integer IntegerKind.I64 8; + Value.Integer IntegerKind.I64 8; + Value.Integer IntegerKind.I64 3; + Value.Integer IntegerKind.I64 4; + Value.Integer IntegerKind.I64 9 + ] + |) + |) + |) + |) + ] + |) + |))). + + (* + const MATRIX_CIRC_MDS_12_COL: [i64; 12] = + first_row_to_first_col(&[1, 1, 2, 1, 8, 9, 10, 7, 5, 9, 4, 10]); + *) + (* Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 12 ] [ Ty.path "i64" ] *) + Definition value_MATRIX_CIRC_MDS_12_COL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 12 ] [ Ty.path "i64" ], + M.get_function (| + "p3_mds::util::first_row_to_first_col", + [ Value.Integer IntegerKind.Usize 12 ], + [ Ty.path "i64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 2; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 8; + Value.Integer IntegerKind.I64 9; + Value.Integer IntegerKind.I64 10; + Value.Integer IntegerKind.I64 7; + Value.Integer IntegerKind.I64 5; + Value.Integer IntegerKind.I64 9; + Value.Integer IntegerKind.I64 4; + Value.Integer IntegerKind.I64 10 + ] + |) + |) + |) + |) + ] + |) + |))). + + (* + const MATRIX_CIRC_MDS_16_COL: [i64; 16] = + first_row_to_first_col(&[1, 1, 51, 1, 11, 17, 2, 1, 101, 63, 15, 2, 67, 22, 13, 3]); + *) + (* Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ Ty.path "i64" ] *) + Definition value_MATRIX_CIRC_MDS_16_COL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ Ty.path "i64" ], + M.get_function (| + "p3_mds::util::first_row_to_first_col", + [ Value.Integer IntegerKind.Usize 16 ], + [ Ty.path "i64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 51; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 11; + Value.Integer IntegerKind.I64 17; + Value.Integer IntegerKind.I64 2; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 101; + Value.Integer IntegerKind.I64 63; + Value.Integer IntegerKind.I64 15; + Value.Integer IntegerKind.I64 2; + Value.Integer IntegerKind.I64 67; + Value.Integer IntegerKind.I64 22; + Value.Integer IntegerKind.I64 13; + Value.Integer IntegerKind.I64 3 + ] + |) + |) + |) + |) + ] + |) + |))). + + (* + const MATRIX_CIRC_MDS_24_COL: [i64; 24] = first_row_to_first_col(&[ + 0x2D0AAAAB, 0x64850517, 0x17F5551D, 0x04ECBEB5, 0x6D91A8D5, 0x60703026, 0x18D6F3CA, + 0x729601A7, 0x77CDA9E2, 0x3C0F5038, 0x26D52A61, 0x0360405D, 0x68FC71C8, 0x2495A71D, + 0x5D57AFC2, 0x1689DD98, 0x3C2C3DBE, 0x0C23DC41, 0x0524C7F2, 0x6BE4DF69, 0x0A6E572C, + 0x5C7790FA, 0x17E118F6, 0x0878A07F, + ]); + *) + (* Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "i64" ] *) + Definition value_MATRIX_CIRC_MDS_24_COL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "i64" ], + M.get_function (| + "p3_mds::util::first_row_to_first_col", + [ Value.Integer IntegerKind.Usize 24 ], + [ Ty.path "i64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 755673771; + Value.Integer IntegerKind.I64 1686439191; + Value.Integer IntegerKind.I64 401954077; + Value.Integer IntegerKind.I64 82624181; + Value.Integer IntegerKind.I64 1838262485; + Value.Integer IntegerKind.I64 1617965094; + Value.Integer IntegerKind.I64 416740298; + Value.Integer IntegerKind.I64 1922433447; + Value.Integer IntegerKind.I64 2009967074; + Value.Integer IntegerKind.I64 1007636536; + Value.Integer IntegerKind.I64 651504225; + Value.Integer IntegerKind.I64 56639581; + Value.Integer IntegerKind.I64 1761374664; + Value.Integer IntegerKind.I64 613787421; + Value.Integer IntegerKind.I64 1566027714; + Value.Integer IntegerKind.I64 378133912; + Value.Integer IntegerKind.I64 1009532350; + Value.Integer IntegerKind.I64 203676737; + Value.Integer IntegerKind.I64 86296562; + Value.Integer IntegerKind.I64 1810161513; + Value.Integer IntegerKind.I64 175003436; + Value.Integer IntegerKind.I64 1551339770; + Value.Integer IntegerKind.I64 400627958; + Value.Integer IntegerKind.I64 142123135 + ] + |) + |) + |) + |) + ] + |) + |))). + + (* + const MATRIX_CIRC_MDS_32_COL: [i64; 32] = first_row_to_first_col(&[ + 0x0BC00000, 0x2BED8F81, 0x337E0652, 0x4C4535D1, 0x4AF2DC32, 0x2DB4050F, 0x676A7CE3, + 0x3A06B68E, 0x5E95C1B1, 0x2C5F54A0, 0x2332F13D, 0x58E757F1, 0x3AA6DCCE, 0x607EE630, + 0x4ED57FF0, 0x6E08555B, 0x4C155556, 0x587FD0CE, 0x462F1551, 0x032A43CC, 0x5E2E43EA, + 0x71609B02, 0x0ED97E45, 0x562CA7E9, 0x2CB70B1D, 0x4E941E23, 0x174A61C1, 0x117A9426, + 0x73562137, 0x54596086, 0x487C560B, 0x68A4ACAB, + ]); + *) + (* Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "i64" ] *) + Definition value_MATRIX_CIRC_MDS_32_COL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "i64" ], + M.get_function (| + "p3_mds::util::first_row_to_first_col", + [ Value.Integer IntegerKind.Usize 32 ], + [ Ty.path "i64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 197132288; + Value.Integer IntegerKind.I64 736989057; + Value.Integer IntegerKind.I64 863897170; + Value.Integer IntegerKind.I64 1279604177; + Value.Integer IntegerKind.I64 1257430066; + Value.Integer IntegerKind.I64 766772495; + Value.Integer IntegerKind.I64 1735032035; + Value.Integer IntegerKind.I64 973518478; + Value.Integer IntegerKind.I64 1586872753; + Value.Integer IntegerKind.I64 744445088; + Value.Integer IntegerKind.I64 590541117; + Value.Integer IntegerKind.I64 1491556337; + Value.Integer IntegerKind.I64 984014030; + Value.Integer IntegerKind.I64 1618929200; + Value.Integer IntegerKind.I64 1322614768; + Value.Integer IntegerKind.I64 1846039899; + Value.Integer IntegerKind.I64 1276466518; + Value.Integer IntegerKind.I64 1484771534; + Value.Integer IntegerKind.I64 1177490769; + Value.Integer IntegerKind.I64 53101516; + Value.Integer IntegerKind.I64 1580090346; + Value.Integer IntegerKind.I64 1902156546; + Value.Integer IntegerKind.I64 249134661; + Value.Integer IntegerKind.I64 1445767145; + Value.Integer IntegerKind.I64 750193437; + Value.Integer IntegerKind.I64 1318329891; + Value.Integer IntegerKind.I64 390750657; + Value.Integer IntegerKind.I64 293245990; + Value.Integer IntegerKind.I64 1935024439; + Value.Integer IntegerKind.I64 1415143558; + Value.Integer IntegerKind.I64 1216108043; + Value.Integer IntegerKind.I64 1755622571 + ] + |) + |) + |) + |) + ] + |) + |))). + + (* + const MATRIX_CIRC_MDS_64_COL: [i64; 64] = first_row_to_first_col(&[ + 0x39577778, 0x0072F4E1, 0x0B1B8404, 0x041E9C88, 0x32D22F9F, 0x4E4BF946, 0x20C7B6D7, + 0x0587C267, 0x55877229, 0x4D186EC4, 0x4A19FD23, 0x1A64A20F, 0x2965CA4D, 0x16D98A5A, + 0x471E544A, 0x193D5C8B, 0x6E66DF0C, 0x28BF1F16, 0x26DB0BC8, 0x5B06CDDB, 0x100DCCA2, + 0x65C268AD, 0x199F09E7, 0x36BA04BE, 0x06C393F2, 0x51B06DFD, 0x6951B0C4, 0x6683A4C2, + 0x3B53D11B, 0x26E5134C, 0x45A5F1C5, 0x6F4D2433, 0x3CE2D82E, 0x36309A7D, 0x3DD9B459, + 0x68051E4C, 0x5C3AA720, 0x11640517, 0x0634D995, 0x1B0F6406, 0x72A18430, 0x26513CC5, + 0x67C0B93C, 0x548AB4A3, 0x6395D20D, 0x3E5DBC41, 0x332AF630, 0x3C5DDCB3, 0x0AA95792, + 0x66EB5492, 0x3F78DDDC, 0x5AC41627, 0x16CD5124, 0x3564DA96, 0x461867C9, 0x157B4E11, + 0x1AA486C8, 0x0C5095A9, 0x3833C0C6, 0x008FEBA5, 0x52ECBE2E, 0x1D178A67, 0x58B3C04B, + 0x6E95CB51, + ]); + *) + (* Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ Ty.path "i64" ] *) + Definition value_MATRIX_CIRC_MDS_64_COL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ Ty.path "i64" ], + M.get_function (| + "p3_mds::util::first_row_to_first_col", + [ Value.Integer IntegerKind.Usize 64 ], + [ Ty.path "i64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 962033528; + Value.Integer IntegerKind.I64 7533793; + Value.Integer IntegerKind.I64 186352644; + Value.Integer IntegerKind.I64 69115016; + Value.Integer IntegerKind.I64 852635551; + Value.Integer IntegerKind.I64 1313601862; + Value.Integer IntegerKind.I64 549959383; + Value.Integer IntegerKind.I64 92783207; + Value.Integer IntegerKind.I64 1434939945; + Value.Integer IntegerKind.I64 1293446852; + Value.Integer IntegerKind.I64 1243217187; + Value.Integer IntegerKind.I64 442802703; + Value.Integer IntegerKind.I64 694536781; + Value.Integer IntegerKind.I64 383355482; + Value.Integer IntegerKind.I64 1193169994; + Value.Integer IntegerKind.I64 423451787; + Value.Integer IntegerKind.I64 1852235532; + Value.Integer IntegerKind.I64 683613974; + Value.Integer IntegerKind.I64 651889608; + Value.Integer IntegerKind.I64 1527172571; + Value.Integer IntegerKind.I64 269339810; + Value.Integer IntegerKind.I64 1707239597; + Value.Integer IntegerKind.I64 429853159; + Value.Integer IntegerKind.I64 918160574; + Value.Integer IntegerKind.I64 113480690; + Value.Integer IntegerKind.I64 1370516989; + Value.Integer IntegerKind.I64 1766961348; + Value.Integer IntegerKind.I64 1719903426; + Value.Integer IntegerKind.I64 995348763; + Value.Integer IntegerKind.I64 652546892; + Value.Integer IntegerKind.I64 1168503237; + Value.Integer IntegerKind.I64 1867326515; + Value.Integer IntegerKind.I64 1021499438; + Value.Integer IntegerKind.I64 909154941; + Value.Integer IntegerKind.I64 1037677657; + Value.Integer IntegerKind.I64 1745165900; + Value.Integer IntegerKind.I64 1547347744; + Value.Integer IntegerKind.I64 291767575; + Value.Integer IntegerKind.I64 104126869; + Value.Integer IntegerKind.I64 453993478; + Value.Integer IntegerKind.I64 1923187760; + Value.Integer IntegerKind.I64 642858181; + Value.Integer IntegerKind.I64 1740683580; + Value.Integer IntegerKind.I64 1418376355; + Value.Integer IntegerKind.I64 1670763021; + Value.Integer IntegerKind.I64 1046330433; + Value.Integer IntegerKind.I64 858453552; + Value.Integer IntegerKind.I64 1012784307; + Value.Integer IntegerKind.I64 178870162; + Value.Integer IntegerKind.I64 1726698642; + Value.Integer IntegerKind.I64 1064885724; + Value.Integer IntegerKind.I64 1522800167; + Value.Integer IntegerKind.I64 382554404; + Value.Integer IntegerKind.I64 895802006; + Value.Integer IntegerKind.I64 1176004553; + Value.Integer IntegerKind.I64 360402449; + Value.Integer IntegerKind.I64 446990024; + Value.Integer IntegerKind.I64 206607785; + Value.Integer IntegerKind.I64 942915782; + Value.Integer IntegerKind.I64 9431973; + Value.Integer IntegerKind.I64 1391246894; + Value.Integer IntegerKind.I64 488082023; + Value.Integer IntegerKind.I64 1488175179; + Value.Integer IntegerKind.I64 1855310673 + ] + |) + |) + |) + |) + ] + |) + |))). + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::mds::MDSUtils" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_MATRIX_CIRC_MDS_8_COL", InstanceField.Method value_MATRIX_CIRC_MDS_8_COL); + ("value_MATRIX_CIRC_MDS_12_COL", InstanceField.Method value_MATRIX_CIRC_MDS_12_COL); + ("value_MATRIX_CIRC_MDS_16_COL", InstanceField.Method value_MATRIX_CIRC_MDS_16_COL); + ("value_MATRIX_CIRC_MDS_24_COL", InstanceField.Method value_MATRIX_CIRC_MDS_24_COL); + ("value_MATRIX_CIRC_MDS_32_COL", InstanceField.Method value_MATRIX_CIRC_MDS_32_COL); + ("value_MATRIX_CIRC_MDS_64_COL", InstanceField.Method value_MATRIX_CIRC_MDS_64_COL) + ]. + End Impl_p3_monty_31_mds_MDSUtils_for_p3_baby_bear_mds_MDSBabyBearData. + + Axiom MdsMatrixBabyBear : + (Ty.path "p3_baby_bear::mds::MdsMatrixBabyBear") = + (Ty.apply + (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") + [] + [ Ty.path "p3_baby_bear::mds::MDSBabyBearData" ]). +End mds. diff --git a/CoqOfRust/plonky3/baby-bear/src/poseidon2.rs b/CoqOfRust/plonky3/baby-bear/src/poseidon2.rs new file mode 100644 index 000000000..02c0cc3c1 --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/poseidon2.rs @@ -0,0 +1,511 @@ +//! Implementation of Poseidon2, see: https://eprint.iacr.org/2023/323 +//! +//! For the diffusion matrix, 1 + Diag(V), we perform a search to find an optimized +//! vector V composed of elements with efficient multiplication algorithms in AVX2/AVX512/NEON. +//! +//! This leads to using small values (e.g. 1, 2, 3, 4) where multiplication is implemented using addition +//! and inverse powers of 2 where it is possible to avoid monty reductions. +//! Additionally, for technical reasons, having the first entry be -2 is useful. +//! +//! Optimized Diagonal for BabyBear16: +//! [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/2^27, -1/2^8, -1/16, -1/2^27]. +//! Optimized Diagonal for BabyBear24: +//! [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/2^7, 1/2^9, 1/2^27, -1/2^8, -1/4, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^27] +//! See poseidon2\src\diffusion.rs for information on how to double check these matrices in Sage. + +use p3_field::{Algebra, Field, PrimeCharacteristicRing, PrimeField32}; +use p3_monty_31::{ + GenericPoseidon2LinearLayersMonty31, InternalLayerBaseParameters, InternalLayerParameters, + MontyField31, Poseidon2ExternalLayerMonty31, Poseidon2InternalLayerMonty31, +}; +use p3_poseidon2::{ExternalLayerConstants, Poseidon2}; + +use crate::{BabyBear, BabyBearParameters}; + +pub type Poseidon2InternalLayerBabyBear = + Poseidon2InternalLayerMonty31; + +pub type Poseidon2ExternalLayerBabyBear = + Poseidon2ExternalLayerMonty31; + +/// Degree of the chosen permutation polynomial for BabyBear, used as the Poseidon2 S-Box. +/// +/// As p - 1 = 15 * 2^{27} the neither 3 nor 5 satisfy gcd(p - 1, D) = 1. +/// Instead we use the next smallest available value, namely 7. +const BABYBEAR_S_BOX_DEGREE: u64 = 7; + +/// An implementation of the Poseidon2 hash function specialised to run on the current architecture. +/// +/// It acts on arrays of the form either `[BabyBear::Packing; WIDTH]` or `[BabyBear; WIDTH]`. For speed purposes, +/// wherever possible, input arrays should of the form `[BabyBear::Packing; WIDTH]`. +pub type Poseidon2BabyBear = Poseidon2< + BabyBear, + Poseidon2ExternalLayerBabyBear, + Poseidon2InternalLayerBabyBear, + WIDTH, + BABYBEAR_S_BOX_DEGREE, +>; + +/// An implementation of the matrix multiplications in the internal and external layers of Poseidon2. +/// +/// This can act on `[A; WIDTH]` for any ring implementing `Algebra`. +/// If you have either `[BabyBear::Packing; WIDTH]` or `[BabyBear; WIDTH]` it will be much faster +/// to use `Poseidon2BabyBear` instead of building a Poseidon2 permutation using this. +pub type GenericPoseidon2LinearLayersBabyBear = + GenericPoseidon2LinearLayersMonty31; + +// In order to use BabyBear::new_array we need to convert our vector to a vector of u32's. +// To do this we make use of the fact that BabyBear::ORDER_U32 - 1 = 15 * 2^27 so for 0 <= n <= 27: +// -1/2^n = (BabyBear::ORDER_U32 - 1) >> n +// 1/2^n = -(-1/2^n) = BabyBear::ORDER_U32 - ((BabyBear::ORDER_U32 - 1) >> n) + +/// The vector `[-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/2^27, -1/2^8, -1/16, -1/2^27]` +/// saved as an array of BabyBear elements. +const INTERNAL_DIAG_MONTY_16: [BabyBear; 16] = BabyBear::new_array([ + BabyBear::ORDER_U32 - 2, + 1, + 2, + (BabyBear::ORDER_U32 + 1) >> 1, + 3, + 4, + (BabyBear::ORDER_U32 - 1) >> 1, + BabyBear::ORDER_U32 - 3, + BabyBear::ORDER_U32 - 4, + BabyBear::ORDER_U32 - ((BabyBear::ORDER_U32 - 1) >> 8), + BabyBear::ORDER_U32 - ((BabyBear::ORDER_U32 - 1) >> 2), + BabyBear::ORDER_U32 - ((BabyBear::ORDER_U32 - 1) >> 3), + BabyBear::ORDER_U32 - 15, + (BabyBear::ORDER_U32 - 1) >> 8, + (BabyBear::ORDER_U32 - 1) >> 4, + 15, +]); + +/// The vector [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/2^7, 1/2^9, 1/2^27, -1/2^8, -1/4, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^27] +/// saved as an array of BabyBear elements. +const INTERNAL_DIAG_MONTY_24: [BabyBear; 24] = BabyBear::new_array([ + BabyBear::ORDER_U32 - 2, + 1, + 2, + (BabyBear::ORDER_U32 + 1) >> 1, + 3, + 4, + (BabyBear::ORDER_U32 - 1) >> 1, + BabyBear::ORDER_U32 - 3, + BabyBear::ORDER_U32 - 4, + BabyBear::ORDER_U32 - ((BabyBear::ORDER_U32 - 1) >> 8), + BabyBear::ORDER_U32 - ((BabyBear::ORDER_U32 - 1) >> 2), + BabyBear::ORDER_U32 - ((BabyBear::ORDER_U32 - 1) >> 3), + BabyBear::ORDER_U32 - ((BabyBear::ORDER_U32 - 1) >> 4), + BabyBear::ORDER_U32 - ((BabyBear::ORDER_U32 - 1) >> 7), + BabyBear::ORDER_U32 - ((BabyBear::ORDER_U32 - 1) >> 9), + BabyBear::ORDER_U32 - 15, + (BabyBear::ORDER_U32 - 1) >> 8, + (BabyBear::ORDER_U32 - 1) >> 2, + (BabyBear::ORDER_U32 - 1) >> 3, + (BabyBear::ORDER_U32 - 1) >> 4, + (BabyBear::ORDER_U32 - 1) >> 5, + (BabyBear::ORDER_U32 - 1) >> 6, + (BabyBear::ORDER_U32 - 1) >> 7, + 15, +]); + +/// Initial round constants for the 16-width Poseidon2 external layer on BabyBear. +/// +/// See https://github.com/HorizenLabs/poseidon2/blob/main/plain_implementations/src/poseidon2/poseidon2_instance_babybear.rs +pub const BABYBEAR_RC16_EXTERNAL_INITIAL: [[BabyBear; 16]; 4] = BabyBear::new_2d_array([ + [ + 0x69cbb6af, 0x46ad93f9, 0x60a00f4e, 0x6b1297cd, 0x23189afe, 0x732e7bef, 0x72c246de, + 0x2c941900, 0x0557eede, 0x1580496f, 0x3a3ea77b, 0x54f3f271, 0x0f49b029, 0x47872fe1, + 0x221e2e36, 0x1ab7202e, + ], + [ + 0x487779a6, 0x3851c9d8, 0x38dc17c0, 0x209f8849, 0x268dcee8, 0x350c48da, 0x5b9ad32e, + 0x0523272b, 0x3f89055b, 0x01e894b2, 0x13ddedde, 0x1b2ef334, 0x7507d8b4, 0x6ceeb94e, + 0x52eb6ba2, 0x50642905, + ], + [ + 0x05453f3f, 0x06349efc, 0x6922787c, 0x04bfff9c, 0x768c714a, 0x3e9ff21a, 0x15737c9c, + 0x2229c807, 0x0d47f88c, 0x097e0ecc, 0x27eadba0, 0x2d7d29e4, 0x3502aaa0, 0x0f475fd7, + 0x29fbda49, 0x018afffd, + ], + [ + 0x0315b618, 0x6d4497d1, 0x1b171d9e, 0x52861abd, 0x2e5d0501, 0x3ec8646c, 0x6e5f250a, + 0x148ae8e6, 0x17f5fa4a, 0x3e66d284, 0x0051aa3b, 0x483f7913, 0x2cfe5f15, 0x023427ca, + 0x2cc78315, 0x1e36ea47, + ], +]); + +/// Final round constants for the 16-width Poseidon2's external layer on BabyBear. +/// +/// See https://github.com/HorizenLabs/poseidon2/blob/main/plain_implementations/src/poseidon2/poseidon2_instance_babybear.rs +pub const BABYBEAR_RC16_EXTERNAL_FINAL: [[BabyBear; 16]; 4] = BabyBear::new_2d_array([ + [ + 0x7290a80d, 0x6f7e5329, 0x598ec8a8, 0x76a859a0, 0x6559e868, 0x657b83af, 0x13271d3f, + 0x1f876063, 0x0aeeae37, 0x706e9ca6, 0x46400cee, 0x72a05c26, 0x2c589c9e, 0x20bd37a7, + 0x6a2d3d10, 0x20523767, + ], + [ + 0x5b8fe9c4, 0x2aa501d6, 0x1e01ac3e, 0x1448bc54, 0x5ce5ad1c, 0x4918a14d, 0x2c46a83f, + 0x4fcf6876, 0x61d8d5c8, 0x6ddf4ff9, 0x11fda4d3, 0x02933a8f, 0x170eaf81, 0x5a9c314f, + 0x49a12590, 0x35ec52a1, + ], + [ + 0x58eb1611, 0x5e481e65, 0x367125c9, 0x0eba33ba, 0x1fc28ded, 0x066399ad, 0x0cbec0ea, + 0x75fd1af0, 0x50f5bf4e, 0x643d5f41, 0x6f4fe718, 0x5b3cbbde, 0x1e3afb3e, 0x296fb027, + 0x45e1547b, 0x4a8db2ab, + ], + [ + 0x59986d19, 0x30bcdfa3, 0x1db63932, 0x1d7c2824, 0x53b33681, 0x0673b747, 0x038a98a3, + 0x2c5bce60, 0x351979cd, 0x5008fb73, 0x547bca78, 0x711af481, 0x3f93bf64, 0x644d987b, + 0x3c8bcd87, 0x608758b8, + ], +]); + +/// Round constants for the 16-width Poseidon2's internal layer on BabyBear. +/// +/// See https://github.com/HorizenLabs/poseidon2/blob/main/plain_implementations/src/poseidon2/poseidon2_instance_babybear.rs +pub const BABYBEAR_RC16_INTERNAL: [BabyBear; 13] = BabyBear::new_array([ + 0x5a8053c0, 0x693be639, 0x3858867d, 0x19334f6b, 0x128f0fd8, 0x4e2b1ccb, 0x61210ce0, 0x3c318939, + 0x0b5b2f22, 0x2edb11d5, 0x213effdf, 0x0cac4606, 0x241af16d, +]); + +/// A default Poseidon2 for BabyBear using the round constants from the Horizon Labs implementation. +/// +/// See https://github.com/HorizenLabs/poseidon2/blob/main/plain_implementations/src/poseidon2/poseidon2_instance_babybear.rs +pub fn default_babybear_poseidon2_16() -> Poseidon2BabyBear<16> { + Poseidon2::new( + ExternalLayerConstants::new( + BABYBEAR_RC16_EXTERNAL_INITIAL.to_vec(), + BABYBEAR_RC16_EXTERNAL_FINAL.to_vec(), + ), + BABYBEAR_RC16_INTERNAL.to_vec(), + ) +} + +/// Initial round constants for the 24-width Poseidon2 external layer on BabyBear. +/// +/// See https://github.com/HorizenLabs/poseidon2/blob/main/plain_implementations/src/poseidon2/poseidon2_instance_babybear.rs +pub const BABYBEAR_RC24_EXTERNAL_INITIAL: [[BabyBear; 24]; 4] = BabyBear::new_2d_array([ + [ + 0x0fa20c37, 0x0795bb97, 0x12c60b9c, 0x0eabd88e, 0x096485ca, 0x07093527, 0x1b1d4e50, + 0x30a01ace, 0x3bd86f5a, 0x69af7c28, 0x3f94775f, 0x731560e8, 0x465a0ecd, 0x574ef807, + 0x62fd4870, 0x52ccfe44, 0x14772b14, 0x4dedf371, 0x260acd7c, 0x1f51dc58, 0x75125532, + 0x686a4d7b, 0x54bac179, 0x31947706, + ], + [ + 0x29799d3b, 0x6e01ae90, 0x203a7a64, 0x4f7e25be, 0x72503f77, 0x45bd3b69, 0x769bd6b4, + 0x5a867f08, 0x4fdba082, 0x251c4318, 0x28f06201, 0x6788c43a, 0x4c6d6a99, 0x357784a8, + 0x2abaf051, 0x770f7de6, 0x1794b784, 0x4796c57a, 0x724b7a10, 0x449989a7, 0x64935cf1, + 0x59e14aac, 0x0e620bb8, 0x3af5a33b, + ], + [ + 0x4465cc0e, 0x019df68f, 0x4af8d068, 0x08784f82, 0x0cefdeae, 0x6337a467, 0x32fa7a16, + 0x486f62d6, 0x386a7480, 0x20f17c4a, 0x54e50da8, 0x2012cf03, 0x5fe52950, 0x09afb6cd, + 0x2523044e, 0x5c54d0ef, 0x71c01f3c, 0x60b2c4fb, 0x4050b379, 0x5e6a70a5, 0x418543f5, + 0x71debe56, 0x1aad2994, 0x3368a483, + ], + [ + 0x07a86f3a, 0x5ea43ff1, 0x2443780e, 0x4ce444f7, 0x146f9882, 0x3132b089, 0x197ea856, + 0x667030c3, 0x2317d5dc, 0x0c2c48a7, 0x56b2df66, 0x67bd81e9, 0x4fcdfb19, 0x4baaef32, + 0x0328d30a, 0x6235760d, 0x12432912, 0x0a49e258, 0x030e1b70, 0x48caeb03, 0x49e4d9e9, + 0x1051b5c6, 0x6a36dbbe, 0x4cff27a5, + ], +]); + +/// Final round constants for the 24-width Poseidon2's external layer on BabyBear. +/// +/// See https://github.com/HorizenLabs/poseidon2/blob/main/plain_implementations/src/poseidon2/poseidon2_instance_babybear.rs +pub const BABYBEAR_RC24_EXTERNAL_FINAL: [[BabyBear; 24]; 4] = BabyBear::new_2d_array([ + [ + 0x032959ad, 0x2b18af6a, 0x55d3dc8c, 0x43bd26c8, 0x0c41595f, 0x7048d2e2, 0x00db8983, + 0x2af563d7, 0x6e84758f, 0x611d64e1, 0x1f9977e2, 0x64163a0a, 0x5c5fc27b, 0x02e22561, + 0x3a2d75db, 0x1ba7b71a, 0x34343f64, 0x7406b35d, 0x19df8299, 0x6ff4480a, 0x514a81c8, + 0x57ab52ce, 0x6ad69f52, 0x3e0c0e0d, + ], + [ + 0x48126114, 0x2a9d62cc, 0x17441f23, 0x485762bb, 0x2f218674, 0x06fdc64a, 0x0861b7f2, + 0x3b36eee6, 0x70a11040, 0x04b31737, 0x3722a872, 0x2a351c63, 0x623560dc, 0x62584ab2, + 0x382c7c04, 0x3bf9edc7, 0x0e38fe51, 0x376f3b10, 0x5381e178, 0x3afc61c7, 0x5c1bcb4d, + 0x6643ce1f, 0x2d0af1c1, 0x08f583cc, + ], + [ + 0x5d6ff60f, 0x6324c1e5, 0x74412fb7, 0x70c0192e, 0x0b72f141, 0x4067a111, 0x57388c4f, + 0x351009ec, 0x0974c159, 0x539a58b3, 0x038c0cff, 0x476c0392, 0x3f7bc15f, 0x4491dd2c, + 0x4d1fef55, 0x04936ae3, 0x58214dd4, 0x683c6aad, 0x1b42f16b, 0x6dc79135, 0x2d4e71ec, + 0x3e2946ea, 0x59dce8db, 0x6cee892a, + ], + [ + 0x47f07350, 0x7106ce93, 0x3bd4a7a9, 0x2bfe636a, 0x430011e9, 0x001cd66a, 0x307faf5b, + 0x0d9ef3fe, 0x6d40043a, 0x2e8f470c, 0x1b6865e8, 0x0c0e6c01, 0x4d41981f, 0x423b9d3d, + 0x410408cc, 0x263f0884, 0x5311bbd0, 0x4dae58d8, 0x30401cea, 0x09afa575, 0x4b3d5b42, + 0x63ac0b37, 0x5fe5bb14, 0x5244e9d4, + ], +]); + +/// Round constants for the 24-width Poseidon2's internal layer on BabyBear. +/// +/// See https://github.com/HorizenLabs/poseidon2/blob/main/plain_implementations/src/poseidon2/poseidon2_instance_babybear.rs +pub const BABYBEAR_RC24_INTERNAL: [BabyBear; 21] = BabyBear::new_array([ + 0x1da78ec2, 0x730b0924, 0x3eb56cf3, 0x5bd93073, 0x37204c97, 0x51642d89, 0x66e943e8, 0x1a3e72de, + 0x70beb1e9, 0x30ff3b3f, 0x4240d1c4, 0x12647b8d, 0x65d86965, 0x49ef4d7c, 0x47785697, 0x46b3969f, + 0x5c7b7a0e, 0x7078fc60, 0x4f22d482, 0x482a9aee, 0x6beb839d, +]); + +/// A default Poseidon2 for BabyBear using the round constants from the Horizon Labs implementation. +/// +/// See https://github.com/HorizenLabs/poseidon2/blob/main/plain_implementations/src/poseidon2/poseidon2_instance_babybear.rs +pub fn default_babybear_poseidon2_24() -> Poseidon2BabyBear<24> { + Poseidon2::new( + ExternalLayerConstants::new( + BABYBEAR_RC24_EXTERNAL_INITIAL.to_vec(), + BABYBEAR_RC24_EXTERNAL_FINAL.to_vec(), + ), + BABYBEAR_RC24_INTERNAL.to_vec(), + ) +} + +/// Contains data needed to define the internal layers of the Poseidon2 permutation. +#[derive(Debug, Clone, Default)] +pub struct BabyBearInternalLayerParameters; + +impl InternalLayerBaseParameters for BabyBearInternalLayerParameters { + type ArrayLike = [MontyField31; 15]; + + const INTERNAL_DIAG_MONTY: [BabyBear; 16] = INTERNAL_DIAG_MONTY_16; + + /// Perform the internal matrix multiplication: s -> (1 + Diag(V))s. + /// We ignore `state[0]` as it is handled separately. + fn internal_layer_mat_mul( + state: &mut [MontyField31; 16], + sum: MontyField31, + ) { + // The diagonal matrix is defined by the vector: + // V = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/2^27, -1/2^8, -1/16, -1/2^27] + state[1] += sum; + state[2] = state[2].double() + sum; + state[3] = state[3].halve() + sum; + state[4] = sum + state[4].double() + state[4]; + state[5] = sum + state[5].double().double(); + state[6] = sum - state[6].halve(); + state[7] = sum - (state[7].double() + state[7]); + state[8] = sum - state[8].double().double(); + state[9] = state[9].div_2exp_u64(8); + state[9] += sum; + state[10] = state[10].div_2exp_u64(2); + state[10] += sum; + state[11] = state[11].div_2exp_u64(3); + state[11] += sum; + state[12] = state[12].div_2exp_u64(27); + state[12] += sum; + state[13] = state[13].div_2exp_u64(8); + state[13] = sum - state[13]; + state[14] = state[14].div_2exp_u64(4); + state[14] = sum - state[14]; + state[15] = state[15].div_2exp_u64(27); + state[15] = sum - state[15]; + } + + fn generic_internal_linear_layer>(state: &mut [A; 16]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use multiplication. + // This could probably be improved slightly by making use of the + // mul_2exp_u64 and div_2exp_u64 but this would involve porting div_2exp_u64 to PrimeCharacteristicRing. + state + .iter_mut() + .zip(INTERNAL_DIAG_MONTY_16) + .skip(3) + .for_each(|(val, diag_elem)| { + *val = full_sum.clone() + val.clone() * diag_elem; + }); + } +} + +impl InternalLayerBaseParameters for BabyBearInternalLayerParameters { + type ArrayLike = [MontyField31; 23]; + + const INTERNAL_DIAG_MONTY: [BabyBear; 24] = INTERNAL_DIAG_MONTY_24; + + /// Perform the internal matrix multiplication: s -> (1 + Diag(V))s. + /// We ignore `state[0]` as it is handled separately. + fn internal_layer_mat_mul( + state: &mut [MontyField31; 24], + sum: MontyField31, + ) { + // The diagonal matrix is defined by the vector: + // V = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/2^7, 1/2^9, 1/2^27, -1/2^8, -1/4, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^27] + state[1] += sum; + state[2] = state[2].double() + sum; + state[3] = state[3].halve() + sum; + state[4] = sum + state[4].double() + state[4]; + state[5] = sum + state[5].double().double(); + state[6] = sum - state[6].halve(); + state[7] = sum - (state[7].double() + state[7]); + state[8] = sum - state[8].double().double(); + state[9] = state[9].div_2exp_u64(8); + state[9] += sum; + state[10] = state[10].div_2exp_u64(2); + state[10] += sum; + state[11] = state[11].div_2exp_u64(3); + state[11] += sum; + state[12] = state[12].div_2exp_u64(4); + state[12] += sum; + state[13] = state[13].div_2exp_u64(7); + state[13] += sum; + state[14] = state[14].div_2exp_u64(9); + state[14] += sum; + state[15] = state[15].div_2exp_u64(27); + state[15] += sum; + state[16] = state[16].div_2exp_u64(8); + state[16] = sum - state[16]; + state[17] = state[17].div_2exp_u64(2); + state[17] = sum - state[17]; + state[18] = state[18].div_2exp_u64(3); + state[18] = sum - state[18]; + state[19] = state[19].div_2exp_u64(4); + state[19] = sum - state[19]; + state[20] = state[20].div_2exp_u64(5); + state[20] = sum - state[20]; + state[21] = state[21].div_2exp_u64(6); + state[21] = sum - state[21]; + state[22] = state[22].div_2exp_u64(7); + state[22] = sum - state[22]; + state[23] = state[23].div_2exp_u64(27); + state[23] = sum - state[23]; + } + + fn generic_internal_linear_layer>(state: &mut [A; 24]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use multiplication. + // This could probably be improved slightly by making use of the + // mul_2exp_u64 and div_2exp_u64 but this would involve porting div_2exp_u64 to PrimeCharacteristicRing. + state + .iter_mut() + .zip(INTERNAL_DIAG_MONTY_24) + .skip(3) + .for_each(|(val, diag_elem)| { + *val = full_sum.clone() + val.clone() * diag_elem; + }); + } +} + +impl InternalLayerParameters for BabyBearInternalLayerParameters {} +impl InternalLayerParameters for BabyBearInternalLayerParameters {} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::{Rng, SeedableRng}; + use rand_xoshiro::Xoroshiro128Plus; + + use super::*; + + type F = BabyBear; + + // We need to make some round constants. We use Xoroshiro128Plus for this as we can easily match this PRNG in sage. + // See: https://github.com/0xPolygonZero/hash-constants for the sage code used to create all these tests. + + /// Test on a roughly random input. + /// This random input is generated by the following sage code: + /// set_random_seed(16) + /// vector([BB.random_element() for t in range(16)]). + #[test] + fn test_poseidon2_width_16_random() { + let mut input: [F; 16] = BabyBear::new_array([ + 894848333, 1437655012, 1200606629, 1690012884, 71131202, 1749206695, 1717947831, + 120589055, 19776022, 42382981, 1831865506, 724844064, 171220207, 1299207443, 227047920, + 1783754913, + ]); + + let expected: [F; 16] = BabyBear::new_array([ + 1255099308, 941729227, 93609187, 112406640, 492658670, 1824768948, 812517469, + 1055381989, 670973674, 1407235524, 891397172, 1003245378, 1381303998, 1564172645, + 1399931635, 1005462965, + ]); + + let mut rng = Xoroshiro128Plus::seed_from_u64(1); + let perm = Poseidon2BabyBear::new_from_rng_128(&mut rng); + + perm.permute_mut(&mut input); + assert_eq!(input, expected); + } + + /// Test on a roughly random input. + /// This random input is generated by the following sage code: + /// set_random_seed(24) + /// vector([BB.random_element() for t in range(24)]). + #[test] + fn test_poseidon2_width_24_random() { + let mut input: [F; 24] = BabyBear::new_array([ + 886409618, 1327899896, 1902407911, 591953491, 648428576, 1844789031, 1198336108, + 355597330, 1799586834, 59617783, 790334801, 1968791836, 559272107, 31054313, + 1042221543, 474748436, 135686258, 263665994, 1962340735, 1741539604, 449439011, + 1131357108, 50869465, 1589724894, + ]); + + let expected: [F; 24] = BabyBear::new_array([ + 249424342, 562262148, 757431114, 354243402, 57767055, 976981973, 1393169022, + 1774550827, 1527742125, 1019514605, 1776327602, 266236737, 1412355182, 1070239213, + 426390978, 1775539440, 1527732214, 1101406020, 1417710778, 1699632661, 413672313, + 820348291, 1067197851, 1669055675, + ]); + + let mut rng = Xoroshiro128Plus::seed_from_u64(1); + let perm = Poseidon2BabyBear::new_from_rng_128(&mut rng); + + perm.permute_mut(&mut input); + + assert_eq!(input, expected); + } + + /// Test the generic internal layer against the optimized internal layer + /// for a random input of width 16. + #[test] + fn test_generic_internal_linear_layer_16() { + let mut rng = Xoroshiro128Plus::seed_from_u64(1); + let mut input1: [F; 16] = rng.random(); + let mut input2 = input1; + + let part_sum: F = input1[1..].iter().copied().sum(); + let full_sum = part_sum + input1[0]; + + input1[0] = part_sum - input1[0]; + + BabyBearInternalLayerParameters::internal_layer_mat_mul(&mut input1, full_sum); + BabyBearInternalLayerParameters::generic_internal_linear_layer(&mut input2); + + assert_eq!(input1, input2); + } + + /// Test the generic internal layer against the optimized internal layer + /// for a random input of width 24. + #[test] + fn test_generic_internal_linear_layer_24() { + let mut rng = Xoroshiro128Plus::seed_from_u64(1); + let mut input1: [F; 24] = rng.random(); + let mut input2 = input1; + + let part_sum: F = input1[1..].iter().copied().sum(); + let full_sum = part_sum + input1[0]; + + input1[0] = part_sum - input1[0]; + + BabyBearInternalLayerParameters::internal_layer_mat_mul(&mut input1, full_sum); + BabyBearInternalLayerParameters::generic_internal_linear_layer(&mut input2); + + assert_eq!(input1, input2); + } +} diff --git a/CoqOfRust/plonky3/baby-bear/src/poseidon2.v b/CoqOfRust/plonky3/baby-bear/src/poseidon2.v new file mode 100644 index 000000000..033ff04a3 --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/poseidon2.v @@ -0,0 +1,6158 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module poseidon2. + Axiom Poseidon2InternalLayerBabyBear : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_baby_bear::poseidon2::Poseidon2InternalLayerBabyBear") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ WIDTH ] + [ + Ty.path "p3_baby_bear::baby_bear::BabyBearParameters"; + Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters" + ]). + + Axiom Poseidon2ExternalLayerBabyBear : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_baby_bear::poseidon2::Poseidon2ExternalLayerBabyBear") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ WIDTH ] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]). + + Definition value_BABYBEAR_S_BOX_DEGREE + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U64 7 |))). + + Global Instance Instance_IsConstant_value_BABYBEAR_S_BOX_DEGREE : + M.IsFunction.C "p3_baby_bear::poseidon2::BABYBEAR_S_BOX_DEGREE" value_BABYBEAR_S_BOX_DEGREE. + Admitted. + Global Typeclasses Opaque value_BABYBEAR_S_BOX_DEGREE. + + Axiom Poseidon2BabyBear : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_baby_bear::poseidon2::Poseidon2BabyBear") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ + WIDTH; + M.unevaluated_const (mk_str (| "p3_baby_bear_poseidon2_Poseidon2BabyBear_discriminant" |)) + ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ WIDTH ] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ WIDTH ] + [ + Ty.path "p3_baby_bear::baby_bear::BabyBearParameters"; + Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters" + ] + ]). + + Axiom GenericPoseidon2LinearLayersBabyBear : + (Ty.path "p3_baby_bear::poseidon2::GenericPoseidon2LinearLayersBabyBear") = + (Ty.apply + (Ty.path "p3_monty_31::poseidon2::GenericPoseidon2LinearLayersMonty31") + [] + [ + Ty.path "p3_baby_bear::baby_bear::BabyBearParameters"; + Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters" + ]). + + Definition value_INTERNAL_DIAG_MONTY_16 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ + Value.Array + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 2 + ] + |); + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 2; + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 1 + ] + |); + Value.Integer IntegerKind.U32 3; + Value.Integer IntegerKind.U32 4; + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 1 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 3 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 4 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 8 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 2 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 3 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 15 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 8 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 4 + ] + |); + Value.Integer IntegerKind.U32 15 + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_INTERNAL_DIAG_MONTY_16 : + M.IsFunction.C "p3_baby_bear::poseidon2::INTERNAL_DIAG_MONTY_16" value_INTERNAL_DIAG_MONTY_16. + Admitted. + Global Typeclasses Opaque value_INTERNAL_DIAG_MONTY_16. + + Definition value_INTERNAL_DIAG_MONTY_24 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 24 ], + [] + |), + [ + Value.Array + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 2 + ] + |); + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 2; + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 1 + ] + |); + Value.Integer IntegerKind.U32 3; + Value.Integer IntegerKind.U32 4; + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 1 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 3 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 4 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 8 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 2 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 3 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 4 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 7 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 9 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 15 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 8 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 2 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 3 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 4 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 5 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 6 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 7 + ] + |); + Value.Integer IntegerKind.U32 15 + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_INTERNAL_DIAG_MONTY_24 : + M.IsFunction.C "p3_baby_bear::poseidon2::INTERNAL_DIAG_MONTY_24" value_INTERNAL_DIAG_MONTY_24. + Admitted. + Global Typeclasses Opaque value_INTERNAL_DIAG_MONTY_24. + + Definition value_BABYBEAR_RC16_EXTERNAL_INITIAL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_2d_array", + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + Value.Array + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1774958255; + Value.Integer IntegerKind.U32 1185780729; + Value.Integer IntegerKind.U32 1621102414; + Value.Integer IntegerKind.U32 1796380621; + Value.Integer IntegerKind.U32 588815102; + Value.Integer IntegerKind.U32 1932426223; + Value.Integer IntegerKind.U32 1925334750; + Value.Integer IntegerKind.U32 747903232; + Value.Integer IntegerKind.U32 89648862; + Value.Integer IntegerKind.U32 360728943; + Value.Integer IntegerKind.U32 977184635; + Value.Integer IntegerKind.U32 1425273457; + Value.Integer IntegerKind.U32 256487465; + Value.Integer IntegerKind.U32 1200041953; + Value.Integer IntegerKind.U32 572403254; + Value.Integer IntegerKind.U32 448208942 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 1215789478; + Value.Integer IntegerKind.U32 944884184; + Value.Integer IntegerKind.U32 953948096; + Value.Integer IntegerKind.U32 547326025; + Value.Integer IntegerKind.U32 646827752; + Value.Integer IntegerKind.U32 889997530; + Value.Integer IntegerKind.U32 1536873262; + Value.Integer IntegerKind.U32 86189867; + Value.Integer IntegerKind.U32 1065944411; + Value.Integer IntegerKind.U32 32019634; + Value.Integer IntegerKind.U32 333311454; + Value.Integer IntegerKind.U32 456061748; + Value.Integer IntegerKind.U32 1963448500; + Value.Integer IntegerKind.U32 1827584334; + Value.Integer IntegerKind.U32 1391160226; + Value.Integer IntegerKind.U32 1348741381 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 88424255; + Value.Integer IntegerKind.U32 104111868; + Value.Integer IntegerKind.U32 1763866748; + Value.Integer IntegerKind.U32 79691676; + Value.Integer IntegerKind.U32 1988915530; + Value.Integer IntegerKind.U32 1050669594; + Value.Integer IntegerKind.U32 359890076; + Value.Integer IntegerKind.U32 573163527; + Value.Integer IntegerKind.U32 222820492; + Value.Integer IntegerKind.U32 159256268; + Value.Integer IntegerKind.U32 669703072; + Value.Integer IntegerKind.U32 763177444; + Value.Integer IntegerKind.U32 889367200; + Value.Integer IntegerKind.U32 256335831; + Value.Integer IntegerKind.U32 704371273; + Value.Integer IntegerKind.U32 25886717 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 51754520; + Value.Integer IntegerKind.U32 1833211857; + Value.Integer IntegerKind.U32 454499742; + Value.Integer IntegerKind.U32 1384520381; + Value.Integer IntegerKind.U32 777848065; + Value.Integer IntegerKind.U32 1053320300; + Value.Integer IntegerKind.U32 1851729162; + Value.Integer IntegerKind.U32 344647910; + Value.Integer IntegerKind.U32 401996362; + Value.Integer IntegerKind.U32 1046925956; + Value.Integer IntegerKind.U32 5351995; + Value.Integer IntegerKind.U32 1212119315; + Value.Integer IntegerKind.U32 754867989; + Value.Integer IntegerKind.U32 36972490; + Value.Integer IntegerKind.U32 751272725; + Value.Integer IntegerKind.U32 506915399 + ] + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_BABYBEAR_RC16_EXTERNAL_INITIAL : + M.IsFunction.C + "p3_baby_bear::poseidon2::BABYBEAR_RC16_EXTERNAL_INITIAL" + value_BABYBEAR_RC16_EXTERNAL_INITIAL. + Admitted. + Global Typeclasses Opaque value_BABYBEAR_RC16_EXTERNAL_INITIAL. + + Definition value_BABYBEAR_RC16_EXTERNAL_FINAL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_2d_array", + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + Value.Array + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1922082829; + Value.Integer IntegerKind.U32 1870549801; + Value.Integer IntegerKind.U32 1502529704; + Value.Integer IntegerKind.U32 1990744480; + Value.Integer IntegerKind.U32 1700391016; + Value.Integer IntegerKind.U32 1702593455; + Value.Integer IntegerKind.U32 321330495; + Value.Integer IntegerKind.U32 528965731; + Value.Integer IntegerKind.U32 183414327; + Value.Integer IntegerKind.U32 1886297254; + Value.Integer IntegerKind.U32 1178602734; + Value.Integer IntegerKind.U32 1923111974; + Value.Integer IntegerKind.U32 744004766; + Value.Integer IntegerKind.U32 549271463; + Value.Integer IntegerKind.U32 1781349648; + Value.Integer IntegerKind.U32 542259047 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 1536158148; + Value.Integer IntegerKind.U32 715456982; + Value.Integer IntegerKind.U32 503426110; + Value.Integer IntegerKind.U32 340311124; + Value.Integer IntegerKind.U32 1558555932; + Value.Integer IntegerKind.U32 1226350925; + Value.Integer IntegerKind.U32 742828095; + Value.Integer IntegerKind.U32 1338992758; + Value.Integer IntegerKind.U32 1641600456; + Value.Integer IntegerKind.U32 1843351545; + Value.Integer IntegerKind.U32 301835475; + Value.Integer IntegerKind.U32 43203215; + Value.Integer IntegerKind.U32 386838401; + Value.Integer IntegerKind.U32 1520185679; + Value.Integer IntegerKind.U32 1235297680; + Value.Integer IntegerKind.U32 904680097 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 1491801617; + Value.Integer IntegerKind.U32 1581784677; + Value.Integer IntegerKind.U32 913384905; + Value.Integer IntegerKind.U32 247083962; + Value.Integer IntegerKind.U32 532844013; + Value.Integer IntegerKind.U32 107190701; + Value.Integer IntegerKind.U32 213827818; + Value.Integer IntegerKind.U32 1979521776; + Value.Integer IntegerKind.U32 1358282574; + Value.Integer IntegerKind.U32 1681743681; + Value.Integer IntegerKind.U32 1867507480; + Value.Integer IntegerKind.U32 1530706910; + Value.Integer IntegerKind.U32 507181886; + Value.Integer IntegerKind.U32 695185447; + Value.Integer IntegerKind.U32 1172395131; + Value.Integer IntegerKind.U32 1250800299 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 1503161625; + Value.Integer IntegerKind.U32 817684387; + Value.Integer IntegerKind.U32 498481458; + Value.Integer IntegerKind.U32 494676004; + Value.Integer IntegerKind.U32 1404253825; + Value.Integer IntegerKind.U32 108246855; + Value.Integer IntegerKind.U32 59414691; + Value.Integer IntegerKind.U32 744214112; + Value.Integer IntegerKind.U32 890862029; + Value.Integer IntegerKind.U32 1342765939; + Value.Integer IntegerKind.U32 1417398904; + Value.Integer IntegerKind.U32 1897591937; + Value.Integer IntegerKind.U32 1066647396; + Value.Integer IntegerKind.U32 1682806907; + Value.Integer IntegerKind.U32 1015795079; + Value.Integer IntegerKind.U32 1619482808 + ] + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_BABYBEAR_RC16_EXTERNAL_FINAL : + M.IsFunction.C + "p3_baby_bear::poseidon2::BABYBEAR_RC16_EXTERNAL_FINAL" + value_BABYBEAR_RC16_EXTERNAL_FINAL. + Admitted. + Global Typeclasses Opaque value_BABYBEAR_RC16_EXTERNAL_FINAL. + + Definition value_BABYBEAR_RC16_INTERNAL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 13 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1518359488; + Value.Integer IntegerKind.U32 1765533241; + Value.Integer IntegerKind.U32 945325693; + Value.Integer IntegerKind.U32 422793067; + Value.Integer IntegerKind.U32 311365592; + Value.Integer IntegerKind.U32 1311448267; + Value.Integer IntegerKind.U32 1629555936; + Value.Integer IntegerKind.U32 1009879353; + Value.Integer IntegerKind.U32 190525218; + Value.Integer IntegerKind.U32 786108885; + Value.Integer IntegerKind.U32 557776863; + Value.Integer IntegerKind.U32 212616710; + Value.Integer IntegerKind.U32 605745517 + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_BABYBEAR_RC16_INTERNAL : + M.IsFunction.C "p3_baby_bear::poseidon2::BABYBEAR_RC16_INTERNAL" value_BABYBEAR_RC16_INTERNAL. + Admitted. + Global Typeclasses Opaque value_BABYBEAR_RC16_INTERNAL. + + (* + pub fn default_babybear_poseidon2_16() -> Poseidon2BabyBear<16> { + Poseidon2::new( + ExternalLayerConstants::new( + BABYBEAR_RC16_EXTERNAL_INITIAL.to_vec(), + BABYBEAR_RC16_EXTERNAL_FINAL.to_vec(), + ), + BABYBEAR_RC16_INTERNAL.to_vec(), + ) + } + *) + Definition default_babybear_poseidon2_16 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.U64 7 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.path "p3_baby_bear::baby_bear::BabyBearParameters"; + Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.U64 7 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.path "p3_baby_bear::baby_bear::BabyBearParameters"; + Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters" + ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + "to_vec", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_baby_bear::poseidon2::BABYBEAR_RC16_EXTERNAL_INITIAL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + |) + |)) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + "to_vec", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_baby_bear::poseidon2::BABYBEAR_RC16_EXTERNAL_FINAL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + |) + |)) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "to_vec", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_baby_bear::poseidon2::BABYBEAR_RC16_INTERNAL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + |) + |)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_default_babybear_poseidon2_16 : + M.IsFunction.C + "p3_baby_bear::poseidon2::default_babybear_poseidon2_16" + default_babybear_poseidon2_16. + Admitted. + Global Typeclasses Opaque default_babybear_poseidon2_16. + + Definition value_BABYBEAR_RC24_EXTERNAL_INITIAL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_2d_array", + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + Value.Array + [ + Value.Array + [ + Value.Integer IntegerKind.U32 262278199; + Value.Integer IntegerKind.U32 127253399; + Value.Integer IntegerKind.U32 314968988; + Value.Integer IntegerKind.U32 246143118; + Value.Integer IntegerKind.U32 157582794; + Value.Integer IntegerKind.U32 118043943; + Value.Integer IntegerKind.U32 454905424; + Value.Integer IntegerKind.U32 815798990; + Value.Integer IntegerKind.U32 1004040026; + Value.Integer IntegerKind.U32 1773108264; + Value.Integer IntegerKind.U32 1066694495; + Value.Integer IntegerKind.U32 1930780904; + Value.Integer IntegerKind.U32 1180307149; + Value.Integer IntegerKind.U32 1464793095; + Value.Integer IntegerKind.U32 1660766320; + Value.Integer IntegerKind.U32 1389166148; + Value.Integer IntegerKind.U32 343354132; + Value.Integer IntegerKind.U32 1307439985; + Value.Integer IntegerKind.U32 638242172; + Value.Integer IntegerKind.U32 525458520; + Value.Integer IntegerKind.U32 1964135730; + Value.Integer IntegerKind.U32 1751797115; + Value.Integer IntegerKind.U32 1421525369; + Value.Integer IntegerKind.U32 831813382 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 695835963; + Value.Integer IntegerKind.U32 1845603984; + Value.Integer IntegerKind.U32 540703332; + Value.Integer IntegerKind.U32 1333667262; + Value.Integer IntegerKind.U32 1917861751; + Value.Integer IntegerKind.U32 1170029417; + Value.Integer IntegerKind.U32 1989924532; + Value.Integer IntegerKind.U32 1518763784; + Value.Integer IntegerKind.U32 1339793538; + Value.Integer IntegerKind.U32 622609176; + Value.Integer IntegerKind.U32 686842369; + Value.Integer IntegerKind.U32 1737016378; + Value.Integer IntegerKind.U32 1282239129; + Value.Integer IntegerKind.U32 897025192; + Value.Integer IntegerKind.U32 716894289; + Value.Integer IntegerKind.U32 1997503974; + Value.Integer IntegerKind.U32 395622276; + Value.Integer IntegerKind.U32 1201063290; + Value.Integer IntegerKind.U32 1917549072; + Value.Integer IntegerKind.U32 1150912935; + Value.Integer IntegerKind.U32 1687379185; + Value.Integer IntegerKind.U32 1507936940; + Value.Integer IntegerKind.U32 241306552; + Value.Integer IntegerKind.U32 989176635 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 1147522062; + Value.Integer IntegerKind.U32 27129487; + Value.Integer IntegerKind.U32 1257820264; + Value.Integer IntegerKind.U32 142102402; + Value.Integer IntegerKind.U32 217046702; + Value.Integer IntegerKind.U32 1664590951; + Value.Integer IntegerKind.U32 855276054; + Value.Integer IntegerKind.U32 1215259350; + Value.Integer IntegerKind.U32 946500736; + Value.Integer IntegerKind.U32 552696906; + Value.Integer IntegerKind.U32 1424297384; + Value.Integer IntegerKind.U32 538103555; + Value.Integer IntegerKind.U32 1608853840; + Value.Integer IntegerKind.U32 162510541; + Value.Integer IntegerKind.U32 623051854; + Value.Integer IntegerKind.U32 1549062383; + Value.Integer IntegerKind.U32 1908416316; + Value.Integer IntegerKind.U32 1622328571; + Value.Integer IntegerKind.U32 1079030649; + Value.Integer IntegerKind.U32 1584033957; + Value.Integer IntegerKind.U32 1099252725; + Value.Integer IntegerKind.U32 1910423126; + Value.Integer IntegerKind.U32 447555988; + Value.Integer IntegerKind.U32 862495875 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 128479034; + Value.Integer IntegerKind.U32 1587822577; + Value.Integer IntegerKind.U32 608401422; + Value.Integer IntegerKind.U32 1290028279; + Value.Integer IntegerKind.U32 342857858; + Value.Integer IntegerKind.U32 825405577; + Value.Integer IntegerKind.U32 427731030; + Value.Integer IntegerKind.U32 1718628547; + Value.Integer IntegerKind.U32 588764636; + Value.Integer IntegerKind.U32 204228775; + Value.Integer IntegerKind.U32 1454563174; + Value.Integer IntegerKind.U32 1740472809; + Value.Integer IntegerKind.U32 1338899225; + Value.Integer IntegerKind.U32 1269493554; + Value.Integer IntegerKind.U32 53007114; + Value.Integer IntegerKind.U32 1647670797; + Value.Integer IntegerKind.U32 306391314; + Value.Integer IntegerKind.U32 172614232; + Value.Integer IntegerKind.U32 51256176; + Value.Integer IntegerKind.U32 1221257987; + Value.Integer IntegerKind.U32 1239734761; + Value.Integer IntegerKind.U32 273790406; + Value.Integer IntegerKind.U32 1781980094; + Value.Integer IntegerKind.U32 1291790245 + ] + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_BABYBEAR_RC24_EXTERNAL_INITIAL : + M.IsFunction.C + "p3_baby_bear::poseidon2::BABYBEAR_RC24_EXTERNAL_INITIAL" + value_BABYBEAR_RC24_EXTERNAL_INITIAL. + Admitted. + Global Typeclasses Opaque value_BABYBEAR_RC24_EXTERNAL_INITIAL. + + Definition value_BABYBEAR_RC24_EXTERNAL_FINAL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_2d_array", + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + Value.Array + [ + Value.Array + [ + Value.Integer IntegerKind.U32 53041581; + Value.Integer IntegerKind.U32 723038058; + Value.Integer IntegerKind.U32 1439947916; + Value.Integer IntegerKind.U32 1136469704; + Value.Integer IntegerKind.U32 205609311; + Value.Integer IntegerKind.U32 1883820770; + Value.Integer IntegerKind.U32 14387587; + Value.Integer IntegerKind.U32 720724951; + Value.Integer IntegerKind.U32 1854174607; + Value.Integer IntegerKind.U32 1629316321; + Value.Integer IntegerKind.U32 530151394; + Value.Integer IntegerKind.U32 1679178250; + Value.Integer IntegerKind.U32 1549779579; + Value.Integer IntegerKind.U32 48375137; + Value.Integer IntegerKind.U32 976057819; + Value.Integer IntegerKind.U32 463976218; + Value.Integer IntegerKind.U32 875839332; + Value.Integer IntegerKind.U32 1946596189; + Value.Integer IntegerKind.U32 434078361; + Value.Integer IntegerKind.U32 1878280202; + Value.Integer IntegerKind.U32 1363837384; + Value.Integer IntegerKind.U32 1470845646; + Value.Integer IntegerKind.U32 1792450386; + Value.Integer IntegerKind.U32 1040977421 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 1209164052; + Value.Integer IntegerKind.U32 714957516; + Value.Integer IntegerKind.U32 390340387; + Value.Integer IntegerKind.U32 1213686459; + Value.Integer IntegerKind.U32 790726260; + Value.Integer IntegerKind.U32 117294666; + Value.Integer IntegerKind.U32 140621810; + Value.Integer IntegerKind.U32 993455846; + Value.Integer IntegerKind.U32 1889603648; + Value.Integer IntegerKind.U32 78845751; + Value.Integer IntegerKind.U32 925018226; + Value.Integer IntegerKind.U32 708123747; + Value.Integer IntegerKind.U32 1647665372; + Value.Integer IntegerKind.U32 1649953458; + Value.Integer IntegerKind.U32 942439428; + Value.Integer IntegerKind.U32 1006235079; + Value.Integer IntegerKind.U32 238616145; + Value.Integer IntegerKind.U32 930036496; + Value.Integer IntegerKind.U32 1401020792; + Value.Integer IntegerKind.U32 989618631; + Value.Integer IntegerKind.U32 1545325389; + Value.Integer IntegerKind.U32 1715719711; + Value.Integer IntegerKind.U32 755691969; + Value.Integer IntegerKind.U32 150307788 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 1567618575; + Value.Integer IntegerKind.U32 1663353317; + Value.Integer IntegerKind.U32 1950429111; + Value.Integer IntegerKind.U32 1891637550; + Value.Integer IntegerKind.U32 192082241; + Value.Integer IntegerKind.U32 1080533265; + Value.Integer IntegerKind.U32 1463323727; + Value.Integer IntegerKind.U32 890243564; + Value.Integer IntegerKind.U32 158646617; + Value.Integer IntegerKind.U32 1402624179; + Value.Integer IntegerKind.U32 59510015; + Value.Integer IntegerKind.U32 1198261138; + Value.Integer IntegerKind.U32 1065075039; + Value.Integer IntegerKind.U32 1150410028; + Value.Integer IntegerKind.U32 1293938517; + Value.Integer IntegerKind.U32 76770019; + Value.Integer IntegerKind.U32 1478577620; + Value.Integer IntegerKind.U32 1748789933; + Value.Integer IntegerKind.U32 457372011; + Value.Integer IntegerKind.U32 1841795381; + Value.Integer IntegerKind.U32 760115692; + Value.Integer IntegerKind.U32 1042892522; + Value.Integer IntegerKind.U32 1507649755; + Value.Integer IntegerKind.U32 1827572010 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 1206940496; + Value.Integer IntegerKind.U32 1896271507; + Value.Integer IntegerKind.U32 1003792297; + Value.Integer IntegerKind.U32 738091882; + Value.Integer IntegerKind.U32 1124078057; + Value.Integer IntegerKind.U32 1889898; + Value.Integer IntegerKind.U32 813674331; + Value.Integer IntegerKind.U32 228520958; + Value.Integer IntegerKind.U32 1832911930; + Value.Integer IntegerKind.U32 781141772; + Value.Integer IntegerKind.U32 459826664; + Value.Integer IntegerKind.U32 202271745; + Value.Integer IntegerKind.U32 1296144415; + Value.Integer IntegerKind.U32 1111203133; + Value.Integer IntegerKind.U32 1090783436; + Value.Integer IntegerKind.U32 641665156; + Value.Integer IntegerKind.U32 1393671120; + Value.Integer IntegerKind.U32 1303271640; + Value.Integer IntegerKind.U32 809508074; + Value.Integer IntegerKind.U32 162506101; + Value.Integer IntegerKind.U32 1262312258; + Value.Integer IntegerKind.U32 1672219447; + Value.Integer IntegerKind.U32 1608891156; + Value.Integer IntegerKind.U32 1380248020 + ] + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_BABYBEAR_RC24_EXTERNAL_FINAL : + M.IsFunction.C + "p3_baby_bear::poseidon2::BABYBEAR_RC24_EXTERNAL_FINAL" + value_BABYBEAR_RC24_EXTERNAL_FINAL. + Admitted. + Global Typeclasses Opaque value_BABYBEAR_RC24_EXTERNAL_FINAL. + + Definition value_BABYBEAR_RC24_INTERNAL + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 21 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 21 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 497520322; + Value.Integer IntegerKind.U32 1930103076; + Value.Integer IntegerKind.U32 1052077299; + Value.Integer IntegerKind.U32 1540960371; + Value.Integer IntegerKind.U32 924863639; + Value.Integer IntegerKind.U32 1365519753; + Value.Integer IntegerKind.U32 1726563304; + Value.Integer IntegerKind.U32 440300254; + Value.Integer IntegerKind.U32 1891545577; + Value.Integer IntegerKind.U32 822033215; + Value.Integer IntegerKind.U32 1111544260; + Value.Integer IntegerKind.U32 308575117; + Value.Integer IntegerKind.U32 1708681573; + Value.Integer IntegerKind.U32 1240419708; + Value.Integer IntegerKind.U32 1199068823; + Value.Integer IntegerKind.U32 1186174623; + Value.Integer IntegerKind.U32 1551596046; + Value.Integer IntegerKind.U32 1886977120; + Value.Integer IntegerKind.U32 1327682690; + Value.Integer IntegerKind.U32 1210751726; + Value.Integer IntegerKind.U32 1810596765 + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_BABYBEAR_RC24_INTERNAL : + M.IsFunction.C "p3_baby_bear::poseidon2::BABYBEAR_RC24_INTERNAL" value_BABYBEAR_RC24_INTERNAL. + Admitted. + Global Typeclasses Opaque value_BABYBEAR_RC24_INTERNAL. + + (* + pub fn default_babybear_poseidon2_24() -> Poseidon2BabyBear<24> { + Poseidon2::new( + ExternalLayerConstants::new( + BABYBEAR_RC24_EXTERNAL_INITIAL.to_vec(), + BABYBEAR_RC24_EXTERNAL_FINAL.to_vec(), + ), + BABYBEAR_RC24_INTERNAL.to_vec(), + ) + } + *) + Definition default_babybear_poseidon2_24 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.U64 7 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.path "p3_baby_bear::baby_bear::BabyBearParameters"; + Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.U64 7 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.path "p3_baby_bear::baby_bear::BabyBearParameters"; + Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters" + ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + "to_vec", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_baby_bear::poseidon2::BABYBEAR_RC24_EXTERNAL_INITIAL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + |) + |)) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + "to_vec", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_baby_bear::poseidon2::BABYBEAR_RC24_EXTERNAL_FINAL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + |) + |)) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "to_vec", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_baby_bear::poseidon2::BABYBEAR_RC24_INTERNAL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 21 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + |) + |)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_default_babybear_poseidon2_24 : + M.IsFunction.C + "p3_baby_bear::poseidon2::default_babybear_poseidon2_24" + default_babybear_poseidon2_24. + Admitted. + Global Typeclasses Opaque default_babybear_poseidon2_24. + + (* StructTuple + { + name := "BabyBearInternalLayerParameters"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_fmt_Debug_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "BabyBearInternalLayerParameters" |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + + Module Impl_core_clone_Clone_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + + Module Impl_core_default_Default_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + + Module Impl_p3_monty_31_poseidon2_InternalLayerBaseParameters_Usize_16_p3_baby_bear_baby_bear_BabyBearParameters_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters". + + (* type ArrayLike = [MontyField31; 15]; *) + Definition _ArrayLike : Ty.t := + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ]. + + (* const INTERNAL_DIAG_MONTY: [BabyBear; 16] = INTERNAL_DIAG_MONTY_16; *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] *) + Definition value_INTERNAL_DIAG_MONTY + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (get_constant (| + "p3_baby_bear::poseidon2::INTERNAL_DIAG_MONTY_16", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + |))). + + (* + fn internal_layer_mat_mul( + state: &mut [MontyField31; 16], + sum: MontyField31, + ) { + // The diagonal matrix is defined by the vector: + // V = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/2^27, -1/2^8, -1/16, -1/2^27] + state[1] += sum; + state[2] = state[2].double() + sum; + state[3] = state[3].halve() + sum; + state[4] = sum + state[4].double() + state[4]; + state[5] = sum + state[5].double().double(); + state[6] = sum - state[6].halve(); + state[7] = sum - (state[7].double() + state[7]); + state[8] = sum - state[8].double().double(); + state[9] = state[9].div_2exp_u64(8); + state[9] += sum; + state[10] = state[10].div_2exp_u64(2); + state[10] += sum; + state[11] = state[11].div_2exp_u64(3); + state[11] += sum; + state[12] = state[12].div_2exp_u64(27); + state[12] += sum; + state[13] = state[13].div_2exp_u64(8); + state[13] = sum - state[13]; + state[14] = state[14].div_2exp_u64(4); + state[14] = sum - state[14]; + state[15] = state[15].div_2exp_u64(27); + state[15] = sum - state[15]; + } + *) + Definition internal_layer_mat_mul (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ state; sum ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let sum := M.alloc (| sum |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.read (| sum |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.read (| sum |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 5 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 5 + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 6 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 6 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |) + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 8 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 8 + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |) + |); + Value.Integer IntegerKind.U64 8 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |) + |); + Value.Integer IntegerKind.U64 2 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |) + |); + Value.Integer IntegerKind.U64 3 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |) + |); + Value.Integer IntegerKind.U64 27 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |) + |); + Value.Integer IntegerKind.U64 8 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |) + |); + Value.Integer IntegerKind.U64 4 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |) + |); + Value.Integer IntegerKind.U64 27 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn generic_internal_linear_layer>(state: &mut [A; 16]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use multiplication. + // This could probably be improved slightly by making use of the + // mul_2exp_u64 and div_2exp_u64 but this would involve porting div_2exp_u64 to PrimeCharacteristicRing. + state + .iter_mut() + .zip(INTERNAL_DIAG_MONTY_16) + .skip(3) + .for_each(|(val, diag_elem)| { + *val = full_sum.clone() + val.clone() * diag_elem; + }); + } + *) + Definition generic_internal_linear_layer + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ A ], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ part_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + [], + [], + "sum", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + [], + [], + "cloned", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ A ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ A ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| state |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ full_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, part_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Sub", A, [], [ A ], "sub", [], [] |), + [ + M.read (| part_sum |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ A ]; + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + [], + [], + "skip", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.read (| + get_constant (| + "p3_baby_bear::poseidon2::INTERNAL_DIAG_MONTY_16", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 3 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ A ]; + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ + Ty.path + "p3_baby_bear::baby_bear::BabyBearParameters" + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let val := M.copy (| γ0_0 |) in + let diag_elem := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| val |) |), + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Add", + A, + [], + [ A ], + "add", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + Ty.path + "p3_baby_bear::baby_bear::BabyBearParameters" + ] + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| val |) |) + |) + ] + |); + M.read (| diag_elem |) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::poseidon2::InternalLayerBaseParameters" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 16 ] + (* Trait polymorphic types *) [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + Self + (* Instance *) + [ + ("ArrayLike", InstanceField.Ty _ArrayLike); + ("value_INTERNAL_DIAG_MONTY", InstanceField.Method value_INTERNAL_DIAG_MONTY); + ("internal_layer_mat_mul", InstanceField.Method internal_layer_mat_mul); + ("generic_internal_linear_layer", InstanceField.Method generic_internal_linear_layer) + ]. + End Impl_p3_monty_31_poseidon2_InternalLayerBaseParameters_Usize_16_p3_baby_bear_baby_bear_BabyBearParameters_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + + Module Impl_p3_monty_31_poseidon2_InternalLayerBaseParameters_Usize_24_p3_baby_bear_baby_bear_BabyBearParameters_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters". + + (* type ArrayLike = [MontyField31; 23]; *) + Definition _ArrayLike : Ty.t := + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 23 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ]. + + (* const INTERNAL_DIAG_MONTY: [BabyBear; 24] = INTERNAL_DIAG_MONTY_24; *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] *) + Definition value_INTERNAL_DIAG_MONTY + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (get_constant (| + "p3_baby_bear::poseidon2::INTERNAL_DIAG_MONTY_24", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + |))). + + (* + fn internal_layer_mat_mul( + state: &mut [MontyField31; 24], + sum: MontyField31, + ) { + // The diagonal matrix is defined by the vector: + // V = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/2^7, 1/2^9, 1/2^27, -1/2^8, -1/4, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^27] + state[1] += sum; + state[2] = state[2].double() + sum; + state[3] = state[3].halve() + sum; + state[4] = sum + state[4].double() + state[4]; + state[5] = sum + state[5].double().double(); + state[6] = sum - state[6].halve(); + state[7] = sum - (state[7].double() + state[7]); + state[8] = sum - state[8].double().double(); + state[9] = state[9].div_2exp_u64(8); + state[9] += sum; + state[10] = state[10].div_2exp_u64(2); + state[10] += sum; + state[11] = state[11].div_2exp_u64(3); + state[11] += sum; + state[12] = state[12].div_2exp_u64(4); + state[12] += sum; + state[13] = state[13].div_2exp_u64(7); + state[13] += sum; + state[14] = state[14].div_2exp_u64(9); + state[14] += sum; + state[15] = state[15].div_2exp_u64(27); + state[15] += sum; + state[16] = state[16].div_2exp_u64(8); + state[16] = sum - state[16]; + state[17] = state[17].div_2exp_u64(2); + state[17] = sum - state[17]; + state[18] = state[18].div_2exp_u64(3); + state[18] = sum - state[18]; + state[19] = state[19].div_2exp_u64(4); + state[19] = sum - state[19]; + state[20] = state[20].div_2exp_u64(5); + state[20] = sum - state[20]; + state[21] = state[21].div_2exp_u64(6); + state[21] = sum - state[21]; + state[22] = state[22].div_2exp_u64(7); + state[22] = sum - state[22]; + state[23] = state[23].div_2exp_u64(27); + state[23] = sum - state[23]; + } + *) + Definition internal_layer_mat_mul (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ state; sum ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let sum := M.alloc (| sum |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.read (| sum |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.read (| sum |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 5 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 5 + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 6 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 6 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |) + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 8 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 8 + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |) + |); + Value.Integer IntegerKind.U64 8 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |) + |); + Value.Integer IntegerKind.U64 2 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |) + |); + Value.Integer IntegerKind.U64 3 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |) + |); + Value.Integer IntegerKind.U64 4 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |) + |); + Value.Integer IntegerKind.U64 7 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |) + |); + Value.Integer IntegerKind.U64 9 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |) + |); + Value.Integer IntegerKind.U64 27 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 16 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 16 + |) + |); + Value.Integer IntegerKind.U64 8 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 16 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 16 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 17 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 17 + |) + |); + Value.Integer IntegerKind.U64 2 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 17 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 17 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 18 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 18 + |) + |); + Value.Integer IntegerKind.U64 3 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 18 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 18 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 19 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 19 + |) + |); + Value.Integer IntegerKind.U64 4 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 19 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 19 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 20 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 20 + |) + |); + Value.Integer IntegerKind.U64 5 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 20 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 20 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 21 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 21 + |) + |); + Value.Integer IntegerKind.U64 6 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 21 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 21 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 22 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 22 + |) + |); + Value.Integer IntegerKind.U64 7 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 22 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 22 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 23 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 23 + |) + |); + Value.Integer IntegerKind.U64 27 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 23 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 23 + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn generic_internal_linear_layer>(state: &mut [A; 24]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use multiplication. + // This could probably be improved slightly by making use of the + // mul_2exp_u64 and div_2exp_u64 but this would involve porting div_2exp_u64 to PrimeCharacteristicRing. + state + .iter_mut() + .zip(INTERNAL_DIAG_MONTY_24) + .skip(3) + .for_each(|(val, diag_elem)| { + *val = full_sum.clone() + val.clone() * diag_elem; + }); + } + *) + Definition generic_internal_linear_layer + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ A ], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ part_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + [], + [], + "sum", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + [], + [], + "cloned", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ A ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ A ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| state |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ full_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, part_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Sub", A, [], [ A ], "sub", [], [] |), + [ + M.read (| part_sum |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ A ]; + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + [], + [], + "skip", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.read (| + get_constant (| + "p3_baby_bear::poseidon2::INTERNAL_DIAG_MONTY_24", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + ] + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 3 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ A ]; + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ + Ty.path + "p3_baby_bear::baby_bear::BabyBearParameters" + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let val := M.copy (| γ0_0 |) in + let diag_elem := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| val |) |), + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Add", + A, + [], + [ A ], + "add", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + Ty.path + "p3_baby_bear::baby_bear::BabyBearParameters" + ] + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| val |) |) + |) + ] + |); + M.read (| diag_elem |) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::poseidon2::InternalLayerBaseParameters" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 24 ] + (* Trait polymorphic types *) [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + Self + (* Instance *) + [ + ("ArrayLike", InstanceField.Ty _ArrayLike); + ("value_INTERNAL_DIAG_MONTY", InstanceField.Method value_INTERNAL_DIAG_MONTY); + ("internal_layer_mat_mul", InstanceField.Method internal_layer_mat_mul); + ("generic_internal_linear_layer", InstanceField.Method generic_internal_linear_layer) + ]. + End Impl_p3_monty_31_poseidon2_InternalLayerBaseParameters_Usize_24_p3_baby_bear_baby_bear_BabyBearParameters_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + + Module Impl_p3_monty_31_poseidon2_InternalLayerParameters_Usize_16_p3_baby_bear_baby_bear_BabyBearParameters_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters". + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::poseidon2::InternalLayerParameters" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 16 ] + (* Trait polymorphic types *) [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + Self + (* Instance *) []. + End Impl_p3_monty_31_poseidon2_InternalLayerParameters_Usize_16_p3_baby_bear_baby_bear_BabyBearParameters_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + + Module Impl_p3_monty_31_poseidon2_InternalLayerParameters_Usize_24_p3_baby_bear_baby_bear_BabyBearParameters_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_baby_bear::poseidon2::BabyBearInternalLayerParameters". + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::poseidon2::InternalLayerParameters" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 24 ] + (* Trait polymorphic types *) [ Ty.path "p3_baby_bear::baby_bear::BabyBearParameters" ] + Self + (* Instance *) []. + End Impl_p3_monty_31_poseidon2_InternalLayerParameters_Usize_24_p3_baby_bear_baby_bear_BabyBearParameters_for_p3_baby_bear_poseidon2_BabyBearInternalLayerParameters. +End poseidon2. diff --git a/CoqOfRust/plonky3/baby-bear/src/x86_64_avx2/mod.rs b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx2/mod.rs new file mode 100644 index 000000000..d47a7ccc5 --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx2/mod.rs @@ -0,0 +1,4 @@ +mod packing; +mod poseidon2; + +pub use packing::*; diff --git a/CoqOfRust/plonky3/baby-bear/src/x86_64_avx2/packing.rs b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx2/packing.rs new file mode 100644 index 000000000..b77adfe05 --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx2/packing.rs @@ -0,0 +1,35 @@ +use core::arch::x86_64::__m256i; +use core::mem::transmute; + +use p3_monty_31::{MontyParametersAVX2, PackedMontyField31AVX2}; + +use crate::BabyBearParameters; + +pub type PackedBabyBearAVX2 = PackedMontyField31AVX2; + +const WIDTH: usize = 8; + +impl MontyParametersAVX2 for BabyBearParameters { + const PACKED_P: __m256i = unsafe { transmute::<[u32; WIDTH], _>([0x78000001; WIDTH]) }; + const PACKED_MU: __m256i = unsafe { transmute::<[u32; WIDTH], _>([0x88000001; WIDTH]) }; +} + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::WIDTH; + use crate::BabyBear; + + const SPECIAL_VALS: [BabyBear; WIDTH] = BabyBear::new_array([ + 0x00000000, 0x00000001, 0x78000000, 0x77ffffff, 0x3c000000, 0x0ffffffe, 0x68000003, + 0x70000002, + ]); + + test_packed_field!( + crate::PackedBabyBearAVX2, + &[crate::PackedBabyBearAVX2::ZERO], + &[crate::PackedBabyBearAVX2::ONE], + p3_monty_31::PackedMontyField31AVX2::(super::SPECIAL_VALS) + ); +} diff --git a/CoqOfRust/plonky3/baby-bear/src/x86_64_avx2/poseidon2.rs b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx2/poseidon2.rs new file mode 100644 index 000000000..79e784b89 --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx2/poseidon2.rs @@ -0,0 +1,170 @@ +use core::arch::x86_64::__m256i; + +use p3_monty_31::{ + InternalLayerParametersAVX2, mul_2exp_neg_8_avx2, mul_2exp_neg_n_avx2, + mul_2exp_neg_two_adicity_avx2, mul_neg_2exp_neg_8_avx2, mul_neg_2exp_neg_n_avx2, + mul_neg_2exp_neg_two_adicity_avx2, +}; + +use crate::{BabyBearInternalLayerParameters, BabyBearParameters}; + +impl InternalLayerParametersAVX2 for BabyBearInternalLayerParameters { + type ArrayLike = [__m256i; 15]; + + /// For the BabyBear field and width 16 we multiply by the diagonal matrix: + /// + /// D = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/2^27, -1/2^8, -1/16, -1/2^27]. + /// The first 9 entries are handled elsewhere, this function handles all the positive/negative inverse powers of two. + /// The inputs must be in canonical form, otherwise the result is undefined. + /// Even when the inputs are in canonical form, we make no guarantees on the output except that, provided + /// the output is piped directly into add_sum the vector will be modified such that x[i] = D[i]*x[i] + sum. + #[inline(always)] + unsafe fn diagonal_mul_remainder(input: &mut [__m256i; 15]) { + unsafe { + // As far as we know this is optimal in that it need the fewest instructions to perform all of these + // multiplications. (Note that -1, 0 are not allowed on the diagonal for technical reasons). + // If there exist other numbers b for which x*b mod P can be computed quickly this diagonal can be updated. + + // input[8] -> sum + input[8]/2**8 + input[8] = mul_2exp_neg_8_avx2::(input[8]); + + // input[9] -> sum + input[9]/2**2 + input[9] = mul_2exp_neg_n_avx2::(input[9]); + + // input[10] -> sum + input[10]/2**3 + input[10] = mul_2exp_neg_n_avx2::(input[10]); + + // input[11] -> sum + input[11]/2**27 + input[11] = mul_2exp_neg_two_adicity_avx2::(input[11]); + + // input[12] -> sum - input[12]/2**8 + input[12] = mul_neg_2exp_neg_8_avx2::(input[12]); + + // input[13] -> sum - input[13]/2**4 + input[13] = mul_neg_2exp_neg_n_avx2::(input[13]); + + // input[14] -> sum - input[14]/2**27 + input[14] = mul_neg_2exp_neg_two_adicity_avx2::(input[14]); + } + } +} + +impl InternalLayerParametersAVX2 for BabyBearInternalLayerParameters { + type ArrayLike = [__m256i; 23]; + + /// For the BabyBear field and width 24 we multiply by the diagonal matrix: + /// + /// D = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/2^7, 1/2^9, 1/2^27, -1/2^8, -1/4, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^27] + /// The first 9 entries are handled elsewhere, this function handles all the positive/negative inverse powers of two. + /// The inputs must be in canonical form, otherwise the result is undefined. + /// Even when the inputs are in canonical form, we make no guarantees on the output except that, provided + /// the output is piped directly into add_sum, the vector will be modified such that x[i] = D[i]*x[i] + sum. + #[inline(always)] + unsafe fn diagonal_mul_remainder(input: &mut [__m256i; 23]) { + unsafe { + // As far as we know this is optimal in that it need the fewest instructions to perform all of these + // multiplications. (Note that -1, 0 are not allowed on the diagonal for technical reasons). + // If there exist other number b for which x*b mod P can be computed quickly this diagonal can be updated. + + // input[8] -> sum + input[8]/2**8 + input[8] = mul_2exp_neg_8_avx2::(input[8]); + + // input[9] -> sum + input[9]/2**2 + input[9] = mul_2exp_neg_n_avx2::(input[9]); + + // input[10] -> sum + input[10]/2**3 + input[10] = mul_2exp_neg_n_avx2::(input[10]); + + // input[11] -> sum + input[11]/2**4 + input[11] = mul_2exp_neg_n_avx2::(input[11]); + + // input[12] -> sum + input[12]/2**7 + input[12] = mul_2exp_neg_n_avx2::(input[12]); + + // input[13] -> sum + input[13]/2**9 + input[13] = mul_2exp_neg_n_avx2::(input[13]); + + // input[14] -> sum + input[14]/2**27 + input[14] = mul_2exp_neg_two_adicity_avx2::(input[14]); + + // input[15] -> sum - input[15]/2**8 + input[15] = mul_neg_2exp_neg_8_avx2::(input[15]); + + // input[16] -> sum - input[16]/2**2 + input[16] = mul_neg_2exp_neg_n_avx2::(input[16]); + + // input[17] -> sum - input[17]/2**3 + input[17] = mul_neg_2exp_neg_n_avx2::(input[17]); + + // input[18] -> sum - input[18]/2**4 + input[18] = mul_neg_2exp_neg_n_avx2::(input[18]); + + // input[19] -> sum - input[19]/2**5 + input[19] = mul_neg_2exp_neg_n_avx2::(input[19]); + + // input[20] -> sum - input[20]/2**6 + input[20] = mul_neg_2exp_neg_n_avx2::(input[20]); + + // input[21] -> sum - input[21]/2**7 + input[21] = mul_neg_2exp_neg_n_avx2::(input[21]); + + // input[22] -> sum - input[22]/2**27 + input[22] = mul_neg_2exp_neg_two_adicity_avx2::(input[22]); + } + } +} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use crate::{BabyBear, PackedBabyBearAVX2, Poseidon2BabyBear}; + + type F = BabyBear; + type Perm16 = Poseidon2BabyBear<16>; + type Perm24 = Poseidon2BabyBear<24>; + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_avx2_poseidon2_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm16::new_from_rng_128(&mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + + assert_eq!(avx2_output, expected); + } + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_avx2_poseidon2_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm24::new_from_rng_128(&mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + + assert_eq!(avx2_output, expected); + } +} diff --git a/CoqOfRust/plonky3/baby-bear/src/x86_64_avx512/mod.rs b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx512/mod.rs new file mode 100644 index 000000000..d47a7ccc5 --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx512/mod.rs @@ -0,0 +1,4 @@ +mod packing; +mod poseidon2; + +pub use packing::*; diff --git a/CoqOfRust/plonky3/baby-bear/src/x86_64_avx512/packing.rs b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx512/packing.rs new file mode 100644 index 000000000..dc9fd7855 --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx512/packing.rs @@ -0,0 +1,36 @@ +use core::arch::x86_64::__m512i; +use core::mem::transmute; + +use p3_monty_31::{MontyParametersAVX512, PackedMontyField31AVX512}; + +use crate::BabyBearParameters; + +pub type PackedBabyBearAVX512 = PackedMontyField31AVX512; + +const WIDTH: usize = 16; + +impl MontyParametersAVX512 for BabyBearParameters { + const PACKED_P: __m512i = unsafe { transmute::<[u32; WIDTH], _>([0x78000001; WIDTH]) }; + const PACKED_MU: __m512i = unsafe { transmute::<[u32; WIDTH], _>([0x88000001; WIDTH]) }; +} + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::WIDTH; + use crate::BabyBear; + + const SPECIAL_VALS: [BabyBear; WIDTH] = BabyBear::new_array([ + 0x00000000, 0x00000001, 0x78000000, 0x77ffffff, 0x3c000000, 0x0ffffffe, 0x68000003, + 0x70000002, 0x00000000, 0x00000001, 0x78000000, 0x77ffffff, 0x3c000000, 0x0ffffffe, + 0x68000003, 0x70000002, + ]); + + test_packed_field!( + crate::PackedBabyBearAVX512, + &[crate::PackedBabyBearAVX512::ZERO], + &[crate::PackedBabyBearAVX512::ONE], + p3_monty_31::PackedMontyField31AVX512::(super::SPECIAL_VALS) + ); +} diff --git a/CoqOfRust/plonky3/baby-bear/src/x86_64_avx512/poseidon2.rs b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx512/poseidon2.rs new file mode 100644 index 000000000..da0f6a9fa --- /dev/null +++ b/CoqOfRust/plonky3/baby-bear/src/x86_64_avx512/poseidon2.rs @@ -0,0 +1,181 @@ +use core::arch::x86_64::__m512i; + +use p3_monty_31::{ + InternalLayerParametersAVX512, mul_neg_2exp_neg_8_avx512, mul_neg_2exp_neg_n_avx512, + mul_neg_2exp_neg_two_adicity_avx512, +}; + +use crate::{BabyBearInternalLayerParameters, BabyBearParameters}; + +impl InternalLayerParametersAVX512 for BabyBearInternalLayerParameters { + type ArrayLike = [__m512i; 15]; + + /// For the BabyBear field and width 16 we multiply by the diagonal matrix: + /// D = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/2^27, -1/2^8, -1/16, -1/2^27]. + /// The inputs must be in canonical form, otherwise the result is undefined. + /// Even when the inputs are in canonical form, we make no guarantees on the output except that, provided + /// the output is piped directly into add_sum the vector will be modified such that x[i] = D[i]*x[i] + sum. + #[inline(always)] + unsafe fn diagonal_mul_remainder(input: &mut [__m512i; 15]) { + unsafe { + // As far as we know this is optimal in that it need the fewest instructions to perform all of these + // multiplications. (Note that -1, 0 are not allowed on the diagonal for technical reasons). + // If there exist other numbers b for which x*b mod P can be computed quickly this diagonal can be updated. + + // This following 4 muls (from input[8] to input[11]) output the negative of what we want. + // This will be handled in add_sum. + + // input[8] -> sum + input[8]/2**8 + input[8] = mul_neg_2exp_neg_8_avx512::(input[8]); + + // input[9] -> sum + input[9]/2**2 + input[9] = mul_neg_2exp_neg_n_avx512::(input[9]); + + // input[10] -> sum + input[10]/2**3 + input[10] = mul_neg_2exp_neg_n_avx512::(input[10]); + + // input[11] -> sum + input[11]/2**27 + input[11] = mul_neg_2exp_neg_two_adicity_avx512::(input[11]); + + // The remaining muls output the correct value again. + + // input[12] -> sum - input[12]/2**8 + input[12] = mul_neg_2exp_neg_8_avx512::(input[12]); + + // input[13] -> sum - input[13]/2**4 + input[13] = mul_neg_2exp_neg_n_avx512::(input[13]); + + // input[14] -> sum - input[14]/2**27 + input[14] = mul_neg_2exp_neg_two_adicity_avx512::(input[14]); + } + } + + /// There are 4 positive inverse powers of two after the 4: 1/2^8, 1/4, 1/8, 1/2^27. + const NUM_POS: usize = 4; +} + +impl InternalLayerParametersAVX512 for BabyBearInternalLayerParameters { + type ArrayLike = [__m512i; 23]; + + /// For the BabyBear field and width 24 we multiply by the diagonal matrix: + /// D = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/2^7, 1/2^9, 1/2^27, -1/2^8, -1/4, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^27] + /// The inputs must be in canonical form, otherwise the result is undefined. + /// Even when the inputs are in canonical form, we make no guarantees on the output except that, provided + /// the output is piped directly into add_sum, the vector will be modified such that x[i] = D[i]*x[i] + sum. + #[inline(always)] + unsafe fn diagonal_mul_remainder(input: &mut [__m512i; 23]) { + unsafe { + // As far as we know this is optimal in that it need the fewest instructions to perform all of these + // multiplications. (Note that -1, 0 are not allowed on the diagonal for technical reasons). + // If there exist other number b for which x*b mod P can be computed quickly this diagonal can be updated. + + // This following 7 muls (from input[8] to input[14]) output the negative of what we want. + // This will be handled in add_sum. + + // input[8] -> sum + input[8]/2**8 + input[8] = mul_neg_2exp_neg_8_avx512::(input[8]); + + // input[9] -> sum + input[9]/2**2 + input[9] = mul_neg_2exp_neg_n_avx512::(input[9]); + + // input[10] -> sum + input[10]/2**3 + input[10] = mul_neg_2exp_neg_n_avx512::(input[10]); + + // input[11] -> sum + input[11]/2**4 + input[11] = mul_neg_2exp_neg_n_avx512::(input[11]); + + // input[12] -> sum + input[12]/2**7 + input[12] = mul_neg_2exp_neg_n_avx512::(input[12]); + + // input[13] -> sum + input[13]/2**9 + input[13] = mul_neg_2exp_neg_n_avx512::(input[13]); + + // input[14] -> sum + input[14]/2**27 + input[14] = mul_neg_2exp_neg_two_adicity_avx512::(input[14]); + + // The remaining muls output the correct value again. + + // input[15] -> sum - input[15]/2**8 + input[15] = mul_neg_2exp_neg_8_avx512::(input[15]); + + // input[16] -> sum - input[16]/2**2 + input[16] = mul_neg_2exp_neg_n_avx512::(input[16]); + + // input[17] -> sum - input[17]/2**3 + input[17] = mul_neg_2exp_neg_n_avx512::(input[17]); + + // input[18] -> sum - input[18]/2**4 + input[18] = mul_neg_2exp_neg_n_avx512::(input[18]); + + // input[19] -> sum - input[19]/2**5 + input[19] = mul_neg_2exp_neg_n_avx512::(input[19]); + + // input[20] -> sum - input[20]/2**6 + input[20] = mul_neg_2exp_neg_n_avx512::(input[20]); + + // input[21] -> sum - input[21]/2**7 + input[21] = mul_neg_2exp_neg_n_avx512::(input[21]); + + // input[22] -> sum - input[22]/2**27 + input[22] = mul_neg_2exp_neg_two_adicity_avx512::(input[22]); + } + } + + /// There are 7 positive inverse powers of two after the 4: 1/2^8, 1/4, 1/8, 1/16, 1/2^7, 1/2^9, 1/2^27,. + const NUM_POS: usize = 7; +} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use crate::{BabyBear, PackedBabyBearAVX512, Poseidon2BabyBear}; + + type F = BabyBear; + type Perm16 = Poseidon2BabyBear<16>; + type Perm24 = Poseidon2BabyBear<24>; + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_avx512_poseidon2_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm16::new_from_rng_128(&mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx512_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx512_input); + + let avx512_output = avx512_input.map(|x| x.0[0]); + + assert_eq!(avx512_output, expected); + } + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_avx512_poseidon2_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm24::new_from_rng_128(&mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx512_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx512_input); + + let avx512_output = avx512_input.map(|x| x.0[0]); + + assert_eq!(avx512_output, expected); + } +} diff --git a/CoqOfRust/plonky3/blake3/src/lib.rs b/CoqOfRust/plonky3/blake3/src/lib.rs new file mode 100644 index 000000000..ffcde5a28 --- /dev/null +++ b/CoqOfRust/plonky3/blake3/src/lib.rs @@ -0,0 +1,34 @@ +//! The blake3 hash function. + +#![no_std] + +use p3_symmetric::CryptographicHasher; + +/// The blake3 hash function. +#[derive(Copy, Clone, Debug)] +pub struct Blake3; + +impl CryptographicHasher for Blake3 { + fn hash_iter(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + const BUFLEN: usize = 512; // Tweakable parameter; determined by experiment + let mut hasher = blake3::Hasher::new(); + p3_util::apply_to_chunks::(input, |buf| { + hasher.update(buf); + }); + hasher.finalize().into() + } + + fn hash_iter_slices<'a, I>(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + let mut hasher = blake3::Hasher::new(); + for chunk in input { + hasher.update(chunk); + } + hasher.finalize().into() + } +} diff --git a/CoqOfRust/plonky3/blake3/src/lib.v b/CoqOfRust/plonky3/blake3/src/lib.v new file mode 100644 index 000000000..88574108a --- /dev/null +++ b/CoqOfRust/plonky3/blake3/src/lib.v @@ -0,0 +1,411 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +(* StructTuple + { + name := "Blake3"; + const_params := []; + ty_params := []; + fields := []; + } *) + +Module Impl_core_marker_Copy_for_p3_blake3_Blake3. + Definition Self : Ty.t := Ty.path "p3_blake3::Blake3". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. +End Impl_core_marker_Copy_for_p3_blake3_Blake3. + +Module Impl_core_clone_Clone_for_p3_blake3_Blake3. + Definition Self : Ty.t := Ty.path "p3_blake3::Blake3". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. +End Impl_core_clone_Clone_for_p3_blake3_Blake3. + +Module Impl_core_fmt_Debug_for_p3_blake3_Blake3. + Definition Self : Ty.t := Ty.path "p3_blake3::Blake3". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Blake3" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. +End Impl_core_fmt_Debug_for_p3_blake3_Blake3. + +Module Impl_p3_symmetric_hasher_CryptographicHasher_u8_array_Usize_32_u8_for_p3_blake3_Blake3. + Definition Self : Ty.t := Ty.path "p3_blake3::Blake3". + + (* + fn hash_iter(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + const BUFLEN: usize = 512; // Tweakable parameter; determined by experiment + let mut hasher = blake3::Hasher::new(); + p3_util::apply_to_chunks::(input, |buf| { + hasher.update(buf); + }); + hasher.finalize().into() + } + *) + Definition hash_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ hasher : Ty.apply (Ty.path "*") [] [ Ty.path "blake3::Hasher" ] := + M.alloc (| + M.call_closure (| + Ty.path "blake3::Hasher", + M.get_associated_function (| Ty.path "blake3::Hasher", "new", [], [] |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::apply_to_chunks", + [ Value.Integer IntegerKind.Usize 512 ], + [ + I; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let buf := M.copy (| γ |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "blake3::Hasher" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "blake3::Hasher" ], + M.get_associated_function (| + Ty.path "blake3::Hasher", + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, hasher |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| buf |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ], + M.get_trait_method (| + "core::convert::Into", + Ty.path "blake3::Hash", + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "blake3::Hash", + M.get_associated_function (| Ty.path "blake3::Hasher", "finalize", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, hasher |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn hash_iter_slices<'a, I>(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + let mut hasher = blake3::Hasher::new(); + for chunk in input { + hasher.update(chunk); + } + hasher.finalize().into() + } + *) + Definition hash_iter_slices (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ hasher : Ty.apply (Ty.path "*") [] [ Ty.path "blake3::Hasher" ] := + M.alloc (| + M.call_closure (| + Ty.path "blake3::Hasher", + M.get_associated_function (| Ty.path "blake3::Hasher", "new", [], [] |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let chunk := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "blake3::Hasher" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.path "blake3::Hasher" ], + M.get_associated_function (| + Ty.path "blake3::Hasher", + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, hasher |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| chunk |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ], + M.get_trait_method (| + "core::convert::Into", + Ty.path "blake3::Hash", + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "blake3::Hash", + M.get_associated_function (| Ty.path "blake3::Hasher", "finalize", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, hasher |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::hasher::CryptographicHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.path "u8"; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ] + Self + (* Instance *) + [ + ("hash_iter", InstanceField.Method hash_iter); + ("hash_iter_slices", InstanceField.Method hash_iter_slices) + ]. +End Impl_p3_symmetric_hasher_CryptographicHasher_u8_array_Usize_32_u8_for_p3_blake3_Blake3. diff --git a/CoqOfRust/plonky3/blake3-air/air.rs b/CoqOfRust/plonky3/blake3_air/air.rs similarity index 100% rename from CoqOfRust/plonky3/blake3-air/air.rs rename to CoqOfRust/plonky3/blake3_air/air.rs diff --git a/CoqOfRust/plonky3/blake3-air/air.v b/CoqOfRust/plonky3/blake3_air/air.v similarity index 100% rename from CoqOfRust/plonky3/blake3-air/air.v rename to CoqOfRust/plonky3/blake3_air/air.v diff --git a/CoqOfRust/plonky3/blake3-air/columns.rs b/CoqOfRust/plonky3/blake3_air/columns.rs similarity index 100% rename from CoqOfRust/plonky3/blake3-air/columns.rs rename to CoqOfRust/plonky3/blake3_air/columns.rs diff --git a/CoqOfRust/plonky3/blake3-air/columns.v b/CoqOfRust/plonky3/blake3_air/columns.v similarity index 100% rename from CoqOfRust/plonky3/blake3-air/columns.v rename to CoqOfRust/plonky3/blake3_air/columns.v diff --git a/CoqOfRust/plonky3/blake3-air/constants.rs b/CoqOfRust/plonky3/blake3_air/constants.rs similarity index 100% rename from CoqOfRust/plonky3/blake3-air/constants.rs rename to CoqOfRust/plonky3/blake3_air/constants.rs diff --git a/CoqOfRust/plonky3/blake3-air/constants.v b/CoqOfRust/plonky3/blake3_air/constants.v similarity index 100% rename from CoqOfRust/plonky3/blake3-air/constants.v rename to CoqOfRust/plonky3/blake3_air/constants.v diff --git a/CoqOfRust/plonky3/blake3-air/generation.rs b/CoqOfRust/plonky3/blake3_air/generation.rs similarity index 100% rename from CoqOfRust/plonky3/blake3-air/generation.rs rename to CoqOfRust/plonky3/blake3_air/generation.rs diff --git a/CoqOfRust/plonky3/blake3-air/generation.v b/CoqOfRust/plonky3/blake3_air/generation.v similarity index 100% rename from CoqOfRust/plonky3/blake3-air/generation.v rename to CoqOfRust/plonky3/blake3_air/generation.v diff --git a/CoqOfRust/plonky3/blake3-air/lib.rs b/CoqOfRust/plonky3/blake3_air/lib.rs similarity index 100% rename from CoqOfRust/plonky3/blake3-air/lib.rs rename to CoqOfRust/plonky3/blake3_air/lib.rs diff --git a/CoqOfRust/plonky3/blake3_air/links/air.v b/CoqOfRust/plonky3/blake3_air/links/air.v new file mode 100644 index 000000000..1567ef4d9 --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/links/air.v @@ -0,0 +1,185 @@ +Require Import CoqOfRust.CoqOfRust. +Require Import CoqOfRust.links.M. +Require Import plonky3.blake3_air.air. +Require Import plonky3.field.links.field. +Require Import plonky3.blake3_air.links.columns. +Require Import plonky3.air.links.air. +Require Import plonky3.matrix.links.dense. + +(* +TODO: +- Move all files under `src` to their parent files for consistency +- In future, refer to `gas` to deal with different impls +- In future, for all dependencies, fix their type path to actual path that starts with `p_3` +- Check if AirBuilder needs `AB_types` +*) + +(* pub struct Blake3Air {} *) +Module Blake3Air. + Record t : Set := {}. + + Parameter to_value : t -> Value.t. + + Global Instance IsLink : Link t := { + (* TODO: fix path here *) + Φ := Ty.path "plonky3::blake3_air::air::Blake3Air"; + φ := to_value; + }. + + Definition of_ty : OfTy.t (Ty.path "plonky3::blake3_air::air::Blake3Air"). + Proof. eapply OfTy.Make with (A := t); reflexivity. Defined. + Smpl Add apply of_ty : of_ty. +End Blake3Air. + +Module Impl_Blake3Air. + Definition Self := Blake3Air.t. + (* + impl Blake3Air { + pub fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + *) + Instance run_generate_trace_rows + {F : Set} `{Link F} + {run_PrimeField64_for_F : PrimeField64.Run F} + (self : Ref.t Pointer.Kind.Ref Self) (num_hashes : Usize.t) (extra_capacity_bits : Usize.t) : + Run.Trait + blake3_air.air.air.Impl_p3_blake3_air_air_Blake3Air.generate_trace_rows [] [ Φ F ] [ φ num_hashes; φ extra_capacity_bits ] + (RowMajorMatrix.t F). + Proof. + constructor. + run_symbolic. + Admitted. + + (* + fn quarter_round_function( + &self, + builder: &mut AB, + trace: &QuarterRound<::Var, ::Expr>, + ) + *) + Instance run_quarter_round_function + {AB : Set} `{Link AB} + {run_AirBuilder_for_AB : AirBuilder.Run AB} + (* TODO: check if AirBuilder needs `AB_types` *) + (self : Ref.t Pointer.Kind.Ref Self) + (builder : Ref.t Pointer.Kind.MutRef AB) + (* TODO: translate `trace: &QuarterRound<::Var, ::Expr>` *) + (trace : Set) + : + Run.Trait + blake3_air.air.air.Impl_p3_blake3_air_air_Blake3Air.quarter_round_function [] [ Φ AB ] [ φ builder (* ; φ trace *) ] + unit. + Proof. + constructor. + run_symbolic. + Admitted. + + (* + const fn full_round_to_column_quarter_round<'a, T: Copy, U>( + &self, + input: &'a Blake3State, + round_data: &'a FullRound, + m_vector: &'a [[U; 2]; 16], + index: usize, + ) -> QuarterRound<'a, T, U> + *) + Instance run_full_round_to_column_quarter_round + (* NOTE: seems like there are some issues with T and U being defined here *) + {T U : Set} `{Link T} `{Link U} + (self : Ref.t Pointer.Kind.Ref Self) + (input : Ref.t Pointer.Kind.Ref (Blake3State.t T)) + (round_data : Ref.t Pointer.Kind.Ref (FullRound.t T)) + (m_vector : list (list U)) + (index : Usize.t) + : + Run.Trait + blake3_air.air.air.Impl_p3_blake3_air_air_Blake3Air.full_round_to_column_quarter_round [] [ Φ T; Φ U ] + [ (* φ input; φ round_data; φ m_vector; φ index *) ] + (QuarterRound.t T U). + Proof. + constructor. + run_symbolic. + Admitted. + + (* + const fn full_round_to_diagonal_quarter_round<'a, T: Copy, U>( + &self, + round_data: &'a FullRound, + m_vector: &'a [[U; 2]; 16], + index: usize, + ) -> QuarterRound<'a, T, U> + *) + Instance run_full_round_to_diagonal_quarter_round + {T U : Set} `{Link T} `{Link U} + (self : Ref.t Pointer.Kind.Ref Self) + (round_data : Ref.t Pointer.Kind.Ref (FullRound.t T)) + (m_vector : list (list U)) + (index : Usize.t) + : + Run.Trait + blake3_air.air.air.Impl_p3_blake3_air_air_Blake3Air.full_round_to_diagonal_quarter_round [] [ Φ T; Φ U ] + [ (* φ input; φ round_data; φ m_vector; φ index *) ] + (QuarterRound.t T U). + Proof. + constructor. + run_symbolic. + Admitted. + + (* + fn verify_round( + &self, + builder: &mut AB, + input: &Blake3State, + round_data: &FullRound, + m_vector: &[[AB::Expr; 2]; 16], + ) + *) + Instance run_verify_round + {AB : Set} `{Link AB} + {run_AirBuilder_for_AB : AirBuilder.Run AB} + (self : Ref.t Pointer.Kind.Ref Self) + (builder : Ref.t Pointer.Kind.MutRef AB) + (* TODO: translate correctly the following variables *) + (* (input : Ref.t Pointer.Kind.Ref Blake3State.t (AB.Var)) *) + (* (round_data : Ref.t Pointer.Kind.Ref FullRound (AB.Var)) *) + (* (m_vector : list (list Set)) *) + : + Run.Trait + blake3_air.air.air.Impl_p3_blake3_air_air_Blake3Air.verify_round [] [ Φ AB ] + [ φ builder (* ; φ input; φ round_data; φ m_vector *) ] + unit. + Proof. + constructor. + run_symbolic. + Admitted. +End Impl_Blake3Air. + +(* +impl BaseAir for Blake3Air { + fn width(&self) -> usize { + NUM_BLAKE3_COLS + } +} +*) +Module Impl_BaseAir_for_Blake3Air. + Definition Self : Set := + Blake3Air.t. + + (* Instance run : BaseAir.Run Self. *) + (* Admitted. *) +End Impl_BaseAir_for_Blake3Air. + +(* +impl Air for Blake3Air { + fn eval(&self, builder: &mut AB) +*) +Module Impl_Air_for_Blake3Air. + Definition Self : Set := + Blake3Air.t. + + (* Instance run : Air.Run Self. *) + (* Admitted. *) +End Impl_Air_for_Blake3Air. diff --git a/CoqOfRust/plonky3/blake3_air/links/columns.v b/CoqOfRust/plonky3/blake3_air/links/columns.v new file mode 100644 index 000000000..774302ac5 --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/links/columns.v @@ -0,0 +1,120 @@ +Require Import CoqOfRust.CoqOfRust. +Require Import CoqOfRust.links.M. +Require Import plonky3.blake3_air.columns. + +(* +pub(crate) struct QuarterRound<'a, T, U> { + pub a: &'a [T; U32_LIMBS], + pub b: &'a [T; 32], + pub c: &'a [T; U32_LIMBS], + pub d: &'a [T; 32], + + pub m_two_i: &'a [U; U32_LIMBS], // m_{2i} + + pub a_prime: &'a [T; U32_LIMBS], + pub b_prime: &'a [T; 32], + pub c_prime: &'a [T; U32_LIMBS], + pub d_prime: &'a [T; 32], + + pub m_two_i_plus_one: &'a [U; U32_LIMBS], // m_{2i + 1} + + pub a_output: &'a [T; U32_LIMBS], + pub b_output: &'a [T; 32], + pub c_output: &'a [T; U32_LIMBS], + pub d_output: &'a [T; 32], +} +*) +Module QuarterRound. + Record t (T U : Set) : Set := { + a : list T; + b : list T; + c : list T; + d : list T; + m_two_i : list U; + a_prime : list T; + b_prime : list T; + c_prime : list T; + d_prime : list T; + m_two_i_plus_one : list U; + a_output : list T; + b_output : list T; + c_output : list T; + d_output : list T; + }. + Arguments t : clear implicits. + + Parameter to_value : forall {T U : Set}, t T U -> Value.t. + + Global Instance IsLink (T U : Set) `{Link T} `{Link U} : Link (t T U) := { + Φ := Ty.apply (Ty.path "plonky3::blake3_air::columns::QuarterRound") [] [ Φ T; Φ U ]; + φ := to_value; + }. + + Definition of_ty (T_ty U_ty : Ty.t) : + OfTy.t T_ty -> OfTy.t U_ty -> + OfTy.t (Ty.apply (Ty.path "plonky3::blake3_air::columns::QuarterRound") [] [ T_ty ; U_ty ]). + Proof. intros [T] [U]. eapply OfTy.Make with (A := t T U). now subst. Defined. + Smpl Add eapply of_ty : of_ty. +End QuarterRound. + +(* +pub struct Blake3State { + pub row0: [[T; U32_LIMBS]; 4], + pub row1: [[T; 32]; 4], + pub row2: [[T; U32_LIMBS]; 4], + pub row3: [[T; 32]; 4], +} +*) +Module Blake3State. + Record t (T : Set) : Set := { + row0 : list (list T); + row1 : list (list T); + row2 : list (list T); + row3 : list (list T); + }. + Arguments t : clear implicits. + + Parameter to_value : forall {T : Set}, t T -> Value.t. + + Global Instance IsLink (T : Set) `{Link T} : Link (t T) := { + Φ := Ty.apply (Ty.path "plonky3::blake3_air::columns::Blake3State") [] [ Φ T ]; + φ := to_value; + }. + + Definition of_ty (T_ty : Ty.t) : + OfTy.t T_ty -> + OfTy.t (Ty.apply (Ty.path "plonky3::blake3_air::columns::Blake3State") [] [ T_ty ]). + Proof. intros [T]. eapply OfTy.Make with (A := t T). now subst. Defined. + Smpl Add eapply of_ty : of_ty. +End Blake3State. + +(* +pub struct FullRound { + pub state_prime: Blake3State, + pub state_middle: Blake3State, + pub state_middle_prime: Blake3State, + pub state_output: Blake3State, +} +*) +Module FullRound. + Record t (T : Set) : Set := { + state_prime : Blake3State.t T; + state_middle : Blake3State.t T; + state_middle_prime : Blake3State.t T; + state_output : Blake3State.t T; + }. + Arguments t : clear implicits. + + Parameter to_value : forall {T : Set}, t T -> Value.t. + + Global Instance IsLink (T : Set) `{Link T} : Link (t T) := { + Φ := Ty.apply (Ty.path "plonky3::blake3_air::columns::FullRound") [] [ Φ T ]; + φ := to_value; + }. + + Definition of_ty (T_ty : Ty.t) : + OfTy.t T_ty -> + OfTy.t (Ty.apply (Ty.path "plonky3::blake3_air::columns::FullRound") [] [ T_ty ]). + Proof. intros [T]. eapply OfTy.Make with (A := t T). now subst. Defined. + Smpl Add eapply of_ty : of_ty. +End FullRound. \ No newline at end of file diff --git a/CoqOfRust/plonky3/blake3_air/src/air.rs b/CoqOfRust/plonky3/blake3_air/src/air.rs new file mode 100644 index 000000000..ba867644a --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/src/air.rs @@ -0,0 +1,444 @@ +use alloc::vec::Vec; +use core::borrow::Borrow; + +use itertools::izip; +use p3_air::utils::{add2, add3, pack_bits_le, xor_32_shift}; +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{PrimeCharacteristicRing, PrimeField64}; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use rand::rngs::SmallRng; +use rand::{Rng, SeedableRng}; + +use crate::columns::{Blake3Cols, NUM_BLAKE3_COLS}; +use crate::constants::{BITS_PER_LIMB, IV, permute}; +use crate::{Blake3State, FullRound, QuarterRound, generate_trace_rows}; + +/// Assumes the field size is at least 16 bits. +#[derive(Debug)] +pub struct Blake3Air {} + +impl Blake3Air { + pub fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix { + let mut rng = SmallRng::seed_from_u64(1); + let inputs = (0..num_hashes).map(|_| rng.random()).collect::>(); + generate_trace_rows(inputs, extra_capacity_bits) + } + + /// Verify that the quarter round function has been correctly computed. + /// + /// We assume that the values in a, b, c, d have all been range checked to be + /// either boolean (for b, d) or < 2^16 (for a, c). This both range checks all x', x'' + /// and auxiliary variables as well as checking the relevant constraints between + /// them to conclude that the outputs are correct given the inputs. + fn quarter_round_function( + &self, + builder: &mut AB, + trace: &QuarterRound<::Var, ::Expr>, + ) { + // We need to pack some bits together to verify the additions. + // First we verify a' = a + b + m_{2i} mod 2^32 + let b_0_16 = pack_bits_le(trace.b[..BITS_PER_LIMB].iter().copied()); + let b_16_32 = pack_bits_le(trace.b[BITS_PER_LIMB..].iter().copied()); + + add3( + builder, + trace.a_prime, + trace.a, + &[b_0_16, b_16_32], + trace.m_two_i, + ); + + // Next we verify that d' = (a' ^ d) >> 16 which is equivalently: a' = d ^ (d' << 16) + // This also range checks d' and a'. + xor_32_shift(builder, trace.a_prime, trace.d, trace.d_prime, 16); + + // Next we verify c' = c + d' mod 2^32 + let d_prime_0_16 = pack_bits_le(trace.d_prime[..BITS_PER_LIMB].iter().copied()); + let d_prime_16_32 = pack_bits_le(trace.d_prime[BITS_PER_LIMB..].iter().copied()); + add2( + builder, + trace.c_prime, + trace.c, + &[d_prime_0_16, d_prime_16_32], + ); + + // Next we verify that b' = (c' ^ b) >> 12 which is equivalently: c' = b ^ (b' << 12) + // This also range checks b' and c'. + xor_32_shift(builder, trace.c_prime, trace.b, trace.b_prime, 12); + + // Next we verify a'' = a' + b' + m_{2i + 1} mod 2^32 + let b_prime_0_16 = pack_bits_le(trace.b_prime[..BITS_PER_LIMB].iter().copied()); + let b_prime_16_32 = pack_bits_le(trace.b_prime[BITS_PER_LIMB..].iter().copied()); + + add3( + builder, + trace.a_output, + trace.a_prime, + &[b_prime_0_16, b_prime_16_32], + trace.m_two_i_plus_one, + ); + + // Next we verify that d'' = (a'' ^ d') << 8 which is equivalently: a'' = d' ^ (d'' << 8) + // This also range checks d'' and a''. + + xor_32_shift(builder, trace.a_output, trace.d_prime, trace.d_output, 8); + + // Next we verify c'' = c' + d'' mod 2^32 + let d_output_0_16 = pack_bits_le(trace.d_output[..BITS_PER_LIMB].iter().copied()); + let d_output_16_32 = pack_bits_le(trace.d_output[BITS_PER_LIMB..].iter().copied()); + add2( + builder, + trace.c_output, + trace.c_prime, + &[d_output_0_16, d_output_16_32], + ); + + // Finally we verify that b'' = (c'' ^ b') << 7 which is equivalently: c'' = b' ^ (b'' << 7) + // This also range checks b'' and c''. + xor_32_shift(builder, trace.c_output, trace.b_prime, trace.b_output, 7); + + // Assuming all checks pass, a'', b'', c'', d'' are the correct values and have all been range checked. + } + + /// Given data for a full round, produce the data corresponding to a + /// single application of the quarter round function on a column. + const fn full_round_to_column_quarter_round<'a, T: Copy, U>( + &self, + input: &'a Blake3State, + round_data: &'a FullRound, + m_vector: &'a [[U; 2]; 16], + index: usize, + ) -> QuarterRound<'a, T, U> { + QuarterRound { + a: &input.row0[index], + b: &input.row1[index], + c: &input.row2[index], + d: &input.row3[index], + + m_two_i: &m_vector[2 * index], + + a_prime: &round_data.state_prime.row0[index], + b_prime: &round_data.state_prime.row1[index], + c_prime: &round_data.state_prime.row2[index], + d_prime: &round_data.state_prime.row3[index], + + m_two_i_plus_one: &m_vector[2 * index + 1], + + a_output: &round_data.state_middle.row0[index], + b_output: &round_data.state_middle.row1[index], + c_output: &round_data.state_middle.row2[index], + d_output: &round_data.state_middle.row3[index], + } + } + + /// Given data for a full round, produce the data corresponding to a + /// single application of the quarter round function on a diagonal. + const fn full_round_to_diagonal_quarter_round<'a, T: Copy, U>( + &self, + round_data: &'a FullRound, + m_vector: &'a [[U; 2]; 16], + index: usize, + ) -> QuarterRound<'a, T, U> { + QuarterRound { + a: &round_data.state_middle.row0[index], + b: &round_data.state_middle.row1[(index + 1) % 4], + c: &round_data.state_middle.row2[(index + 2) % 4], + d: &round_data.state_middle.row3[(index + 3) % 4], + + m_two_i: &m_vector[2 * index + 8], + + a_prime: &round_data.state_middle_prime.row0[index], + b_prime: &round_data.state_middle_prime.row1[(index + 1) % 4], + c_prime: &round_data.state_middle_prime.row2[(index + 2) % 4], + d_prime: &round_data.state_middle_prime.row3[(index + 3) % 4], + + m_two_i_plus_one: &m_vector[2 * index + 9], + + a_output: &round_data.state_output.row0[index], + b_output: &round_data.state_output.row1[(index + 1) % 4], + c_output: &round_data.state_output.row2[(index + 2) % 4], + d_output: &round_data.state_output.row3[(index + 3) % 4], + } + } + + /// Verify a full round of the Blake-3 permutation. + fn verify_round( + &self, + builder: &mut AB, + input: &Blake3State, + round_data: &FullRound, + m_vector: &[[AB::Expr; 2]; 16], + ) { + // First we mix the columns. + + // The first column quarter round function involves the states in position: 0, 4, 8, 12 + // Along with the two m_vector elements in the 0 and 1 positions. + let trace_column_0 = + self.full_round_to_column_quarter_round(input, round_data, m_vector, 0); + self.quarter_round_function(builder, &trace_column_0); + + // The next column quarter round function involves the states in position: 1, 5, 9, 13 + // Along with the two m_vector elements in the 2 and 3 positions. + let trace_column_1 = + self.full_round_to_column_quarter_round(input, round_data, m_vector, 1); + self.quarter_round_function(builder, &trace_column_1); + + // The next column quarter round function involves the states in position: 2, 6, 10, 14 + // Along with the two m_vector elements in the 4 and 5 positions. + let trace_column_2 = + self.full_round_to_column_quarter_round(input, round_data, m_vector, 2); + self.quarter_round_function(builder, &trace_column_2); + + // The final column quarter round function involves the states in position: 3, 7, 11, 15 + // Along with the two m_vector elements in the 6 and 7 positions. + let trace_column_3 = + self.full_round_to_column_quarter_round(input, round_data, m_vector, 3); + self.quarter_round_function(builder, &trace_column_3); + + // Second we mix the diagonals. + + // The first diagonal quarter round function involves the states in position: 0, 5, 10, 15 + // Along with the two m_vector elements in the 8 and 9 positions. + let trace_diagonal_0 = self.full_round_to_diagonal_quarter_round(round_data, m_vector, 0); + self.quarter_round_function(builder, &trace_diagonal_0); + + // The next diagonal quarter round function involves the states in position: 1, 6, 11, 12 + // Along with the two m_vector elements in the 10 and 11 positions. + let trace_diagonal_1 = self.full_round_to_diagonal_quarter_round(round_data, m_vector, 1); + self.quarter_round_function(builder, &trace_diagonal_1); + + // The next diagonal quarter round function involves the states in position: 2, 7, 8, 13 + // Along with the two m_vector elements in the 12 and 13 positions. + let trace_diagonal_2 = self.full_round_to_diagonal_quarter_round(round_data, m_vector, 2); + self.quarter_round_function(builder, &trace_diagonal_2); + + // The final diagonal quarter round function involves the states in position: 3, 4, 9, 14 + // Along with the two m_vector elements in the 14 and 15 positions. + let trace_diagonal_3 = self.full_round_to_diagonal_quarter_round(round_data, m_vector, 3); + self.quarter_round_function(builder, &trace_diagonal_3); + } +} + +impl BaseAir for Blake3Air { + fn width(&self) -> usize { + NUM_BLAKE3_COLS + } +} + +impl Air for Blake3Air { + #[inline] + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let local: &Blake3Cols = (*local).borrow(); + + let initial_row_3 = [ + local.counter_low, + local.counter_hi, + local.block_len, + local.flags, + ]; + + // We start by checking that all the initialization inputs are boolean values. + local + .inputs + .iter() + .chain(local.chaining_values[0].iter()) + .chain(local.chaining_values[1].iter()) + .chain(initial_row_3.iter()) + .for_each(|elem| elem.iter().for_each(|&bool| builder.assert_bool(bool))); + + // Next we ensure that the row0 and row2 for our initial state have been initialized correctly. + + // row0 should contain the packing of the first 4 chaining_values. + local.chaining_values[0] + .iter() + .zip(local.initial_row0) + .for_each(|(bits, word)| { + let low_16 = pack_bits_le(bits[..BITS_PER_LIMB].iter().copied()); + let hi_16 = pack_bits_le(bits[BITS_PER_LIMB..].iter().copied()); + builder.assert_eq(low_16, word[0]); + builder.assert_eq(hi_16, word[1]); + }); + + // row2 should contain the first four constants in IV. + local + .initial_row2 + .iter() + .zip(IV) + .for_each(|(row_elem, constant)| { + builder.assert_eq(row_elem[0], AB::Expr::from_u16(constant[0])); + builder.assert_eq(row_elem[1], AB::Expr::from_u16(constant[1])); + }); + + let mut m_values: [[AB::Expr; 2]; 16] = local.inputs.map(|bits| { + [ + pack_bits_le(bits[..BITS_PER_LIMB].iter().copied()), + pack_bits_le(bits[BITS_PER_LIMB..].iter().copied()), + ] + }); + + let initial_state = Blake3State { + row0: local.initial_row0, + row1: local.chaining_values[1], + row2: local.initial_row2, + row3: initial_row_3, + }; + + // Now we can move to verifying that each of the seven rounds have been computed correctly. + + // Round 1: + self.verify_round(builder, &initial_state, &local.full_rounds[0], &m_values); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 2: + self.verify_round( + builder, + &local.full_rounds[0].state_output, + &local.full_rounds[1], + &m_values, + ); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 3: + self.verify_round( + builder, + &local.full_rounds[1].state_output, + &local.full_rounds[2], + &m_values, + ); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 4: + self.verify_round( + builder, + &local.full_rounds[2].state_output, + &local.full_rounds[3], + &m_values, + ); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 5: + self.verify_round( + builder, + &local.full_rounds[3].state_output, + &local.full_rounds[4], + &m_values, + ); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 6: + self.verify_round( + builder, + &local.full_rounds[4].state_output, + &local.full_rounds[5], + &m_values, + ); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 7: + self.verify_round( + builder, + &local.full_rounds[5].state_output, + &local.full_rounds[6], + &m_values, + ); + + // Verify the final set of xor's. + // For the first 8 of these we xor state[i] and state[i + 8] (i = 0, .., 7) + + // When i = 0, 1, 2, 3 both inputs are given as 16 bit integers. Hence we need to get the individual bits + // of one of them in order to test this. + + local + .final_round_helpers + .iter() + .zip(local.full_rounds[6].state_output.row2) + .for_each(|(bits, word)| { + let low_16 = pack_bits_le(bits[..BITS_PER_LIMB].iter().copied()); + let hi_16 = pack_bits_le(bits[BITS_PER_LIMB..].iter().copied()); + builder.assert_eq(low_16, word[0]); + builder.assert_eq(hi_16, word[1]); + }); + // Additionally, we need to ensure that both local.final_round_helpers and local.outputs[0] are boolean. + + local + .final_round_helpers + .iter() + .chain(local.outputs[0].iter()) + .for_each(|bits| bits.iter().for_each(|&bit| builder.assert_bool(bit))); + + // Finally we check the xor by xor'ing the output with final_round_helpers, packing the bits + // and comparing with the words in local.full_rounds[6].state_output.row0. + + for (out_bits, left_words, right_bits) in izip!( + local.outputs[0], + local.full_rounds[6].state_output.row0, + local.final_round_helpers + ) { + // We can reuse xor_32_shift with a shift of 0. + // As a = b ^ c if and only if b = a ^ c we can perform our xor on the + // elements which we have the bits of and then check against a. + xor_32_shift(builder, &left_words, &out_bits, &right_bits, 0) + } + + // When i = 4, 5, 6, 7 we already have the bits of state[i] and state[i + 8] making this easy. + // This check also ensures that local.outputs[1] contains only boolean values. + + for (out_bits, left_bits, right_bits) in izip!( + local.outputs[1], + local.full_rounds[6].state_output.row1, + local.full_rounds[6].state_output.row3 + ) { + for (out_bit, left_bit, right_bit) in izip!(out_bits, left_bits, right_bits) { + builder.assert_eq(out_bit, left_bit.into().xor(&right_bit.into())); + } + } + + // For the remaining 8, we xor state[i] and chaining_value[i - 8] (i = 8, .., 15) + + // When i = 8, 9, 10, 11, we have the bits state[i] already as we used then in the + // i = 0, 1, 2, 3 case. Additionally we also have the bits of chaining_value[i - 8]. + // Hence we can directly check that the output is correct. + + for (out_bits, left_bits, right_bits) in izip!( + local.outputs[2], + local.chaining_values[0], + local.final_round_helpers + ) { + for (out_bit, left_bit, right_bit) in izip!(out_bits, left_bits, right_bits) { + builder.assert_eq(out_bit, left_bit.into().xor(&right_bit.into())); + } + } + + // This is easy when i = 12, 13, 14, 15 as we already have the bits. + // This check also ensures that local.outputs[3] contains only boolean values. + + for (out_bits, left_bits, right_bits) in izip!( + local.outputs[3], + local.chaining_values[1], + local.full_rounds[6].state_output.row3 + ) { + for (out_bit, left_bit, right_bit) in izip!(out_bits, left_bits, right_bits) { + builder.assert_eq(out_bit, left_bit.into().xor(&right_bit.into())); + } + } + } +} diff --git a/CoqOfRust/plonky3/blake3_air/src/air.v b/CoqOfRust/plonky3/blake3_air/src/air.v new file mode 100644 index 000000000..21532d8ec --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/src/air.v @@ -0,0 +1,17251 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module air. + (* StructTuple + { + name := "Blake3Air"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_fmt_Debug_for_p3_blake3_air_air_Blake3Air. + Definition Self : Ty.t := Ty.path "p3_blake3_air::air::Blake3Air". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Blake3Air" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_blake3_air_air_Blake3Air. + + Module Impl_p3_blake3_air_air_Blake3Air. + Definition Self : Ty.t := Ty.path "p3_blake3_air::air::Blake3Air". + + (* + pub fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix { + let mut rng = SmallRng::seed_from_u64(1); + let inputs = (0..num_hashes).map(|_| rng.random()).collect::>(); + generate_trace_rows(inputs, extra_capacity_bits) + } + *) + Definition generate_trace_rows (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ self; num_hashes; extra_capacity_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_hashes := M.alloc (| num_hashes |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ inputs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| num_hashes |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_function (| "p3_blake3_air::generation::generate_trace_rows", [], [ F ] |), + [ M.read (| inputs |); M.read (| extra_capacity_bits |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_generate_trace_rows : + M.IsAssociatedFunction.C Self "generate_trace_rows" generate_trace_rows. + Admitted. + Global Typeclasses Opaque generate_trace_rows. + + (* + fn quarter_round_function( + &self, + builder: &mut AB, + trace: &QuarterRound<::Var, ::Expr>, + ) { + // We need to pack some bits together to verify the additions. + // First we verify a' = a + b + m_{2i} mod 2^32 + let b_0_16 = pack_bits_le(trace.b[..BITS_PER_LIMB].iter().copied()); + let b_16_32 = pack_bits_le(trace.b[BITS_PER_LIMB..].iter().copied()); + + add3( + builder, + trace.a_prime, + trace.a, + &[b_0_16, b_16_32], + trace.m_two_i, + ); + + // Next we verify that d' = (a' ^ d) >> 16 which is equivalently: a' = d ^ (d' << 16) + // This also range checks d' and a'. + xor_32_shift(builder, trace.a_prime, trace.d, trace.d_prime, 16); + + // Next we verify c' = c + d' mod 2^32 + let d_prime_0_16 = pack_bits_le(trace.d_prime[..BITS_PER_LIMB].iter().copied()); + let d_prime_16_32 = pack_bits_le(trace.d_prime[BITS_PER_LIMB..].iter().copied()); + add2( + builder, + trace.c_prime, + trace.c, + &[d_prime_0_16, d_prime_16_32], + ); + + // Next we verify that b' = (c' ^ b) >> 12 which is equivalently: c' = b ^ (b' << 12) + // This also range checks b' and c'. + xor_32_shift(builder, trace.c_prime, trace.b, trace.b_prime, 12); + + // Next we verify a'' = a' + b' + m_{2i + 1} mod 2^32 + let b_prime_0_16 = pack_bits_le(trace.b_prime[..BITS_PER_LIMB].iter().copied()); + let b_prime_16_32 = pack_bits_le(trace.b_prime[BITS_PER_LIMB..].iter().copied()); + + add3( + builder, + trace.a_output, + trace.a_prime, + &[b_prime_0_16, b_prime_16_32], + trace.m_two_i_plus_one, + ); + + // Next we verify that d'' = (a'' ^ d') << 8 which is equivalently: a'' = d' ^ (d'' << 8) + // This also range checks d'' and a''. + + xor_32_shift(builder, trace.a_output, trace.d_prime, trace.d_output, 8); + + // Next we verify c'' = c' + d'' mod 2^32 + let d_output_0_16 = pack_bits_le(trace.d_output[..BITS_PER_LIMB].iter().copied()); + let d_output_16_32 = pack_bits_le(trace.d_output[BITS_PER_LIMB..].iter().copied()); + add2( + builder, + trace.c_output, + trace.c_prime, + &[d_output_0_16, d_output_16_32], + ); + + // Finally we verify that b'' = (c'' ^ b') << 7 which is equivalently: c'' = b' ^ (b'' << 7) + // This also range checks b'' and c''. + xor_32_shift(builder, trace.c_output, trace.b_prime, trace.b_output, 7); + + // Assuming all checks pass, a'', b'', c'', d'' are the correct values and have all been range checked. + } + *) + Definition quarter_round_function (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ AB ], [ self; builder; trace ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let builder := M.alloc (| builder |) in + let trace := M.alloc (| trace |) in + M.read (| + let~ b_0_16 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [], + "copied", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "b" + |) + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ b_16_32 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [], + "copied", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "b" + |) + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_air::utils::add3", [], [ AB ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "a_prime" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "a" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ M.read (| b_0_16 |); M.read (| b_16_32 |) ] |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "m_two_i" + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_air::utils::xor_32_shift", [], [ AB ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "a_prime" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "d" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "d_prime" + |) + |) + |) + |); + Value.Integer IntegerKind.Usize 16 + ] + |) + |) in + let~ d_prime_0_16 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [], + "copied", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "d_prime" + |) + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ d_prime_16_32 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [], + "copied", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "d_prime" + |) + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_air::utils::add2", [], [ AB ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "c_prime" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "c" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ M.read (| d_prime_0_16 |); M.read (| d_prime_16_32 |) ] + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_air::utils::xor_32_shift", [], [ AB ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "c_prime" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "b" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "b_prime" + |) + |) + |) + |); + Value.Integer IntegerKind.Usize 12 + ] + |) + |) in + let~ b_prime_0_16 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [], + "copied", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "b_prime" + |) + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ b_prime_16_32 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [], + "copied", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "b_prime" + |) + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_air::utils::add3", [], [ AB ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "a_output" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "a_prime" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ M.read (| b_prime_0_16 |); M.read (| b_prime_16_32 |) ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "m_two_i_plus_one" + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_air::utils::xor_32_shift", [], [ AB ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "a_output" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "d_prime" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "d_output" + |) + |) + |) + |); + Value.Integer IntegerKind.Usize 8 + ] + |) + |) in + let~ d_output_0_16 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [], + "copied", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "d_output" + |) + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ d_output_16_32 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [], + "copied", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "d_output" + |) + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_air::utils::add2", [], [ AB ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "c_output" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "c_prime" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ M.read (| d_output_0_16 |); M.read (| d_output_16_32 |) ] + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_air::utils::xor_32_shift", [], [ AB ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "c_output" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "b_prime" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::QuarterRound", + "b_output" + |) + |) + |) + |); + Value.Integer IntegerKind.Usize 7 + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_quarter_round_function : + M.IsAssociatedFunction.C Self "quarter_round_function" quarter_round_function. + Admitted. + Global Typeclasses Opaque quarter_round_function. + + (* + const fn full_round_to_column_quarter_round<'a, T: Copy, U>( + &self, + input: &'a Blake3State, + round_data: &'a FullRound, + m_vector: &'a [[U; 2]; 16], + index: usize, + ) -> QuarterRound<'a, T, U> { + QuarterRound { + a: &input.row0[index], + b: &input.row1[index], + c: &input.row2[index], + d: &input.row3[index], + + m_two_i: &m_vector[2 * index], + + a_prime: &round_data.state_prime.row0[index], + b_prime: &round_data.state_prime.row1[index], + c_prime: &round_data.state_prime.row2[index], + d_prime: &round_data.state_prime.row3[index], + + m_two_i_plus_one: &m_vector[2 * index + 1], + + a_output: &round_data.state_middle.row0[index], + b_output: &round_data.state_middle.row1[index], + c_output: &round_data.state_middle.row2[index], + d_output: &round_data.state_middle.row3[index], + } + } + *) + Definition full_round_to_column_quarter_round + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ T; U ], [ self; input; round_data; m_vector; index ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + let round_data := M.alloc (| round_data |) in + let m_vector := M.alloc (| m_vector |) in + let index := M.alloc (| index |) in + Value.StructRecord + "p3_blake3_air::columns::QuarterRound" + [ + ("a", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| input |) |), + "p3_blake3_air::columns::Blake3State", + "row0" + |), + M.read (| index |) + |) + |) + |) + |)); + ("b", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| input |) |), + "p3_blake3_air::columns::Blake3State", + "row1" + |), + M.read (| index |) + |) + |) + |) + |)); + ("c", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| input |) |), + "p3_blake3_air::columns::Blake3State", + "row2" + |), + M.read (| index |) + |) + |) + |) + |)); + ("d", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| input |) |), + "p3_blake3_air::columns::Blake3State", + "row3" + |), + M.read (| index |) + |) + |) + |) + |)); + ("m_two_i", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| m_vector |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| index |) ] + |) + |) + |) + |) + |)); + ("a_prime", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_prime" + |), + "p3_blake3_air::columns::Blake3State", + "row0" + |), + M.read (| index |) + |) + |) + |) + |)); + ("b_prime", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_prime" + |), + "p3_blake3_air::columns::Blake3State", + "row1" + |), + M.read (| index |) + |) + |) + |) + |)); + ("c_prime", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_prime" + |), + "p3_blake3_air::columns::Blake3State", + "row2" + |), + M.read (| index |) + |) + |) + |) + |)); + ("d_prime", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_prime" + |), + "p3_blake3_air::columns::Blake3State", + "row3" + |), + M.read (| index |) + |) + |) + |) + |)); + ("m_two_i_plus_one", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| m_vector |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| index |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) + |) + |)); + ("a_output", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle" + |), + "p3_blake3_air::columns::Blake3State", + "row0" + |), + M.read (| index |) + |) + |) + |) + |)); + ("b_output", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle" + |), + "p3_blake3_air::columns::Blake3State", + "row1" + |), + M.read (| index |) + |) + |) + |) + |)); + ("c_output", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle" + |), + "p3_blake3_air::columns::Blake3State", + "row2" + |), + M.read (| index |) + |) + |) + |) + |)); + ("d_output", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle" + |), + "p3_blake3_air::columns::Blake3State", + "row3" + |), + M.read (| index |) + |) + |) + |) + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_full_round_to_column_quarter_round : + M.IsAssociatedFunction.C + Self + "full_round_to_column_quarter_round" + full_round_to_column_quarter_round. + Admitted. + Global Typeclasses Opaque full_round_to_column_quarter_round. + + (* + const fn full_round_to_diagonal_quarter_round<'a, T: Copy, U>( + &self, + round_data: &'a FullRound, + m_vector: &'a [[U; 2]; 16], + index: usize, + ) -> QuarterRound<'a, T, U> { + QuarterRound { + a: &round_data.state_middle.row0[index], + b: &round_data.state_middle.row1[(index + 1) % 4], + c: &round_data.state_middle.row2[(index + 2) % 4], + d: &round_data.state_middle.row3[(index + 3) % 4], + + m_two_i: &m_vector[2 * index + 8], + + a_prime: &round_data.state_middle_prime.row0[index], + b_prime: &round_data.state_middle_prime.row1[(index + 1) % 4], + c_prime: &round_data.state_middle_prime.row2[(index + 2) % 4], + d_prime: &round_data.state_middle_prime.row3[(index + 3) % 4], + + m_two_i_plus_one: &m_vector[2 * index + 9], + + a_output: &round_data.state_output.row0[index], + b_output: &round_data.state_output.row1[(index + 1) % 4], + c_output: &round_data.state_output.row2[(index + 2) % 4], + d_output: &round_data.state_output.row3[(index + 3) % 4], + } + } + *) + Definition full_round_to_diagonal_quarter_round + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ T; U ], [ self; round_data; m_vector; index ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let round_data := M.alloc (| round_data |) in + let m_vector := M.alloc (| m_vector |) in + let index := M.alloc (| index |) in + Value.StructRecord + "p3_blake3_air::columns::QuarterRound" + [ + ("a", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle" + |), + "p3_blake3_air::columns::Blake3State", + "row0" + |), + M.read (| index |) + |) + |) + |) + |)); + ("b", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle" + |), + "p3_blake3_air::columns::Blake3State", + "row1" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| index |); Value.Integer IntegerKind.Usize 1 ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |) + |) + |)); + ("c", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle" + |), + "p3_blake3_air::columns::Blake3State", + "row2" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| index |); Value.Integer IntegerKind.Usize 2 ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |) + |) + |)); + ("d", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle" + |), + "p3_blake3_air::columns::Blake3State", + "row3" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| index |); Value.Integer IntegerKind.Usize 3 ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |) + |) + |)); + ("m_two_i", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| m_vector |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| index |) ] + |); + Value.Integer IntegerKind.Usize 8 + ] + |) + |) + |) + |) + |)); + ("a_prime", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle_prime" + |), + "p3_blake3_air::columns::Blake3State", + "row0" + |), + M.read (| index |) + |) + |) + |) + |)); + ("b_prime", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle_prime" + |), + "p3_blake3_air::columns::Blake3State", + "row1" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| index |); Value.Integer IntegerKind.Usize 1 ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |) + |) + |)); + ("c_prime", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle_prime" + |), + "p3_blake3_air::columns::Blake3State", + "row2" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| index |); Value.Integer IntegerKind.Usize 2 ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |) + |) + |)); + ("d_prime", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle_prime" + |), + "p3_blake3_air::columns::Blake3State", + "row3" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| index |); Value.Integer IntegerKind.Usize 3 ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |) + |) + |)); + ("m_two_i_plus_one", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| m_vector |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| index |) ] + |); + Value.Integer IntegerKind.Usize 9 + ] + |) + |) + |) + |) + |)); + ("a_output", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_output" + |), + "p3_blake3_air::columns::Blake3State", + "row0" + |), + M.read (| index |) + |) + |) + |) + |)); + ("b_output", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_output" + |), + "p3_blake3_air::columns::Blake3State", + "row1" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| index |); Value.Integer IntegerKind.Usize 1 ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |) + |) + |)); + ("c_output", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_output" + |), + "p3_blake3_air::columns::Blake3State", + "row2" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| index |); Value.Integer IntegerKind.Usize 2 ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |) + |) + |)); + ("d_output", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_output" + |), + "p3_blake3_air::columns::Blake3State", + "row3" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| index |); Value.Integer IntegerKind.Usize 3 ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |) + |) + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_full_round_to_diagonal_quarter_round : + M.IsAssociatedFunction.C + Self + "full_round_to_diagonal_quarter_round" + full_round_to_diagonal_quarter_round. + Admitted. + Global Typeclasses Opaque full_round_to_diagonal_quarter_round. + + (* + fn verify_round( + &self, + builder: &mut AB, + input: &Blake3State, + round_data: &FullRound, + m_vector: &[[AB::Expr; 2]; 16], + ) { + // First we mix the columns. + + // The first column quarter round function involves the states in position: 0, 4, 8, 12 + // Along with the two m_vector elements in the 0 and 1 positions. + let trace_column_0 = + self.full_round_to_column_quarter_round(input, round_data, m_vector, 0); + self.quarter_round_function(builder, &trace_column_0); + + // The next column quarter round function involves the states in position: 1, 5, 9, 13 + // Along with the two m_vector elements in the 2 and 3 positions. + let trace_column_1 = + self.full_round_to_column_quarter_round(input, round_data, m_vector, 1); + self.quarter_round_function(builder, &trace_column_1); + + // The next column quarter round function involves the states in position: 2, 6, 10, 14 + // Along with the two m_vector elements in the 4 and 5 positions. + let trace_column_2 = + self.full_round_to_column_quarter_round(input, round_data, m_vector, 2); + self.quarter_round_function(builder, &trace_column_2); + + // The final column quarter round function involves the states in position: 3, 7, 11, 15 + // Along with the two m_vector elements in the 6 and 7 positions. + let trace_column_3 = + self.full_round_to_column_quarter_round(input, round_data, m_vector, 3); + self.quarter_round_function(builder, &trace_column_3); + + // Second we mix the diagonals. + + // The first diagonal quarter round function involves the states in position: 0, 5, 10, 15 + // Along with the two m_vector elements in the 8 and 9 positions. + let trace_diagonal_0 = self.full_round_to_diagonal_quarter_round(round_data, m_vector, 0); + self.quarter_round_function(builder, &trace_diagonal_0); + + // The next diagonal quarter round function involves the states in position: 1, 6, 11, 12 + // Along with the two m_vector elements in the 10 and 11 positions. + let trace_diagonal_1 = self.full_round_to_diagonal_quarter_round(round_data, m_vector, 1); + self.quarter_round_function(builder, &trace_diagonal_1); + + // The next diagonal quarter round function involves the states in position: 2, 7, 8, 13 + // Along with the two m_vector elements in the 12 and 13 positions. + let trace_diagonal_2 = self.full_round_to_diagonal_quarter_round(round_data, m_vector, 2); + self.quarter_round_function(builder, &trace_diagonal_2); + + // The final diagonal quarter round function involves the states in position: 3, 4, 9, 14 + // Along with the two m_vector elements in the 14 and 15 positions. + let trace_diagonal_3 = self.full_round_to_diagonal_quarter_round(round_data, m_vector, 3); + self.quarter_round_function(builder, &trace_diagonal_3); + } + *) + Definition verify_round (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ AB ], [ self; builder; input; round_data; m_vector ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let builder := M.alloc (| builder |) in + let input := M.alloc (| input |) in + let round_data := M.alloc (| round_data |) in + let m_vector := M.alloc (| m_vector |) in + M.read (| + let~ trace_column_0 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "full_round_to_column_quarter_round", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| round_data |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| m_vector |) |) |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "quarter_round_function", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trace_column_0 |) |) + |) + ] + |) + |) in + let~ trace_column_1 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "full_round_to_column_quarter_round", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| round_data |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| m_vector |) |) |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "quarter_round_function", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trace_column_1 |) |) + |) + ] + |) + |) in + let~ trace_column_2 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "full_round_to_column_quarter_round", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| round_data |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| m_vector |) |) |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "quarter_round_function", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trace_column_2 |) |) + |) + ] + |) + |) in + let~ trace_column_3 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "full_round_to_column_quarter_round", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| round_data |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| m_vector |) |) |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "quarter_round_function", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trace_column_3 |) |) + |) + ] + |) + |) in + let~ trace_diagonal_0 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "full_round_to_diagonal_quarter_round", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| round_data |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| m_vector |) |) |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "quarter_round_function", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trace_diagonal_0 |) |) + |) + ] + |) + |) in + let~ trace_diagonal_1 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "full_round_to_diagonal_quarter_round", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| round_data |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| m_vector |) |) |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "quarter_round_function", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trace_diagonal_1 |) |) + |) + ] + |) + |) in + let~ trace_diagonal_2 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "full_round_to_diagonal_quarter_round", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| round_data |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| m_vector |) |) |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "quarter_round_function", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trace_diagonal_2 |) |) + |) + ] + |) + |) in + let~ trace_diagonal_3 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_blake3_air::columns::QuarterRound") + [] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "full_round_to_diagonal_quarter_round", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| round_data |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| m_vector |) |) |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "quarter_round_function", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trace_diagonal_3 |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_verify_round : + M.IsAssociatedFunction.C Self "verify_round" verify_round. + Admitted. + Global Typeclasses Opaque verify_round. + End Impl_p3_blake3_air_air_Blake3Air. + + Module Impl_p3_air_air_BaseAir_F_for_p3_blake3_air_air_Blake3Air. + Definition Self (F : Ty.t) : Ty.t := Ty.path "p3_blake3_air::air::Blake3Air". + + (* + fn width(&self) -> usize { + NUM_BLAKE3_COLS + } + *) + Definition width (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + get_constant (| "p3_blake3_air::columns::NUM_BLAKE3_COLS", Ty.path "usize" |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_air::air::BaseAir" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) [ ("width", InstanceField.Method (width F)) ]. + End Impl_p3_air_air_BaseAir_F_for_p3_blake3_air_air_Blake3Air. + + Module Impl_p3_air_air_Air_where_p3_air_air_AirBuilder_AB_AB_for_p3_blake3_air_air_Blake3Air. + Definition Self (AB : Ty.t) : Ty.t := Ty.path "p3_blake3_air::air::Blake3Air". + + (* + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let local: &Blake3Cols = ( *local).borrow(); + + let initial_row_3 = [ + local.counter_low, + local.counter_hi, + local.block_len, + local.flags, + ]; + + // We start by checking that all the initialization inputs are boolean values. + local + .inputs + .iter() + .chain(local.chaining_values[0].iter()) + .chain(local.chaining_values[1].iter()) + .chain(initial_row_3.iter()) + .for_each(|elem| elem.iter().for_each(|&bool| builder.assert_bool(bool))); + + // Next we ensure that the row0 and row2 for our initial state have been initialized correctly. + + // row0 should contain the packing of the first 4 chaining_values. + local.chaining_values[0] + .iter() + .zip(local.initial_row0) + .for_each(|(bits, word)| { + let low_16 = pack_bits_le(bits[..BITS_PER_LIMB].iter().copied()); + let hi_16 = pack_bits_le(bits[BITS_PER_LIMB..].iter().copied()); + builder.assert_eq(low_16, word[0]); + builder.assert_eq(hi_16, word[1]); + }); + + // row2 should contain the first four constants in IV. + local + .initial_row2 + .iter() + .zip(IV) + .for_each(|(row_elem, constant)| { + builder.assert_eq(row_elem[0], AB::Expr::from_u16(constant[0])); + builder.assert_eq(row_elem[1], AB::Expr::from_u16(constant[1])); + }); + + let mut m_values: [[AB::Expr; 2]; 16] = local.inputs.map(|bits| { + [ + pack_bits_le(bits[..BITS_PER_LIMB].iter().copied()), + pack_bits_le(bits[BITS_PER_LIMB..].iter().copied()), + ] + }); + + let initial_state = Blake3State { + row0: local.initial_row0, + row1: local.chaining_values[1], + row2: local.initial_row2, + row3: initial_row_3, + }; + + // Now we can move to verifying that each of the seven rounds have been computed correctly. + + // Round 1: + self.verify_round(builder, &initial_state, &local.full_rounds[0], &m_values); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 2: + self.verify_round( + builder, + &local.full_rounds[0].state_output, + &local.full_rounds[1], + &m_values, + ); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 3: + self.verify_round( + builder, + &local.full_rounds[1].state_output, + &local.full_rounds[2], + &m_values, + ); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 4: + self.verify_round( + builder, + &local.full_rounds[2].state_output, + &local.full_rounds[3], + &m_values, + ); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 5: + self.verify_round( + builder, + &local.full_rounds[3].state_output, + &local.full_rounds[4], + &m_values, + ); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 6: + self.verify_round( + builder, + &local.full_rounds[4].state_output, + &local.full_rounds[5], + &m_values, + ); + + // Permute the vector of m_values. + permute(&mut m_values); + + // Round 7: + self.verify_round( + builder, + &local.full_rounds[5].state_output, + &local.full_rounds[6], + &m_values, + ); + + // Verify the final set of xor's. + // For the first 8 of these we xor state[i] and state[i + 8] (i = 0, .., 7) + + // When i = 0, 1, 2, 3 both inputs are given as 16 bit integers. Hence we need to get the individual bits + // of one of them in order to test this. + + local + .final_round_helpers + .iter() + .zip(local.full_rounds[6].state_output.row2) + .for_each(|(bits, word)| { + let low_16 = pack_bits_le(bits[..BITS_PER_LIMB].iter().copied()); + let hi_16 = pack_bits_le(bits[BITS_PER_LIMB..].iter().copied()); + builder.assert_eq(low_16, word[0]); + builder.assert_eq(hi_16, word[1]); + }); + // Additionally, we need to ensure that both local.final_round_helpers and local.outputs[0] are boolean. + + local + .final_round_helpers + .iter() + .chain(local.outputs[0].iter()) + .for_each(|bits| bits.iter().for_each(|&bit| builder.assert_bool(bit))); + + // Finally we check the xor by xor'ing the output with final_round_helpers, packing the bits + // and comparing with the words in local.full_rounds[6].state_output.row0. + + for (out_bits, left_words, right_bits) in izip!( + local.outputs[0], + local.full_rounds[6].state_output.row0, + local.final_round_helpers + ) { + // We can reuse xor_32_shift with a shift of 0. + // As a = b ^ c if and only if b = a ^ c we can perform our xor on the + // elements which we have the bits of and then check against a. + xor_32_shift(builder, &left_words, &out_bits, &right_bits, 0) + } + + // When i = 4, 5, 6, 7 we already have the bits of state[i] and state[i + 8] making this easy. + // This check also ensures that local.outputs[1] contains only boolean values. + + for (out_bits, left_bits, right_bits) in izip!( + local.outputs[1], + local.full_rounds[6].state_output.row1, + local.full_rounds[6].state_output.row3 + ) { + for (out_bit, left_bit, right_bit) in izip!(out_bits, left_bits, right_bits) { + builder.assert_eq(out_bit, left_bit.into().xor(&right_bit.into())); + } + } + + // For the remaining 8, we xor state[i] and chaining_value[i - 8] (i = 8, .., 15) + + // When i = 8, 9, 10, 11, we have the bits state[i] already as we used then in the + // i = 0, 1, 2, 3 case. Additionally we also have the bits of chaining_value[i - 8]. + // Hence we can directly check that the output is correct. + + for (out_bits, left_bits, right_bits) in izip!( + local.outputs[2], + local.chaining_values[0], + local.final_round_helpers + ) { + for (out_bit, left_bit, right_bit) in izip!(out_bits, left_bits, right_bits) { + builder.assert_eq(out_bit, left_bit.into().xor(&right_bit.into())); + } + } + + // This is easy when i = 12, 13, 14, 15 as we already have the bits. + // This check also ensures that local.outputs[3] contains only boolean values. + + for (out_bits, left_bits, right_bits) in izip!( + local.outputs[3], + local.chaining_values[1], + local.full_rounds[6].state_output.row3 + ) { + for (out_bit, left_bit, right_bit) in izip!(out_bits, left_bits, right_bits) { + builder.assert_eq(out_bit, left_bit.into().xor(&right_bit.into())); + } + } + } + *) + Definition eval (AB : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self AB in + match ε, τ, α with + | [], [], [ self; builder ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let builder := M.alloc (| builder |) in + M.read (| + let~ main : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + M.get_trait_method (| "p3_air::air::AirBuilder", AB, [], [], "main", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| builder |) |) |) ] + |) + |) in + let~ local : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "row_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, main |); Value.Integer IntegerKind.Usize 0 ] + |) + |) in + let~ local : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, local |) ] + |) + |) + |) + ] + |) + |) + |) + |) in + let~ initial_row_3 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] := + M.alloc (| + Value.Array + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "counter_low" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "counter_hi" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "block_len" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "flags" + |) + |) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ] + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "inputs" + |) + |)) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "chaining_values" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "chaining_values" + |), + Value.Integer IntegerKind.Usize 1 + |) + |)) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, initial_row_3 |)) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let elem := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| elem |) |) + |)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let bool := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_bool", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.read (| bool |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "chaining_values" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "initial_row0" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let bits := M.copy (| γ0_0 |) in + let word := M.copy (| γ0_1 |) in + M.read (| + let~ low_16 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "copied", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bits |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ hi_16 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "copied", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bits |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.read (| low_16 |); + M.read (| + M.SubPointer.get_array_field (| + word, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.read (| hi_16 |); + M.read (| + M.SubPointer.get_array_field (| + word, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "initial_row2" + |) + |)) + ] + |); + M.read (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let row_elem := M.copy (| γ0_0 |) in + let constant := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| row_elem |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "from_u16", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + constant, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| row_elem |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "from_u16", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + constant, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ m_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + "map", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ]); + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "inputs" + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let bits := M.copy (| γ |) in + Value.Array + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "copied", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, bits |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "copied", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, bits |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ initial_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3State") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] := + M.alloc (| + Value.StructRecord + "p3_blake3_air::columns::Blake3State" + [ + ("row0", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "initial_row0" + |) + |)); + ("row1", + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "chaining_values" + |), + Value.Integer IntegerKind.Usize 1 + |) + |)); + ("row2", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "initial_row2" + |) + |)); + ("row3", M.read (| initial_row_3 |)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "verify_round", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, initial_state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::constants::permute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "verify_round", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 0 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::constants::permute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "verify_round", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 1 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 2 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::constants::permute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "verify_round", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 2 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 3 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::constants::permute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "verify_round", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 3 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 4 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::constants::permute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "verify_round", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 4 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 5 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::constants::permute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "verify_round", + [], + [ AB ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 5 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 6 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_values |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "final_round_helpers" + |) + |)) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 6 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |), + "p3_blake3_air::columns::Blake3State", + "row2" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let bits := M.copy (| γ0_0 |) in + let word := M.copy (| γ0_1 |) in + M.read (| + let~ low_16 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "copied", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bits |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ hi_16 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_function (| + "p3_air::utils::pack_bits_le", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "copied", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bits |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.read (| + get_constant (| + "p3_blake3_air::constants::BITS_PER_LIMB", + Ty.path "usize" + |) + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.read (| low_16 |); + M.read (| + M.SubPointer.get_array_field (| + word, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.read (| hi_16 |); + M.read (| + M.SubPointer.get_array_field (| + word, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "final_round_helpers" + |) + |)) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "outputs" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let bits := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bits |) |) + |)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let bit := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_bool", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.read (| bit |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "outputs" + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 6 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |), + "p3_blake3_air::columns::Blake3State", + "row0" + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "final_round_helpers" + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let a := M.copy (| γ1_0 |) in + let b := M.copy (| γ1_1 |) in + let b := M.copy (| γ0_1 |) in + Value.Tuple + [ M.read (| a |); M.read (| b |); M.read (| b |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let γ1_2 := M.SubPointer.get_tuple_field (| γ0_0, 2 |) in + let out_bits := M.copy (| γ1_0 |) in + let left_words := M.copy (| γ1_1 |) in + let right_bits := M.copy (| γ1_2 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_air::utils::xor_32_shift", + [], + [ AB ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, left_words |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, out_bits |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, right_bits |) + |) + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "outputs" + |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 6 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |), + "p3_blake3_air::columns::Blake3State", + "row1" + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 6 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |), + "p3_blake3_air::columns::Blake3State", + "row3" + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let a := M.copy (| γ1_0 |) in + let b := M.copy (| γ1_1 |) in + let b := M.copy (| γ0_1 |) in + Value.Tuple + [ M.read (| a |); M.read (| b |); M.read (| b |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let γ1_2 := M.SubPointer.get_tuple_field (| γ0_0, 2 |) in + let out_bits := M.copy (| γ1_0 |) in + let left_bits := M.copy (| γ1_1 |) in + let right_bits := M.copy (| γ1_2 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| out_bits |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + |), + [ M.read (| iter |); M.read (| left_bits |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + |), + [ M.read (| iter |); M.read (| right_bits |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := + M.copy (| γ1_0 |) in + let b := + M.copy (| γ1_1 |) in + let b := + M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ1_2 := + M.SubPointer.get_tuple_field (| + γ0_0, + 2 + |) in + let out_bit := M.copy (| γ1_0 |) in + let left_bit := M.copy (| γ1_1 |) in + let right_bit := M.copy (| γ1_2 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| builder |) + |) + |); + M.read (| out_bit |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + left_bit + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + right_bit + |) + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "outputs" + |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "chaining_values" + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "final_round_helpers" + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let a := M.copy (| γ1_0 |) in + let b := M.copy (| γ1_1 |) in + let b := M.copy (| γ0_1 |) in + Value.Tuple + [ M.read (| a |); M.read (| b |); M.read (| b |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let γ1_2 := M.SubPointer.get_tuple_field (| γ0_0, 2 |) in + let out_bits := M.copy (| γ1_0 |) in + let left_bits := M.copy (| γ1_1 |) in + let right_bits := M.copy (| γ1_2 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| out_bits |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + |), + [ M.read (| iter |); M.read (| left_bits |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + |), + [ M.read (| iter |); M.read (| right_bits |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := + M.copy (| γ1_0 |) in + let b := + M.copy (| γ1_1 |) in + let b := + M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ1_2 := + M.SubPointer.get_tuple_field (| + γ0_0, + 2 + |) in + let out_bit := M.copy (| γ1_0 |) in + let left_bit := M.copy (| γ1_1 |) in + let right_bit := M.copy (| γ1_2 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| builder |) + |) + |); + M.read (| out_bit |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + left_bit + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + right_bit + |) + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "outputs" + |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "chaining_values" + |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 6 + |), + "p3_blake3_air::columns::FullRound", + "state_output" + |), + "p3_blake3_air::columns::Blake3State", + "row3" + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let a := M.copy (| γ1_0 |) in + let b := M.copy (| γ1_1 |) in + let b := M.copy (| γ0_1 |) in + Value.Tuple + [ M.read (| a |); M.read (| b |); M.read (| b |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let γ1_2 := M.SubPointer.get_tuple_field (| γ0_0, 2 |) in + let out_bits := M.copy (| γ1_0 |) in + let left_bits := M.copy (| γ1_1 |) in + let right_bits := M.copy (| γ1_2 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| out_bits |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + |), + [ M.read (| iter |); M.read (| left_bits |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + |), + [ M.read (| iter |); M.read (| right_bits |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := + M.copy (| γ1_0 |) in + let b := + M.copy (| γ1_1 |) in + let b := + M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.apply + (Ty.path + "core::array::iter::IntoIter") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ1_2 := + M.SubPointer.get_tuple_field (| + γ0_0, + 2 + |) in + let out_bit := M.copy (| γ1_0 |) in + let left_bit := M.copy (| γ1_1 |) in + let right_bit := M.copy (| γ1_2 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| builder |) + |) + |); + M.read (| out_bit |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + left_bit + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + right_bit + |) + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (AB : Ty.t), + M.IsTraitInstance + "p3_air::air::Air" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ AB ] + (Self AB) + (* Instance *) [ ("eval", InstanceField.Method (eval AB)) ]. + End Impl_p3_air_air_Air_where_p3_air_air_AirBuilder_AB_AB_for_p3_blake3_air_air_Blake3Air. +End air. diff --git a/CoqOfRust/plonky3/blake3_air/src/columns.rs b/CoqOfRust/plonky3/blake3_air/src/columns.rs new file mode 100644 index 000000000..72eca1167 --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/src/columns.rs @@ -0,0 +1,118 @@ +use core::borrow::{Borrow, BorrowMut}; +use core::mem::size_of; + +use crate::constants::U32_LIMBS; + +/// Columns for a Blake-3 AIR which computes one permutation per row. +/// +/// This is a pretty wide trace but that should be fine. +#[repr(C)] +pub struct Blake3Cols { + // The inputs to the hash function. + pub inputs: [[T; 32]; 16], + + // The chaining values are the first eight outputs of the previous compression. + pub chaining_values: [[[T; 32]; 4]; 2], + + // A few auxiliary values use to flesh out the first state. + pub counter_low: [T; 32], + pub counter_hi: [T; 32], + pub block_len: [T; 32], + pub flags: [T; 32], + + // It should be possible to remove these two but this makes a negligible difference to the overall width of the trace. + pub initial_row0: [[T; U32_LIMBS]; 4], + pub initial_row2: [[T; U32_LIMBS]; 4], + + pub full_rounds: [FullRound; 7], + + pub final_round_helpers: [[T; 32]; 4], + + pub outputs: [[[T; 32]; 4]; 4], +} + +/// A state at a single instance of time. +/// +/// Rows `0` and `2` are saved as `2` `16` bit limbs. +/// Rows `1` and `3` are saved as `32` boolean values. +#[repr(C)] +pub struct Blake3State { + pub row0: [[T; U32_LIMBS]; 4], + pub row1: [[T; 32]; 4], + pub row2: [[T; U32_LIMBS]; 4], + pub row3: [[T; 32]; 4], +} + +/// Full round columns. +#[repr(C)] +pub struct FullRound { + // A full round of the Blake3 hash consists of 2 sub rounds each containing 4 applications + // of the quarter round function. + // + // In the first sub round, the quarter round function is applied to each column of the matrix. + // In the second sub round, the quarter round function is applied to each left-right diagonal of the matrix. + // + // We use the output of the previous row to get the input to this row. + // + /// The outputs after applying the first half of the column quarter round functions. + pub state_prime: Blake3State, + + /// The outputs after the first sub round. + pub state_middle: Blake3State, + + /// The outputs after applying the first half of the diagonal quarter round functions. + pub state_middle_prime: Blake3State, + + /// This will also be the input to the next row. + pub state_output: Blake3State, +} + +/// Data needed to verify a single quarter round function. +#[repr(C)] +pub(crate) struct QuarterRound<'a, T, U> { + // The inputs to the quarter round function. + pub a: &'a [T; U32_LIMBS], + pub b: &'a [T; 32], + pub c: &'a [T; U32_LIMBS], + pub d: &'a [T; 32], + + pub m_two_i: &'a [U; U32_LIMBS], // m_{2i} + + // The state after the first half of the quarter round function. + pub a_prime: &'a [T; U32_LIMBS], + pub b_prime: &'a [T; 32], + pub c_prime: &'a [T; U32_LIMBS], + pub d_prime: &'a [T; 32], + + pub m_two_i_plus_one: &'a [U; U32_LIMBS], // m_{2i + 1} + + // The output from the quarter round function. + pub a_output: &'a [T; U32_LIMBS], + pub b_output: &'a [T; 32], + pub c_output: &'a [T; U32_LIMBS], + pub d_output: &'a [T; 32], +} + +pub const NUM_BLAKE3_COLS: usize = size_of::>(); + +impl Borrow> for [T] { + fn borrow(&self) -> &Blake3Cols { + debug_assert_eq!(self.len(), NUM_BLAKE3_COLS); + let (prefix, shorts, suffix) = unsafe { self.align_to::>() }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &shorts[0] + } +} + +impl BorrowMut> for [T] { + fn borrow_mut(&mut self) -> &mut Blake3Cols { + debug_assert_eq!(self.len(), NUM_BLAKE3_COLS); + let (prefix, shorts, suffix) = unsafe { self.align_to_mut::>() }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &mut shorts[0] + } +} diff --git a/CoqOfRust/plonky3/blake3_air/src/columns.v b/CoqOfRust/plonky3/blake3_air/src/columns.v new file mode 100644 index 000000000..4390e19e4 --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/src/columns.v @@ -0,0 +1,1459 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module columns. + (* StructRecord + { + name := "Blake3Cols"; + const_params := []; + ty_params := [ "T" ]; + fields := + [ + ("inputs", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ]); + ("chaining_values", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ] + ]); + ("counter_low", Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ]); + ("counter_hi", Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ]); + ("block_len", Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ]); + ("flags", Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ]); + ("initial_row0", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_Blake3Cols_initial_row0_discriminant" |)) + ] + [ T ] + ]); + ("initial_row2", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_Blake3Cols_initial_row2_discriminant" |)) + ] + [ T ] + ]); + ("full_rounds", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 7 ] + [ Ty.apply (Ty.path "p3_blake3_air::columns::FullRound") [] [ T ] ]); + ("final_round_helpers", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ]); + ("outputs", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ] + ]) + ]; + } *) + + (* StructRecord + { + name := "Blake3State"; + const_params := []; + ty_params := [ "T" ]; + fields := + [ + ("row0", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_Blake3State_row0_discriminant" |)) + ] + [ T ] + ]); + ("row1", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ]); + ("row2", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_Blake3State_row2_discriminant" |)) + ] + [ T ] + ]); + ("row3", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ]) + ]; + } *) + + (* StructRecord + { + name := "FullRound"; + const_params := []; + ty_params := [ "T" ]; + fields := + [ + ("state_prime", Ty.apply (Ty.path "p3_blake3_air::columns::Blake3State") [] [ T ]); + ("state_middle", Ty.apply (Ty.path "p3_blake3_air::columns::Blake3State") [] [ T ]); + ("state_middle_prime", Ty.apply (Ty.path "p3_blake3_air::columns::Blake3State") [] [ T ]); + ("state_output", Ty.apply (Ty.path "p3_blake3_air::columns::Blake3State") [] [ T ]) + ]; + } *) + + (* StructRecord + { + name := "QuarterRound"; + const_params := []; + ty_params := [ "T"; "U" ]; + fields := + [ + ("a", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_QuarterRound_a_discriminant" |)) + ] + [ T ] + ]); + ("b", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ]); + ("c", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_QuarterRound_c_discriminant" |)) + ] + [ T ] + ]); + ("d", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ]); + ("m_two_i", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_QuarterRound_m_two_i_discriminant" |)) + ] + [ U ] + ]); + ("a_prime", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_QuarterRound_a_prime_discriminant" |)) + ] + [ T ] + ]); + ("b_prime", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ]); + ("c_prime", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_QuarterRound_c_prime_discriminant" |)) + ] + [ T ] + ]); + ("d_prime", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ]); + ("m_two_i_plus_one", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| + "p3_blake3_air_columns_QuarterRound_m_two_i_plus_one_discriminant" + |)) + ] + [ U ] + ]); + ("a_output", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_QuarterRound_a_output_discriminant" |)) + ] + [ T ] + ]); + ("b_output", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ]); + ("c_output", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_blake3_air_columns_QuarterRound_c_output_discriminant" |)) + ] + [ T ] + ]); + ("d_output", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ] ]) + ]; + } *) + + Definition value_NUM_BLAKE3_COLS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ Ty.path "u8" ] ] + |), + [] + |) + |))). + + Global Instance Instance_IsConstant_value_NUM_BLAKE3_COLS : + M.IsFunction.C "p3_blake3_air::columns::NUM_BLAKE3_COLS" value_NUM_BLAKE3_COLS. + Admitted. + Global Typeclasses Opaque value_NUM_BLAKE3_COLS. + + Module Impl_core_borrow_Borrow_p3_blake3_air_columns_Blake3Cols_T_for_slice_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ T ]. + + (* + fn borrow(&self) -> &Blake3Cols { + debug_assert_eq!(self.len(), NUM_BLAKE3_COLS); + let (prefix, shorts, suffix) = unsafe { self.align_to::>() }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &shorts[0] + } + *) + Definition borrow (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_blake3_air::columns::NUM_BLAKE3_COLS", + Ty.path "usize" + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ T ] ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ T ] ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "align_to", + [], + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ T ] ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let shorts := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ T ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shorts |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 1 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| shorts |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ T ] ] + (Self T) + (* Instance *) [ ("borrow", InstanceField.Method (borrow T)) ]. + End Impl_core_borrow_Borrow_p3_blake3_air_columns_Blake3Cols_T_for_slice_T. + + Module Impl_core_borrow_BorrowMut_p3_blake3_air_columns_Blake3Cols_T_for_slice_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ T ]. + + (* + fn borrow_mut(&mut self) -> &mut Blake3Cols { + debug_assert_eq!(self.len(), NUM_BLAKE3_COLS); + let (prefix, shorts, suffix) = unsafe { self.align_to_mut::>() }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &mut shorts[0] + } + *) + Definition borrow_mut (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_blake3_air::columns::NUM_BLAKE3_COLS", + Ty.path "usize" + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ T ] ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ T ] ] + ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "align_to_mut", + [], + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ T ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let shorts := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_blake3_air::columns::Blake3Cols") + [] + [ T ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shorts |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 1 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| shorts |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + |))) + ] + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ T ] ] + (Self T) + (* Instance *) [ ("borrow_mut", InstanceField.Method (borrow_mut T)) ]. + End Impl_core_borrow_BorrowMut_p3_blake3_air_columns_Blake3Cols_T_for_slice_T. +End columns. diff --git a/CoqOfRust/plonky3/blake3_air/src/constants.rs b/CoqOfRust/plonky3/blake3_air/src/constants.rs new file mode 100644 index 000000000..6cf7173ad --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/src/constants.rs @@ -0,0 +1,36 @@ +pub const BITS_PER_LIMB: usize = 16; +pub const U32_LIMBS: usize = 32 / BITS_PER_LIMB; + +// The constants from the reference implementation. +// Saved as pairs of 16 bit integers in [lo, hi] format. +pub(crate) const IV: [[u16; 2]; 8] = [ + [0xE667, 0x6A09], + [0xAE85, 0xBB67], + [0xF372, 0x3C6E], + [0xF53A, 0xA54F], + [0x527F, 0x510E], + [0x688C, 0x9B05], + [0xD9AB, 0x1F83], + [0xCD19, 0x5BE0], +]; + +// The index map for the permutation used to permute the block words is: +// `[2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8]` +// +// This permutation decomposes into 2 cycles of length 8: +// `0 -> 2 -> 3 -> 10 -> 12 -> 9 -> 11 -> 5 -> 0` +// `1 -> 6 -> 4 -> 7 -> 13 -> 14 -> 15 -> 8 -> 1` +// +// There might be a way to use this decomposition to slightly speed permute up. + +/// The index map for the permutation used to permute the block words. +const MSG_PERMUTATION: [usize; 16] = [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8]; + +/// Apply the MSG_PERMUTATION to an array. +pub(crate) fn permute(m: &mut [T; 16]) { + let mut permuted = m.clone(); + for i in 0..16 { + permuted[i] = m[MSG_PERMUTATION[i]].clone(); + } + *m = permuted; +} diff --git a/CoqOfRust/plonky3/blake3_air/src/constants.v b/CoqOfRust/plonky3/blake3_air/src/constants.v new file mode 100644 index 000000000..56e7a219a --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/src/constants.v @@ -0,0 +1,257 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module constants. + Definition value_BITS_PER_LIMB (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 16 |))). + + Global Instance Instance_IsConstant_value_BITS_PER_LIMB : + M.IsFunction.C "p3_blake3_air::constants::BITS_PER_LIMB" value_BITS_PER_LIMB. + Admitted. + Global Typeclasses Opaque value_BITS_PER_LIMB. + + Definition value_U32_LIMBS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + Value.Integer IntegerKind.Usize 32; + M.read (| + get_constant (| "p3_blake3_air::constants::BITS_PER_LIMB", Ty.path "usize" |) + |) + ] + |) + |))). + + Global Instance Instance_IsConstant_value_U32_LIMBS : + M.IsFunction.C "p3_blake3_air::constants::U32_LIMBS" value_U32_LIMBS. + Admitted. + Global Typeclasses Opaque value_U32_LIMBS. + + Definition value_IV (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Array + [ Value.Integer IntegerKind.U16 58983; Value.Integer IntegerKind.U16 27145 ]; + Value.Array + [ Value.Integer IntegerKind.U16 44677; Value.Integer IntegerKind.U16 47975 ]; + Value.Array + [ Value.Integer IntegerKind.U16 62322; Value.Integer IntegerKind.U16 15470 ]; + Value.Array + [ Value.Integer IntegerKind.U16 62778; Value.Integer IntegerKind.U16 42319 ]; + Value.Array + [ Value.Integer IntegerKind.U16 21119; Value.Integer IntegerKind.U16 20750 ]; + Value.Array + [ Value.Integer IntegerKind.U16 26764; Value.Integer IntegerKind.U16 39685 ]; + Value.Array [ Value.Integer IntegerKind.U16 55723; Value.Integer IntegerKind.U16 8067 ]; + Value.Array [ Value.Integer IntegerKind.U16 52505; Value.Integer IntegerKind.U16 23520 ] + ] + |))). + + Global Instance Instance_IsConstant_value_IV : + M.IsFunction.C "p3_blake3_air::constants::IV" value_IV. + Admitted. + Global Typeclasses Opaque value_IV. + + Definition value_MSG_PERMUTATION (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 6; + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 10; + Value.Integer IntegerKind.Usize 7; + Value.Integer IntegerKind.Usize 0; + Value.Integer IntegerKind.Usize 4; + Value.Integer IntegerKind.Usize 13; + Value.Integer IntegerKind.Usize 1; + Value.Integer IntegerKind.Usize 11; + Value.Integer IntegerKind.Usize 12; + Value.Integer IntegerKind.Usize 5; + Value.Integer IntegerKind.Usize 9; + Value.Integer IntegerKind.Usize 14; + Value.Integer IntegerKind.Usize 15; + Value.Integer IntegerKind.Usize 8 + ] + |))). + + Global Instance Instance_IsConstant_value_MSG_PERMUTATION : + M.IsFunction.C "p3_blake3_air::constants::MSG_PERMUTATION" value_MSG_PERMUTATION. + Admitted. + Global Typeclasses Opaque value_MSG_PERMUTATION. + + (* + pub(crate) fn permute(m: &mut [T; 16]) { + let mut permuted = m.clone(); + for i in 0..16 { + permuted[i] = m[MSG_PERMUTATION[i]].clone(); + } + *m = permuted; + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ m ] => + ltac:(M.monadic + (let m := M.alloc (| m |) in + M.read (| + let~ permuted : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ T ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ T ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ T ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| m |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 16) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + permuted, + M.read (| i |) + |), + M.call_closure (| + T, + M.get_trait_method (| + "core::clone::Clone", + T, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| m |) |), + M.read (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::MSG_PERMUTATION", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "usize" ] + |), + M.read (| i |) + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.write (| M.deref (| M.read (| m |) |), M.read (| permuted |) |) |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_permute : + M.IsFunction.C "p3_blake3_air::constants::permute" permute. + Admitted. + Global Typeclasses Opaque permute. +End constants. diff --git a/CoqOfRust/plonky3/blake3_air/src/generation.rs b/CoqOfRust/plonky3/blake3_air/src/generation.rs new file mode 100644 index 000000000..3a93bea73 --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/src/generation.rs @@ -0,0 +1,250 @@ +use alloc::vec::Vec; +use core::array; + +use p3_air::utils::u32_to_bits_le; +use p3_field::{PrimeCharacteristicRing, PrimeField64}; +use p3_matrix::dense::RowMajorMatrix; +use p3_maybe_rayon::prelude::*; +use tracing::instrument; + +use crate::columns::{Blake3Cols, NUM_BLAKE3_COLS}; +use crate::constants::{IV, permute}; +use crate::{Blake3State, FullRound}; + +// TODO: Take generic iterable +#[instrument(name = "generate Blake3 trace", skip_all)] +pub fn generate_trace_rows( + inputs: Vec<[u32; 24]>, + extra_capacity_bits: usize, +) -> RowMajorMatrix { + let num_rows = inputs.len(); + assert!( + num_rows.is_power_of_two(), + "Callers expected to pad inputs to VECTOR_LEN times a power of two" + ); + + let trace_length = num_rows * NUM_BLAKE3_COLS; + + // We allocate extra_capacity_bits now as this will be needed by the dft. + let mut long_trace = F::zero_vec(trace_length << extra_capacity_bits); + long_trace.truncate(trace_length); + + let mut trace = RowMajorMatrix::new(long_trace, NUM_BLAKE3_COLS); + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::>() }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(rows.len(), num_rows); + + rows.par_iter_mut() + .zip(inputs) + .enumerate() + .for_each(|(counter, (row, input))| { + generate_trace_rows_for_perm(row, input, counter, num_rows); + }); + + trace +} + +/// Each row is one full implementation of the Blake-3 hash. +fn generate_trace_rows_for_perm( + row: &mut Blake3Cols, + input: [u32; 24], + counter: usize, + block_len: usize, +) { + // We split the input into 2 parts. + // The first 16 elements we treat as the inputs or block_words + row.inputs = array::from_fn(|i| u32_to_bits_le(input[i])); + + // the remaining 8 elements are interpreted as the chaining values. + row.chaining_values = + array::from_fn(|i| array::from_fn(|j| u32_to_bits_le(input[16 + 4 * i + j]))); + + row.counter_low = u32_to_bits_le(counter as u32); + row.counter_hi = u32_to_bits_le(counter.wrapping_shr(32) as u32); + row.block_len = u32_to_bits_le(block_len as u32); + + // We set the flags initial value to just be 0. + row.flags = u32_to_bits_le(0); + + row.initial_row0 = array::from_fn(|i| { + [ + F::from_u16(input[16 + i] as u16), + F::from_u16((input[16 + i] >> 16) as u16), + ] + }); + + row.initial_row2 = array::from_fn(|i| [F::from_u16(IV[i][0]), F::from_u16(IV[i][1])]); + + // We save the state and m_vec as u_32's we will quickly compute the hash using these whilst saving + // the appropriate data in the trace as we go. + let mut m_vec: [u32; 16] = array::from_fn(|i| input[i]); + let mut state = [ + [input[16], input[16 + 1], input[16 + 2], input[16 + 3]], + [input[16 + 4], input[16 + 5], input[16 + 6], input[16 + 7]], + [ + (IV[0][0] as u32) + ((IV[0][1] as u32) << 16), + (IV[1][0] as u32) + ((IV[1][1] as u32) << 16), + (IV[2][0] as u32) + ((IV[2][1] as u32) << 16), + (IV[3][0] as u32) + ((IV[3][1] as u32) << 16), + ], + [ + counter as u32, + counter.wrapping_shr(32) as u32, + block_len as u32, + 0, + ], + ]; + + generate_trace_row_for_round(&mut row.full_rounds[0], &mut state, &m_vec); // round 1 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[1], &mut state, &m_vec); // round 2 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[2], &mut state, &m_vec); // round 3 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[3], &mut state, &m_vec); // round 4 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[4], &mut state, &m_vec); // round 5 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[5], &mut state, &m_vec); // round 6 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[6], &mut state, &m_vec); // round 7 + + // After performing all the rounds, all that is left to do is to populate the final xor data. + + row.final_round_helpers = array::from_fn(|i| u32_to_bits_le(state[2][i])); + + row.outputs[0] = array::from_fn(|i| u32_to_bits_le(state[0][i] ^ state[2][i])); + row.outputs[1] = array::from_fn(|i| u32_to_bits_le(state[1][i] ^ state[3][i])); + row.outputs[2] = array::from_fn(|i| u32_to_bits_le(state[2][i] ^ input[16 + i])); + row.outputs[3] = array::from_fn(|i| u32_to_bits_le(state[3][i] ^ input[20 + i])); +} + +fn generate_trace_row_for_round( + round_data: &mut FullRound, + state: &mut [[u32; 4]; 4], + m_vec: &[u32; 16], +) { + // We populate the round_data as we iterate through and compute the permutation following the reference implementation. + + // We start by performing the first half of the four column quarter round functions. + (0..4).for_each(|i| { + (state[0][i], state[1][i], state[2][i], state[3][i]) = verifiable_half_round( + state[0][i], + state[1][i], + state[2][i], + state[3][i], + m_vec[2 * i], + false, + ) + }); + + // After the first four operations we need to save a copy of the state into the trace. + save_state_to_trace(&mut round_data.state_prime, state); + + // Next we do the second half of the four column quarter round functions. + (0..4).for_each(|i| { + (state[0][i], state[1][i], state[2][i], state[3][i]) = verifiable_half_round( + state[0][i], + state[1][i], + state[2][i], + state[3][i], + m_vec[2 * i + 1], + true, + ) + }); + + // Again we save another copy of the state. + save_state_to_trace(&mut round_data.state_middle, state); + + // We repeat with the diagonals quarter round function. + + // Do the first half of the four diagonal quarter round functions. + (0..4).for_each(|i| { + ( + state[0][i], + state[1][(i + 1) % 4], + state[2][(i + 2) % 4], + state[3][(i + 3) % 4], + ) = verifiable_half_round( + state[0][i], + state[1][(i + 1) % 4], + state[2][(i + 2) % 4], + state[3][(i + 3) % 4], + m_vec[8 + 2 * i], + false, + ) + }); + + // Save a copy of the state to the trace. + save_state_to_trace(&mut round_data.state_middle_prime, state); + + // Do the second half of the four diagonal quarter round functions. + (0..4).for_each(|i| { + ( + state[0][i], + state[1][(i + 1) % 4], + state[2][(i + 2) % 4], + state[3][(i + 3) % 4], + ) = verifiable_half_round( + state[0][i], + state[1][(i + 1) % 4], + state[2][(i + 2) % 4], + state[3][(i + 3) % 4], + m_vec[9 + 2 * i], + true, + ) + }); + + // Save a copy of the state to the trace. + save_state_to_trace(&mut round_data.state_output, state); +} + +/// Perform half of a quarter round on the given elements. +/// +/// The boolean flag, indicates whether this is the first (false) or second (true) half round. +const fn verifiable_half_round( + mut a: u32, + mut b: u32, + mut c: u32, + mut d: u32, + m: u32, + flag: bool, +) -> (u32, u32, u32, u32) { + let (rot_1, rot_2) = if flag { (8, 7) } else { (16, 12) }; + + // The first summation: + a = a.wrapping_add(b); + a = a.wrapping_add(m); + + // The first xor: + d = (d ^ a).rotate_right(rot_1); + + // The second summation: + c = c.wrapping_add(d); + + // The second xor: + b = (b ^ c).rotate_right(rot_2); + + (a, b, c, d) +} + +fn save_state_to_trace( + trace: &mut Blake3State, + state: &[[u32; 4]; 4], +) { + trace.row0 = array::from_fn(|i| { + [ + R::from_u16(state[0][i] as u16), // Store the bottom 16 bits packed. + R::from_u16((state[0][i] >> 16) as u16), // Store the top 16 bits packed. + ] + }); + trace.row1 = array::from_fn(|i| u32_to_bits_le(state[1][i])); // Store all 32 bits unpacked. + trace.row2 = array::from_fn(|i| { + [ + R::from_u16(state[2][i] as u16), // Store the bottom 16 bits packed. + R::from_u16((state[2][i] >> 16) as u16), // Store the top 16 bits packed. + ] + }); + trace.row3 = array::from_fn(|i| u32_to_bits_le(state[3][i])); // Store all 32 bits unpacked. +} diff --git a/CoqOfRust/plonky3/blake3_air/src/generation.v b/CoqOfRust/plonky3/blake3_air/src/generation.v new file mode 100644 index 000000000..db560f806 --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/src/generation.v @@ -0,0 +1,5045 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module generation. + (* #[instrument(name = "generate Blake3 trace", skip_all)] *) + Definition generate_trace_rows (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ inputs; extra_capacity_bits ] => + ltac:(M.monadic + (let inputs := M.alloc (| inputs |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.catch_return + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_blake3_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_blake3_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_blake3_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_blake3_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ num_rows : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inputs |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "usize", + "is_power_of_two", + [], + [] + |), + [ M.read (| num_rows |) ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Callers expected to pad inputs to VECTOR_LEN times a power of two" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ trace_length : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| num_rows |); + M.read (| + get_constant (| + "p3_blake3_air::columns::NUM_BLAKE3_COLS", + Ty.path "usize" + |) + |) + ] + |) + |) in + let~ long_trace : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "zero_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ M.read (| trace_length |); M.read (| extra_capacity_bits |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "truncate", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, long_trace |); M.read (| trace_length |) ] + |) + |) in + let~ trace : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.read (| long_trace |); + M.read (| + get_constant (| + "p3_blake3_air::columns::NUM_BLAKE3_COLS", + Ty.path "usize" + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ F ] ] + ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "align_to_mut", + [], + [ Ty.apply (Ty.path "p3_blake3_air::columns::Blake3Cols") [] [ F ] ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + trace, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let rows := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Alignment should match" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Alignment should match" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ F ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| rows |) |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, num_rows |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ F ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ F ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ F ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ F ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ F ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ F ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u32" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ F ] + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelRefMutIterator", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_blake3_air::columns::Blake3Cols") + [] + [ F ] + ], + [], + [], + "par_iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| rows |) |) + |) + ] + |); + M.read (| inputs |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_blake3_air::columns::Blake3Cols") + [] + [ F ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 + ] + [ Ty.path "u32" ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let counter := M.copy (| γ0_0 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_1, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_1, 1 |) in + let row := M.copy (| γ1_0 |) in + let input := M.copy (| γ1_1 |) in + M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::generation::generate_trace_rows_for_perm", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| row |) |) + |); + M.read (| input |); + M.read (| counter |); + M.read (| num_rows |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + trace)) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_trace_rows : + M.IsFunction.C "p3_blake3_air::generation::generate_trace_rows" generate_trace_rows. + Admitted. + Global Typeclasses Opaque generate_trace_rows. + + (* + fn generate_trace_rows_for_perm( + row: &mut Blake3Cols, + input: [u32; 24], + counter: usize, + block_len: usize, + ) { + // We split the input into 2 parts. + // The first 16 elements we treat as the inputs or block_words + row.inputs = array::from_fn(|i| u32_to_bits_le(input[i])); + + // the remaining 8 elements are interpreted as the chaining values. + row.chaining_values = + array::from_fn(|i| array::from_fn(|j| u32_to_bits_le(input[16 + 4 * i + j]))); + + row.counter_low = u32_to_bits_le(counter as u32); + row.counter_hi = u32_to_bits_le(counter.wrapping_shr(32) as u32); + row.block_len = u32_to_bits_le(block_len as u32); + + // We set the flags initial value to just be 0. + row.flags = u32_to_bits_le(0); + + row.initial_row0 = array::from_fn(|i| { + [ + F::from_u16(input[16 + i] as u16), + F::from_u16((input[16 + i] >> 16) as u16), + ] + }); + + row.initial_row2 = array::from_fn(|i| [F::from_u16(IV[i][0]), F::from_u16(IV[i][1])]); + + // We save the state and m_vec as u_32's we will quickly compute the hash using these whilst saving + // the appropriate data in the trace as we go. + let mut m_vec: [u32; 16] = array::from_fn(|i| input[i]); + let mut state = [ + [input[16], input[16 + 1], input[16 + 2], input[16 + 3]], + [input[16 + 4], input[16 + 5], input[16 + 6], input[16 + 7]], + [ + (IV[0][0] as u32) + ((IV[0][1] as u32) << 16), + (IV[1][0] as u32) + ((IV[1][1] as u32) << 16), + (IV[2][0] as u32) + ((IV[2][1] as u32) << 16), + (IV[3][0] as u32) + ((IV[3][1] as u32) << 16), + ], + [ + counter as u32, + counter.wrapping_shr(32) as u32, + block_len as u32, + 0, + ], + ]; + + generate_trace_row_for_round(&mut row.full_rounds[0], &mut state, &m_vec); // round 1 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[1], &mut state, &m_vec); // round 2 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[2], &mut state, &m_vec); // round 3 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[3], &mut state, &m_vec); // round 4 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[4], &mut state, &m_vec); // round 5 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[5], &mut state, &m_vec); // round 6 + permute(&mut m_vec); + generate_trace_row_for_round(&mut row.full_rounds[6], &mut state, &m_vec); // round 7 + + // After performing all the rounds, all that is left to do is to populate the final xor data. + + row.final_round_helpers = array::from_fn(|i| u32_to_bits_le(state[2][i])); + + row.outputs[0] = array::from_fn(|i| u32_to_bits_le(state[0][i] ^ state[2][i])); + row.outputs[1] = array::from_fn(|i| u32_to_bits_le(state[1][i] ^ state[3][i])); + row.outputs[2] = array::from_fn(|i| u32_to_bits_le(state[2][i] ^ input[16 + i])); + row.outputs[3] = array::from_fn(|i| u32_to_bits_le(state[3][i] ^ input[20 + i])); + } + *) + Definition generate_trace_rows_for_perm + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ row; input; counter; block_len ] => + ltac:(M.monadic + (let row := M.alloc (| row |) in + let input := M.alloc (| input |) in + let counter := M.alloc (| counter |) in + let block_len := M.alloc (| block_len |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "inputs" + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 16 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ], + M.get_function (| + "p3_air::utils::u32_to_bits_le", + [], + [ F ] + |), + [ + M.read (| + M.SubPointer.get_array_field (| input, M.read (| i |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "chaining_values" + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ] ] + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 2 ], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ] ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ] + ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ] + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 + ] + [ F ], + M.get_function (| + "p3_air::utils::u32_to_bits_le", + [], + [ F ] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + Value.Integer + IntegerKind.Usize + 16; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer + IntegerKind.Usize + 4; + M.read (| i |) + ] + |) + ] + |); + M.read (| j |) + ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "counter_low" + |), + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ], + M.get_function (| "p3_air::utils::u32_to_bits_le", [], [ F ] |), + [ M.cast (Ty.path "u32") (M.read (| counter |)) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "counter_hi" + |), + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ], + M.get_function (| "p3_air::utils::u32_to_bits_le", [], [ F ] |), + [ + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "wrapping_shr", [], [] |), + [ M.read (| counter |); Value.Integer IntegerKind.U32 32 ] + |)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "block_len" + |), + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ], + M.get_function (| "p3_air::utils::u32_to_bits_le", [], [ F ] |), + [ M.cast (Ty.path "u32") (M.read (| block_len |)) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "flags" + |), + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ], + M.get_function (| "p3_air::utils::u32_to_bits_le", [], [ F ] |), + [ Value.Integer IntegerKind.U32 0 ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "initial_row0" + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + Value.Array + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_u16", + [], + [] + |), + [ + M.cast + (Ty.path "u16") + (M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + Value.Integer IntegerKind.Usize 16; + M.read (| i |) + ] + |) + |) + |)) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_u16", + [], + [] + |), + [ + M.cast + (Ty.path "u16") + (M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + Value.Integer IntegerKind.Usize 16; + M.read (| i |) + ] + |) + |) + |); + Value.Integer IntegerKind.I32 16 + ] + |)) + ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "initial_row2" + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + Value.Array + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_u16", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |), + M.read (| i |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_u16", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |), + M.read (| i |) + |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ m_vec : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "u32" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ Ty.path "u32" ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 16 ], + [ Ty.path "u32"; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.path "u32") ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.path "u32") ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + M.SubPointer.get_array_field (| input, M.read (| i |) |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u32" ] + ] + ] := + M.alloc (| + Value.Array + [ + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| input, Value.Integer IntegerKind.Usize 16 |) + |); + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 2 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 3 + ] + |) + |) + |) + ]; + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 5 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 6 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 7 + ] + |) + |) + |) + ]; + Value.Array + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.cast + (Ty.path "u32") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |), + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |)); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ + M.cast + (Ty.path "u32") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |), + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 1 + |) + |)); + Value.Integer IntegerKind.I32 16 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.cast + (Ty.path "u32") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |), + Value.Integer IntegerKind.Usize 1 + |), + Value.Integer IntegerKind.Usize 0 + |) + |)); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ + M.cast + (Ty.path "u32") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |), + Value.Integer IntegerKind.Usize 1 + |), + Value.Integer IntegerKind.Usize 1 + |) + |)); + Value.Integer IntegerKind.I32 16 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.cast + (Ty.path "u32") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |), + Value.Integer IntegerKind.Usize 2 + |), + Value.Integer IntegerKind.Usize 0 + |) + |)); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ + M.cast + (Ty.path "u32") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |), + Value.Integer IntegerKind.Usize 2 + |), + Value.Integer IntegerKind.Usize 1 + |) + |)); + Value.Integer IntegerKind.I32 16 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.cast + (Ty.path "u32") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |), + Value.Integer IntegerKind.Usize 3 + |), + Value.Integer IntegerKind.Usize 0 + |) + |)); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ + M.cast + (Ty.path "u32") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_blake3_air::constants::IV", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u16" ] + ] + |), + Value.Integer IntegerKind.Usize 3 + |), + Value.Integer IntegerKind.Usize 1 + |) + |)); + Value.Integer IntegerKind.I32 16 + ] + |) + ] + |) + ]; + Value.Array + [ + M.cast (Ty.path "u32") (M.read (| counter |)); + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "wrapping_shr", [], [] |), + [ M.read (| counter |); Value.Integer IntegerKind.U32 32 ] + |)); + M.cast (Ty.path "u32") (M.read (| block_len |)); + Value.Integer IntegerKind.U32 0 + ] + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::generation::generate_trace_row_for_round", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_blake3_air::constants::permute", [], [ Ty.path "u32" ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::generation::generate_trace_row_for_round", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_blake3_air::constants::permute", [], [ Ty.path "u32" ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::generation::generate_trace_row_for_round", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 2 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_blake3_air::constants::permute", [], [ Ty.path "u32" ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::generation::generate_trace_row_for_round", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 3 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_blake3_air::constants::permute", [], [ Ty.path "u32" ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::generation::generate_trace_row_for_round", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 4 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_blake3_air::constants::permute", [], [ Ty.path "u32" ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::generation::generate_trace_row_for_round", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 5 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_blake3_air::constants::permute", [], [ Ty.path "u32" ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_blake3_air::generation::generate_trace_row_for_round", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "full_rounds" + |), + Value.Integer IntegerKind.Usize 6 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, m_vec |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "final_round_helpers" + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ], + M.get_function (| + "p3_air::utils::u32_to_bits_le", + [], + [ F ] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 2 + |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "outputs" + |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ], + M.get_function (| + "p3_air::utils::u32_to_bits_le", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_xor, + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 2 + |), + M.read (| i |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "outputs" + |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ], + M.get_function (| + "p3_air::utils::u32_to_bits_le", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_xor, + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 1 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 3 + |), + M.read (| i |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "outputs" + |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ], + M.get_function (| + "p3_air::utils::u32_to_bits_le", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_xor, + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 2 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + Value.Integer IntegerKind.Usize 16; + M.read (| i |) + ] + |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_blake3_air::columns::Blake3Cols", + "outputs" + |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ F ], + M.get_function (| + "p3_air::utils::u32_to_bits_le", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_xor, + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 3 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + input, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + Value.Integer IntegerKind.Usize 20; + M.read (| i |) + ] + |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_trace_rows_for_perm : + M.IsFunction.C + "p3_blake3_air::generation::generate_trace_rows_for_perm" + generate_trace_rows_for_perm. + Admitted. + Global Typeclasses Opaque generate_trace_rows_for_perm. + + (* + fn generate_trace_row_for_round( + round_data: &mut FullRound, + state: &mut [[u32; 4]; 4], + m_vec: &[u32; 16], + ) { + // We populate the round_data as we iterate through and compute the permutation following the reference implementation. + + // We start by performing the first half of the four column quarter round functions. + (0..4).for_each(|i| { + (state[0][i], state[1][i], state[2][i], state[3][i]) = verifiable_half_round( + state[0][i], + state[1][i], + state[2][i], + state[3][i], + m_vec[2 * i], + false, + ) + }); + + // After the first four operations we need to save a copy of the state into the trace. + save_state_to_trace(&mut round_data.state_prime, state); + + // Next we do the second half of the four column quarter round functions. + (0..4).for_each(|i| { + (state[0][i], state[1][i], state[2][i], state[3][i]) = verifiable_half_round( + state[0][i], + state[1][i], + state[2][i], + state[3][i], + m_vec[2 * i + 1], + true, + ) + }); + + // Again we save another copy of the state. + save_state_to_trace(&mut round_data.state_middle, state); + + // We repeat with the diagonals quarter round function. + + // Do the first half of the four diagonal quarter round functions. + (0..4).for_each(|i| { + ( + state[0][i], + state[1][(i + 1) % 4], + state[2][(i + 2) % 4], + state[3][(i + 3) % 4], + ) = verifiable_half_round( + state[0][i], + state[1][(i + 1) % 4], + state[2][(i + 2) % 4], + state[3][(i + 3) % 4], + m_vec[8 + 2 * i], + false, + ) + }); + + // Save a copy of the state to the trace. + save_state_to_trace(&mut round_data.state_middle_prime, state); + + // Do the second half of the four diagonal quarter round functions. + (0..4).for_each(|i| { + ( + state[0][i], + state[1][(i + 1) % 4], + state[2][(i + 2) % 4], + state[3][(i + 3) % 4], + ) = verifiable_half_round( + state[0][i], + state[1][(i + 1) % 4], + state[2][(i + 2) % 4], + state[3][(i + 3) % 4], + m_vec[9 + 2 * i], + true, + ) + }); + + // Save a copy of the state to the trace. + save_state_to_trace(&mut round_data.state_output, state); + } + *) + Definition generate_trace_row_for_round + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ round_data; state; m_vec ] => + ltac:(M.monadic + (let round_data := M.alloc (| round_data |) in + let state := M.alloc (| state |) in + let m_vec := M.alloc (| m_vec |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "for_each", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.tuple []) ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 4) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.path "u32"; + Ty.path "u32"; + Ty.path "u32"; + Ty.path "u32" + ], + M.get_function (| + "p3_blake3_air::generation::verifiable_half_round", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| m_vec |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 2; + M.read (| i |) + ] + |) + |) + |); + Value.Bool false + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let γ0_3 := M.SubPointer.get_tuple_field (| γ, 3 |) in + let lhs := M.copy (| γ0_0 |) in + let lhs := M.copy (| γ0_1 |) in + let lhs := M.copy (| γ0_2 |) in + let lhs := M.copy (| γ0_3 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| i |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.read (| i |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.read (| i |) + |), + M.read (| lhs |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_blake3_air::generation::save_state_to_trace", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_prime" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "for_each", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.tuple []) ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 4) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.path "u32"; + Ty.path "u32"; + Ty.path "u32"; + Ty.path "u32" + ], + M.get_function (| + "p3_blake3_air::generation::verifiable_half_round", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| m_vec |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 2; + M.read (| i |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |); + Value.Bool true + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let γ0_3 := M.SubPointer.get_tuple_field (| γ, 3 |) in + let lhs := M.copy (| γ0_0 |) in + let lhs := M.copy (| γ0_1 |) in + let lhs := M.copy (| γ0_2 |) in + let lhs := M.copy (| γ0_3 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| i |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.read (| i |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.read (| i |) + |), + M.read (| lhs |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_blake3_air::generation::save_state_to_trace", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "for_each", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.tuple []) ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 4) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.path "u32"; + Ty.path "u32"; + Ty.path "u32"; + Ty.path "u32" + ], + M.get_function (| + "p3_blake3_air::generation::verifiable_half_round", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 2 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 3 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| m_vec |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + Value.Integer IntegerKind.Usize 8; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 2; + M.read (| i |) + ] + |) + ] + |) + |) + |); + Value.Bool false + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let γ0_3 := M.SubPointer.get_tuple_field (| γ, 3 |) in + let lhs := M.copy (| γ0_0 |) in + let lhs := M.copy (| γ0_1 |) in + let lhs := M.copy (| γ0_2 |) in + let lhs := M.copy (| γ0_3 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 2 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 3 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |), + M.read (| lhs |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_blake3_air::generation::save_state_to_trace", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_middle_prime" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "for_each", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.tuple []) ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 4) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.path "u32"; + Ty.path "u32"; + Ty.path "u32"; + Ty.path "u32" + ], + M.get_function (| + "p3_blake3_air::generation::verifiable_half_round", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 2 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 3 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| m_vec |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + Value.Integer IntegerKind.Usize 9; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 2; + M.read (| i |) + ] + |) + ] + |) + |) + |); + Value.Bool true + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let γ0_3 := M.SubPointer.get_tuple_field (| γ, 3 |) in + let lhs := M.copy (| γ0_0 |) in + let lhs := M.copy (| γ0_1 |) in + let lhs := M.copy (| γ0_2 |) in + let lhs := M.copy (| γ0_3 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 2 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 3 + ] + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |), + M.read (| lhs |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_blake3_air::generation::save_state_to_trace", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| round_data |) |), + "p3_blake3_air::columns::FullRound", + "state_output" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_trace_row_for_round : + M.IsFunction.C + "p3_blake3_air::generation::generate_trace_row_for_round" + generate_trace_row_for_round. + Admitted. + Global Typeclasses Opaque generate_trace_row_for_round. + + (* + const fn verifiable_half_round( + mut a: u32, + mut b: u32, + mut c: u32, + mut d: u32, + m: u32, + flag: bool, + ) -> (u32, u32, u32, u32) { + let (rot_1, rot_2) = if flag { (8, 7) } else { (16, 12) }; + + // The first summation: + a = a.wrapping_add(b); + a = a.wrapping_add(m); + + // The first xor: + d = (d ^ a).rotate_right(rot_1); + + // The second summation: + c = c.wrapping_add(d); + + // The second xor: + b = (b ^ c).rotate_right(rot_2); + + (a, b, c, d) + } + *) + Definition verifiable_half_round (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ a; b; c; d; m; flag ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let b := M.alloc (| b |) in + let c := M.alloc (| c |) in + let d := M.alloc (| d |) in + let m := M.alloc (| m |) in + let flag := M.alloc (| flag |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [ Ty.path "u32"; Ty.path "u32"; Ty.path "u32"; Ty.path "u32" ] ], + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [ Ty.path "u32"; Ty.path "u32" ] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use flag in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.Tuple + [ Value.Integer IntegerKind.U32 8; Value.Integer IntegerKind.U32 7 ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ Value.Integer IntegerKind.U32 16; Value.Integer IntegerKind.U32 12 ] + |))) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let rot_1 := M.copy (| γ0_0 |) in + let rot_2 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + a, + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "wrapping_add", [], [] |), + [ M.read (| a |); M.read (| b |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + a, + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "wrapping_add", [], [] |), + [ M.read (| a |); M.read (| m |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + d, + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "rotate_right", [], [] |), + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_xor, + [ M.read (| d |); M.read (| a |) ] + |); + M.read (| rot_1 |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + c, + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "wrapping_add", [], [] |), + [ M.read (| c |); M.read (| d |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + b, + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "rotate_right", [], [] |), + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_xor, + [ M.read (| b |); M.read (| c |) ] + |); + M.read (| rot_2 |) + ] + |) + |) + |) in + M.alloc (| + Value.Tuple [ M.read (| a |); M.read (| b |); M.read (| c |); M.read (| d |) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_verifiable_half_round : + M.IsFunction.C "p3_blake3_air::generation::verifiable_half_round" verifiable_half_round. + Admitted. + Global Typeclasses Opaque verifiable_half_round. + + (* + fn save_state_to_trace( + trace: &mut Blake3State, + state: &[[u32; 4]; 4], + ) { + trace.row0 = array::from_fn(|i| { + [ + R::from_u16(state[0][i] as u16), // Store the bottom 16 bits packed. + R::from_u16((state[0][i] >> 16) as u16), // Store the top 16 bits packed. + ] + }); + trace.row1 = array::from_fn(|i| u32_to_bits_le(state[1][i])); // Store all 32 bits unpacked. + trace.row2 = array::from_fn(|i| { + [ + R::from_u16(state[2][i] as u16), // Store the bottom 16 bits packed. + R::from_u16((state[2][i] >> 16) as u16), // Store the top 16 bits packed. + ] + }); + trace.row3 = array::from_fn(|i| u32_to_bits_le(state[3][i])); // Store all 32 bits unpacked. + } + *) + Definition save_state_to_trace (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ trace; state ] => + ltac:(M.monadic + (let trace := M.alloc (| trace |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::Blake3State", + "row0" + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ R ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ R ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ R ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ R ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + Value.Array + [ + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "from_u16", + [], + [] + |), + [ + M.cast + (Ty.path "u16") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |) + |)) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "from_u16", + [], + [] + |), + [ + M.cast + (Ty.path "u16") + (M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| i |) + |) + |); + Value.Integer IntegerKind.I32 16 + ] + |)) + ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::Blake3State", + "row1" + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ R ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ R ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ R ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ R ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ R ], + M.get_function (| + "p3_air::utils::u32_to_bits_le", + [], + [ R ] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::Blake3State", + "row2" + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ R ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ R ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ R ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ R ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + Value.Array + [ + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "from_u16", + [], + [] + |), + [ + M.cast + (Ty.path "u16") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.read (| i |) + |) + |)) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "from_u16", + [], + [] + |), + [ + M.cast + (Ty.path "u16") + (M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.read (| i |) + |) + |); + Value.Integer IntegerKind.I32 16 + ] + |)) + ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| trace |) |), + "p3_blake3_air::columns::Blake3State", + "row3" + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ R ] ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ R ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ R ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ R ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ R ], + M.get_function (| + "p3_air::utils::u32_to_bits_le", + [], + [ R ] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_save_state_to_trace : + M.IsFunction.C "p3_blake3_air::generation::save_state_to_trace" save_state_to_trace. + Admitted. + Global Typeclasses Opaque save_state_to_trace. +End generation. diff --git a/CoqOfRust/plonky3/blake3_air/src/lib.rs b/CoqOfRust/plonky3/blake3_air/src/lib.rs new file mode 100644 index 000000000..9d9fc71ce --- /dev/null +++ b/CoqOfRust/plonky3/blake3_air/src/lib.rs @@ -0,0 +1,14 @@ +//! An AIR for the Blake-3 permutation. Assumes the field size is between 2^20 and 2^32. + +#![no_std] + +extern crate alloc; + +mod air; +mod columns; +mod constants; +mod generation; + +pub use air::*; +pub use columns::*; +pub use generation::*; diff --git a/CoqOfRust/plonky3/bn254-fr/src/lib.rs b/CoqOfRust/plonky3/bn254-fr/src/lib.rs new file mode 100644 index 000000000..cd9fb64fe --- /dev/null +++ b/CoqOfRust/plonky3/bn254-fr/src/lib.rs @@ -0,0 +1,392 @@ +//! The scalar field of the BN254 curve, defined as `F_r` where `r = 21888242871839275222246405745257275088548364400416034343698204186575808495617`. +#![no_std] + +mod poseidon2; + +extern crate alloc; + +use alloc::vec::Vec; +use core::fmt::{Debug, Display, Formatter}; +use core::hash::{Hash, Hasher}; +use core::iter::{Product, Sum}; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; +use core::{fmt, stringify}; + +pub use halo2curves::bn256::Fr as FFBn254Fr; +use halo2curves::ff::{Field as FFField, PrimeField as FFPrimeField}; +use halo2curves::serde::SerdeObject; +use num_bigint::BigUint; +use p3_field::integers::QuotientMap; +use p3_field::{ + Field, InjectiveMonomial, Packable, PrimeCharacteristicRing, PrimeField, TwoAdicField, + quotient_map_small_int, +}; +pub use poseidon2::Poseidon2Bn254; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; +use serde::{Deserialize, Deserializer, Serialize}; + +/// The BN254 curve scalar field prime, defined as `F_r` where `r = 21888242871839275222246405745257275088548364400416034343698204186575808495617`. +#[derive(Copy, Clone, Default, Eq, PartialEq)] +pub struct Bn254Fr { + pub(crate) value: FFBn254Fr, +} + +impl Bn254Fr { + pub(crate) const fn new(value: FFBn254Fr) -> Self { + Self { value } + } +} + +impl Serialize for Bn254Fr { + /// Serializes to raw bytes, which are typically of the Montgomery representation of the field element. + // See https://github.com/privacy-scaling-explorations/halo2curves/blob/d34e9e46f7daacd194739455de3b356ca6c03206/derive/src/field/mod.rs#L493 + fn serialize(&self, serializer: S) -> Result { + let bytes = self.value.to_raw_bytes(); + serializer.serialize_bytes(&bytes) + } +} + +impl<'de> Deserialize<'de> for Bn254Fr { + /// Deserializes from raw bytes, which are typically of the Montgomery representation of the field element. + /// Performs a check that the deserialized field element corresponds to a value less than the field modulus, and + /// returns error otherwise. + // See https://github.com/privacy-scaling-explorations/halo2curves/blob/d34e9e46f7daacd194739455de3b356ca6c03206/derive/src/field/mod.rs#L485 + fn deserialize>(d: D) -> Result { + let bytes: Vec = Deserialize::deserialize(d)?; + + FFBn254Fr::from_raw_bytes(&bytes) + .map(Self::new) + .ok_or_else(|| serde::de::Error::custom("Invalid field element")) + } +} + +impl Packable for Bn254Fr {} + +impl Hash for Bn254Fr { + fn hash(&self, state: &mut H) { + for byte in self.value.to_repr().as_ref() { + state.write_u8(*byte); + } + } +} + +impl Ord for Bn254Fr { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.value.cmp(&other.value) + } +} + +impl PartialOrd for Bn254Fr { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Display for Bn254Fr { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.value.fmt(f) + } +} + +impl Debug for Bn254Fr { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Debug::fmt(&self.value, f) + } +} + +impl PrimeCharacteristicRing for Bn254Fr { + type PrimeSubfield = Self; + + const ZERO: Self = Self::new(FFBn254Fr::ZERO); + const ONE: Self = Self::new(FFBn254Fr::ONE); + const TWO: Self = Self::new(FFBn254Fr::from_raw([2u64, 0, 0, 0])); + + // r - 1 = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000 + const NEG_ONE: Self = Self::new(FFBn254Fr::from_raw([ + 0x43e1f593f0000000, + 0x2833e84879b97091, + 0xb85045b68181585d, + 0x30644e72e131a029, + ])); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f + } +} + +/// Degree of the smallest permutation polynomial for BN254. +/// +/// As p - 1 is divisible by 2 and 3 the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 5. +impl InjectiveMonomial<5> for Bn254Fr {} + +// TODO: Implement PermutationMonomial<5> for Bn254Fr. +// Not a priority given how slow (and unused) this will be. + +impl Field for Bn254Fr { + type Packing = Self; + + // generator is 5 + const GENERATOR: Self = Self::new(FFBn254Fr::from_raw([5u64, 0, 0, 0])); + + fn is_zero(&self) -> bool { + self.value.is_zero().into() + } + + fn try_inverse(&self) -> Option { + let inverse = self.value.invert(); + + if inverse.is_some().into() { + Some(Self::new(inverse.unwrap())) + } else { + None + } + } + + /// r = 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001 + fn order() -> BigUint { + BigUint::from_slice(&[ + 0xf0000001, 0x43e1f593, 0x79b97091, 0x2833e848, 0x8181585d, 0xb85045b6, 0xe131a029, + 0x30644e72, + ]) + } +} + +quotient_map_small_int!(Bn254Fr, u128, [u8, u16, u32, u64]); +quotient_map_small_int!(Bn254Fr, i128, [i8, i16, i32, i64]); + +impl QuotientMap for Bn254Fr { + /// Due to the size of the `BN254` prime, the input value is always canonical. + #[inline] + fn from_int(int: u128) -> Self { + Self::new(FFBn254Fr::from_raw([int as u64, (int >> 64) as u64, 0, 0])) + } + + /// Due to the size of the `BN254` prime, the input value is always canonical. + #[inline] + fn from_canonical_checked(int: u128) -> Option { + Some(Self::from_int(int)) + } + + /// Due to the size of the `BN254` prime, the input value is always canonical. + #[inline] + unsafe fn from_canonical_unchecked(int: u128) -> Self { + Self::from_int(int) + } +} + +impl QuotientMap for Bn254Fr { + /// Due to the size of the `BN254` prime, the input value is always canonical. + #[inline] + fn from_int(int: i128) -> Self { + // Nothing better than just branching based on the sign of int. + if int >= 0 { + Self::from_int(int as u128) + } else { + -Self::from_int((-int) as u128) + } + } + + /// Due to the size of the `BN254` prime, the input value is always canonical. + #[inline] + fn from_canonical_checked(int: i128) -> Option { + Some(Self::from_int(int)) + } + + /// Due to the size of the `BN254` prime, the input value is always canonical. + #[inline] + unsafe fn from_canonical_unchecked(int: i128) -> Self { + Self::from_int(int) + } +} + +impl PrimeField for Bn254Fr { + fn as_canonical_biguint(&self) -> BigUint { + let repr = self.value.to_repr(); + let le_bytes = repr.as_ref(); + BigUint::from_bytes_le(le_bytes) + } +} + +impl Add for Bn254Fr { + type Output = Self; + + fn add(self, rhs: Self) -> Self { + Self::new(self.value + rhs.value) + } +} + +impl AddAssign for Bn254Fr { + fn add_assign(&mut self, rhs: Self) { + self.value += rhs.value; + } +} + +impl Sum for Bn254Fr { + fn sum>(iter: I) -> Self { + iter.reduce(|x, y| x + y).unwrap_or(Self::ZERO) + } +} + +impl Sub for Bn254Fr { + type Output = Self; + + fn sub(self, rhs: Self) -> Self { + Self::new(self.value.sub(rhs.value)) + } +} + +impl SubAssign for Bn254Fr { + fn sub_assign(&mut self, rhs: Self) { + self.value -= rhs.value; + } +} + +impl Neg for Bn254Fr { + type Output = Self; + + fn neg(self) -> Self::Output { + self * Self::NEG_ONE + } +} + +impl Mul for Bn254Fr { + type Output = Self; + + fn mul(self, rhs: Self) -> Self { + Self::new(self.value * rhs.value) + } +} + +impl MulAssign for Bn254Fr { + fn mul_assign(&mut self, rhs: Self) { + self.value *= rhs.value; + } +} + +impl Product for Bn254Fr { + fn product>(iter: I) -> Self { + iter.reduce(|x, y| x * y).unwrap_or(Self::ONE) + } +} + +impl Div for Bn254Fr { + type Output = Self; + + #[allow(clippy::suspicious_arithmetic_impl)] + fn div(self, rhs: Self) -> Self { + self * rhs.inverse() + } +} + +impl Distribution for StandardUniform { + #[inline] + fn sample(&self, rng: &mut R) -> Bn254Fr { + // Simple implementation of rejection sampling: + loop { + let mut trial_element: [u8; 32] = rng.random(); + + // Set top 2 bits to 0 as bn254 is a 254-bit field. + // `from_bytes` expects little endian input, so we adjust byte 31: + trial_element[31] &= (1_u8 << 6) - 1; + + let x = FFBn254Fr::from_bytes(&trial_element); + if x.is_some().into() { + // x.unwrap() is safe because x.is_some() is true + return Bn254Fr::new(x.unwrap()); + } + } + } +} + +impl TwoAdicField for Bn254Fr { + const TWO_ADICITY: usize = FFBn254Fr::S as usize; + + fn two_adic_generator(bits: usize) -> Self { + let mut omega = FFBn254Fr::ROOT_OF_UNITY; + for _ in bits..Self::TWO_ADICITY { + omega = omega.square(); + } + Self::new(omega) + } +} + +#[cfg(test)] +mod tests { + use p3_field_testing::{test_field, test_prime_field}; + + use super::*; + + type F = Bn254Fr; + + #[test] + fn test_bn254fr() { + let f = F::new(FFBn254Fr::from_u128(100)); + assert_eq!(f.as_canonical_biguint(), BigUint::from(100u32)); + + let f = F::new(FFBn254Fr::from_str_vartime(&F::order().to_str_radix(10)).unwrap()); + assert!(f.is_zero()); + + // Generator check + let expected_multiplicative_group_generator = F::new(FFBn254Fr::from_u128(5)); + assert_eq!(F::GENERATOR, expected_multiplicative_group_generator); + assert_eq!(F::GENERATOR.as_canonical_biguint(), BigUint::from(5u32)); + + let f_1 = F::ONE; + let f_2 = F::TWO; + let f_r_minus_1 = F::NEG_ONE; + let f_r_minus_2 = F::NEG_ONE + F::NEG_ONE; + + let f_serialized = serde_json::to_string(&f).unwrap(); + let f_deserialized: F = serde_json::from_str(&f_serialized).unwrap(); + assert_eq!(f, f_deserialized); + + let f_1_serialized = serde_json::to_string(&f_1).unwrap(); + let f_1_deserialized: F = serde_json::from_str(&f_1_serialized).unwrap(); + let f_1_serialized_again = serde_json::to_string(&f_1_deserialized).unwrap(); + let f_1_deserialized_again: F = serde_json::from_str(&f_1_serialized_again).unwrap(); + assert_eq!(f_1, f_1_deserialized); + assert_eq!(f_1, f_1_deserialized_again); + + let f_2_serialized = serde_json::to_string(&f_2).unwrap(); + let f_2_deserialized: F = serde_json::from_str(&f_2_serialized).unwrap(); + assert_eq!(f_2, f_2_deserialized); + + let f_r_minus_1_serialized = serde_json::to_string(&f_r_minus_1).unwrap(); + let f_r_minus_1_deserialized: F = serde_json::from_str(&f_r_minus_1_serialized).unwrap(); + assert_eq!(f_r_minus_1, f_r_minus_1_deserialized); + + let f_r_minus_2_serialized = serde_json::to_string(&f_r_minus_2).unwrap(); + let f_r_minus_2_deserialized: F = serde_json::from_str(&f_r_minus_2_serialized).unwrap(); + assert_eq!(f_r_minus_2, f_r_minus_2_deserialized); + } + + const ZERO: Bn254Fr = Bn254Fr::ZERO; + const ONE: Bn254Fr = Bn254Fr::ONE; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 10] { + [ + (BigUint::from(2u8), 28), + (BigUint::from(3u8), 2), + (BigUint::from(13u8), 1), + (BigUint::from(29u8), 1), + (BigUint::from(983u16), 1), + (BigUint::from(11003u16), 1), + (BigUint::from(237073u32), 1), + (BigUint::from(405928799u32), 1), + (BigUint::from(1670836401704629u64), 1), + (BigUint::from(13818364434197438864469338081u128), 1), + ] + } + test_field!( + crate::Bn254Fr, + &[super::ZERO], + &[super::ONE], + &super::multiplicative_group_prime_factorization() + ); + + test_prime_field!(crate::Bn254Fr); +} diff --git a/CoqOfRust/plonky3/bn254-fr/src/lib.v b/CoqOfRust/plonky3/bn254-fr/src/lib.v new file mode 100644 index 000000000..7af8a52ae --- /dev/null +++ b/CoqOfRust/plonky3/bn254-fr/src/lib.v @@ -0,0 +1,2941 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +(* StructRecord + { + name := "Bn254Fr"; + const_params := []; + ty_params := []; + fields := [ ("value", Ty.path "halo2curves::bn256::fr::Fr") ]; + } *) + +Module Impl_core_marker_Copy_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. +End Impl_core_marker_Copy_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_clone_Clone_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_bn254_fr::Bn254Fr" ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. +End Impl_core_clone_Clone_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_default_Default_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_bn254_fr::Bn254Fr" + [ + ("value", + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_trait_method (| + "core::default::Default", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. +End Impl_core_default_Default_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_cmp_Eq_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. +End Impl_core_cmp_Eq_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_marker_StructuralPartialEq_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. +End Impl_core_marker_StructuralPartialEq_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_cmp_PartialEq_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. +End Impl_core_cmp_PartialEq_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + pub(crate) const fn new(value: FFBn254Fr) -> Self { + Self { value } + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructRecord "p3_bn254_fr::Bn254Fr" [ ("value", M.read (| value |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.C Self "new" new. + Admitted. + Global Typeclasses Opaque new. +End Impl_p3_bn254_fr_Bn254Fr. + +Module Impl_serde_ser_Serialize_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn serialize(&self, serializer: S) -> Result { + let bytes = self.value.to_raw_bytes(); + serializer.serialize_bytes(&bytes) + } + *) + Definition serialize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as S ], [ self; serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let serializer := M.alloc (| serializer |) in + M.read (| + let~ bytes : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "halo2curves::serde::SerdeObject", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [], + "to_raw_bytes", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + S, + [], + [], + "serialize_bytes", + [], + [] + |), + [ + M.read (| serializer |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, bytes |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("serialize", InstanceField.Method serialize) ]. +End Impl_serde_ser_Serialize_for_p3_bn254_fr_Bn254Fr. + +Module Impl_serde_de_Deserialize_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn deserialize>(d: D) -> Result { + let bytes: Vec = Deserialize::deserialize(d)?; + + FFBn254Fr::from_raw_bytes(&bytes) + .map(Self::new) + .ok_or_else(|| serde::de::Error::custom("Invalid field element")) + } + *) + Definition deserialize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ D ], [ d ] => + ltac:(M.monadic + (let d := M.alloc (| d |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ bytes : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ], + M.get_trait_method (| + "serde::de::Deserialize", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deserialize", + [], + [ D ] + |), + [ M.read (| d |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ], + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "ok_or_else", + [], + [ + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error"; + Ty.function + [ Ty.tuple [] ] + (Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "map", + [], + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.function + [ Ty.path "halo2curves::bn256::fr::Fr" ] + (Ty.path "p3_bn254_fr::Bn254Fr") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "halo2curves::bn256::fr::Fr" ], + M.get_trait_method (| + "halo2curves::serde::SerdeObject", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [], + "from_raw_bytes", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, bytes |) |) + |) + ] + |) + |) + |) + ] + |); + M.get_associated_function (| + Ty.path "p3_bn254_fr::Bn254Fr", + "new", + [], + [] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error", + M.get_trait_method (| + "serde::de::Error", + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error", + [], + [], + "custom", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + |), + [ mk_str (| "Invalid field element" |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("deserialize", InstanceField.Method deserialize) ]. +End Impl_serde_de_Deserialize_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_packed_Packable_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + Axiom Implements : + M.IsTraitInstance + "p3_field::packed::Packable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. +End Impl_p3_field_packed_Packable_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_hash_Hash_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn hash(&self, state: &mut H) { + for byte in self.value.to_repr().as_ref() { + state.write_u8( *byte); + } + } + *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.apply + (Ty.path "halo2curves::serde::Repr") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "halo2curves::serde::Repr") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_trait_method (| + "ff::PrimeField", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [], + "to_repr", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let byte := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hasher", + H, + [], + [], + "write_u8", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |); + M.read (| M.deref (| M.read (| byte |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. +End Impl_core_hash_Hash_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_cmp_Ord_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.value.cmp(&other.value) + } + *) + Definition cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("cmp", InstanceField.Method cmp) ]. +End Impl_core_cmp_Ord_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_cmp_PartialOrd_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. +End Impl_core_cmp_PartialOrd_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_fmt_Display_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.value.fmt(f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Debug", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. +End Impl_core_fmt_Display_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_fmt_Debug_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Debug::fmt(&self.value, f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Debug", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. +End Impl_core_fmt_Debug_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_field_PrimeCharacteristicRing_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* type PrimeSubfield = Self; *) + Definition _PrimeSubfield : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* const ZERO: Self = Self::new(FFBn254Fr::ZERO); *) + (* Ty.path "p3_bn254_fr::Bn254Fr" *) + Definition value_ZERO (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| Ty.path "p3_bn254_fr::Bn254Fr", "new", [], [] |), + [ M.read (| get_constant (| "ff::Field::ZERO", Ty.path "halo2curves::bn256::fr::Fr" |) |) + ] + |) + |))). + + (* const ONE: Self = Self::new(FFBn254Fr::ONE); *) + (* Ty.path "p3_bn254_fr::Bn254Fr" *) + Definition value_ONE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| Ty.path "p3_bn254_fr::Bn254Fr", "new", [], [] |), + [ M.read (| get_constant (| "ff::Field::ONE", Ty.path "halo2curves::bn256::fr::Fr" |) |) ] + |) + |))). + + (* const TWO: Self = Self::new(FFBn254Fr::from_raw([2u64, 0, 0, 0])); *) + (* Ty.path "p3_bn254_fr::Bn254Fr" *) + Definition value_TWO (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| Ty.path "p3_bn254_fr::Bn254Fr", "new", [], [] |), + [ + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_associated_function (| + Ty.path "halo2curves::bn256::fr::Fr", + "from_raw", + [], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U64 2; + Value.Integer IntegerKind.U64 0; + Value.Integer IntegerKind.U64 0; + Value.Integer IntegerKind.U64 0 + ] + ] + |) + ] + |) + |))). + + (* + const NEG_ONE: Self = Self::new(FFBn254Fr::from_raw([ + 0x43e1f593f0000000, + 0x2833e84879b97091, + 0xb85045b68181585d, + 0x30644e72e131a029, + ])); + *) + (* Ty.path "p3_bn254_fr::Bn254Fr" *) + Definition value_NEG_ONE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| Ty.path "p3_bn254_fr::Bn254Fr", "new", [], [] |), + [ + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_associated_function (| + Ty.path "halo2curves::bn256::fr::Fr", + "from_raw", + [], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U64 4891460686036598784; + Value.Integer IntegerKind.U64 2896914383306846353; + Value.Integer IntegerKind.U64 13281191951274694749; + Value.Integer IntegerKind.U64 3486998266802970665 + ] + ] + |) + ] + |) + |))). + + (* + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f + } + *) + Definition from_prime_subfield (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.read (| f |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PrimeCharacteristicRing" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("PrimeSubfield", InstanceField.Ty _PrimeSubfield); + ("value_ZERO", InstanceField.Method value_ZERO); + ("value_ONE", InstanceField.Method value_ONE); + ("value_TWO", InstanceField.Method value_TWO); + ("value_NEG_ONE", InstanceField.Method value_NEG_ONE); + ("from_prime_subfield", InstanceField.Method from_prime_subfield) + ]. +End Impl_p3_field_field_PrimeCharacteristicRing_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_field_InjectiveMonomial_U64_5_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::InjectiveMonomial" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.U64 5 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. +End Impl_p3_field_field_InjectiveMonomial_U64_5_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_field_Field_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* type Packing = Self; *) + Definition _Packing : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* const GENERATOR: Self = Self::new(FFBn254Fr::from_raw([5u64, 0, 0, 0])); *) + (* Ty.path "p3_bn254_fr::Bn254Fr" *) + Definition value_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| Ty.path "p3_bn254_fr::Bn254Fr", "new", [], [] |), + [ + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_associated_function (| + Ty.path "halo2curves::bn256::fr::Fr", + "from_raw", + [], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U64 5; + Value.Integer IntegerKind.U64 0; + Value.Integer IntegerKind.U64 0; + Value.Integer IntegerKind.U64 0 + ] + ] + |) + ] + |) + |))). + + (* + fn is_zero(&self) -> bool { + self.value.is_zero().into() + } + *) + Definition is_zero (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::convert::Into", + Ty.path "subtle::Choice", + [], + [ Ty.path "bool" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "subtle::Choice", + M.get_trait_method (| + "ff::Field", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [], + "is_zero", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn try_inverse(&self) -> Option { + let inverse = self.value.invert(); + + if inverse.is_some().into() { + Some(Self::new(inverse.unwrap())) + } else { + None + } + } + *) + Definition try_inverse (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ inverse : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "subtle::CtOption") [] [ Ty.path "halo2curves::bn256::fr::Fr" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "subtle::CtOption") [] [ Ty.path "halo2curves::bn256::fr::Fr" ], + M.get_trait_method (| + "ff::Field", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [], + "invert", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "p3_bn254_fr::Bn254Fr" ] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::convert::Into", + Ty.path "subtle::Choice", + [], + [ Ty.path "bool" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "subtle::Choice", + M.get_associated_function (| + Ty.apply + (Ty.path "subtle::CtOption") + [] + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "is_some", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inverse |) ] + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| + Ty.path "p3_bn254_fr::Bn254Fr", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_associated_function (| + Ty.apply + (Ty.path "subtle::CtOption") + [] + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "unwrap", + [], + [] + |), + [ M.read (| inverse |) ] + |) + ] + |) + ] + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn order() -> BigUint { + BigUint::from_slice(&[ + 0xf0000001, 0x43e1f593, 0x79b97091, 0x2833e848, 0x8181585d, 0xb85045b6, 0xe131a029, + 0x30644e72, + ]) + } + *) + Definition order (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_associated_function (| + Ty.path "num_bigint::biguint::BigUint", + "from_slice", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U32 4026531841; + Value.Integer IntegerKind.U32 1138881939; + Value.Integer IntegerKind.U32 2042196113; + Value.Integer IntegerKind.U32 674490440; + Value.Integer IntegerKind.U32 2172737629; + Value.Integer IntegerKind.U32 3092268470; + Value.Integer IntegerKind.U32 3778125865; + Value.Integer IntegerKind.U32 811880050 + ] + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::Field" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Packing", InstanceField.Ty _Packing); + ("value_GENERATOR", InstanceField.Method value_GENERATOR); + ("is_zero", InstanceField.Method is_zero); + ("try_inverse", InstanceField.Method try_inverse); + ("order", InstanceField.Method order) + ]. +End Impl_p3_field_field_Field_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_integers_QuotientMap_u128_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn from_int(int: u128) -> Self { + Self::new(FFBn254Fr::from_raw([int as u64, (int >> 64) as u64, 0, 0])) + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| Ty.path "p3_bn254_fr::Bn254Fr", "new", [], [] |), + [ + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_associated_function (| + Ty.path "halo2curves::bn256::fr::Fr", + "from_raw", + [], + [] + |), + [ + Value.Array + [ + M.cast (Ty.path "u64") (M.read (| int |)); + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "u128", + BinOp.Wrap.shr, + [ M.read (| int |); Value.Integer IntegerKind.I32 64 ] + |)); + Value.Integer IntegerKind.U64 0; + Value.Integer IntegerKind.U64 0 + ] + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: u128) -> Option { + Some(Self::from_int(int)) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: u128) -> Self { + Self::from_int(int) + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u128" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. +End Impl_p3_field_integers_QuotientMap_u128_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_integers_QuotientMap_i128_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn from_int(int: i128) -> Self { + // Nothing better than just branching based on the sign of int. + if int >= 0 { + Self::from_int(int as u128) + } else { + -Self::from_int((-int) as u128) + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_bn254_fr::Bn254Fr" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| int |); Value.Integer IntegerKind.I128 0 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_int", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "core::ops::arith::Neg", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [], + "neg", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_int", + [], + [] + |), + [ M.cast (Ty.path "u128") (UnOp.neg (| M.read (| int |) |)) ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: i128) -> Option { + Some(Self::from_int(int)) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: i128) -> Self { + Self::from_int(int) + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i128" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. +End Impl_p3_field_integers_QuotientMap_i128_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_field_PrimeField_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn as_canonical_biguint(&self) -> BigUint { + let repr = self.value.to_repr(); + let le_bytes = repr.as_ref(); + BigUint::from_bytes_le(le_bytes) + } + *) + Definition as_canonical_biguint (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ repr : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "halo2curves::serde::Repr") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "halo2curves::serde::Repr") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_trait_method (| + "ff::PrimeField", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [], + "to_repr", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |) + ] + |) + |) in + let~ le_bytes : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.apply + (Ty.path "halo2curves::serde::Repr") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, repr |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_associated_function (| + Ty.path "num_bigint::biguint::BigUint", + "from_bytes_le", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| le_bytes |) |) |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PrimeField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("as_canonical_biguint", InstanceField.Method as_canonical_biguint) ]. +End Impl_p3_field_field_PrimeField_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_ops_arith_Add_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn add(self, rhs: Self) -> Self { + Self::new(self.value + rhs.value) + } + *) + Definition add (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| Ty.path "p3_bn254_fr::Bn254Fr", "new", [], [] |), + [ + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| self, "p3_bn254_fr::Bn254Fr", "value" |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| rhs, "p3_bn254_fr::Bn254Fr", "value" |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("add", InstanceField.Method add) ]. +End Impl_core_ops_arith_Add_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_ops_arith_AddAssign_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn add_assign(&mut self, rhs: Self) { + self.value += rhs.value; + } + *) + Definition add_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| rhs, "p3_bn254_fr::Bn254Fr", "value" |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("add_assign", InstanceField.Method add_assign) ]. +End Impl_core_ops_arith_AddAssign_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_iter_traits_accum_Sum_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn sum>(iter: I) -> Self { + iter.reduce(|x, y| x + y).unwrap_or(Self::ZERO) + } + *) + Definition sum (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "p3_bn254_fr::Bn254Fr" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "p3_bn254_fr::Bn254Fr" ] ] + (Ty.path "p3_bn254_fr::Bn254Fr") + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.path "p3_bn254_fr::Bn254Fr" + ] + ] + (Ty.path "p3_bn254_fr::Bn254Fr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.path "p3_bn254_fr::Bn254Fr" + ] + ] + (Ty.path "p3_bn254_fr::Bn254Fr") + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := M.copy (| γ |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_bn254_fr::Bn254Fr" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::accum::Sum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("sum", InstanceField.Method sum) ]. +End Impl_core_iter_traits_accum_Sum_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_ops_arith_Sub_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn sub(self, rhs: Self) -> Self { + Self::new(self.value.sub(rhs.value)) + } + *) + Definition sub (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| Ty.path "p3_bn254_fr::Bn254Fr", "new", [], [] |), + [ + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| self, "p3_bn254_fr::Bn254Fr", "value" |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| rhs, "p3_bn254_fr::Bn254Fr", "value" |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("sub", InstanceField.Method sub) ]. +End Impl_core_ops_arith_Sub_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_ops_arith_SubAssign_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn sub_assign(&mut self, rhs: Self) { + self.value -= rhs.value; + } + *) + Definition sub_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| rhs, "p3_bn254_fr::Bn254Fr", "value" |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("sub_assign", InstanceField.Method sub_assign) ]. +End Impl_core_ops_arith_SubAssign_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_ops_arith_Neg_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn neg(self) -> Self::Output { + self * Self::NEG_ONE + } + *) + Definition neg (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "mul", + [], + [] + |), + [ + M.read (| self |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + Ty.path "p3_bn254_fr::Bn254Fr" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("neg", InstanceField.Method neg) ]. +End Impl_core_ops_arith_Neg_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_ops_arith_Mul_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn mul(self, rhs: Self) -> Self { + Self::new(self.value * rhs.value) + } + *) + Definition mul (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| Ty.path "p3_bn254_fr::Bn254Fr", "new", [], [] |), + [ + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| self, "p3_bn254_fr::Bn254Fr", "value" |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| rhs, "p3_bn254_fr::Bn254Fr", "value" |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("mul", InstanceField.Method mul) ]. +End Impl_core_ops_arith_Mul_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_ops_arith_MulAssign_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn mul_assign(&mut self, rhs: Self) { + self.value *= rhs.value; + } + *) + Definition mul_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Ty.path "halo2curves::bn256::fr::Fr", + [], + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::Bn254Fr", + "value" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| rhs, "p3_bn254_fr::Bn254Fr", "value" |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("mul_assign", InstanceField.Method mul_assign) ]. +End Impl_core_ops_arith_MulAssign_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_iter_traits_accum_Product_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn product>(iter: I) -> Self { + iter.reduce(|x, y| x * y).unwrap_or(Self::ONE) + } + *) + Definition product (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "p3_bn254_fr::Bn254Fr" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "p3_bn254_fr::Bn254Fr" ] ] + (Ty.path "p3_bn254_fr::Bn254Fr") + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.path "p3_bn254_fr::Bn254Fr" + ] + ] + (Ty.path "p3_bn254_fr::Bn254Fr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.path "p3_bn254_fr::Bn254Fr" + ] + ] + (Ty.path "p3_bn254_fr::Bn254Fr") + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := M.copy (| γ |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.path "p3_bn254_fr::Bn254Fr" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::accum::Product" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("product", InstanceField.Method product) ]. +End Impl_core_iter_traits_accum_Product_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_core_ops_arith_Div_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn div(self, rhs: Self) -> Self { + self * rhs.inverse() + } + *) + Definition div (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "mul", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::field::Field", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Div" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("div", InstanceField.Method div) ]. +End Impl_core_ops_arith_Div_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_Bn254Fr. + +Module Impl_rand_distr_distribution_Distribution_p3_bn254_fr_Bn254Fr_for_rand_distr_StandardUniform. + Definition Self : Ty.t := Ty.path "rand::distr::StandardUniform". + + (* + fn sample(&self, rng: &mut R) -> Bn254Fr { + // Simple implementation of rejection sampling: + loop { + let mut trial_element: [u8; 32] = rng.random(); + + // Set top 2 bits to 0 as bn254 is a 254-bit field. + // `from_bytes` expects little endian input, so we adjust byte 31: + trial_element[31] &= (1_u8 << 6) - 1; + + let x = FFBn254Fr::from_bytes(&trial_element); + if x.is_some().into() { + // x.unwrap() is safe because x.is_some() is true + return Bn254Fr::new(x.unwrap()); + } + } + } + *) + Definition sample (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ self; rng ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rng := M.alloc (| rng |) in + M.catch_return (Ty.path "p3_bn254_fr::Bn254Fr") (| + ltac:(M.monadic + (M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic + (let~ trial_element : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ], + M.get_trait_method (| + "rand::rng::Rng", + R, + [], + [], + "random", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := + M.SubPointer.get_array_field (| + trial_element, + Value.Integer IntegerKind.Usize 31 + |) in + M.write (| + β, + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_and, + [ + M.read (| β |); + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.I32 6 + ] + |); + Value.Integer IntegerKind.U8 1 + ] + |) + ] + |) + |) + |) in + let~ x : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "subtle::CtOption") + [] + [ Ty.path "halo2curves::bn256::fr::Fr" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "subtle::CtOption") + [] + [ Ty.path "halo2curves::bn256::fr::Fr" ], + M.get_associated_function (| + Ty.path "halo2curves::bn256::fr::Fr", + "from_bytes", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trial_element |) |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::convert::Into", + Ty.path "subtle::Choice", + [], + [ Ty.path "bool" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "subtle::Choice", + M.get_associated_function (| + Ty.apply + (Ty.path "subtle::CtOption") + [] + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "is_some", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| + Ty.path "p3_bn254_fr::Bn254Fr", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_associated_function (| + Ty.apply + (Ty.path "subtle::CtOption") + [] + [ Ty.path "halo2curves::bn256::fr::Fr" ], + "unwrap", + [], + [] + |), + [ M.read (| x |) ] + |) + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "rand::distr::distribution::Distribution" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("sample", InstanceField.Method sample) ]. +End Impl_rand_distr_distribution_Distribution_p3_bn254_fr_Bn254Fr_for_rand_distr_StandardUniform. + +Module Impl_p3_field_field_TwoAdicField_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* const TWO_ADICITY: usize = FFBn254Fr::S as usize; *) + (* Ty.path "usize" *) + Definition value_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.cast + (Ty.path "usize") + (M.read (| get_constant (| "ff::PrimeField::S", Ty.path "u32" |) |)) + |))). + + (* + fn two_adic_generator(bits: usize) -> Self { + let mut omega = FFBn254Fr::ROOT_OF_UNITY; + for _ in bits..Self::TWO_ADICITY { + omega = omega.square(); + } + Self::new(omega) + } + *) + Definition two_adic_generator (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.read (| + let~ omega : Ty.apply (Ty.path "*") [] [ Ty.path "halo2curves::bn256::fr::Fr" ] := + M.copy (| + get_constant (| + "ff::PrimeField::ROOT_OF_UNITY", + Ty.path "halo2curves::bn256::fr::Fr" + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| bits |)); + ("end_", + M.read (| + get_constant (| + "p3_field::field::TwoAdicField::TWO_ADICITY", + Ty.path "usize" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + omega, + M.call_closure (| + Ty.path "halo2curves::bn256::fr::Fr", + M.get_associated_function (| + Ty.path "halo2curves::bn256::fr::Fr", + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, omega |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_associated_function (| Ty.path "p3_bn254_fr::Bn254Fr", "new", [], [] |), + [ M.read (| omega |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::TwoAdicField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_TWO_ADICITY", InstanceField.Method value_TWO_ADICITY); + ("two_adic_generator", InstanceField.Method two_adic_generator) + ]. +End Impl_p3_field_field_TwoAdicField_for_p3_bn254_fr_Bn254Fr. diff --git a/CoqOfRust/plonky3/bn254-fr/src/poseidon2.rs b/CoqOfRust/plonky3/bn254-fr/src/poseidon2.rs new file mode 100644 index 000000000..c9c7a1ea4 --- /dev/null +++ b/CoqOfRust/plonky3/bn254-fr/src/poseidon2.rs @@ -0,0 +1,195 @@ +//! Diffusion matrix for Bn254 +//! +//! Reference: https://github.com/HorizenLabs/poseidon2/blob/main/plain_implementations/src/poseidon2/poseidon2_instance_bn256.rs + +extern crate alloc; + +use alloc::vec::Vec; + +use p3_field::PrimeCharacteristicRing; +use p3_poseidon2::{ + ExternalLayer, ExternalLayerConstants, ExternalLayerConstructor, HLMDSMat4, InternalLayer, + InternalLayerConstructor, Poseidon2, add_rc_and_sbox_generic, external_initial_permute_state, + external_terminal_permute_state, internal_permute_state, +}; + +use crate::Bn254Fr; + +/// Degree of the chosen permutation polynomial for BN254, used as the Poseidon2 S-Box. +/// +/// As p - 1 is divisible by 2 and 3 the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 5. +const BN254_S_BOX_DEGREE: u64 = 5; + +/// An implementation of the Poseidon2 hash function for the Bn254Fr field. +/// +/// It acts on arrays of the form `[Bn254Fr; WIDTH]`. +pub type Poseidon2Bn254 = Poseidon2< + Bn254Fr, + Poseidon2ExternalLayerBn254, + Poseidon2InternalLayerBn254, + WIDTH, + BN254_S_BOX_DEGREE, +>; + +/// Currently we only support a single width for Poseidon2 BN254. +const BN254_WIDTH: usize = 3; + +#[derive(Debug, Clone, Default)] +pub struct Poseidon2InternalLayerBn254 { + internal_constants: Vec, +} + +impl InternalLayerConstructor for Poseidon2InternalLayerBn254 { + fn new_from_constants(internal_constants: Vec) -> Self { + Self { internal_constants } + } +} + +/// A faster version of `matmul_internal` making use of the fact that +/// the internal matrix is equal to: +/// ```ignore +/// [2, 1, 1] +/// 1 + Diag([1, 1, 2]) = [1, 2, 1] +/// [1, 1, 3] +/// ``` +fn bn254_matmul_internal(state: &mut [Bn254Fr; 3]) { + // We bracket in this way as the s-box is applied to state[0] so this lets us + // begin this computation before the s-box finishes. + let sum = state[0] + (state[1] + state[2]); + + state[0] += sum; + state[1] += sum; + state[2] = state[2].double() + sum; +} + +impl InternalLayer for Poseidon2InternalLayerBn254 { + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [Bn254Fr; BN254_WIDTH]) { + internal_permute_state(state, bn254_matmul_internal, &self.internal_constants) + } +} + +pub type Poseidon2ExternalLayerBn254 = ExternalLayerConstants; + +impl ExternalLayerConstructor + for Poseidon2ExternalLayerBn254 +{ + fn new_from_constants(external_constants: Self) -> Self { + external_constants + } +} + +impl ExternalLayer + for Poseidon2ExternalLayerBn254 +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [Bn254Fr; WIDTH]) { + external_initial_permute_state( + state, + self.get_initial_constants(), + add_rc_and_sbox_generic, + &HLMDSMat4, + ); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [Bn254Fr; WIDTH]) { + external_terminal_permute_state( + state, + self.get_terminal_constants(), + add_rc_and_sbox_generic, + &HLMDSMat4, + ); + } +} + +#[cfg(test)] +mod tests { + use num_bigint::BigUint; + use p3_poseidon2::ExternalLayerConstants; + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + use zkhash::ark_ff::{BigInteger, PrimeField as ark_PrimeField}; + use zkhash::fields::bn256::FpBN256 as ark_FpBN256; + use zkhash::poseidon2::poseidon2::Poseidon2 as Poseidon2Ref; + use zkhash::poseidon2::poseidon2_instance_bn256::{POSEIDON2_BN256_PARAMS, RC3}; + + use super::*; + use crate::FFBn254Fr; + + fn bn254_from_ark_ff(input: ark_FpBN256) -> Bn254Fr { + let mut full_bytes = [0; 32]; + let bytes = input.into_bigint().to_bytes_le(); + full_bytes[..bytes.len()].copy_from_slice(&bytes); + let value = FFBn254Fr::from_bytes(&full_bytes); + + if value.is_some().into() { + Bn254Fr { + value: value.unwrap(), + } + } else { + panic!("Invalid field element") + } + } + + fn ark_ff_from_bn254(input: Bn254Fr) -> ark_FpBN256 { + let bigint = BigUint::from_bytes_le(&input.value.to_bytes()); + ark_FpBN256::from(bigint) + } + + #[test] + fn test_poseidon2_bn254() { + const WIDTH: usize = 3; + const ROUNDS_F: usize = 8; + const ROUNDS_P: usize = 56; + + type F = Bn254Fr; + + let mut rng = SmallRng::seed_from_u64(1); + + // Poiseidon2 reference implementation from zkhash repo. + let poseidon2_ref = Poseidon2Ref::new(&POSEIDON2_BN256_PARAMS); + + // Copy over round constants from zkhash. + let mut round_constants: Vec<[F; WIDTH]> = RC3 + .iter() + .map(|vec| { + vec.iter() + .copied() + .map(bn254_from_ark_ff) + .collect::>() + .try_into() + .unwrap() + }) + .collect(); + + let internal_start = ROUNDS_F / 2; + let internal_end = (ROUNDS_F / 2) + ROUNDS_P; + let internal_round_constants = round_constants + .drain(internal_start..internal_end) + .map(|vec| vec[0]) + .collect::>(); + let external_round_constants = ExternalLayerConstants::new( + round_constants[..(ROUNDS_F / 2)].to_vec(), + round_constants[(ROUNDS_F / 2)..].to_vec(), + ); + // Our Poseidon2 implementation. + let poseidon2 = Poseidon2Bn254::new(external_round_constants, internal_round_constants); + + // Generate random input and convert to both field formats. + let input = rng.random::<[F; WIDTH]>(); + let input_ark_ff = input.map(ark_ff_from_bn254); + + // Run reference implementation. + let output_ref: [ark_FpBN256; WIDTH] = + poseidon2_ref.permutation(&input_ark_ff).try_into().unwrap(); + let expected: [F; WIDTH] = output_ref.map(bn254_from_ark_ff); + + // Run our implementation. + let mut output = input; + poseidon2.permute_mut(&mut output); + + assert_eq!(output, expected); + } +} diff --git a/CoqOfRust/plonky3/bn254-fr/src/poseidon2.v b/CoqOfRust/plonky3/bn254-fr/src/poseidon2.v new file mode 100644 index 000000000..fae5b3d5a --- /dev/null +++ b/CoqOfRust/plonky3/bn254-fr/src/poseidon2.v @@ -0,0 +1,838 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module poseidon2. + Definition value_BN254_S_BOX_DEGREE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U64 5 |))). + + Global Instance Instance_IsConstant_value_BN254_S_BOX_DEGREE : + M.IsFunction.C "p3_bn254_fr::poseidon2::BN254_S_BOX_DEGREE" value_BN254_S_BOX_DEGREE. + Admitted. + Global Typeclasses Opaque value_BN254_S_BOX_DEGREE. + + Axiom Poseidon2Bn254 : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_bn254_fr::poseidon2::Poseidon2Bn254") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ + WIDTH; + M.unevaluated_const (mk_str (| "p3_bn254_fr_poseidon2_Poseidon2Bn254_discriminant" |)) + ] + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ]; + Ty.path "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254" + ]). + + Definition value_BN254_WIDTH (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 3 |))). + + Global Instance Instance_IsConstant_value_BN254_WIDTH : + M.IsFunction.C "p3_bn254_fr::poseidon2::BN254_WIDTH" value_BN254_WIDTH. + Admitted. + Global Typeclasses Opaque value_BN254_WIDTH. + + (* StructRecord + { + name := "Poseidon2InternalLayerBn254"; + const_params := []; + ty_params := []; + fields := + [ + ("internal_constants", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "alloc::alloc::Global" ]) + ]; + } *) + + Module Impl_core_fmt_Debug_for_p3_bn254_fr_poseidon2_Poseidon2InternalLayerBn254. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Poseidon2InternalLayerBn254" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "internal_constants" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254", + "internal_constants" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_bn254_fr_poseidon2_Poseidon2InternalLayerBn254. + + Module Impl_core_clone_Clone_for_p3_bn254_fr_poseidon2_Poseidon2InternalLayerBn254. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254" + [ + ("internal_constants", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254", + "internal_constants" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_bn254_fr_poseidon2_Poseidon2InternalLayerBn254. + + Module Impl_core_default_Default_for_p3_bn254_fr_poseidon2_Poseidon2InternalLayerBn254. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254" + [ + ("internal_constants", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "alloc::alloc::Global" ], + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_bn254_fr_poseidon2_Poseidon2InternalLayerBn254. + + Module Impl_p3_poseidon2_internal_InternalLayerConstructor_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_poseidon2_Poseidon2InternalLayerBn254. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254". + + (* + fn new_from_constants(internal_constants: Vec) -> Self { + Self { internal_constants } + } + *) + Definition new_from_constants (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ internal_constants ] => + ltac:(M.monadic + (let internal_constants := M.alloc (| internal_constants |) in + Value.StructRecord + "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254" + [ ("internal_constants", M.read (| internal_constants |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayerConstructor" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("new_from_constants", InstanceField.Method new_from_constants) ]. + End Impl_p3_poseidon2_internal_InternalLayerConstructor_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_poseidon2_Poseidon2InternalLayerBn254. + + (* + fn bn254_matmul_internal(state: &mut [Bn254Fr; 3]) { + // We bracket in this way as the s-box is applied to state[0] so this lets us + // begin this computation before the s-box finishes. + let sum = state[0] + (state[1] + state[2]); + + state[0] += sum; + state[1] += sum; + state[2] = state[2].double() + sum; + } + *) + Definition bn254_matmul_internal (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ sum : Ty.apply (Ty.path "*") [] [ Ty.path "p3_bn254_fr::Bn254Fr" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.read (| sum |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_bn254_matmul_internal : + M.IsFunction.C "p3_bn254_fr::poseidon2::bn254_matmul_internal" bn254_matmul_internal. + Admitted. + Global Typeclasses Opaque bn254_matmul_internal. + + Module Impl_p3_poseidon2_internal_InternalLayer_expr_expr_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_poseidon2_Poseidon2InternalLayerBn254. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254". + + (* + fn permute_state(&self, state: &mut [Bn254Fr; BN254_WIDTH]) { + internal_permute_state(state, bn254_matmul_internal, &self.internal_constants) + } + *) + Definition permute_state (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::internal_permute_state", + [ Value.Integer IntegerKind.Usize 3; Value.Integer IntegerKind.U64 5 ], + [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "p3_bn254_fr::Bn254Fr" ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| "p3_bn254_fr::poseidon2::bn254_matmul_internal", [], [] |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "p3_bn254_fr::Bn254Fr" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_bn254_fr::poseidon2::Poseidon2InternalLayerBn254", + "internal_constants" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayer" + (* Trait polymorphic consts *) + [ + M.unevaluated_const (mk_str (| "p3_bn254_fr_poseidon2_discriminant" |)); + M.unevaluated_const (mk_str (| "p3_bn254_fr_poseidon2_discriminant" |)) + ] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + Self + (* Instance *) [ ("permute_state", InstanceField.Method permute_state) ]. + End Impl_p3_poseidon2_internal_InternalLayer_expr_expr_p3_bn254_fr_Bn254Fr_for_p3_bn254_fr_poseidon2_Poseidon2InternalLayerBn254. + + Axiom Poseidon2ExternalLayerBn254 : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_bn254_fr::poseidon2::Poseidon2ExternalLayerBn254") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ]). + + Module Impl_p3_poseidon2_external_ExternalLayerConstructor_WIDTH_p3_bn254_fr_Bn254Fr_for_p3_poseidon2_external_ExternalLayerConstants_WIDTH_p3_bn254_fr_Bn254Fr. + Definition Self (WIDTH : Value.t) : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ]. + + (* + fn new_from_constants(external_constants: Self) -> Self { + external_constants + } + *) + Definition new_from_constants + (WIDTH : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ external_constants ] => + ltac:(M.monadic + (let external_constants := M.alloc (| external_constants |) in + M.read (| external_constants |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t), + M.IsTraitInstance + "p3_poseidon2::external::ExternalLayerConstructor" + (* Trait polymorphic consts *) [ WIDTH ] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + (Self WIDTH) + (* Instance *) [ ("new_from_constants", InstanceField.Method (new_from_constants WIDTH)) ]. + End Impl_p3_poseidon2_external_ExternalLayerConstructor_WIDTH_p3_bn254_fr_Bn254Fr_for_p3_poseidon2_external_ExternalLayerConstants_WIDTH_p3_bn254_fr_Bn254Fr. + + Module Impl_p3_poseidon2_external_ExternalLayer_WIDTH_expr_p3_bn254_fr_Bn254Fr_for_p3_poseidon2_external_ExternalLayerConstants_WIDTH_p3_bn254_fr_Bn254Fr. + Definition Self (WIDTH : Value.t) : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ]. + + (* + fn permute_state_initial(&self, state: &mut [Bn254Fr; WIDTH]) { + external_initial_permute_state( + state, + self.get_initial_constants(), + add_rc_and_sbox_generic, + &HLMDSMat4, + ); + } + *) + Definition permute_state_initial + (WIDTH : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_initial_permute_state", + [ WIDTH ], + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.path "p3_poseidon2::external::HLMDSMat4" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "get_initial_constants", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) + ] + |) + |) + |) + ] + |) + |) + |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ Value.Integer IntegerKind.U64 5 ], + [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "p3_bn254_fr::Bn254Fr" ] + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::HLMDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_state_terminal(&self, state: &mut [Bn254Fr; WIDTH]) { + external_terminal_permute_state( + state, + self.get_terminal_constants(), + add_rc_and_sbox_generic, + &HLMDSMat4, + ); + } + *) + Definition permute_state_terminal + (WIDTH : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_terminal_permute_state", + [ WIDTH ], + [ + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.path "p3_bn254_fr::Bn254Fr"; + Ty.path "p3_poseidon2::external::HLMDSMat4" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_bn254_fr::Bn254Fr" ], + "get_terminal_constants", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) + ] + |) + |) + |) + ] + |) + |) + |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ Value.Integer IntegerKind.U64 5 ], + [ Ty.path "p3_bn254_fr::Bn254Fr"; Ty.path "p3_bn254_fr::Bn254Fr" ] + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::HLMDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t), + M.IsTraitInstance + "p3_poseidon2::external::ExternalLayer" + (* Trait polymorphic consts *) + [ WIDTH; M.unevaluated_const (mk_str (| "p3_bn254_fr_poseidon2_discriminant" |)) ] + (* Trait polymorphic types *) [ Ty.path "p3_bn254_fr::Bn254Fr" ] + (Self WIDTH) + (* Instance *) + [ + ("permute_state_initial", InstanceField.Method (permute_state_initial WIDTH)); + ("permute_state_terminal", InstanceField.Method (permute_state_terminal WIDTH)) + ]. + End Impl_p3_poseidon2_external_ExternalLayer_WIDTH_expr_p3_bn254_fr_Bn254Fr_for_p3_poseidon2_external_ExternalLayerConstants_WIDTH_p3_bn254_fr_Bn254Fr. +End poseidon2. diff --git a/CoqOfRust/plonky3/challenger/src/duplex_challenger.rs b/CoqOfRust/plonky3/challenger/src/duplex_challenger.rs new file mode 100644 index 000000000..9d7685f84 --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/duplex_challenger.rs @@ -0,0 +1,246 @@ +use alloc::vec; +use alloc::vec::Vec; + +use p3_field::{BasedVectorSpace, Field, PrimeField64}; +use p3_symmetric::{CryptographicPermutation, Hash}; + +use crate::{CanObserve, CanSample, CanSampleBits, FieldChallenger}; + +#[derive(Clone, Debug)] +pub struct DuplexChallenger +where + F: Clone, + P: CryptographicPermutation<[F; WIDTH]>, +{ + pub sponge_state: [F; WIDTH], + pub input_buffer: Vec, + pub output_buffer: Vec, + pub permutation: P, +} + +impl DuplexChallenger +where + F: Copy, + P: CryptographicPermutation<[F; WIDTH]>, +{ + pub fn new(permutation: P) -> Self + where + F: Default, + { + Self { + sponge_state: [F::default(); WIDTH], + input_buffer: vec![], + output_buffer: vec![], + permutation, + } + } + + fn duplexing(&mut self) { + assert!(self.input_buffer.len() <= RATE); + + // Overwrite the first r elements with the inputs. + for (i, val) in self.input_buffer.drain(..).enumerate() { + self.sponge_state[i] = val; + } + + // Apply the permutation. + self.permutation.permute_mut(&mut self.sponge_state); + + self.output_buffer.clear(); + self.output_buffer.extend(&self.sponge_state[..RATE]); + } +} + +impl FieldChallenger + for DuplexChallenger +where + F: PrimeField64, + P: CryptographicPermutation<[F; WIDTH]>, +{ +} + +impl CanObserve + for DuplexChallenger +where + F: Copy, + P: CryptographicPermutation<[F; WIDTH]>, +{ + fn observe(&mut self, value: F) { + // Any buffered output is now invalid. + self.output_buffer.clear(); + + self.input_buffer.push(value); + + if self.input_buffer.len() == RATE { + self.duplexing(); + } + } +} + +impl CanObserve<[F; N]> + for DuplexChallenger +where + F: Copy, + P: CryptographicPermutation<[F; WIDTH]>, +{ + fn observe(&mut self, values: [F; N]) { + for value in values { + self.observe(value); + } + } +} + +impl CanObserve> + for DuplexChallenger +where + F: Copy, + P: CryptographicPermutation<[F; WIDTH]>, +{ + fn observe(&mut self, values: Hash) { + for value in values { + self.observe(value); + } + } +} + +// for TrivialPcs +impl CanObserve>> + for DuplexChallenger +where + F: Copy, + P: CryptographicPermutation<[F; WIDTH]>, +{ + fn observe(&mut self, valuess: Vec>) { + for values in valuess { + for value in values { + self.observe(value); + } + } + } +} + +impl CanSample + for DuplexChallenger +where + F: Field, + EF: BasedVectorSpace, + P: CryptographicPermutation<[F; WIDTH]>, +{ + fn sample(&mut self) -> EF { + EF::from_basis_coefficients_fn(|_| { + // If we have buffered inputs, we must perform a duplexing so that the challenge will + // reflect them. Or if we've run out of outputs, we must perform a duplexing to get more. + if !self.input_buffer.is_empty() || self.output_buffer.is_empty() { + self.duplexing(); + } + + self.output_buffer + .pop() + .expect("Output buffer should be non-empty") + }) + } +} + +impl CanSampleBits + for DuplexChallenger +where + F: PrimeField64, + P: CryptographicPermutation<[F; WIDTH]>, +{ + fn sample_bits(&mut self, bits: usize) -> usize { + assert!(bits < (usize::BITS as usize)); + assert!((1 << bits) < F::ORDER_U64); + let rand_f: F = self.sample(); + let rand_usize = rand_f.as_canonical_u64() as usize; + rand_usize & ((1 << bits) - 1) + } +} + +#[cfg(test)] +mod tests { + use core::iter; + + use p3_baby_bear::BabyBear; + use p3_field::PrimeCharacteristicRing; + use p3_goldilocks::Goldilocks; + use p3_symmetric::Permutation; + + use super::*; + use crate::grinding_challenger::GrindingChallenger; + + const WIDTH: usize = 24; + const RATE: usize = 16; + + type G = Goldilocks; + type BB = BabyBear; + + #[derive(Clone)] + struct TestPermutation {} + + impl Permutation<[F; WIDTH]> for TestPermutation { + fn permute_mut(&self, input: &mut [F; WIDTH]) { + input.reverse() + } + } + + impl CryptographicPermutation<[F; WIDTH]> for TestPermutation {} + + #[test] + fn test_duplex_challenger() { + type Chal = DuplexChallenger; + let permutation = TestPermutation {}; + let mut duplex_challenger = DuplexChallenger::new(permutation); + + // Observe 12 elements. + (0..12).for_each(|element| duplex_challenger.observe(G::from_u8(element as u8))); + + let state_after_duplexing: Vec<_> = iter::repeat_n(G::ZERO, 12) + .chain((0..12).map(G::from_u8).rev()) + .collect(); + + let expected_samples: Vec = state_after_duplexing[..16].iter().copied().rev().collect(); + let samples = >::sample_vec(&mut duplex_challenger, 16); + assert_eq!(samples, expected_samples); + } + + #[test] + #[should_panic] + fn test_duplex_challenger_sample_bits_security() { + type GoldilocksChal = DuplexChallenger; + let permutation = TestPermutation {}; + let mut duplex_challenger = GoldilocksChal::new(permutation); + + for _ in 0..100 { + assert!(duplex_challenger.sample_bits(129) < 4); + } + } + + #[test] + #[should_panic] + fn test_duplex_challenger_sample_bits_security_small_field() { + type BabyBearChal = DuplexChallenger; + let permutation = TestPermutation {}; + let mut duplex_challenger = BabyBearChal::new(permutation); + + for _ in 0..100 { + assert!(duplex_challenger.sample_bits(40) < 1 << 31); + } + } + + #[test] + #[should_panic] + fn test_duplex_challenger_grind_security() { + type GoldilocksChal = DuplexChallenger; + let permutation = TestPermutation {}; + let mut duplex_challenger = GoldilocksChal::new(permutation); + + // This should cause sample_bits (and hence grind and check_witness) to + // panic. If bit sizes were not constrained correctly inside the + // challenger, (1 << too_many_bits) would loop around, incorrectly + // grinding and accepting a 1-bit PoW. + let too_many_bits = usize::BITS as usize; + + let witness = duplex_challenger.grind(too_many_bits); + assert!(duplex_challenger.check_witness(too_many_bits, witness)); + } +} diff --git a/CoqOfRust/plonky3/challenger/src/duplex_challenger.v b/CoqOfRust/plonky3/challenger/src/duplex_challenger.v new file mode 100644 index 000000000..187dec74a --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/duplex_challenger.v @@ -0,0 +1,1868 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module duplex_challenger. + (* StructRecord + { + name := "DuplexChallenger"; + const_params := [ "WIDTH"; "RATE" ]; + ty_params := [ "F"; "P" ]; + fields := + [ + ("sponge_state", Ty.apply (Ty.path "array") [ WIDTH ] [ F ]); + ("input_buffer", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]); + ("output_buffer", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]); + ("permutation", P) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_P_where_core_clone_Clone_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + (* Clone *) + Definition clone + (WIDTH RATE : Value.t) + (F P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F P in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_challenger::duplex_challenger::DuplexChallenger" + [ + ("sponge_state", + M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ WIDTH ] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "sponge_state" + |) + |) + |) + |) + ] + |)); + ("input_buffer", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "input_buffer" + |) + |) + |) + |) + ] + |)); + ("output_buffer", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "output_buffer" + |) + |) + |) + |) + ] + |)); + ("permutation", + M.call_closure (| + P, + M.get_trait_method (| "core::clone::Clone", P, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "permutation" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F P : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE F P) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH RATE F P)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_P_where_core_clone_Clone_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_P_where_core_clone_Clone_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + (* Debug *) + Definition fmt + (WIDTH RATE : Value.t) + (F P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F P in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field4_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "DuplexChallenger" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "sponge_state" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "sponge_state" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "input_buffer" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "input_buffer" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "output_buffer" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "output_buffer" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "permutation" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "permutation" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F P : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE F P) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH RATE F P)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_P_where_core_clone_Clone_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + + Module Impl_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + (* + pub fn new(permutation: P) -> Self + where + F: Default, + { + Self { + sponge_state: [F::default(); WIDTH], + input_buffer: vec![], + output_buffer: vec![], + permutation, + } + } + *) + Definition new + (WIDTH RATE : Value.t) + (F P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F P in + match ε, τ, α with + | [], [], [ permutation ] => + ltac:(M.monadic + (let permutation := M.alloc (| permutation |) in + Value.StructRecord + "p3_challenger::duplex_challenger::DuplexChallenger" + [ + ("sponge_state", + repeat (| + M.call_closure (| + F, + M.get_trait_method (| "core::default::Default", F, [], [], "default", [], [] |), + [] + |), + WIDTH + |)); + ("input_buffer", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |)); + ("output_buffer", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |)); + ("permutation", M.read (| permutation |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (WIDTH RATE : Value.t) (F P : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH RATE F P) "new" (new WIDTH RATE F P). + Admitted. + Global Typeclasses Opaque new. + + (* + fn duplexing(&mut self) { + assert!(self.input_buffer.len() <= RATE); + + // Overwrite the first r elements with the inputs. + for (i, val) in self.input_buffer.drain(..).enumerate() { + self.sponge_state[i] = val; + } + + // Apply the permutation. + self.permutation.permute_mut(&mut self.sponge_state); + + self.output_buffer.clear(); + self.output_buffer.extend(&self.sponge_state[..RATE]); + } + *) + Definition duplexing + (WIDTH RATE : Value.t) + (F P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F P in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "input_buffer" + |) + |) + ] + |); + RATE + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: self.input_buffer.len() <= RATE" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "alloc::vec::drain::Drain") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "alloc::vec::drain::Drain") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "alloc::vec::drain::Drain") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::drain::Drain") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::drain::Drain") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "drain", + [], + [ Ty.path "core::ops::range::RangeFull" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "input_buffer" + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "alloc::vec::drain::Drain") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let i := M.copy (| γ1_0 |) in + let val := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "sponge_state" + |), + M.read (| i |) + |), + M.read (| val |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + P, + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "permutation" + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "sponge_state" + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "clear", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "output_buffer" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.apply (Ty.path "&") [] [ F ] ], + "extend", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "output_buffer" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ WIDTH ] [ F ], + [], + [ Ty.apply (Ty.path "core::ops::range::RangeTo") [] [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "sponge_state" + |) + |); + Value.StructRecord "core::ops::range::RangeTo" [ ("end_", RATE) ] + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_duplexing : + forall (WIDTH RATE : Value.t) (F P : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH RATE F P) "duplexing" (duplexing WIDTH RATE F P). + Admitted. + Global Typeclasses Opaque duplexing. + End Impl_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + + Module Impl_p3_challenger_FieldChallenger_where_p3_field_field_PrimeField64_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F P : Ty.t), + M.IsTraitInstance + "p3_challenger::FieldChallenger" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self WIDTH RATE F P) + (* Instance *) []. + End Impl_p3_challenger_FieldChallenger_where_p3_field_field_PrimeField64_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + + Module Impl_p3_challenger_CanObserve_where_core_marker_Copy_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + (* + fn observe(&mut self, value: F) { + // Any buffered output is now invalid. + self.output_buffer.clear(); + + self.input_buffer.push(value); + + if self.input_buffer.len() == RATE { + self.duplexing(); + } + } + *) + Definition observe + (WIDTH RATE : Value.t) + (F P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F P in + match ε, τ, α with + | [], [], [ self; value ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let value := M.alloc (| value |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "clear", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "output_buffer" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "input_buffer" + |) + |); + M.read (| value |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "input_buffer" + |) + |) + ] + |); + RATE + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ], + "duplexing", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self WIDTH RATE F P) + (* Instance *) [ ("observe", InstanceField.Method (observe WIDTH RATE F P)) ]. + End Impl_p3_challenger_CanObserve_where_core_marker_Copy_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + + Module Impl_p3_challenger_CanObserve_where_core_marker_Copy_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_array_N_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (N WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + (* + fn observe(&mut self, values: [F; N]) { + for value in values { + self.observe(value); + } + } + *) + Definition observe + (N WIDTH RATE : Value.t) + (F P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N WIDTH RATE F P in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.apply + (Ty.path + "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ], + [], + [ F ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.read (| value |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N WIDTH RATE : Value.t) (F P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ F ] ] + (Self N WIDTH RATE F P) + (* Instance *) [ ("observe", InstanceField.Method (observe N WIDTH RATE F P)) ]. + End Impl_p3_challenger_CanObserve_where_core_marker_Copy_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_array_N_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + + Module Impl_p3_challenger_CanObserve_where_core_marker_Copy_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_p3_symmetric_hash_Hash_N_F_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (N WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + (* + fn observe(&mut self, values: Hash) { + for value in values { + self.observe(value); + } + } + *) + Definition observe + (N WIDTH RATE : Value.t) + (F P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N WIDTH RATE F P in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; F ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.apply + (Ty.path + "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ], + [], + [ F ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.read (| value |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N WIDTH RATE : Value.t) (F P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; F ] ] + (Self N WIDTH RATE F P) + (* Instance *) [ ("observe", InstanceField.Method (observe N WIDTH RATE F P)) ]. + End Impl_p3_challenger_CanObserve_where_core_marker_Copy_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_p3_symmetric_hash_Hash_N_F_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + + Module Impl_p3_challenger_CanObserve_where_core_marker_Copy_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_alloc_vec_Vec_alloc_vec_Vec_F_alloc_alloc_Global_alloc_alloc_Global_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + (* + fn observe(&mut self, valuess: Vec>) { + for values in valuess { + for value in values { + self.observe(value); + } + } + } + *) + Definition observe + (WIDTH RATE : Value.t) + (F P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F P in + match ε, τ, α with + | [], [], [ self; valuess ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let valuess := M.alloc (| valuess |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| valuess |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let values := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.apply + (Ty.path + "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ], + [], + [ F ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| self |) + |) + |); + M.read (| value |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + (Self WIDTH RATE F P) + (* Instance *) [ ("observe", InstanceField.Method (observe WIDTH RATE F P)) ]. + End Impl_p3_challenger_CanObserve_where_core_marker_Copy_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_alloc_vec_Vec_alloc_vec_Vec_F_alloc_alloc_Global_alloc_alloc_Global_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + + Module Impl_p3_challenger_CanSample_where_p3_field_field_Field_F_where_p3_field_field_BasedVectorSpace_EF_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_EF_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (WIDTH RATE : Value.t) (F EF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + (* + fn sample(&mut self) -> EF { + EF::from_basis_coefficients_fn(|_| { + // If we have buffered inputs, we must perform a duplexing so that the challenge will + // reflect them. Or if we've run out of outputs, we must perform a duplexing to get more. + if !self.input_buffer.is_empty() || self.output_buffer.is_empty() { + self.duplexing(); + } + + self.output_buffer + .pop() + .expect("Output buffer should be non-empty") + }) + } + *) + Definition sample + (WIDTH RATE : Value.t) + (F EF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F EF P in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + EF, + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + EF, + [], + [ F ], + "from_basis_coefficients_fn", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "input_buffer" + |) + |) + ] + |) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "output_buffer" + |) + |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ], + "duplexing", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "pop", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::duplex_challenger::DuplexChallenger", + "output_buffer" + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| "Output buffer should be non-empty" |) + |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F EF P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSample" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ EF ] + (Self WIDTH RATE F EF P) + (* Instance *) [ ("sample", InstanceField.Method (sample WIDTH RATE F EF P)) ]. + End Impl_p3_challenger_CanSample_where_p3_field_field_Field_F_where_p3_field_field_BasedVectorSpace_EF_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_EF_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + + Module Impl_p3_challenger_CanSampleBits_where_p3_field_field_PrimeField64_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_usize_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + (* + fn sample_bits(&mut self, bits: usize) -> usize { + assert!(bits < (usize::BITS as usize)); + assert!((1 << bits) < F::ORDER_U64); + let rand_f: F = self.sample(); + let rand_usize = rand_f.as_canonical_u64() as usize; + rand_usize & ((1 << bits) - 1) + } + *) + Definition sample_bits + (WIDTH RATE : Value.t) + (F P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F P in + match ε, τ, α with + | [], [], [ self; bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| bits |); + M.cast + (Ty.path "usize") + (M.read (| + get_associated_constant (| + Ty.path "usize", + "BITS", + Ty.path "u32" + |) + |)) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits < (usize::BITS as usize)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U64 1; M.read (| bits |) ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: (1 << bits) < F::ORDER_U64" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ rand_f : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_challenger::CanSample", + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ], + [], + [ F ], + "sample", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ rand_usize : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + F, + [], + [], + "as_canonical_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rand_f |) ] + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ + M.read (| rand_usize |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| bits |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSampleBits" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + (Self WIDTH RATE F P) + (* Instance *) [ ("sample_bits", InstanceField.Method (sample_bits WIDTH RATE F P)) ]. + End Impl_p3_challenger_CanSampleBits_where_p3_field_field_PrimeField64_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_usize_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. +End duplex_challenger. diff --git a/CoqOfRust/plonky3/challenger/src/grinding_challenger.rs b/CoqOfRust/plonky3/challenger/src/grinding_challenger.rs new file mode 100644 index 000000000..59b0d9318 --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/grinding_challenger.rs @@ -0,0 +1,72 @@ +use p3_field::{Field, PrimeField, PrimeField32, PrimeField64}; +use p3_maybe_rayon::prelude::*; +use p3_symmetric::CryptographicPermutation; +use tracing::instrument; + +use crate::{CanObserve, CanSampleBits, DuplexChallenger, MultiField32Challenger}; + +pub trait GrindingChallenger: + CanObserve + CanSampleBits + Sync + Clone +{ + type Witness: Field; + + fn grind(&mut self, bits: usize) -> Self::Witness; + + #[must_use] + fn check_witness(&mut self, bits: usize, witness: Self::Witness) -> bool { + self.observe(witness); + self.sample_bits(bits) == 0 + } +} + +impl GrindingChallenger + for DuplexChallenger +where + F: PrimeField64, + P: CryptographicPermutation<[F; WIDTH]>, +{ + type Witness = F; + + #[instrument(name = "grind for proof-of-work witness", skip_all)] + fn grind(&mut self, bits: usize) -> Self::Witness { + assert!(bits < (usize::BITS as usize)); + assert!((1 << bits) < F::ORDER_U64); + + let witness = (0..F::ORDER_U64) + .into_par_iter() + .map(|i| unsafe { + // i < F::ORDER_U64 by construction so this is safe. + F::from_canonical_unchecked(i) + }) + .find_any(|witness| self.clone().check_witness(bits, *witness)) + .expect("failed to find witness"); + assert!(self.check_witness(bits, witness)); + witness + } +} + +impl GrindingChallenger + for MultiField32Challenger +where + F: PrimeField32, + PF: PrimeField, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + type Witness = F; + + #[instrument(name = "grind for proof-of-work witness", skip_all)] + fn grind(&mut self, bits: usize) -> Self::Witness { + assert!(bits < (usize::BITS as usize)); + assert!((1 << bits) < F::ORDER_U32); + let witness = (0..F::ORDER_U32) + .into_par_iter() + .map(|i| unsafe { + // i < F::ORDER_U32 by construction so this is safe. + F::from_canonical_unchecked(i) + }) + .find_any(|witness| self.clone().check_witness(bits, *witness)) + .expect("failed to find witness"); + assert!(self.check_witness(bits, witness)); + witness + } +} diff --git a/CoqOfRust/plonky3/challenger/src/grinding_challenger.v b/CoqOfRust/plonky3/challenger/src/grinding_challenger.v new file mode 100644 index 000000000..19bad2839 --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/grinding_challenger.v @@ -0,0 +1,2081 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module grinding_challenger. + (* Trait *) + Module GrindingChallenger. + Definition check_witness + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; bits; witness ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bits := M.alloc (| bits |) in + let witness := M.alloc (| witness |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Self, + [], + [ + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Self + "Witness" + ], + "observe", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |); + M.read (| witness |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_challenger::CanSampleBits", + Self, + [], + [ Ty.path "usize" ], + "sample_bits", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |); + M.read (| bits |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_check_witness : + M.IsProvidedMethod + "p3_challenger::grinding_challenger::GrindingChallenger" + "check_witness" + check_witness. + End GrindingChallenger. + + Module Impl_p3_challenger_grinding_challenger_GrindingChallenger_where_p3_field_field_PrimeField64_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + Definition Self (WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]. + + (* type Witness = F; *) + Definition _Witness (WIDTH RATE : Value.t) (F P : Ty.t) : Ty.t := F. + + (* #[instrument(name = "grind for proof-of-work witness", skip_all)] *) + Definition grind + (WIDTH RATE : Value.t) + (F P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F P in + match ε, τ, α with + | [], [], [ self; bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bits := M.alloc (| bits |) in + M.catch_return + (Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + (Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ]) + "Witness") (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::grinding_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::grinding_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::grinding_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::grinding_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| bits |); + M.cast + (Ty.path "usize") + (M.read (| + get_associated_constant (| + Ty.path "usize", + "BITS", + Ty.path "u32" + |) + |)) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits < (usize::BITS as usize)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U64 1; M.read (| bits |) ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: (1 << bits) < F::ORDER_U64" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ witness : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParIterExt", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ]; + Ty.function [ Ty.tuple [ Ty.path "u64" ] ] F + ], + [], + [], + "find_any", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] + (Ty.path "bool") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ]; + Ty.function [ Ty.tuple [ Ty.path "u64" ] ] F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ], + [], + [], + "map", + [], + [ F; Ty.function [ Ty.tuple [ Ty.path "u64" ] ] F ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "u64" ], + [], + [], + "into_par_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.U64 0); + ("end_", + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |)) + ] + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "u64" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::integers::QuotientMap", + F, + [], + [ Ty.path "u64" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.read (| i |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let witness := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Ty.apply + (Ty.path + "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ], + [], + [], + "check_witness", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |); + M.read (| bits |); + M.read (| M.deref (| M.read (| witness |) |) |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "failed to find witness" |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Ty.apply + (Ty.path + "p3_challenger::duplex_challenger::DuplexChallenger") + [ WIDTH; RATE ] + [ F; P ], + [], + [], + "check_witness", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.read (| bits |); + M.read (| witness |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: self.check_witness(bits, witness)" |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + witness + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F P : Ty.t), + M.IsTraitInstance + "p3_challenger::grinding_challenger::GrindingChallenger" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE F P) + (* Instance *) + [ + ("Witness", InstanceField.Ty (_Witness WIDTH RATE F P)); + ("grind", InstanceField.Method (grind WIDTH RATE F P)) + ]. + End Impl_p3_challenger_grinding_challenger_GrindingChallenger_where_p3_field_field_PrimeField64_F_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_F_for_p3_challenger_duplex_challenger_DuplexChallenger_WIDTH_RATE_F_P. + + Module Impl_p3_challenger_grinding_challenger_GrindingChallenger_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + (* type Witness = F; *) + Definition _Witness (WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := F. + + (* #[instrument(name = "grind for proof-of-work witness", skip_all)] *) + Definition grind + (WIDTH RATE : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F PF P in + match ε, τ, α with + | [], [], [ self; bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bits := M.alloc (| bits |) in + M.catch_return + (Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + (Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]) + "Witness") (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::grinding_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::grinding_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::grinding_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::grinding_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| bits |); + M.cast + (Ty.path "usize") + (M.read (| + get_associated_constant (| + Ty.path "usize", + "BITS", + Ty.path "u32" + |) + |)) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits < (usize::BITS as usize)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U32 1; M.read (| bits |) ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: (1 << bits) < F::ORDER_U32" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ witness : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParIterExt", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u32" ]; + Ty.function [ Ty.tuple [ Ty.path "u32" ] ] F + ], + [], + [], + "find_any", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] + (Ty.path "bool") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u32" ]; + Ty.function [ Ty.tuple [ Ty.path "u32" ] ] F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u32" ], + [], + [], + "map", + [], + [ F; Ty.function [ Ty.tuple [ Ty.path "u32" ] ] F ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u32" ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "u32" ], + [], + [], + "into_par_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.U32 0); + ("end_", + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |)) + ] + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "u32" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::integers::QuotientMap", + F, + [], + [ Ty.path "u32" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.read (| i |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let witness := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Ty.apply + (Ty.path + "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ], + [], + [], + "check_witness", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |); + M.read (| bits |); + M.read (| M.deref (| M.read (| witness |) |) |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "failed to find witness" |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Ty.apply + (Ty.path + "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ], + [], + [], + "check_witness", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.read (| bits |); + M.read (| witness |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: self.check_witness(bits, witness)" |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + witness + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "p3_challenger::grinding_challenger::GrindingChallenger" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE F PF P) + (* Instance *) + [ + ("Witness", InstanceField.Ty (_Witness WIDTH RATE F PF P)); + ("grind", InstanceField.Method (grind WIDTH RATE F PF P)) + ]. + End Impl_p3_challenger_grinding_challenger_GrindingChallenger_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. +End grinding_challenger. diff --git a/CoqOfRust/plonky3/challenger/src/hash_challenger.rs b/CoqOfRust/plonky3/challenger/src/hash_challenger.rs new file mode 100644 index 000000000..041fc6da6 --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/hash_challenger.rs @@ -0,0 +1,338 @@ +use alloc::vec; +use alloc::vec::Vec; + +use p3_symmetric::CryptographicHasher; + +use crate::{CanObserve, CanSample}; + +/// A generic challenger that uses a cryptographic hash function to generate challenges. +#[derive(Clone, Debug)] +pub struct HashChallenger +where + T: Clone, + H: CryptographicHasher, +{ + /// Buffer to store observed values before hashing. + input_buffer: Vec, + /// Buffer to store hashed output values, which are consumed when sampling. + output_buffer: Vec, + /// The cryptographic hash function used for generating challenges. + hasher: H, +} + +impl HashChallenger +where + T: Clone, + H: CryptographicHasher, +{ + pub const fn new(initial_state: Vec, hasher: H) -> Self { + Self { + input_buffer: initial_state, + output_buffer: vec![], + hasher, + } + } + + fn flush(&mut self) { + let inputs = self.input_buffer.drain(..); + let output = self.hasher.hash_iter(inputs); + + self.output_buffer = output.to_vec(); + + // Chaining values. + self.input_buffer.extend(output.to_vec()); + } +} + +impl CanObserve for HashChallenger +where + T: Clone, + H: CryptographicHasher, +{ + fn observe(&mut self, value: T) { + // Any buffered output is now invalid. + self.output_buffer.clear(); + + self.input_buffer.push(value); + } +} + +impl CanObserve<[T; N]> + for HashChallenger +where + T: Clone, + H: CryptographicHasher, +{ + fn observe(&mut self, values: [T; N]) { + for value in values { + self.observe(value); + } + } +} + +impl CanSample for HashChallenger +where + T: Clone, + H: CryptographicHasher, +{ + fn sample(&mut self) -> T { + if self.output_buffer.is_empty() { + self.flush(); + } + self.output_buffer + .pop() + .expect("Output buffer should be non-empty") + } +} + +#[cfg(test)] +mod tests { + use p3_field::PrimeCharacteristicRing; + use p3_goldilocks::Goldilocks; + + use super::*; + + const OUT_LEN: usize = 2; + type F = Goldilocks; + + #[derive(Clone)] + struct TestHasher {} + + impl CryptographicHasher for TestHasher { + /// A very simple hash iterator. From an input of type `IntoIterator`, + /// it outputs the sum of its elements and its length (as a field element). + fn hash_iter(&self, input: I) -> [F; OUT_LEN] + where + I: IntoIterator, + { + let (sum, len) = input + .into_iter() + .fold((F::ZERO, 0_usize), |(acc_sum, acc_len), f| { + (acc_sum + f, acc_len + 1) + }); + [sum, F::from_usize(len)] + } + + /// A very simple slice hash iterator. From an input of type `IntoIterator`, + /// it outputs the sum of its elements and its length (as a field element). + fn hash_iter_slices<'a, I>(&self, input: I) -> [F; OUT_LEN] + where + I: IntoIterator, + F: 'a, + { + let (sum, len) = input + .into_iter() + .fold((F::ZERO, 0_usize), |(acc_sum, acc_len), n| { + ( + acc_sum + n.iter().fold(F::ZERO, |acc, f| acc + *f), + acc_len + n.len(), + ) + }); + [sum, F::from_usize(len)] + } + } + + #[test] + fn test_hash_challenger() { + let initial_state = (1..11_u8).map(F::from_u8).collect::>(); + let test_hasher = TestHasher {}; + let mut hash_challenger = HashChallenger::new(initial_state.clone(), test_hasher); + + assert_eq!(hash_challenger.input_buffer, initial_state); + assert_eq!(hash_challenger.output_buffer, vec![]); + + hash_challenger.flush(); + + let expected_sum = F::from_u8(55); + let expected_len = F::from_u8(10); + assert_eq!( + hash_challenger.input_buffer, + vec![expected_sum, expected_len] + ); + assert_eq!( + hash_challenger.output_buffer, + vec![expected_sum, expected_len] + ); + + let new_element = F::from_u8(11); + hash_challenger.observe(new_element); + assert_eq!( + hash_challenger.input_buffer, + vec![expected_sum, expected_len, new_element] + ); + assert_eq!(hash_challenger.output_buffer, vec![]); + + let new_expected_len = 3; + let new_expected_sum = 76; + + let new_element = hash_challenger.sample(); + assert_eq!(new_element, F::from_u8(new_expected_len)); + assert_eq!( + hash_challenger.output_buffer, + [F::from_u8(new_expected_sum)] + ) + } + + #[test] + fn test_hash_challenger_flush() { + let initial_state = (1..11_u8).map(F::from_u8).collect::>(); + let test_hasher = TestHasher {}; + let mut hash_challenger = HashChallenger::new(initial_state, test_hasher); + + // Sample twice to ensure flush happens + let first_sample = hash_challenger.sample(); + + let second_sample = hash_challenger.sample(); + + // Verify that the first sample is the length of 1..11, (i.e. 10). + assert_eq!(first_sample, F::from_u8(10)); + // Verify that the second sample is the sum of numbers from 1 to 10 (i.e. 55) + assert_eq!(second_sample, F::from_u8(55)); + + // Verify that the output buffer is now empty + assert!(hash_challenger.output_buffer.is_empty()); + } + + #[test] + fn test_observe_single_value() { + let test_hasher = TestHasher {}; + // Initial state non-empty + let mut hash_challenger = HashChallenger::new(vec![F::from_u8(123)], test_hasher); + + // Observe a single value + let value = F::from_u8(42); + hash_challenger.observe(value); + + // Check that the input buffer contains the initial and observed values + assert_eq!( + hash_challenger.input_buffer, + vec![F::from_u8(123), F::from_u8(42)] + ); + // Check that the output buffer is empty (clears after observation) + assert!(hash_challenger.output_buffer.is_empty()); + } + + #[test] + fn test_observe_array() { + let test_hasher = TestHasher {}; + // Initial state non-empty + let mut hash_challenger = HashChallenger::new(vec![F::from_u8(123)], test_hasher); + + // Observe an array of values + let values = [F::from_u8(1), F::from_u8(2), F::from_u8(3)]; + hash_challenger.observe(values); + + // Check that the input buffer contains the values + assert_eq!( + hash_challenger.input_buffer, + vec![F::from_u8(123), F::from_u8(1), F::from_u8(2), F::from_u8(3)] + ); + // Check that the output buffer is empty (clears after observation) + assert!(hash_challenger.output_buffer.is_empty()); + } + + #[test] + fn test_sample_output_buffer() { + let test_hasher = TestHasher {}; + let initial_state = vec![F::from_u8(5), F::from_u8(10)]; + let mut hash_challenger = HashChallenger::new(initial_state, test_hasher); + + let sample = hash_challenger.sample(); + // Verify that the sample is the length of the initial state + assert_eq!(sample, F::from_u8(2)); + // Check that the output buffer contains the sum of the initial state + assert_eq!(hash_challenger.output_buffer, vec![F::from_u8(15)]); + } + + #[test] + fn test_flush_empty_buffer() { + let test_hasher = TestHasher {}; + let mut hash_challenger = HashChallenger::new(vec![], test_hasher); + + // Flush empty buffer + hash_challenger.flush(); + + // Check that the input and output buffers contain the sum and length of the empty buffer + assert_eq!(hash_challenger.input_buffer, vec![F::ZERO, F::ZERO]); + assert_eq!(hash_challenger.output_buffer, vec![F::ZERO, F::ZERO]); + } + + #[test] + fn test_flush_with_data() { + let test_hasher = TestHasher {}; + // Initial state non-empty + let initial_state = vec![F::from_u8(1), F::from_u8(2)]; + let mut hash_challenger = HashChallenger::new(initial_state, test_hasher); + + hash_challenger.flush(); + + // Check that the input buffer contains the sum and length of the initial state + assert_eq!( + hash_challenger.input_buffer, + vec![F::from_u8(3), F::from_u8(2)] + ); + // Check that the output buffer contains the sum and length of the initial state + assert_eq!( + hash_challenger.output_buffer, + vec![F::from_u8(3), F::from_u8(2)] + ); + } + + #[test] + fn test_sample_after_observe() { + let test_hasher = TestHasher {}; + let initial_state = vec![F::from_u8(1), F::from_u8(2)]; + let mut hash_challenger = HashChallenger::new(initial_state, test_hasher); + + // Observe will clear the output buffer + hash_challenger.observe(F::from_u8(3)); + + // Verify that the output buffer is empty + assert!(hash_challenger.output_buffer.is_empty()); + + // Verify the new value is in the input buffer + assert_eq!( + hash_challenger.input_buffer, + vec![F::from_u8(1), F::from_u8(2), F::from_u8(3)] + ); + + let sample = hash_challenger.sample(); + + // Length of initial state + observed value + assert_eq!(sample, F::from_u8(3)); + } + + #[test] + fn test_sample_with_non_empty_output_buffer() { + let test_hasher = TestHasher {}; + let mut hash_challenger = HashChallenger::new(vec![], test_hasher); + + hash_challenger.output_buffer = vec![F::from_u8(42), F::from_u8(24)]; + + let sample = hash_challenger.sample(); + + // Sample will pop the last element from the output buffer + assert_eq!(sample, F::from_u8(24)); + + // Check that the output buffer is now one element shorter + assert_eq!(hash_challenger.output_buffer, vec![F::from_u8(42)]); + } + + #[test] + fn test_output_buffer_cleared_on_observe() { + let test_hasher = TestHasher {}; + let mut hash_challenger = HashChallenger::new(vec![], test_hasher); + + // Populate artificially the output buffer + hash_challenger.output_buffer.push(F::from_u8(42)); + + // Ensure the output buffer is populated + assert!(!hash_challenger.output_buffer.is_empty()); + + // Observe a new value + hash_challenger.observe(F::from_u8(3)); + + // Verify that the output buffer is cleared after observing + assert!(hash_challenger.output_buffer.is_empty()); + } +} diff --git a/CoqOfRust/plonky3/challenger/src/hash_challenger.v b/CoqOfRust/plonky3/challenger/src/hash_challenger.v new file mode 100644 index 000000000..6f442208f --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/hash_challenger.v @@ -0,0 +1,792 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module hash_challenger. + (* StructRecord + { + name := "HashChallenger"; + const_params := [ "OUT_LEN" ]; + ty_params := [ "T"; "H" ]; + fields := + [ + ("input_buffer", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ]); + ("output_buffer", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ]); + ("hasher", H) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_T_where_core_clone_Clone_H_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_OUT_LEN_T_for_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + Definition Self (OUT_LEN : Value.t) (T H : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_challenger::hash_challenger::HashChallenger") [ OUT_LEN ] [ T; H ]. + + (* Clone *) + Definition clone + (OUT_LEN : Value.t) + (T H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self OUT_LEN T H in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_challenger::hash_challenger::HashChallenger" + [ + ("input_buffer", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "input_buffer" + |) + |) + |) + |) + ] + |)); + ("output_buffer", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "output_buffer" + |) + |) + |) + |) + ] + |)); + ("hasher", + M.call_closure (| + H, + M.get_trait_method (| "core::clone::Clone", H, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "hasher" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (OUT_LEN : Value.t) (T H : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self OUT_LEN T H) + (* Instance *) [ ("clone", InstanceField.Method (clone OUT_LEN T H)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_T_where_core_clone_Clone_H_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_OUT_LEN_T_for_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_T_where_core_fmt_Debug_H_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_OUT_LEN_T_for_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + Definition Self (OUT_LEN : Value.t) (T H : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_challenger::hash_challenger::HashChallenger") [ OUT_LEN ] [ T; H ]. + + (* Debug *) + Definition fmt + (OUT_LEN : Value.t) + (T H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self OUT_LEN T H in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "HashChallenger" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "input_buffer" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "input_buffer" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "output_buffer" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "output_buffer" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "hasher" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "hasher" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (OUT_LEN : Value.t) (T H : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self OUT_LEN T H) + (* Instance *) [ ("fmt", InstanceField.Method (fmt OUT_LEN T H)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_T_where_core_fmt_Debug_H_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_OUT_LEN_T_for_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + + Module Impl_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + Definition Self (OUT_LEN : Value.t) (T H : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_challenger::hash_challenger::HashChallenger") [ OUT_LEN ] [ T; H ]. + + (* + pub const fn new(initial_state: Vec, hasher: H) -> Self { + Self { + input_buffer: initial_state, + output_buffer: vec![], + hasher, + } + } + *) + Definition new + (OUT_LEN : Value.t) + (T H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self OUT_LEN T H in + match ε, τ, α with + | [], [], [ initial_state; hasher ] => + ltac:(M.monadic + (let initial_state := M.alloc (| initial_state |) in + let hasher := M.alloc (| hasher |) in + Value.StructRecord + "p3_challenger::hash_challenger::HashChallenger" + [ + ("input_buffer", M.read (| initial_state |)); + ("output_buffer", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |)); + ("hasher", M.read (| hasher |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (OUT_LEN : Value.t) (T H : Ty.t), + M.IsAssociatedFunction.C (Self OUT_LEN T H) "new" (new OUT_LEN T H). + Admitted. + Global Typeclasses Opaque new. + + (* + fn flush(&mut self) { + let inputs = self.input_buffer.drain(..); + let output = self.hasher.hash_iter(inputs); + + self.output_buffer = output.to_vec(); + + // Chaining values. + self.input_buffer.extend(output.to_vec()); + } + *) + Definition flush + (OUT_LEN : Value.t) + (T H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self OUT_LEN T H in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ inputs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::drain::Drain") + [] + [ T; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::drain::Drain") + [] + [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + "drain", + [], + [ Ty.path "core::ops::range::RangeFull" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "input_buffer" + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) in + let~ output : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ OUT_LEN ] [ T ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ OUT_LEN ] [ T ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + H, + [], + [ T; Ty.apply (Ty.path "array") [ OUT_LEN ] [ T ] ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path "alloc::vec::drain::Drain") + [] + [ T; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "hasher" + |) + |); + M.read (| inputs |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "output_buffer" + |), + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "to_vec", + [], + [] + |), + [ (* Unsize *) M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, output |)) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + [], + [ T ], + "extend", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "input_buffer" + |) + |); + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "to_vec", + [], + [] + |), + [ (* Unsize *) M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, output |)) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_flush : + forall (OUT_LEN : Value.t) (T H : Ty.t), + M.IsAssociatedFunction.C (Self OUT_LEN T H) "flush" (flush OUT_LEN T H). + Admitted. + Global Typeclasses Opaque flush. + End Impl_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + + Module Impl_p3_challenger_CanObserve_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_OUT_LEN_T_T_for_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + Definition Self (OUT_LEN : Value.t) (T H : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_challenger::hash_challenger::HashChallenger") [ OUT_LEN ] [ T; H ]. + + (* + fn observe(&mut self, value: T) { + // Any buffered output is now invalid. + self.output_buffer.clear(); + + self.input_buffer.push(value); + } + *) + Definition observe + (OUT_LEN : Value.t) + (T H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self OUT_LEN T H in + match ε, τ, α with + | [], [], [ self; value ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let value := M.alloc (| value |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + "clear", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "output_buffer" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "input_buffer" + |) + |); + M.read (| value |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (OUT_LEN : Value.t) (T H : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self OUT_LEN T H) + (* Instance *) [ ("observe", InstanceField.Method (observe OUT_LEN T H)) ]. + End Impl_p3_challenger_CanObserve_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_OUT_LEN_T_T_for_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + + Module Impl_p3_challenger_CanObserve_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_OUT_LEN_T_array_N_T_for_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + Definition Self (N OUT_LEN : Value.t) (T H : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_challenger::hash_challenger::HashChallenger") [ OUT_LEN ] [ T; H ]. + + (* + fn observe(&mut self, values: [T; N]) { + for value in values { + self.observe(value); + } + } + *) + Definition observe + (N OUT_LEN : Value.t) + (T H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N OUT_LEN T H in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ T ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "array") [ N ] [ T ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ T ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ T ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.apply + (Ty.path + "p3_challenger::hash_challenger::HashChallenger") + [ OUT_LEN ] + [ T; H ], + [], + [ T ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.read (| value |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N OUT_LEN : Value.t) (T H : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ T ] ] + (Self N OUT_LEN T H) + (* Instance *) [ ("observe", InstanceField.Method (observe N OUT_LEN T H)) ]. + End Impl_p3_challenger_CanObserve_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_OUT_LEN_T_array_N_T_for_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + + Module Impl_p3_challenger_CanSample_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_OUT_LEN_T_T_for_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. + Definition Self (OUT_LEN : Value.t) (T H : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_challenger::hash_challenger::HashChallenger") [ OUT_LEN ] [ T; H ]. + + (* + fn sample(&mut self) -> T { + if self.output_buffer.is_empty() { + self.flush(); + } + self.output_buffer + .pop() + .expect("Output buffer should be non-empty") + } + *) + Definition sample + (OUT_LEN : Value.t) + (T H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self OUT_LEN T H in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "output_buffer" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ OUT_LEN ] + [ T; H ], + "flush", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + T, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ T ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + "pop", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::hash_challenger::HashChallenger", + "output_buffer" + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Output buffer should be non-empty" |) |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (OUT_LEN : Value.t) (T H : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSample" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self OUT_LEN T H) + (* Instance *) [ ("sample", InstanceField.Method (sample OUT_LEN T H)) ]. + End Impl_p3_challenger_CanSample_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_OUT_LEN_T_T_for_p3_challenger_hash_challenger_HashChallenger_OUT_LEN_T_H. +End hash_challenger. diff --git a/CoqOfRust/plonky3/challenger/src/lib.rs b/CoqOfRust/plonky3/challenger/src/lib.rs new file mode 100644 index 000000000..885b8d9b2 --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/lib.rs @@ -0,0 +1,125 @@ +//! Utilities for generating Fiat-Shamir challenges based on an IOP's transcript. + +#![no_std] + +extern crate alloc; + +mod duplex_challenger; +mod grinding_challenger; +mod hash_challenger; +mod multi_field_challenger; +mod serializing_challenger; + +use alloc::vec::Vec; +use core::array; + +pub use duplex_challenger::*; +pub use grinding_challenger::*; +pub use hash_challenger::*; +pub use multi_field_challenger::*; +use p3_field::{BasedVectorSpace, Field}; +pub use serializing_challenger::*; + +pub trait CanObserve { + fn observe(&mut self, value: T); + + fn observe_slice(&mut self, values: &[T]) + where + T: Clone, + { + for value in values { + self.observe(value.clone()); + } + } +} + +pub trait CanSample { + fn sample(&mut self) -> T; + + fn sample_array(&mut self) -> [T; N] { + array::from_fn(|_| self.sample()) + } + + fn sample_vec(&mut self, n: usize) -> Vec { + (0..n).map(|_| self.sample()).collect() + } +} + +pub trait CanSampleBits { + fn sample_bits(&mut self, bits: usize) -> T; +} + +pub trait FieldChallenger: + CanObserve + CanSample + CanSampleBits + Sync +{ + fn observe_algebra_element>(&mut self, alg_elem: A) { + self.observe_slice(alg_elem.as_basis_coefficients_slice()); + } + + fn sample_algebra_element>(&mut self) -> A { + A::from_basis_coefficients_fn(|_| self.sample()) + } +} + +impl CanObserve for &mut C +where + C: CanObserve, +{ + #[inline(always)] + fn observe(&mut self, value: T) { + (*self).observe(value) + } + + #[inline(always)] + fn observe_slice(&mut self, values: &[T]) + where + T: Clone, + { + (*self).observe_slice(values) + } +} + +impl CanSample for &mut C +where + C: CanSample, +{ + #[inline(always)] + fn sample(&mut self) -> T { + (*self).sample() + } + + #[inline(always)] + fn sample_array(&mut self) -> [T; N] { + (*self).sample_array() + } + + #[inline(always)] + fn sample_vec(&mut self, n: usize) -> Vec { + (*self).sample_vec(n) + } +} + +impl CanSampleBits for &mut C +where + C: CanSampleBits, +{ + #[inline(always)] + fn sample_bits(&mut self, bits: usize) -> T { + (*self).sample_bits(bits) + } +} + +impl FieldChallenger for &mut C +where + C: FieldChallenger, +{ + #[inline(always)] + fn observe_algebra_element>(&mut self, ext: EF) { + (*self).observe_algebra_element(ext) + } + + #[inline(always)] + fn sample_algebra_element>(&mut self) -> EF { + (*self).sample_algebra_element() + } +} diff --git a/CoqOfRust/plonky3/challenger/src/lib.v b/CoqOfRust/plonky3/challenger/src/lib.v new file mode 100644 index 000000000..3d4b1835c --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/lib.v @@ -0,0 +1,752 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +(* Trait *) +Module CanObserve. + Definition observe_slice + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ T ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Self, + [], + [ T ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.call_closure (| + T, + M.get_trait_method (| + "core::clone::Clone", + T, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_observe_slice : + forall (T : Ty.t), + M.IsProvidedMethod "p3_challenger::CanObserve" "observe_slice" (observe_slice T). +End CanObserve. + +(* Trait *) +Module CanSample. + Definition sample_array + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ N ], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ T ], + M.get_function (| + "core::array::from_fn", + [ N ], + [ T; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] T ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] T ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + T, + M.get_trait_method (| + "p3_challenger::CanSample", + Self, + [], + [ T ], + "sample", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_sample_array : + forall (T : Ty.t), + M.IsProvidedMethod "p3_challenger::CanSample" "sample_array" (sample_array T). + Definition sample_vec (T Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; n ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let n := M.alloc (| n |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] T + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] T + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ T; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] T ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", M.read (| n |)) ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] T ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + T, + M.get_trait_method (| + "p3_challenger::CanSample", + Self, + [], + [ T ], + "sample", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_sample_vec : + forall (T : Ty.t), + M.IsProvidedMethod "p3_challenger::CanSample" "sample_vec" (sample_vec T). +End CanSample. + +(* Trait *) +(* Empty module 'CanSampleBits' *) + +(* Trait *) +Module FieldChallenger. + Definition observe_algebra_element + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ A ], [ self; alg_elem ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let alg_elem := M.alloc (| alg_elem |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Self, + [], + [ F ], + "observe_slice", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + A, + [], + [ F ], + "as_basis_coefficients_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, alg_elem |) ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_observe_algebra_element : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_challenger::FieldChallenger" + "observe_algebra_element" + (observe_algebra_element F). + Definition sample_algebra_element + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ A ], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + A, + [], + [ F ], + "from_basis_coefficients_fn", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + F, + M.get_trait_method (| + "p3_challenger::CanSample", + Self, + [], + [ F ], + "sample", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_sample_algebra_element : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_challenger::FieldChallenger" + "sample_algebra_element" + (sample_algebra_element F). +End FieldChallenger. + +Module Impl_p3_challenger_CanObserve_where_p3_challenger_CanObserve_C_T_T_for_ref_mut_C. + Definition Self (C T : Ty.t) : Ty.t := Ty.apply (Ty.path "&mut") [] [ C ]. + + (* + fn observe(&mut self, value: T) { + ( *self).observe(value) + } + *) + Definition observe (C T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self C T in + match ε, τ, α with + | [], [], [ self; value ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let value := M.alloc (| value |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| "p3_challenger::CanObserve", C, [], [ T ], "observe", [], [] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.read (| value |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn observe_slice(&mut self, values: &[T]) + where + T: Clone, + { + ( *self).observe_slice(values) + } + *) + Definition observe_slice (C T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self C T in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + C, + [], + [ T ], + "observe_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| values |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (C T : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self C T) + (* Instance *) + [ + ("observe", InstanceField.Method (observe C T)); + ("observe_slice", InstanceField.Method (observe_slice C T)) + ]. +End Impl_p3_challenger_CanObserve_where_p3_challenger_CanObserve_C_T_T_for_ref_mut_C. + +Module Impl_p3_challenger_CanSample_where_p3_challenger_CanSample_C_T_T_for_ref_mut_C. + Definition Self (C T : Ty.t) : Ty.t := Ty.apply (Ty.path "&mut") [] [ C ]. + + (* + fn sample(&mut self) -> T { + ( *self).sample() + } + *) + Definition sample (C T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self C T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + T, + M.get_trait_method (| "p3_challenger::CanSample", C, [], [ T ], "sample", [], [] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn sample_array(&mut self) -> [T; N] { + ( *self).sample_array() + } + *) + Definition sample_array (C T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self C T in + match ε, τ, α with + | [ N ], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ T ], + M.get_trait_method (| + "p3_challenger::CanSample", + C, + [], + [ T ], + "sample_array", + [ N ], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn sample_vec(&mut self, n: usize) -> Vec { + ( *self).sample_vec(n) + } + *) + Definition sample_vec (C T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self C T in + match ε, τ, α with + | [], [], [ self; n ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let n := M.alloc (| n |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| "p3_challenger::CanSample", C, [], [ T ], "sample_vec", [], [] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.read (| n |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (C T : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSample" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self C T) + (* Instance *) + [ + ("sample", InstanceField.Method (sample C T)); + ("sample_array", InstanceField.Method (sample_array C T)); + ("sample_vec", InstanceField.Method (sample_vec C T)) + ]. +End Impl_p3_challenger_CanSample_where_p3_challenger_CanSample_C_T_T_for_ref_mut_C. + +Module Impl_p3_challenger_CanSampleBits_where_p3_challenger_CanSampleBits_C_T_T_for_ref_mut_C. + Definition Self (C T : Ty.t) : Ty.t := Ty.apply (Ty.path "&mut") [] [ C ]. + + (* + fn sample_bits(&mut self, bits: usize) -> T { + ( *self).sample_bits(bits) + } + *) + Definition sample_bits (C T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self C T in + match ε, τ, α with + | [], [], [ self; bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bits := M.alloc (| bits |) in + M.call_closure (| + T, + M.get_trait_method (| + "p3_challenger::CanSampleBits", + C, + [], + [ T ], + "sample_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.read (| bits |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (C T : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSampleBits" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self C T) + (* Instance *) [ ("sample_bits", InstanceField.Method (sample_bits C T)) ]. +End Impl_p3_challenger_CanSampleBits_where_p3_challenger_CanSampleBits_C_T_T_for_ref_mut_C. + +Module Impl_p3_challenger_FieldChallenger_where_p3_field_field_Field_F_where_p3_challenger_FieldChallenger_C_F_F_for_ref_mut_C. + Definition Self (C F : Ty.t) : Ty.t := Ty.apply (Ty.path "&mut") [] [ C ]. + + (* + fn observe_algebra_element>(&mut self, ext: EF) { + ( *self).observe_algebra_element(ext) + } + *) + Definition observe_algebra_element + (C F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self C F in + match ε, τ, α with + | [], [ EF ], [ self; ext ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let ext := M.alloc (| ext |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::FieldChallenger", + C, + [], + [ F ], + "observe_algebra_element", + [], + [ EF ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.read (| ext |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn sample_algebra_element>(&mut self) -> EF { + ( *self).sample_algebra_element() + } + *) + Definition sample_algebra_element + (C F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self C F in + match ε, τ, α with + | [], [ EF ], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + EF, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + C, + [], + [ F ], + "sample_algebra_element", + [], + [ EF ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (C F : Ty.t), + M.IsTraitInstance + "p3_challenger::FieldChallenger" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self C F) + (* Instance *) + [ + ("observe_algebra_element", InstanceField.Method (observe_algebra_element C F)); + ("sample_algebra_element", InstanceField.Method (sample_algebra_element C F)) + ]. +End Impl_p3_challenger_FieldChallenger_where_p3_field_field_Field_F_where_p3_challenger_FieldChallenger_C_F_F_for_ref_mut_C. diff --git a/CoqOfRust/plonky3/challenger/src/multi_field_challenger.rs b/CoqOfRust/plonky3/challenger/src/multi_field_challenger.rs new file mode 100644 index 000000000..e86f6981f --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/multi_field_challenger.rs @@ -0,0 +1,191 @@ +use alloc::string::String; +use alloc::vec; +use alloc::vec::Vec; + +use p3_field::{BasedVectorSpace, Field, PrimeField, PrimeField32, reduce_32, split_32}; +use p3_symmetric::{CryptographicPermutation, Hash}; + +use crate::{CanObserve, CanSample, CanSampleBits, FieldChallenger}; + +/// A challenger that operates natively on PF but produces challenges of F: PrimeField32. +/// +/// Used for optimizing the cost of recursive proof verification of STARKs in SNARKs. +/// +/// SAFETY: There are some bias complications with using this challenger. In particular, +/// samples are actually random in [0, 2^64) and then reduced to be in F. +#[derive(Clone, Debug)] +pub struct MultiField32Challenger +where + F: PrimeField32, + PF: Field, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + sponge_state: [PF; WIDTH], + input_buffer: Vec, + output_buffer: Vec, + permutation: P, + num_f_elms: usize, +} + +impl MultiField32Challenger +where + F: PrimeField32, + PF: Field, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + pub fn new(permutation: P) -> Result { + if F::order() >= PF::order() { + return Err(String::from("F::order() must be less than PF::order()")); + } + let num_f_elms = PF::bits() / 64; + Ok(Self { + sponge_state: [PF::default(); WIDTH], + input_buffer: vec![], + output_buffer: vec![], + permutation, + num_f_elms, + }) + } +} + +impl MultiField32Challenger +where + F: PrimeField32, + PF: PrimeField, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + fn duplexing(&mut self) { + assert!(self.input_buffer.len() <= self.num_f_elms * RATE); + + for (i, f_chunk) in self.input_buffer.chunks(self.num_f_elms).enumerate() { + self.sponge_state[i] = reduce_32(f_chunk); + } + self.input_buffer.clear(); + + // Apply the permutation. + self.permutation.permute_mut(&mut self.sponge_state); + + self.output_buffer.clear(); + for &pf_val in &self.sponge_state { + let f_vals = split_32(pf_val, self.num_f_elms); + for f_val in f_vals { + self.output_buffer.push(f_val); + } + } + } +} + +impl FieldChallenger + for MultiField32Challenger +where + F: PrimeField32, + PF: PrimeField, + P: CryptographicPermutation<[PF; WIDTH]>, +{ +} + +impl CanObserve + for MultiField32Challenger +where + F: PrimeField32, + PF: PrimeField, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + fn observe(&mut self, value: F) { + // Any buffered output is now invalid. + self.output_buffer.clear(); + + self.input_buffer.push(value); + + if self.input_buffer.len() == self.num_f_elms * RATE { + self.duplexing(); + } + } +} + +impl CanObserve<[F; N]> + for MultiField32Challenger +where + F: PrimeField32, + PF: PrimeField, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + fn observe(&mut self, values: [F; N]) { + for value in values { + self.observe(value); + } + } +} + +impl CanObserve> + for MultiField32Challenger +where + F: PrimeField32, + PF: PrimeField, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + fn observe(&mut self, values: Hash) { + for pf_val in values { + let f_vals: Vec = split_32(pf_val, self.num_f_elms); + for f_val in f_vals { + self.observe(f_val); + } + } + } +} + +// for TrivialPcs +impl CanObserve>> + for MultiField32Challenger +where + F: PrimeField32, + PF: PrimeField, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + fn observe(&mut self, valuess: Vec>) { + for values in valuess { + for value in values { + self.observe(value); + } + } + } +} + +impl CanSample + for MultiField32Challenger +where + F: PrimeField32, + EF: BasedVectorSpace, + PF: PrimeField, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + fn sample(&mut self) -> EF { + EF::from_basis_coefficients_fn(|_| { + // If we have buffered inputs, we must perform a duplexing so that the challenge will + // reflect them. Or if we've run out of outputs, we must perform a duplexing to get more. + if !self.input_buffer.is_empty() || self.output_buffer.is_empty() { + self.duplexing(); + } + + self.output_buffer + .pop() + .expect("Output buffer should be non-empty") + }) + } +} + +impl CanSampleBits + for MultiField32Challenger +where + F: PrimeField32, + PF: PrimeField, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + fn sample_bits(&mut self, bits: usize) -> usize { + assert!(bits < (usize::BITS as usize)); + assert!((1 << bits) < F::ORDER_U32); + let rand_f: F = self.sample(); + let rand_usize = rand_f.as_canonical_u32() as usize; + rand_usize & ((1 << bits) - 1) + } +} diff --git a/CoqOfRust/plonky3/challenger/src/multi_field_challenger.v b/CoqOfRust/plonky3/challenger/src/multi_field_challenger.v new file mode 100644 index 000000000..2b2f9f2a8 --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/multi_field_challenger.v @@ -0,0 +1,2482 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module multi_field_challenger. + (* StructRecord + { + name := "MultiField32Challenger"; + const_params := [ "WIDTH"; "RATE" ]; + ty_params := [ "F"; "PF"; "P" ]; + fields := + [ + ("sponge_state", Ty.apply (Ty.path "array") [ WIDTH ] [ PF ]); + ("input_buffer", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]); + ("output_buffer", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]); + ("permutation", P); + ("num_f_elms", Ty.path "usize") + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_PF_where_core_clone_Clone_P_where_p3_field_field_PrimeField32_F_where_p3_field_field_Field_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + (* Clone *) + Definition clone + (WIDTH RATE : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F PF P in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_challenger::multi_field_challenger::MultiField32Challenger" + [ + ("sponge_state", + M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ PF ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ WIDTH ] [ PF ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "sponge_state" + |) + |) + |) + |) + ] + |)); + ("input_buffer", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "input_buffer" + |) + |) + |) + |) + ] + |)); + ("output_buffer", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "output_buffer" + |) + |) + |) + |) + ] + |)); + ("permutation", + M.call_closure (| + P, + M.get_trait_method (| "core::clone::Clone", P, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "permutation" + |) + |) + |) + |) + ] + |)); + ("num_f_elms", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "num_f_elms" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE F PF P) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH RATE F PF P)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_PF_where_core_clone_Clone_P_where_p3_field_field_PrimeField32_F_where_p3_field_field_Field_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_PF_where_core_fmt_Debug_P_where_p3_field_field_PrimeField32_F_where_p3_field_field_Field_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + (* Debug *) + Definition fmt + (WIDTH RATE : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F PF P in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field5_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "MultiField32Challenger" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "sponge_state" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "sponge_state" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "input_buffer" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "input_buffer" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "output_buffer" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "output_buffer" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "permutation" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "permutation" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "num_f_elms" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "num_f_elms" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE F PF P) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH RATE F PF P)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_PF_where_core_fmt_Debug_P_where_p3_field_field_PrimeField32_F_where_p3_field_field_Field_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + + Module Impl_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + (* + pub fn new(permutation: P) -> Result { + if F::order() >= PF::order() { + return Err(String::from("F::order() must be less than PF::order()")); + } + let num_f_elms = PF::bits() / 64; + Ok(Self { + sponge_state: [PF::default(); WIDTH], + input_buffer: vec![], + output_buffer: vec![], + permutation, + num_f_elms, + }) + } + *) + Definition new + (WIDTH RATE : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F PF P in + match ε, τ, α with + | [], [], [ permutation ] => + ltac:(M.monadic + (let permutation := M.alloc (| permutation |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]; + Ty.path "alloc::string::String" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "num_bigint::biguint::BigUint", + [], + [ Ty.path "num_bigint::biguint::BigUint" ], + "ge", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "order", + [], + [] + |), + [] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "p3_field::field::Field", + PF, + [], + [], + "order", + [], + [] + |), + [] + |) + |) + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "core::convert::From", + Ty.path "alloc::string::String", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + "from", + [], + [] + |), + [ mk_str (| "F::order() must be less than PF::order()" |) ] + |) + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ num_f_elms : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_field::field::Field", + PF, + [], + [], + "bits", + [], + [] + |), + [] + |); + Value.Integer IntegerKind.Usize 64 + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructRecord + "p3_challenger::multi_field_challenger::MultiField32Challenger" + [ + ("sponge_state", + repeat (| + M.call_closure (| + PF, + M.get_trait_method (| + "core::default::Default", + PF, + [], + [], + "default", + [], + [] + |), + [] + |), + WIDTH + |)); + ("input_buffer", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |)); + ("output_buffer", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |)); + ("permutation", M.read (| permutation |)); + ("num_f_elms", M.read (| num_f_elms |)) + ] + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH RATE F PF P) "new" (new WIDTH RATE F PF P). + Admitted. + Global Typeclasses Opaque new. + (* + fn duplexing(&mut self) { + assert!(self.input_buffer.len() <= self.num_f_elms * RATE); + + for (i, f_chunk) in self.input_buffer.chunks(self.num_f_elms).enumerate() { + self.sponge_state[i] = reduce_32(f_chunk); + } + self.input_buffer.clear(); + + // Apply the permutation. + self.permutation.permute_mut(&mut self.sponge_state); + + self.output_buffer.clear(); + for &pf_val in &self.sponge_state { + let f_vals = split_32(pf_val, self.num_f_elms); + for f_val in f_vals { + self.output_buffer.push(f_val); + } + } + } + *) + Definition duplexing + (WIDTH RATE : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F PF P in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "input_buffer" + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "num_f_elms" + |) + |); + RATE + ] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: self.input_buffer.len() <= self.num_f_elms * RATE" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "chunks", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "input_buffer" + |) + |) + ] + |) + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "num_f_elms" + |) + |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ] ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let i := M.copy (| γ1_0 |) in + let f_chunk := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "sponge_state" + |), + M.read (| i |) + |), + M.call_closure (| + PF, + M.get_function (| + "p3_field::helpers::reduce_32", + [], + [ F; PF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| f_chunk |) |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "clear", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "input_buffer" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + P, + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ PF ] ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "permutation" + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "sponge_state" + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "clear", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "output_buffer" + |) + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ PF ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ PF ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "sponge_state" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ PF ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ PF ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let pf_val := M.copy (| γ0_0 |) in + let~ f_vals : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_field::helpers::split_32", + [], + [ PF; F ] + |), + [ + M.read (| pf_val |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "num_f_elms" + |) + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| f_vals |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let f_val := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "output_buffer" + |) + |); + M.read (| f_val |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_duplexing : + forall (WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH RATE F PF P) "duplexing" (duplexing WIDTH RATE F PF P). + Admitted. + Global Typeclasses Opaque duplexing. + End Impl_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + + + Module Impl_p3_challenger_FieldChallenger_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_F_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "p3_challenger::FieldChallenger" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self WIDTH RATE F PF P) + (* Instance *) []. + End Impl_p3_challenger_FieldChallenger_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_F_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + + Module Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_F_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + (* + fn observe(&mut self, value: F) { + // Any buffered output is now invalid. + self.output_buffer.clear(); + + self.input_buffer.push(value); + + if self.input_buffer.len() == self.num_f_elms * RATE { + self.duplexing(); + } + } + *) + Definition observe + (WIDTH RATE : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F PF P in + match ε, τ, α with + | [], [], [ self; value ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let value := M.alloc (| value |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "clear", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "output_buffer" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "input_buffer" + |) + |); + M.read (| value |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "input_buffer" + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "num_f_elms" + |) + |); + RATE + ] + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ], + "duplexing", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self WIDTH RATE F PF P) + (* Instance *) [ ("observe", InstanceField.Method (observe WIDTH RATE F PF P)) ]. + End Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_F_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + + Module Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_array_N_F_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (N WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + (* + fn observe(&mut self, values: [F; N]) { + for value in values { + self.observe(value); + } + } + *) + Definition observe + (N WIDTH RATE : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N WIDTH RATE F PF P in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.apply + (Ty.path + "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ], + [], + [ F ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.read (| value |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ F ] ] + (Self N WIDTH RATE F PF P) + (* Instance *) [ ("observe", InstanceField.Method (observe N WIDTH RATE F PF P)) ]. + End Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_array_N_F_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + + Module Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_p3_symmetric_hash_Hash_N_F_PF_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (N WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + (* + fn observe(&mut self, values: Hash) { + for pf_val in values { + let f_vals: Vec = split_32(pf_val, self.num_f_elms); + for f_val in f_vals { + self.observe(f_val); + } + } + } + *) + Definition observe + (N WIDTH RATE : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N WIDTH RATE F PF P in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ PF ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; PF ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ PF ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ PF ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let pf_val := M.copy (| γ0_0 |) in + let~ f_vals : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_field::helpers::split_32", + [], + [ PF; F ] + |), + [ + M.read (| pf_val |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "num_f_elms" + |) + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| f_vals |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let f_val := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.apply + (Ty.path + "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ], + [], + [ F ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| self |) + |) + |); + M.read (| f_val |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; PF ] ] + (Self N WIDTH RATE F PF P) + (* Instance *) [ ("observe", InstanceField.Method (observe N WIDTH RATE F PF P)) ]. + End Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_p3_symmetric_hash_Hash_N_F_PF_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + + Module Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_alloc_vec_Vec_alloc_vec_Vec_F_alloc_alloc_Global_alloc_alloc_Global_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + (* + fn observe(&mut self, valuess: Vec>) { + for values in valuess { + for value in values { + self.observe(value); + } + } + } + *) + Definition observe + (WIDTH RATE : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F PF P in + match ε, τ, α with + | [], [], [ self; valuess ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let valuess := M.alloc (| valuess |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| valuess |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let values := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.apply + (Ty.path + "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ], + [], + [ F ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| self |) + |) + |); + M.read (| value |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + (Self WIDTH RATE F PF P) + (* Instance *) [ ("observe", InstanceField.Method (observe WIDTH RATE F PF P)) ]. + End Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_alloc_vec_Vec_alloc_vec_Vec_F_alloc_alloc_Global_alloc_alloc_Global_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + + Module Impl_p3_challenger_CanSample_where_p3_field_field_PrimeField32_F_where_p3_field_field_BasedVectorSpace_EF_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_EF_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (WIDTH RATE : Value.t) (F EF PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + (* + fn sample(&mut self) -> EF { + EF::from_basis_coefficients_fn(|_| { + // If we have buffered inputs, we must perform a duplexing so that the challenge will + // reflect them. Or if we've run out of outputs, we must perform a duplexing to get more. + if !self.input_buffer.is_empty() || self.output_buffer.is_empty() { + self.duplexing(); + } + + self.output_buffer + .pop() + .expect("Output buffer should be non-empty") + }) + } + *) + Definition sample + (WIDTH RATE : Value.t) + (F EF PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F EF PF P in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + EF, + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + EF, + [], + [ F ], + "from_basis_coefficients_fn", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "input_buffer" + |) + |) + ] + |) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "output_buffer" + |) + |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ], + "duplexing", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "pop", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::multi_field_challenger::MultiField32Challenger", + "output_buffer" + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| "Output buffer should be non-empty" |) + |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F EF PF P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSample" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ EF ] + (Self WIDTH RATE F EF PF P) + (* Instance *) [ ("sample", InstanceField.Method (sample WIDTH RATE F EF PF P)) ]. + End Impl_p3_challenger_CanSample_where_p3_field_field_PrimeField32_F_where_p3_field_field_BasedVectorSpace_EF_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_EF_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + + Module Impl_p3_challenger_CanSampleBits_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_usize_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. + Definition Self (WIDTH RATE : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ]. + + (* + fn sample_bits(&mut self, bits: usize) -> usize { + assert!(bits < (usize::BITS as usize)); + assert!((1 << bits) < F::ORDER_U32); + let rand_f: F = self.sample(); + let rand_usize = rand_f.as_canonical_u32() as usize; + rand_usize & ((1 << bits) - 1) + } + *) + Definition sample_bits + (WIDTH RATE : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE F PF P in + match ε, τ, α with + | [], [], [ self; bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| bits |); + M.cast + (Ty.path "usize") + (M.read (| + get_associated_constant (| + Ty.path "usize", + "BITS", + Ty.path "u32" + |) + |)) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits < (usize::BITS as usize)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U32 1; M.read (| bits |) ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: (1 << bits) < F::ORDER_U32" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ rand_f : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_challenger::CanSample", + Ty.apply + (Ty.path "p3_challenger::multi_field_challenger::MultiField32Challenger") + [ WIDTH; RATE ] + [ F; PF; P ], + [], + [ F ], + "sample", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ rand_usize : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + F, + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rand_f |) ] + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ + M.read (| rand_usize |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| bits |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSampleBits" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + (Self WIDTH RATE F PF P) + (* Instance *) [ ("sample_bits", InstanceField.Method (sample_bits WIDTH RATE F PF P)) ]. + End Impl_p3_challenger_CanSampleBits_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_usize_for_p3_challenger_multi_field_challenger_MultiField32Challenger_WIDTH_RATE_F_PF_P. +End multi_field_challenger. diff --git a/CoqOfRust/plonky3/challenger/src/serializing_challenger.rs b/CoqOfRust/plonky3/challenger/src/serializing_challenger.rs new file mode 100644 index 000000000..f9c173410 --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/serializing_challenger.rs @@ -0,0 +1,277 @@ +use alloc::vec::Vec; +use core::marker::PhantomData; + +use p3_field::{BasedVectorSpace, PrimeField32, PrimeField64}; +use p3_maybe_rayon::prelude::*; +use p3_symmetric::{CryptographicHasher, Hash}; +use p3_util::log2_ceil_u64; +use tracing::instrument; + +use crate::{ + CanObserve, CanSample, CanSampleBits, FieldChallenger, GrindingChallenger, HashChallenger, +}; + +/// Given a challenger that can observe and sample bytes, produces a challenger that is able to +/// sample and observe field elements of a `PrimeField32`. +/// +/// **Observing**: +/// - Takes a field element will serialize it into a byte array and observe each byte. +/// +/// **Sampling**: +/// - Samples a field element in a prime field of size `p` by sampling uniformly an element in the +/// range (0..1 << log_2(p)). This avoids modulo bias. +#[derive(Clone, Debug)] +pub struct SerializingChallenger32 { + inner: Inner, + _marker: PhantomData, +} + +/// Given a challenger that can observe and sample bytes, produces a challenger that is able to +/// sample and observe field elements of a `PrimeField64` field. +/// +/// **Observing**: +/// - Takes a field element will serialize it into a byte array and observe each byte. +/// +/// **Sampling**: +/// - Samples a field element in a prime field of size `p` by sampling uniformly an element in the +/// range (0..1 << log_2(p)). This avoids modulo bias. +#[derive(Clone, Debug)] +pub struct SerializingChallenger64 { + inner: Inner, + _marker: PhantomData, +} + +impl> SerializingChallenger32 { + pub const fn new(inner: Inner) -> Self { + Self { + inner, + _marker: PhantomData, + } + } +} + +impl SerializingChallenger32> +where + F: PrimeField32, + H: CryptographicHasher, +{ + pub const fn from_hasher(initial_state: Vec, hasher: H) -> Self { + Self::new(HashChallenger::new(initial_state, hasher)) + } +} + +impl> CanObserve for SerializingChallenger32 { + fn observe(&mut self, value: F) { + self.inner + .observe_slice(&value.to_unique_u32().to_le_bytes()); + } +} + +impl> CanObserve> + for SerializingChallenger32 +{ + fn observe(&mut self, values: Hash) { + for value in values { + self.inner.observe(value); + } + } +} + +impl> CanObserve> + for SerializingChallenger32 +{ + fn observe(&mut self, values: Hash) { + for value in values { + self.inner.observe_slice(&value.to_le_bytes()); + } + } +} + +impl CanSample for SerializingChallenger32 +where + F: PrimeField32, + EF: BasedVectorSpace, + Inner: CanSample, +{ + fn sample(&mut self) -> EF { + let modulus = F::ORDER_U32; + let log_size = log2_ceil_u64(F::ORDER_U64); + // We use u64 to avoid overflow in the case that log_size = 32. + let pow_of_two_bound = ((1u64 << log_size) - 1) as u32; + // Perform rejection sampling over the uniform range (0..log2_ceil(p)) + let sample_base = |inner: &mut Inner| loop { + let value = u32::from_le_bytes(inner.sample_array()); + let value = value & pow_of_two_bound; + if value < modulus { + return unsafe { + // This is safe as value < F::ORDER_U32. + F::from_canonical_unchecked(value) + }; + } + }; + EF::from_basis_coefficients_fn(|_| sample_base(&mut self.inner)) + } +} + +impl CanSampleBits for SerializingChallenger32 +where + F: PrimeField32, + Inner: CanSample, +{ + fn sample_bits(&mut self, bits: usize) -> usize { + assert!(bits < (usize::BITS as usize)); + // Limiting the number of bits to the field size + assert!((1 << bits) <= F::ORDER_U64 as usize); + let rand_usize = u32::from_le_bytes(self.inner.sample_array()) as usize; + rand_usize & ((1 << bits) - 1) + } +} + +impl GrindingChallenger for SerializingChallenger32 +where + F: PrimeField32, + Inner: CanSample + CanObserve + Clone + Send + Sync, +{ + type Witness = F; + + #[instrument(name = "grind for proof-of-work witness", skip_all)] + fn grind(&mut self, bits: usize) -> Self::Witness { + assert!(bits < (usize::BITS as usize)); + assert!((1 << bits) < F::ORDER_U32); + let witness = (0..F::ORDER_U32) + .into_par_iter() + .map(|i| unsafe { + // i < F::ORDER_U32 by construction so this is safe. + F::from_canonical_unchecked(i) + }) + .find_any(|witness| self.clone().check_witness(bits, *witness)) + .expect("failed to find witness"); + assert!(self.check_witness(bits, witness)); + witness + } +} + +impl FieldChallenger for SerializingChallenger32 +where + F: PrimeField32, + Inner: CanSample + CanObserve + Clone + Send + Sync, +{ +} + +impl> SerializingChallenger64 { + pub const fn new(inner: Inner) -> Self { + Self { + inner, + _marker: PhantomData, + } + } +} + +impl SerializingChallenger64> +where + F: PrimeField64, + H: CryptographicHasher, +{ + pub const fn from_hasher(initial_state: Vec, hasher: H) -> Self { + Self::new(HashChallenger::new(initial_state, hasher)) + } +} + +impl> CanObserve for SerializingChallenger64 { + fn observe(&mut self, value: F) { + self.inner + .observe_slice(&value.to_unique_u64().to_le_bytes()); + } +} + +impl> CanObserve> + for SerializingChallenger64 +{ + fn observe(&mut self, values: Hash) { + for value in values { + self.inner.observe(value); + } + } +} + +impl> CanObserve> + for SerializingChallenger64 +{ + fn observe(&mut self, values: Hash) { + for value in values { + self.inner.observe_slice(&value.to_le_bytes()); + } + } +} + +impl CanSample for SerializingChallenger64 +where + F: PrimeField64, + EF: BasedVectorSpace, + Inner: CanSample, +{ + fn sample(&mut self) -> EF { + let modulus = F::ORDER_U64; + let log_size = log2_ceil_u64(F::ORDER_U64) as u32; + // We use u128 to avoid overflow in the case that log_size = 64. + let pow_of_two_bound = ((1u128 << log_size) - 1) as u64; + + // Perform rejection sampling over the uniform range (0..log2_ceil(p)) + let sample_base = |inner: &mut Inner| loop { + let value = u64::from_le_bytes(inner.sample_array()); + let value = value & pow_of_two_bound; + if value < modulus { + return unsafe { + // This is safe as value < F::ORDER_U64. + F::from_canonical_unchecked(value) + }; + } + }; + EF::from_basis_coefficients_fn(|_| sample_base(&mut self.inner)) + } +} + +impl CanSampleBits for SerializingChallenger64 +where + F: PrimeField64, + Inner: CanSample, +{ + fn sample_bits(&mut self, bits: usize) -> usize { + assert!(bits < (usize::BITS as usize)); + // Limiting the number of bits to the field size + assert!((1 << bits) <= F::ORDER_U64 as usize); + let rand_usize = u64::from_le_bytes(self.inner.sample_array()) as usize; + rand_usize & ((1 << bits) - 1) + } +} + +impl GrindingChallenger for SerializingChallenger64 +where + F: PrimeField64, + Inner: CanSample + CanObserve + Clone + Send + Sync, +{ + type Witness = F; + + #[instrument(name = "grind for proof-of-work witness", skip_all)] + fn grind(&mut self, bits: usize) -> Self::Witness { + assert!(bits < (usize::BITS as usize)); + assert!((1 << bits) < F::ORDER_U64); + let witness = (0..F::ORDER_U64) + .into_par_iter() + .map(|i| unsafe { + // i < F::ORDER_U64 by construction so this is safe. + F::from_canonical_unchecked(i) + }) + .find_any(|witness| self.clone().check_witness(bits, *witness)) + .expect("failed to find witness"); + assert!(self.check_witness(bits, witness)); + witness + } +} + +impl FieldChallenger for SerializingChallenger64 +where + F: PrimeField64, + Inner: CanSample + CanObserve + Clone + Send + Sync, +{ +} diff --git a/CoqOfRust/plonky3/challenger/src/serializing_challenger.v b/CoqOfRust/plonky3/challenger/src/serializing_challenger.v new file mode 100644 index 000000000..459e58b64 --- /dev/null +++ b/CoqOfRust/plonky3/challenger/src/serializing_challenger.v @@ -0,0 +1,4363 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module serializing_challenger. + (* StructRecord + { + name := "SerializingChallenger32"; + const_params := []; + ty_params := [ "F"; "Inner" ]; + fields := + [ ("inner", Inner); ("_marker", Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ]) ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]. + + (* Clone *) + Definition clone (F Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_challenger::serializing_challenger::SerializingChallenger32" + [ + ("inner", + M.call_closure (| + Inner, + M.get_trait_method (| "core::clone::Clone", Inner, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger32", + "inner" + |) + |) + |) + |) + ] + |)); + ("_marker", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger32", + "_marker" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F Inner) + (* Instance *) [ ("clone", InstanceField.Method (clone F Inner)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]. + + (* Debug *) + Definition fmt (F Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "SerializingChallenger32" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inner" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger32", + "inner" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_marker" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger32", + "_marker" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F Inner) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F Inner)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + + (* StructRecord + { + name := "SerializingChallenger64"; + const_params := []; + ty_params := [ "F"; "Inner" ]; + fields := + [ ("inner", Inner); ("_marker", Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ]) ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]. + + (* Clone *) + Definition clone (F Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_challenger::serializing_challenger::SerializingChallenger64" + [ + ("inner", + M.call_closure (| + Inner, + M.get_trait_method (| "core::clone::Clone", Inner, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger64", + "inner" + |) + |) + |) + |) + ] + |)); + ("_marker", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger64", + "_marker" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F Inner) + (* Instance *) [ ("clone", InstanceField.Method (clone F Inner)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]. + + (* Debug *) + Definition fmt (F Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "SerializingChallenger64" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inner" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger64", + "inner" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_marker" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger64", + "_marker" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F Inner) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F Inner)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + + Module Impl_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]. + + (* + pub const fn new(inner: Inner) -> Self { + Self { + inner, + _marker: PhantomData, + } + } + *) + Definition new (F Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ inner ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + Value.StructRecord + "p3_challenger::serializing_challenger::SerializingChallenger32" + [ + ("inner", M.read (| inner |)); + ("_marker", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (F Inner : Ty.t), + M.IsAssociatedFunction.C (Self F Inner) "new" (new F Inner). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + + Module Impl_p3_challenger_serializing_challenger_SerializingChallenger32_F_p3_challenger_hash_challenger_HashChallenger_Usize_32_u8_H. + Definition Self (F H : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; H ] + ]. + + (* + pub const fn from_hasher(initial_state: Vec, hasher: H) -> Self { + Self::new(HashChallenger::new(initial_state, hasher)) + } + *) + Definition from_hasher (F H : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F H in + match ε, τ, α with + | [], [], [ initial_state; hasher ] => + ltac:(M.monadic + (let initial_state := M.alloc (| initial_state |) in + let hasher := M.alloc (| hasher |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; H ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; H ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; H ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; H ], + "new", + [], + [] + |), + [ M.read (| initial_state |); M.read (| hasher |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_hasher : + forall (F H : Ty.t), + M.IsAssociatedFunction.C (Self F H) "from_hasher" (from_hasher F H). + Admitted. + Global Typeclasses Opaque from_hasher. + End Impl_p3_challenger_serializing_challenger_SerializingChallenger32_F_p3_challenger_hash_challenger_HashChallenger_Usize_32_u8_H. + + Module Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanObserve_Inner_u8_F_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]. + + (* + fn observe(&mut self, value: F) { + self.inner + .observe_slice(&value.to_unique_u32().to_le_bytes()); + } + *) + Definition observe (F Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ self; value ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let value := M.alloc (| value |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Inner, + [], + [ Ty.path "u8" ], + "observe_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger32", + "inner" + |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "u32", + "to_le_bytes", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + F, + [], + [], + "to_unique_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ] + |) + |) + |) + |) + |)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F Inner) + (* Instance *) [ ("observe", InstanceField.Method (observe F Inner)) ]. + End Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanObserve_Inner_u8_F_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + + Module Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanObserve_Inner_u8_p3_symmetric_hash_Hash_N_F_u8_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + Definition Self (N : Value.t) (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]. + + (* + fn observe(&mut self, values: Hash) { + for value in values { + self.inner.observe(value); + } + } + *) + Definition observe + (N : Value.t) + (F Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F Inner in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ Ty.path "u8" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; Ty.path "u8" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u8" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ N ] + [ Ty.path "u8" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Inner, + [], + [ Ty.path "u8" ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger32", + "inner" + |) + |); + M.read (| value |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; Ty.path "u8" ] ] + (Self N F Inner) + (* Instance *) [ ("observe", InstanceField.Method (observe N F Inner)) ]. + End Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanObserve_Inner_u8_p3_symmetric_hash_Hash_N_F_u8_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + + Module Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanObserve_Inner_u8_p3_symmetric_hash_Hash_N_F_u64_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + Definition Self (N : Value.t) (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]. + + (* + fn observe(&mut self, values: Hash) { + for value in values { + self.inner.observe_slice(&value.to_le_bytes()); + } + } + *) + Definition observe + (N : Value.t) + (F Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F Inner in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ Ty.path "u64" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; Ty.path "u64" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u64" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ N ] + [ Ty.path "u64" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Inner, + [], + [ Ty.path "u8" ], + "observe_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger32", + "inner" + |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "u64", + "to_le_bytes", + [], + [] + |), + [ M.read (| value |) ] + |) + |) + |) + |) + |)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; Ty.path "u64" ] ] + (Self N F Inner) + (* Instance *) [ ("observe", InstanceField.Method (observe N F Inner)) ]. + End Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanObserve_Inner_u8_p3_symmetric_hash_Hash_N_F_u64_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + + Module Impl_p3_challenger_CanSample_where_p3_field_field_PrimeField32_F_where_p3_field_field_BasedVectorSpace_EF_F_where_p3_challenger_CanSample_Inner_u8_EF_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + Definition Self (F EF Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]. + + (* + fn sample(&mut self) -> EF { + let modulus = F::ORDER_U32; + let log_size = log2_ceil_u64(F::ORDER_U64); + // We use u64 to avoid overflow in the case that log_size = 32. + let pow_of_two_bound = ((1u64 << log_size) - 1) as u32; + // Perform rejection sampling over the uniform range (0..log2_ceil(p)) + let sample_base = |inner: &mut Inner| loop { + let value = u32::from_le_bytes(inner.sample_array()); + let value = value & pow_of_two_bound; + if value < modulus { + return unsafe { + // This is safe as value < F::ORDER_U32. + F::from_canonical_unchecked(value) + }; + } + }; + EF::from_basis_coefficients_fn(|_| sample_base(&mut self.inner)) + } + *) + Definition sample + (F EF Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF Inner in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ modulus : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.copy (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |) in + let~ log_size : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_function (| "p3_util::log2_ceil_u64", [], [] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeField64::ORDER_U64", Ty.path "u64" |) + |) + ] + |) + |) in + let~ pow_of_two_bound : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U64 1; M.read (| log_size |) ] + |); + Value.Integer IntegerKind.U64 1 + ] + |)) + |) in + let~ sample_base : + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Inner ] ] ] F ] := + M.alloc (| + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Inner ] ] ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let inner := M.copy (| γ |) in + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic + (let~ value : + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.path "u32", + "from_le_bytes", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ], + M.get_trait_method (| + "p3_challenger::CanSample", + Inner, + [], + [ Ty.path "u8" ], + "sample_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| inner |) |) + |) + ] + |) + ] + |) + |) in + let~ value : + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ M.read (| value |); M.read (| pow_of_two_bound |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| value |); M.read (| modulus |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::integers::QuotientMap", + F, + [], + [ Ty.path "u32" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.read (| value |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + |) in + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + EF, + [], + [ F ], + "from_basis_coefficients_fn", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + F, + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Inner ] ] ] + F, + [], + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Inner ] ] ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, sample_base |); + Value.Tuple + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger32", + "inner" + |) + |) + |) + |) + ] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F EF Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSample" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ EF ] + (Self F EF Inner) + (* Instance *) [ ("sample", InstanceField.Method (sample F EF Inner)) ]. + End Impl_p3_challenger_CanSample_where_p3_field_field_PrimeField32_F_where_p3_field_field_BasedVectorSpace_EF_F_where_p3_challenger_CanSample_Inner_u8_EF_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + + Module Impl_p3_challenger_CanSampleBits_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanSample_Inner_u8_usize_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]. + + (* + fn sample_bits(&mut self, bits: usize) -> usize { + assert!(bits < (usize::BITS as usize)); + // Limiting the number of bits to the field size + assert!((1 << bits) <= F::ORDER_U64 as usize); + let rand_usize = u32::from_le_bytes(self.inner.sample_array()) as usize; + rand_usize & ((1 << bits) - 1) + } + *) + Definition sample_bits + (F Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ self; bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| bits |); + M.cast + (Ty.path "usize") + (M.read (| + get_associated_constant (| + Ty.path "usize", + "BITS", + Ty.path "u32" + |) + |)) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits < (usize::BITS as usize)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| bits |) ] + |); + M.cast + (Ty.path "usize") + (M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |)) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: (1 << bits) <= F::ORDER_U64 as usize" |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ rand_usize : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "from_le_bytes", [], [] |), + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ], + M.get_trait_method (| + "p3_challenger::CanSample", + Inner, + [], + [ Ty.path "u8" ], + "sample_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger32", + "inner" + |) + |) + ] + |) + ] + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ + M.read (| rand_usize |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| bits |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSampleBits" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + (Self F Inner) + (* Instance *) [ ("sample_bits", InstanceField.Method (sample_bits F Inner)) ]. + End Impl_p3_challenger_CanSampleBits_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanSample_Inner_u8_usize_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + + Module Impl_p3_challenger_grinding_challenger_GrindingChallenger_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanSample_Inner_u8_where_p3_challenger_CanObserve_Inner_u8_where_core_clone_Clone_Inner_where_core_marker_Send_Inner_where_core_marker_Sync_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]. + + (* type Witness = F; *) + Definition _Witness (F Inner : Ty.t) : Ty.t := F. + + (* #[instrument(name = "grind for proof-of-work witness", skip_all)] *) + Definition grind (F Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ self; bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bits := M.alloc (| bits |) in + M.catch_return + (Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + (Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]) + "Witness") (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::serializing_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::serializing_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::serializing_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::serializing_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| bits |); + M.cast + (Ty.path "usize") + (M.read (| + get_associated_constant (| + Ty.path "usize", + "BITS", + Ty.path "u32" + |) + |)) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits < (usize::BITS as usize)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U32 1; M.read (| bits |) ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: (1 << bits) < F::ORDER_U32" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ witness : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParIterExt", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u32" ]; + Ty.function [ Ty.tuple [ Ty.path "u32" ] ] F + ], + [], + [], + "find_any", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] + (Ty.path "bool") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u32" ]; + Ty.function [ Ty.tuple [ Ty.path "u32" ] ] F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u32" ], + [], + [], + "map", + [], + [ F; Ty.function [ Ty.tuple [ Ty.path "u32" ] ] F ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u32" ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "u32" ], + [], + [], + "into_par_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.U32 0); + ("end_", + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |)) + ] + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "u32" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::integers::QuotientMap", + F, + [], + [ Ty.path "u32" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.read (| i |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let witness := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Ty.apply + (Ty.path + "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ], + [], + [], + "check_witness", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |); + M.read (| bits |); + M.read (| M.deref (| M.read (| witness |) |) |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "failed to find witness" |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Ty.apply + (Ty.path + "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ], + [], + [], + "check_witness", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.read (| bits |); + M.read (| witness |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: self.check_witness(bits, witness)" |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + witness + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::grinding_challenger::GrindingChallenger" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F Inner) + (* Instance *) + [ + ("Witness", InstanceField.Ty (_Witness F Inner)); + ("grind", InstanceField.Method (grind F Inner)) + ]. + End Impl_p3_challenger_grinding_challenger_GrindingChallenger_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanSample_Inner_u8_where_p3_challenger_CanObserve_Inner_u8_where_core_clone_Clone_Inner_where_core_marker_Send_Inner_where_core_marker_Sync_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + + Module Impl_p3_challenger_FieldChallenger_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanSample_Inner_u8_where_p3_challenger_CanObserve_Inner_u8_where_core_clone_Clone_Inner_where_core_marker_Send_Inner_where_core_marker_Sync_Inner_F_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ F; Inner ]. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::FieldChallenger" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F Inner) + (* Instance *) []. + End Impl_p3_challenger_FieldChallenger_where_p3_field_field_PrimeField32_F_where_p3_challenger_CanSample_Inner_u8_where_p3_challenger_CanObserve_Inner_u8_where_core_clone_Clone_Inner_where_core_marker_Send_Inner_where_core_marker_Sync_Inner_F_for_p3_challenger_serializing_challenger_SerializingChallenger32_F_Inner. + + Module Impl_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]. + + (* + pub const fn new(inner: Inner) -> Self { + Self { + inner, + _marker: PhantomData, + } + } + *) + Definition new (F Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ inner ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + Value.StructRecord + "p3_challenger::serializing_challenger::SerializingChallenger64" + [ + ("inner", M.read (| inner |)); + ("_marker", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (F Inner : Ty.t), + M.IsAssociatedFunction.C (Self F Inner) "new" (new F Inner). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + + Module Impl_p3_challenger_serializing_challenger_SerializingChallenger64_F_p3_challenger_hash_challenger_HashChallenger_Usize_32_u8_H. + Definition Self (F H : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; H ] + ]. + + (* + pub const fn from_hasher(initial_state: Vec, hasher: H) -> Self { + Self::new(HashChallenger::new(initial_state, hasher)) + } + *) + Definition from_hasher (F H : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F H in + match ε, τ, α with + | [], [], [ initial_state; hasher ] => + ltac:(M.monadic + (let initial_state := M.alloc (| initial_state |) in + let hasher := M.alloc (| hasher |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; H ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; H ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; H ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; H ], + "new", + [], + [] + |), + [ M.read (| initial_state |); M.read (| hasher |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_hasher : + forall (F H : Ty.t), + M.IsAssociatedFunction.C (Self F H) "from_hasher" (from_hasher F H). + Admitted. + Global Typeclasses Opaque from_hasher. + End Impl_p3_challenger_serializing_challenger_SerializingChallenger64_F_p3_challenger_hash_challenger_HashChallenger_Usize_32_u8_H. + + Module Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanObserve_Inner_u8_F_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]. + + (* + fn observe(&mut self, value: F) { + self.inner + .observe_slice(&value.to_unique_u64().to_le_bytes()); + } + *) + Definition observe (F Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ self; value ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let value := M.alloc (| value |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Inner, + [], + [ Ty.path "u8" ], + "observe_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger64", + "inner" + |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "u64", + "to_le_bytes", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + F, + [], + [], + "to_unique_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ] + |) + |) + |) + |) + |)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F Inner) + (* Instance *) [ ("observe", InstanceField.Method (observe F Inner)) ]. + End Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanObserve_Inner_u8_F_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + + Module Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanObserve_Inner_u8_p3_symmetric_hash_Hash_N_F_u8_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + Definition Self (N : Value.t) (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]. + + (* + fn observe(&mut self, values: Hash) { + for value in values { + self.inner.observe(value); + } + } + *) + Definition observe + (N : Value.t) + (F Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F Inner in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ Ty.path "u8" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; Ty.path "u8" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u8" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ N ] + [ Ty.path "u8" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Inner, + [], + [ Ty.path "u8" ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger64", + "inner" + |) + |); + M.read (| value |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; Ty.path "u8" ] ] + (Self N F Inner) + (* Instance *) [ ("observe", InstanceField.Method (observe N F Inner)) ]. + End Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanObserve_Inner_u8_p3_symmetric_hash_Hash_N_F_u8_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + + Module Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanObserve_Inner_u8_p3_symmetric_hash_Hash_N_F_u64_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + Definition Self (N : Value.t) (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]. + + (* + fn observe(&mut self, values: Hash) { + for value in values { + self.inner.observe_slice(&value.to_le_bytes()); + } + } + *) + Definition observe + (N : Value.t) + (F Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F Inner in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ Ty.path "u64" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; Ty.path "u64" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u64" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ N ] + [ Ty.path "u64" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let value := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Inner, + [], + [ Ty.path "u8" ], + "observe_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger64", + "inner" + |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "u64", + "to_le_bytes", + [], + [] + |), + [ M.read (| value |) ] + |) + |) + |) + |) + |)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::CanObserve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ N ] [ F; Ty.path "u64" ] ] + (Self N F Inner) + (* Instance *) [ ("observe", InstanceField.Method (observe N F Inner)) ]. + End Impl_p3_challenger_CanObserve_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanObserve_Inner_u8_p3_symmetric_hash_Hash_N_F_u64_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + + Module Impl_p3_challenger_CanSample_where_p3_field_field_PrimeField64_F_where_p3_field_field_BasedVectorSpace_EF_F_where_p3_challenger_CanSample_Inner_u8_EF_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + Definition Self (F EF Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]. + + (* + fn sample(&mut self) -> EF { + let modulus = F::ORDER_U64; + let log_size = log2_ceil_u64(F::ORDER_U64) as u32; + // We use u128 to avoid overflow in the case that log_size = 64. + let pow_of_two_bound = ((1u128 << log_size) - 1) as u64; + + // Perform rejection sampling over the uniform range (0..log2_ceil(p)) + let sample_base = |inner: &mut Inner| loop { + let value = u64::from_le_bytes(inner.sample_array()); + let value = value & pow_of_two_bound; + if value < modulus { + return unsafe { + // This is safe as value < F::ORDER_U64. + F::from_canonical_unchecked(value) + }; + } + }; + EF::from_basis_coefficients_fn(|_| sample_base(&mut self.inner)) + } + *) + Definition sample + (F EF Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF Inner in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ modulus : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.copy (| + get_constant (| "p3_field::field::PrimeField64::ORDER_U64", Ty.path "u64" |) + |) in + let~ log_size : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u64", + M.get_function (| "p3_util::log2_ceil_u64", [], [] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeField64::ORDER_U64", Ty.path "u64" |) + |) + ] + |)) + |) in + let~ pow_of_two_bound : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "u128", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u128", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U128 1; M.read (| log_size |) ] + |); + Value.Integer IntegerKind.U128 1 + ] + |)) + |) in + let~ sample_base : + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Inner ] ] ] F ] := + M.alloc (| + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Inner ] ] ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let inner := M.copy (| γ |) in + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic + (let~ value : + Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| + Ty.path "u64", + "from_le_bytes", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ], + M.get_trait_method (| + "p3_challenger::CanSample", + Inner, + [], + [ Ty.path "u8" ], + "sample_array", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| inner |) |) + |) + ] + |) + ] + |) + |) in + let~ value : + Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_and, + [ M.read (| value |); M.read (| pow_of_two_bound |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| value |); M.read (| modulus |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::integers::QuotientMap", + F, + [], + [ Ty.path "u64" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.read (| value |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + |) in + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + EF, + [], + [ F ], + "from_basis_coefficients_fn", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + F, + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Inner ] ] ] + F, + [], + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Inner ] ] ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, sample_base |); + Value.Tuple + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger64", + "inner" + |) + |) + |) + |) + ] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F EF Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSample" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ EF ] + (Self F EF Inner) + (* Instance *) [ ("sample", InstanceField.Method (sample F EF Inner)) ]. + End Impl_p3_challenger_CanSample_where_p3_field_field_PrimeField64_F_where_p3_field_field_BasedVectorSpace_EF_F_where_p3_challenger_CanSample_Inner_u8_EF_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + + Module Impl_p3_challenger_CanSampleBits_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanSample_Inner_u8_usize_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]. + + (* + fn sample_bits(&mut self, bits: usize) -> usize { + assert!(bits < (usize::BITS as usize)); + // Limiting the number of bits to the field size + assert!((1 << bits) <= F::ORDER_U64 as usize); + let rand_usize = u64::from_le_bytes(self.inner.sample_array()) as usize; + rand_usize & ((1 << bits) - 1) + } + *) + Definition sample_bits + (F Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ self; bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| bits |); + M.cast + (Ty.path "usize") + (M.read (| + get_associated_constant (| + Ty.path "usize", + "BITS", + Ty.path "u32" + |) + |)) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits < (usize::BITS as usize)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| bits |) ] + |); + M.cast + (Ty.path "usize") + (M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |)) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: (1 << bits) <= F::ORDER_U64 as usize" |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ rand_usize : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u64", + M.get_associated_function (| Ty.path "u64", "from_le_bytes", [], [] |), + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ], + M.get_trait_method (| + "p3_challenger::CanSample", + Inner, + [], + [ Ty.path "u8" ], + "sample_array", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_challenger::serializing_challenger::SerializingChallenger64", + "inner" + |) + |) + ] + |) + ] + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ + M.read (| rand_usize |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| bits |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::CanSampleBits" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + (Self F Inner) + (* Instance *) [ ("sample_bits", InstanceField.Method (sample_bits F Inner)) ]. + End Impl_p3_challenger_CanSampleBits_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanSample_Inner_u8_usize_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + + Module Impl_p3_challenger_grinding_challenger_GrindingChallenger_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanSample_Inner_u8_where_p3_challenger_CanObserve_Inner_u8_where_core_clone_Clone_Inner_where_core_marker_Send_Inner_where_core_marker_Sync_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]. + + (* type Witness = F; *) + Definition _Witness (F Inner : Ty.t) : Ty.t := F. + + (* #[instrument(name = "grind for proof-of-work witness", skip_all)] *) + Definition grind (F Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [], [ self; bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bits := M.alloc (| bits |) in + M.catch_return + (Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + (Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]) + "Witness") (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::serializing_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::serializing_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::serializing_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_challenger::serializing_challenger::grind::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| bits |); + M.cast + (Ty.path "usize") + (M.read (| + get_associated_constant (| + Ty.path "usize", + "BITS", + Ty.path "u32" + |) + |)) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits < (usize::BITS as usize)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U64 1; M.read (| bits |) ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: (1 << bits) < F::ORDER_U64" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ witness : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParIterExt", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ]; + Ty.function [ Ty.tuple [ Ty.path "u64" ] ] F + ], + [], + [], + "find_any", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] + (Ty.path "bool") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ]; + Ty.function [ Ty.tuple [ Ty.path "u64" ] ] F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ], + [], + [], + "map", + [], + [ F; Ty.function [ Ty.tuple [ Ty.path "u64" ] ] F ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "u64" ], + [], + [], + "into_par_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.U64 0); + ("end_", + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |)) + ] + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "u64" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::integers::QuotientMap", + F, + [], + [ Ty.path "u64" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.read (| i |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let witness := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Ty.apply + (Ty.path + "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ], + [], + [], + "check_witness", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |); + M.read (| bits |); + M.read (| M.deref (| M.read (| witness |) |) |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "failed to find witness" |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Ty.apply + (Ty.path + "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ], + [], + [], + "check_witness", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.read (| bits |); + M.read (| witness |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: self.check_witness(bits, witness)" |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + witness + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::grinding_challenger::GrindingChallenger" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F Inner) + (* Instance *) + [ + ("Witness", InstanceField.Ty (_Witness F Inner)); + ("grind", InstanceField.Method (grind F Inner)) + ]. + End Impl_p3_challenger_grinding_challenger_GrindingChallenger_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanSample_Inner_u8_where_p3_challenger_CanObserve_Inner_u8_where_core_clone_Clone_Inner_where_core_marker_Send_Inner_where_core_marker_Sync_Inner_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + + Module Impl_p3_challenger_FieldChallenger_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanSample_Inner_u8_where_p3_challenger_CanObserve_Inner_u8_where_core_clone_Clone_Inner_where_core_marker_Send_Inner_where_core_marker_Sync_Inner_F_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger64") + [] + [ F; Inner ]. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "p3_challenger::FieldChallenger" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F Inner) + (* Instance *) []. + End Impl_p3_challenger_FieldChallenger_where_p3_field_field_PrimeField64_F_where_p3_challenger_CanSample_Inner_u8_where_p3_challenger_CanObserve_Inner_u8_where_core_clone_Clone_Inner_where_core_marker_Send_Inner_where_core_marker_Sync_Inner_F_for_p3_challenger_serializing_challenger_SerializingChallenger64_F_Inner. +End serializing_challenger. diff --git a/CoqOfRust/plonky3/circle/src/cfft.rs b/CoqOfRust/plonky3/circle/src/cfft.rs new file mode 100644 index 000000000..5140595dd --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/cfft.rs @@ -0,0 +1,386 @@ +use alloc::vec; +use alloc::vec::Vec; + +use itertools::{Itertools, iterate, izip}; +use p3_commit::PolynomialSpace; +use p3_dft::{Butterfly, DifButterfly, DitButterfly, divide_by_height}; +use p3_field::extension::ComplexExtendable; +use p3_field::{ExtensionField, Field, batch_multiplicative_inverse}; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_maybe_rayon::prelude::*; +use p3_util::{log2_ceil_usize, log2_strict_usize, reverse_slice_index_bits}; +use tracing::{debug_span, instrument}; + +use crate::domain::CircleDomain; +use crate::point::{Point, compute_lagrange_den_batched}; +use crate::{CfftPermutable, CfftView, cfft_permute_index, cfft_permute_slice}; + +#[derive(Clone)] +pub struct CircleEvaluations> { + pub(crate) domain: CircleDomain, + pub(crate) values: M, +} + +impl> CircleEvaluations { + pub(crate) fn from_cfft_order(domain: CircleDomain, values: M) -> Self { + assert_eq!(1 << domain.log_n, values.height()); + Self { domain, values } + } + pub fn from_natural_order( + domain: CircleDomain, + values: M, + ) -> CircleEvaluations> { + CircleEvaluations::from_cfft_order(domain, values.cfft_perm_rows()) + } + pub fn to_cfft_order(self) -> M { + self.values + } + pub fn to_natural_order(self) -> CfftView { + self.values.cfft_perm_rows() + } +} + +impl> CircleEvaluations { + #[instrument(skip_all, fields(dims = %self.values.dimensions()))] + pub fn interpolate(self) -> RowMajorMatrix { + let Self { domain, values } = self; + let mut values = debug_span!("to_rmm").in_scope(|| values.to_row_major_matrix()); + + let mut twiddles = debug_span!("twiddles").in_scope(|| { + compute_twiddles(domain) + .into_iter() + .map(|ts| { + batch_multiplicative_inverse(&ts) + .into_iter() + .map(|t| DifButterfly(t)) + .collect_vec() + }) + .peekable() + }); + + assert_eq!(twiddles.len(), domain.log_n); + + let par_twiddles = twiddles + .peeking_take_while(|ts| ts.len() >= desired_num_jobs()) + .collect_vec(); + if let Some(min_blks) = par_twiddles.last().map(|ts| ts.len()) { + let max_blk_sz = values.height() / min_blks; + debug_span!("par_layers", log_min_blks = log2_strict_usize(min_blks)).in_scope(|| { + values + .par_row_chunks_exact_mut(max_blk_sz) + .enumerate() + .for_each(|(chunk_i, submat)| { + for ts in &par_twiddles { + let twiddle_chunk_sz = ts.len() / min_blks; + let twiddle_chunk = &ts + [(twiddle_chunk_sz * chunk_i)..(twiddle_chunk_sz * (chunk_i + 1))]; + serial_layer(submat.values, twiddle_chunk); + } + }); + }); + } + + for ts in twiddles { + par_within_blk_layer(&mut values.values, &ts); + } + + // TODO: omit this? + divide_by_height(&mut values); + values + } + + #[instrument(skip_all, fields(dims = %self.values.dimensions()))] + pub fn extrapolate( + self, + target_domain: CircleDomain, + ) -> CircleEvaluations> { + assert!(target_domain.log_n >= self.domain.log_n); + CircleEvaluations::evaluate(target_domain, self.interpolate()) + } + + pub fn evaluate_at_point>(&self, point: Point) -> Vec { + // Compute z_H + let lagrange_num = self.domain.vanishing_poly(point); + + // Permute the domain to get it into the right format. + let permuted_points = cfft_permute_slice(&self.domain.points().collect_vec()); + + // Compute the lagrange denominators. This is batched as it lets us make use of batched_multiplicative_inverse. + let lagrange_den = compute_lagrange_den_batched(&permuted_points, point, self.domain.log_n); + + // The columnwise_dot_product here consumes about 5% of the runtime for example prove_poseidon2_m31_keccak. + // Definitely something worth optimising further. + self.values + .columnwise_dot_product(&lagrange_den) + .into_iter() + .map(|x| x * lagrange_num) + .collect_vec() + } + + #[cfg(test)] + pub(crate) fn dim(&self) -> usize + where + M: Clone, + { + let coeffs = self.clone().interpolate(); + for (i, mut row) in coeffs.rows().enumerate() { + if row.all(|x| x.is_zero()) { + return i; + } + } + coeffs.height() + } +} + +impl CircleEvaluations> { + #[instrument(skip_all, fields(dims = %coeffs.dimensions()))] + pub fn evaluate(domain: CircleDomain, mut coeffs: RowMajorMatrix) -> Self { + let log_n = log2_strict_usize(coeffs.height()); + assert!(log_n <= domain.log_n); + + if log_n < domain.log_n { + // We could simply pad coeffs like this: + // coeffs.pad_to_height(target_domain.size(), F::ZERO); + // But the first `added_bits` layers will simply fill out the zeros + // with the lower order values. (In `DitButterfly`, `x_2` is 0, so + // both `x_1` and `x_2` are set to `x_1`). + // So instead we directly repeat the coeffs and skip the initial layers. + debug_span!("extend coeffs").in_scope(|| { + coeffs.values.reserve(domain.size() * coeffs.width()); + for _ in log_n..domain.log_n { + coeffs.values.extend_from_within(..); + } + }); + } + assert_eq!(coeffs.height(), 1 << domain.log_n); + + let mut twiddles = debug_span!("twiddles").in_scope(|| { + compute_twiddles(domain) + .into_iter() + .map(|ts| ts.into_iter().map(|t| DitButterfly(t)).collect_vec()) + .rev() + .skip(domain.log_n - log_n) + .peekable() + }); + + for ts in twiddles.peeking_take_while(|ts| ts.len() < desired_num_jobs()) { + par_within_blk_layer(&mut coeffs.values, &ts); + } + + let par_twiddles = twiddles.collect_vec(); + if let Some(min_blks) = par_twiddles.first().map(|ts| ts.len()) { + let max_blk_sz = coeffs.height() / min_blks; + debug_span!("par_layers", log_min_blks = log2_strict_usize(min_blks)).in_scope(|| { + coeffs + .par_row_chunks_exact_mut(max_blk_sz) + .enumerate() + .for_each(|(chunk_i, submat)| { + for ts in &par_twiddles { + let twiddle_chunk_sz = ts.len() / min_blks; + let twiddle_chunk = &ts + [(twiddle_chunk_sz * chunk_i)..(twiddle_chunk_sz * (chunk_i + 1))]; + serial_layer(submat.values, twiddle_chunk); + } + }); + }); + } + + Self::from_cfft_order(domain, coeffs) + } +} + +#[inline] +fn serial_layer>(values: &mut [F], twiddles: &[B]) { + let blk_sz = values.len() / twiddles.len(); + for (&t, blk) in izip!(twiddles, values.chunks_exact_mut(blk_sz)) { + let (lo, hi) = blk.split_at_mut(blk_sz / 2); + t.apply_to_rows(lo, hi); + } +} + +#[inline] +#[instrument(level = "debug", skip_all, fields(log_blks = log2_strict_usize(twiddles.len())))] +fn par_within_blk_layer>(values: &mut [F], twiddles: &[B]) { + let blk_sz = values.len() / twiddles.len(); + for (&t, blk) in izip!(twiddles, values.chunks_exact_mut(blk_sz)) { + let (lo, hi) = blk.split_at_mut(blk_sz / 2); + let job_sz = core::cmp::max(1, lo.len() >> log2_ceil_usize(desired_num_jobs())); + lo.par_chunks_mut(job_sz) + .zip(hi.par_chunks_mut(job_sz)) + .for_each(|(lo_job, hi_job)| t.apply_to_rows(lo_job, hi_job)); + } +} + +#[inline] +fn desired_num_jobs() -> usize { + 16 * current_num_threads() +} + +impl CircleDomain { + pub(crate) fn y_twiddles(&self) -> Vec { + let mut ys = self.coset0().map(|p| p.y).collect_vec(); + reverse_slice_index_bits(&mut ys); + ys + } + pub(crate) fn nth_y_twiddle(&self, index: usize) -> F { + self.nth_point(cfft_permute_index(index << 1, self.log_n)).y + } + pub(crate) fn x_twiddles(&self, layer: usize) -> Vec { + let generator = self.subgroup_generator() * (1 << layer); + let shift = self.shift * (1 << layer); + let mut xs = iterate(shift, move |&p| p + generator) + .map(|p| p.x) + .take(1 << (self.log_n - layer - 2)) + .collect_vec(); + reverse_slice_index_bits(&mut xs); + xs + } + pub(crate) fn nth_x_twiddle(&self, index: usize) -> F { + (self.shift + self.subgroup_generator() * index).x + } +} + +fn compute_twiddles(domain: CircleDomain) -> Vec> { + assert!(domain.log_n >= 1); + let mut pts = domain.coset0().collect_vec(); + reverse_slice_index_bits(&mut pts); + let mut twiddles = vec![pts.iter().map(|p| p.y).collect_vec()]; + if domain.log_n >= 2 { + twiddles.push(pts.iter().step_by(2).map(|p| p.x).collect_vec()); + for i in 0..(domain.log_n - 2) { + let prev = twiddles.last().unwrap(); + assert_eq!(prev.len(), 1 << (domain.log_n - 2 - i)); + let cur = prev + .iter() + .step_by(2) + .map(|x| x.square().double() - F::ONE) + .collect_vec(); + twiddles.push(cur); + } + } + twiddles +} + +pub fn circle_basis(p: Point, log_n: usize) -> Vec { + let mut b = vec![F::ONE, p.y]; + let mut x = p.x; + for _ in 0..(log_n - 1) { + for i in 0..b.len() { + b.push(b[i] * x); + } + x = x.square().double() - F::ONE; + } + assert_eq!(b.len(), 1 << log_n); + b +} + +#[cfg(test)] +mod tests { + use itertools::iproduct; + use p3_field::extension::BinomialExtensionField; + use p3_mersenne_31::Mersenne31; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + + type F = Mersenne31; + type EF = BinomialExtensionField; + + #[test] + fn test_cfft_icfft() { + let mut rng = SmallRng::seed_from_u64(1); + for (log_n, width) in iproduct!(2..5, [1, 4, 11]) { + let shift = Point::generator(F::CIRCLE_TWO_ADICITY) * (rng.random::() as usize); + let domain = CircleDomain::new(log_n, shift); + let trace = RowMajorMatrix::::rand(&mut rng, 1 << log_n, width); + let coeffs = CircleEvaluations::from_natural_order(domain, trace.clone()).interpolate(); + assert_eq!( + CircleEvaluations::evaluate(domain, coeffs.clone()) + .to_natural_order() + .to_row_major_matrix(), + trace, + "icfft(cfft(evals)) is identity", + ); + for (i, pt) in domain.points().enumerate() { + assert_eq!( + &*trace.row_slice(i), + coeffs.columnwise_dot_product(&circle_basis(pt, log_n)), + "coeffs can be evaluated with circle_basis", + ); + } + } + } + + #[test] + fn test_extrapolation() { + let mut rng = SmallRng::seed_from_u64(1); + for (log_n, log_blowup) in iproduct!(2..5, [1, 2, 3]) { + let evals = CircleEvaluations::::from_natural_order( + CircleDomain::standard(log_n), + RowMajorMatrix::rand(&mut rng, 1 << log_n, 11), + ); + let lde = evals + .clone() + .extrapolate(CircleDomain::standard(log_n + log_blowup)); + + let coeffs = evals.interpolate(); + let lde_coeffs = lde.interpolate(); + + for r in 0..coeffs.height() { + assert_eq!(&*coeffs.row_slice(r), &*lde_coeffs.row_slice(r)); + } + for r in coeffs.height()..lde_coeffs.height() { + assert!(lde_coeffs.row(r).all(|x| x.is_zero())); + } + } + } + + #[test] + fn eval_at_point_matches_cfft() { + let mut rng = SmallRng::seed_from_u64(1); + for (log_n, width) in iproduct!(2..5, [1, 4, 11]) { + let evals = CircleEvaluations::::from_natural_order( + CircleDomain::standard(log_n), + RowMajorMatrix::rand(&mut rng, 1 << log_n, width), + ); + + let pt = Point::::from_projective_line(rng.random()); + + assert_eq!( + evals.clone().evaluate_at_point(pt), + evals + .interpolate() + .columnwise_dot_product(&circle_basis(pt, log_n)) + ); + } + } + + #[test] + fn eval_at_point_matches_lde() { + let mut rng = SmallRng::seed_from_u64(1); + for (log_n, width, log_blowup) in iproduct!(2..8, [1, 4, 11], [1, 2]) { + let evals = CircleEvaluations::::from_natural_order( + CircleDomain::standard(log_n), + RowMajorMatrix::rand(&mut rng, 1 << log_n, width), + ); + let lde = evals + .clone() + .extrapolate(CircleDomain::standard(log_n + log_blowup)); + let zeta = Point::::from_projective_line(rng.random()); + assert_eq!(evals.evaluate_at_point(zeta), lde.evaluate_at_point(zeta)); + assert_eq!( + evals.evaluate_at_point(zeta), + evals + .interpolate() + .columnwise_dot_product(&circle_basis(zeta, log_n)) + ); + assert_eq!( + lde.evaluate_at_point(zeta), + lde.interpolate() + .columnwise_dot_product(&circle_basis(zeta, log_n + log_blowup)) + ); + } + } +} diff --git a/CoqOfRust/plonky3/circle/src/cfft.v b/CoqOfRust/plonky3/circle/src/cfft.v new file mode 100644 index 000000000..08741c2fe --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/cfft.v @@ -0,0 +1,17311 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module cfft. + (* StructRecord + { + name := "CircleEvaluations"; + const_params := []; + ty_params := [ "F"; "M_" ]; + fields := + [ ("domain", Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]); ("values", M_) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_M__for_p3_circle_cfft_CircleEvaluations_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::cfft::CircleEvaluations") [] [ F; M_ ]. + + (* Clone *) + Definition clone (F M_ : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_circle::cfft::CircleEvaluations" + [ + ("domain", + M.call_closure (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::cfft::CircleEvaluations", + "domain" + |) + |) + |) + |) + ] + |)); + ("values", + M.call_closure (| + M_, + M.get_trait_method (| "core::clone::Clone", M_, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_) + (* Instance *) [ ("clone", InstanceField.Method (clone F M_)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_M__for_p3_circle_cfft_CircleEvaluations_F_M_. + + Module Impl_p3_circle_cfft_CircleEvaluations_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::cfft::CircleEvaluations") [] [ F; M_ ]. + + (* + pub(crate) fn from_cfft_order(domain: CircleDomain, values: M) -> Self { + assert_eq!(1 << domain.log_n, values.height()); + Self { domain, values } + } + *) + Definition from_cfft_order + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ domain; values ] => + ltac:(M.monadic + (let domain := M.alloc (| domain |) in + let values := M.alloc (| values |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, values |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| + Value.StructRecord + "p3_circle::cfft::CircleEvaluations" + [ ("domain", M.read (| domain |)); ("values", M.read (| values |)) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_cfft_order : + forall (F M_ : Ty.t), + M.IsAssociatedFunction.C (Self F M_) "from_cfft_order" (from_cfft_order F M_). + Admitted. + Global Typeclasses Opaque from_cfft_order. + + (* + pub fn from_natural_order( + domain: CircleDomain, + values: M, + ) -> CircleEvaluations> { + CircleEvaluations::from_cfft_order(domain, values.cfft_perm_rows()) + } + *) + Definition from_natural_order + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ domain; values ] => + ltac:(M.monadic + (let domain := M.alloc (| domain |) in + let values := M.alloc (| values |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ Ty.path "p3_circle::ordering::CfftPerm"; M_ ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ Ty.path "p3_circle::ordering::CfftPerm"; M_ ] + ], + "from_cfft_order", + [], + [] + |), + [ + M.read (| domain |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ Ty.path "p3_circle::ordering::CfftPerm"; M_ ], + M.get_trait_method (| + "p3_circle::ordering::CfftPermutable", + M_, + [], + [ F ], + "cfft_perm_rows", + [], + [] + |), + [ M.read (| values |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_natural_order : + forall (F M_ : Ty.t), + M.IsAssociatedFunction.C (Self F M_) "from_natural_order" (from_natural_order F M_). + Admitted. + Global Typeclasses Opaque from_natural_order. + + (* + pub fn to_cfft_order(self) -> M { + self.values + } + *) + Definition to_cfft_order + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_cfft_order : + forall (F M_ : Ty.t), + M.IsAssociatedFunction.C (Self F M_) "to_cfft_order" (to_cfft_order F M_). + Admitted. + Global Typeclasses Opaque to_cfft_order. + + (* + pub fn to_natural_order(self) -> CfftView { + self.values.cfft_perm_rows() + } + *) + Definition to_natural_order + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ Ty.path "p3_circle::ordering::CfftPerm"; M_ ], + M.get_trait_method (| + "p3_circle::ordering::CfftPermutable", + M_, + [], + [ F ], + "cfft_perm_rows", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_natural_order : + forall (F M_ : Ty.t), + M.IsAssociatedFunction.C (Self F M_) "to_natural_order" (to_natural_order F M_). + Admitted. + Global Typeclasses Opaque to_natural_order. + (* #[instrument(skip_all, fields(dims = %self.values.dimensions()))] *) + Definition interpolate + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + F + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_circle::cfft::CircleEvaluations", + "domain" + |) in + let γ0_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_circle::cfft::CircleEvaluations", + "values" + |) in + let domain := M.copy (| γ0_0 |) in + let values := M.copy (| γ0_1 |) in + let~ values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]); + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| values |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ]); + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "peekable", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_circle::cfft::compute_twiddles", + [], + [ F ] + |), + [ M.read (| domain |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let ts := + M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ F ] + ] + (Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ F ] + ] + (Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.function + [ + Ty.tuple + [ F ] + ] + (Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ts + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ + with + | [ α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + F + ] + ] + (Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ + F + ]) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + t := + M.copy (| + γ + |) in + Value.StructTuple + "p3_dft::butterflies::DifButterfly" + [ + M.read (| + t + |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::iter::traits::exact_size::ExactSizeIterator", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ], + [], + [], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, twiddles |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ par_twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ], + [], + [], + "peeking_take_while", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, twiddles |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let ts := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| ts |) |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_circle::cfft::desired_num_jobs", + [], + [] + |), + [] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "map", + [], + [ + Ty.path "usize"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + "last", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, par_twiddles |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "usize") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let ts := M.copy (| γ |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| ts |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let min_blks := M.copy (| γ0_0 |) in + let~ max_blk_sz : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, values |) ] + |); + M.read (| min_blks |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.read (| + min_blks + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::interpolate::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + "par_row_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + values + |); + M.read (| + max_blk_sz + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ] + ] + ] + ] + ] + (Ty.tuple + []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + chunk_i := + M.copy (| + γ0_0 + |) in + let + submat := + M.copy (| + γ0_1 + |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + par_twiddles + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + iter := + M.copy (| + γ + |) in + M.loop (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + ltac:(M.monadic + (let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + ts := + M.copy (| + γ0_0 + |) in + let~ + twiddle_chunk_sz : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path + "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + ts + |) + |) + |) + ] + |); + M.read (| + min_blks + |) + ] + |) + |) in + let~ + twiddle_chunk : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ + F + ] + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ + F + ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + ts + |) + |) + |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + M.read (| + twiddle_chunk_sz + |); + M.read (| + chunk_i + |) + ] + |)); + ("end_", + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + M.read (| + twiddle_chunk_sz + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + chunk_i + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + ] + |)) + ] + ] + |) + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_function (| + "p3_circle::cfft::serial_layer", + [], + [ + F; + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ + F + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + submat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + twiddle_chunk + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| twiddles |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let ts := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_circle::cfft::par_within_blk_layer", + [], + [ + F; + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + values, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ts + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::util::divide_by_height", + [], + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, values |) |) + |) + ] + |) + |) in + values)) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_interpolate : + forall (F M_ : Ty.t), + M.IsAssociatedFunction.C (Self F M_) "interpolate" (interpolate F M_). + Admitted. + Global Typeclasses Opaque interpolate. + + (* #[instrument(skip_all, fields(dims = %self.values.dimensions()))] *) + Definition extrapolate + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ self; target_domain ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let target_domain := M.alloc (| target_domain |) in + M.catch_return + (Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::extrapolate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::extrapolate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::extrapolate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + F + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::extrapolate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + target_domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::cfft::CircleEvaluations", + "domain" + |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: target_domain.log_n >= self.domain.log_n" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + "evaluate", + [], + [] + |), + [ + M.read (| target_domain |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::cfft::CircleEvaluations") [] [ F; M_ ], + "interpolate", + [], + [] + |), + [ M.read (| self |) ] + |) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_extrapolate : + forall (F M_ : Ty.t), + M.IsAssociatedFunction.C (Self F M_) "extrapolate" (extrapolate F M_). + Admitted. + Global Typeclasses Opaque extrapolate. + + (* + pub fn evaluate_at_point>(&self, point: Point) -> Vec { + // Compute z_H + let lagrange_num = self.domain.vanishing_poly(point); + + // Permute the domain to get it into the right format. + let permuted_points = cfft_permute_slice(&self.domain.points().collect_vec()); + + // Compute the lagrange denominators. This is batched as it lets us make use of batched_multiplicative_inverse. + let lagrange_den = compute_lagrange_den_batched(&permuted_points, point, self.domain.log_n); + + // The columnwise_dot_product here consumes about 5% of the runtime for example prove_poseidon2_m31_keccak. + // Definitely something worth optimising further. + self.values + .columnwise_dot_product(&lagrange_den) + .into_iter() + .map(|x| x * lagrange_num) + .collect_vec() + } + *) + Definition evaluate_at_point + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [ EF ], [ self; point ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let point := M.alloc (| point |) in + M.read (| + let~ lagrange_num : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "vanishing_poly", + [], + [ EF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::cfft::CircleEvaluations", + "domain" + |) + |); + M.read (| point |) + ] + |) + |) in + let~ permuted_points : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_circle::ordering::cfft_permute_slice", + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_unknown, + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ F ], + "points", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::cfft::CircleEvaluations", + "domain" + |) + |) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ lagrange_den : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_circle::point::compute_lagrange_den_batched", + [], + [ F; EF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, permuted_points |) |) + |) + ] + |) + |) + |); + M.read (| point |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::cfft::CircleEvaluations", + "domain" + |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.function [ Ty.tuple [ EF ] ] EF + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.function [ Ty.tuple [ EF ] ] EF + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "map", + [], + [ EF; Ty.function [ Ty.tuple [ EF ] ] EF ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "columnwise_dot_product", + [], + [ EF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, lagrange_den |) |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ EF ] ] EF ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ EF ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| lagrange_num |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_evaluate_at_point : + forall (F M_ : Ty.t), + M.IsAssociatedFunction.C (Self F M_) "evaluate_at_point" (evaluate_at_point F M_). + Admitted. + Global Typeclasses Opaque evaluate_at_point. + End Impl_p3_circle_cfft_CircleEvaluations_F_M_. + + + Module Impl_p3_circle_cfft_CircleEvaluations_F_p3_matrix_dense_DenseMatrix_F_alloc_vec_Vec_F_alloc_alloc_Global. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + ]. + + (* #[instrument(skip_all, fields(dims = %coeffs.dimensions()))] *) + Definition evaluate (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ domain; coeffs ] => + ltac:(M.monadic + (let domain := M.alloc (| domain |) in + let coeffs := M.alloc (| coeffs |) in + M.catch_return + (Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + F + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + coeffs + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coeffs |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| log_n |); + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: log_n <= domain.log_n" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| log_n |); + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ], + "reserve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + coeffs, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ F ], + [], + [], + "size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + domain + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ F ], + "width", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + coeffs + |) + ] + |) + ] + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| log_n |)); + ("end_", + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + "extend_from_within", + [], + [ + Ty.path + "core::ops::range::RangeFull" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + coeffs, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |); + Value.StructTuple + "core::ops::range::RangeFull" + [] + ] + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coeffs |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ]); + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ], + [], + [], + "peekable", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ], + [], + [], + "skip", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "rev", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_circle::cfft::compute_twiddles", + [], + [ F ] + |), + [ M.read (| domain |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let ts := + M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ F ] + ] + (Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ F ] + ] + (Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.function + [ + Ty.tuple + [ F ] + ] + (Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + ts + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ + with + | [ α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + F + ] + ] + (Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ + F + ]) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + t := + M.copy (| + γ + |) in + Value.StructTuple + "p3_dft::butterflies::DitButterfly" + [ + M.read (| + t + |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + M.read (| log_n |) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ], + [], + [], + "peeking_take_while", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, twiddles |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let ts := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| ts |) |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_circle::cfft::desired_num_jobs", + [], + [] + |), + [] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let ts := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_circle::cfft::par_within_blk_layer", + [], + [ + F; + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + coeffs, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, ts |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ par_twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ] + ] + ] + ], + [], + [], + "collect_vec", + [], + [] + |), + [ M.read (| twiddles |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "map", + [], + [ + Ty.path "usize"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + "first", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, par_twiddles |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "usize") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let ts := M.copy (| γ |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| ts |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let min_blks := M.copy (| γ0_0 |) in + let~ max_blk_sz : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coeffs |) ] + |); + M.read (| min_blks |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.read (| + min_blks + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::evaluate::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + "par_row_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + coeffs + |); + M.read (| max_blk_sz |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let chunk_i := + M.copy (| + γ0_0 + |) in + let submat := + M.copy (| + γ0_1 + |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + par_twiddles + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let + iter := + M.copy (| + γ + |) in + M.loop (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + ltac:(M.monadic + (let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + ts := + M.copy (| + γ0_0 + |) in + let~ + twiddle_chunk_sz : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path + "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + ts + |) + |) + |) + ] + |); + M.read (| + min_blks + |) + ] + |) + |) in + let~ + twiddle_chunk : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ + F + ] + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ + F + ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ + F + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + ts + |) + |) + |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + M.read (| + twiddle_chunk_sz + |); + M.read (| + chunk_i + |) + ] + |)); + ("end_", + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + M.read (| + twiddle_chunk_sz + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + chunk_i + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + ] + |)) + ] + ] + |) + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_function (| + "p3_circle::cfft::serial_layer", + [], + [ + F; + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ + F + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + submat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + twiddle_chunk + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + "from_cfft_order", + [], + [] + |), + [ M.read (| domain |); M.read (| coeffs |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_evaluate : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "evaluate" (evaluate F). + Admitted. + Global Typeclasses Opaque evaluate. + End Impl_p3_circle_cfft_CircleEvaluations_F_p3_matrix_dense_DenseMatrix_F_alloc_vec_Vec_F_alloc_alloc_Global. + + (* + fn serial_layer>(values: &mut [F], twiddles: &[B]) { + let blk_sz = values.len() / twiddles.len(); + for (&t, blk) in izip!(twiddles, values.chunks_exact_mut(blk_sz)) { + let (lo, hi) = blk.split_at_mut(blk_sz / 2); + t.apply_to_rows(lo, hi); + } + } + *) + Definition serial_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; B ], [ values; twiddles ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ blk_sz : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| values |) |) |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ B ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| twiddles |) |) |) ] + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ]; + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ]; + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ]; + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ B ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| twiddles |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| values |) |) |); + M.read (| blk_sz |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ B ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ]; + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let γ1_0 := M.read (| γ1_0 |) in + let t := M.copy (| γ1_0 |) in + let blk := M.copy (| γ1_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "split_at_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| blk |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| blk_sz |); Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let lo := M.copy (| γ0_0 |) in + let hi := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + B, + [], + [ F ], + "apply_to_rows", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, t |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| lo |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| hi |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_serial_layer : + M.IsFunction.C "p3_circle::cfft::serial_layer" serial_layer. + Admitted. + Global Typeclasses Opaque serial_layer. + + (* #[instrument(level = "debug", skip_all, fields(log_blks = log2_strict_usize(twiddles.len())))] *) + Definition par_within_blk_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; B ], [ values; twiddles ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let twiddles := M.alloc (| twiddles |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::par_within_blk_layer::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::par_within_blk_layer::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::par_within_blk_layer::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + B + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + twiddles + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::cfft::par_within_blk_layer::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ blk_sz : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| values |) |) |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ B ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| twiddles |) |) |) ] + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ]; + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ]; + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ]; + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ B ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| twiddles |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| values |) |) + |); + M.read (| blk_sz |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ B ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ B ]; + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let γ1_0 := M.read (| γ1_0 |) in + let t := M.copy (| γ1_0 |) in + let blk := M.copy (| γ1_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "split_at_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| blk |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.read (| blk_sz |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let lo := M.copy (| γ0_0 |) in + let hi := M.copy (| γ0_1 |) in + let~ job_sz : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::cmp::max", + [], + [ Ty.path "usize" ] + |), + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| lo |) |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::log2_ceil_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_circle::cfft::desired_num_jobs", + [], + [] + |), + [] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ F ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ F ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Ty.apply (Ty.path "slice") [] [ F ], + [], + [ F ], + "par_chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| lo |) |) + |); + M.read (| job_sz |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Ty.apply (Ty.path "slice") [] [ F ], + [], + [ F ], + "par_chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| hi |) |) + |); + M.read (| job_sz |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lo_job := + M.copy (| γ0_0 |) in + let hi_job := + M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + B, + [], + [ F ], + "apply_to_rows", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + t + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| lo_job |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| hi_job |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_par_within_blk_layer : + M.IsFunction.C "p3_circle::cfft::par_within_blk_layer" par_within_blk_layer. + Admitted. + Global Typeclasses Opaque par_within_blk_layer. + + (* + fn desired_num_jobs() -> usize { + 16 * current_num_threads() + } + *) + Definition desired_num_jobs (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 16; + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_maybe_rayon::serial::current_num_threads", [], [] |), + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_desired_num_jobs : + M.IsFunction.C "p3_circle::cfft::desired_num_jobs" desired_num_jobs. + Admitted. + Global Typeclasses Opaque desired_num_jobs. + + Module Impl_p3_circle_domain_CircleDomain_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]. + + (* + pub(crate) fn y_twiddles(&self) -> Vec { + let mut ys = self.coset0().map(|p| p.y).collect_vec(); + reverse_slice_index_bits(&mut ys); + ys + } + *) + Definition y_twiddles (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ ys : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.associated_unknown; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + F + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.associated_unknown; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "map", + [], + [ + F; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + F + ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "coset0", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let p := M.copy (| γ |) in + M.read (| + M.SubPointer.get_struct_record_field (| + p, + "p3_circle::point::Point", + "y" + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, ys |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + ys + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_y_twiddles : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "y_twiddles" (y_twiddles F). + Admitted. + Global Typeclasses Opaque y_twiddles. + + (* + pub(crate) fn nth_y_twiddle(&self, index: usize) -> F { + self.nth_point(cfft_permute_index(index << 1, self.log_n)).y + } + *) + Definition nth_y_twiddle (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; index ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let index := M.alloc (| index |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "nth_point", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_circle::ordering::cfft_permute_index", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ M.read (| index |); Value.Integer IntegerKind.I32 1 ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + ] + |) + |), + "p3_circle::point::Point", + "y" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_nth_y_twiddle : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "nth_y_twiddle" (nth_y_twiddle F). + Admitted. + Global Typeclasses Opaque nth_y_twiddle. + + (* + pub(crate) fn x_twiddles(&self, layer: usize) -> Vec { + let generator = self.subgroup_generator() * (1 << layer); + let shift = self.shift * (1 << layer); + let mut xs = iterate(shift, move |&p| p + generator) + .map(|p| p.x) + .take(1 << (self.log_n - layer - 2)) + .collect_vec(); + reverse_slice_index_bits(&mut xs); + xs + } + *) + Definition x_twiddles (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; layer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let layer := M.alloc (| layer |) in + M.read (| + let~ generator : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.path "usize" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "subgroup_generator", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| layer |) ] + |) + ] + |) + |) in + let~ shift : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.path "usize" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| layer |) ] + |) + ] + |) + |) in + let~ xs : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + F + ] + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + F + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + F + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ], + M.get_function (| + "itertools::sources::iterate", + [], + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ] + |), + [ + M.read (| shift |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let p := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ], + [], + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ], + "add", + [], + [] + |), + [ M.read (| p |); M.read (| generator |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let p := M.copy (| γ |) in + M.read (| + M.SubPointer.get_struct_record_field (| + p, + "p3_circle::point::Point", + "x" + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + M.read (| layer |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, xs |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + xs + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_x_twiddles : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "x_twiddles" (x_twiddles F). + Admitted. + Global Typeclasses Opaque x_twiddles. + + (* + pub(crate) fn nth_x_twiddle(&self, index: usize) -> F { + (self.shift + self.subgroup_generator() * index).x + } + *) + Definition nth_x_twiddle (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; index ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let index := M.alloc (| index |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |); + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.path "usize" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "subgroup_generator", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.read (| index |) + ] + |) + ] + |) + |), + "p3_circle::point::Point", + "x" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_nth_x_twiddle : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "nth_x_twiddle" (nth_x_twiddle F). + Admitted. + Global Typeclasses Opaque nth_x_twiddle. + End Impl_p3_circle_domain_CircleDomain_F. + + (* + fn compute_twiddles(domain: CircleDomain) -> Vec> { + assert!(domain.log_n >= 1); + let mut pts = domain.coset0().collect_vec(); + reverse_slice_index_bits(&mut pts); + let mut twiddles = vec![pts.iter().map(|p| p.y).collect_vec()]; + if domain.log_n >= 2 { + twiddles.push(pts.iter().step_by(2).map(|p| p.x).collect_vec()); + for i in 0..(domain.log_n - 2) { + let prev = twiddles.last().unwrap(); + assert_eq!(prev.len(), 1 << (domain.log_n - 2 - i)); + let cur = prev + .iter() + .step_by(2) + .map(|x| x.square().double() - F::ONE) + .collect_vec(); + twiddles.push(cur); + } + } + twiddles + } + *) + Definition compute_twiddles (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ domain ] => + ltac:(M.monadic + (let domain := M.alloc (| domain |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: domain.log_n >= 1" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ pts : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_unknown, + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "coset0", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, domain |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::reverse_slice_index_bits", + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, pts |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + F + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, pts |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let p := M.copy (| γ |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| p |) |), + "p3_circle::point::Point", + "y" + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + |) + ] + |) + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, twiddles |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + F + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + [], + [], + "step_by", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, pts |) ] + |) + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let p := M.copy (| γ |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| p |) |), + "p3_circle::point::Point", + "x" + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + Value.Integer IntegerKind.Usize 2 + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ prev : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "last", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + twiddles + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prev |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + Value.Integer + IntegerKind.Usize + 2 + ] + |); + M.read (| i |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ cur : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ F ] ] + ] + F + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ F ] ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ F ] ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ], + [], + [], + "step_by", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| prev |) + |) + |) + ] + |) + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := + M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + x + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, twiddles |); + M.read (| cur |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + twiddles + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_compute_twiddles : + M.IsFunction.C "p3_circle::cfft::compute_twiddles" compute_twiddles. + Admitted. + Global Typeclasses Opaque compute_twiddles. + + (* + pub fn circle_basis(p: Point, log_n: usize) -> Vec { + let mut b = vec![F::ONE, p.y]; + let mut x = p.x; + for _ in 0..(log_n - 1) { + for i in 0..b.len() { + b.push(b[i] * x); + } + x = x.square().double() - F::ONE; + } + assert_eq!(b.len(), 1 << log_n); + b + } + *) + Definition circle_basis (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ p; log_n ] => + ltac:(M.monadic + (let p := M.alloc (| p |) in + let log_n := M.alloc (| log_n |) in + M.read (| + let~ b : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + p, + "p3_circle::point::Point", + "y" + |) + |) + ] + |) + ] + |) + |)) + ] + |) + |) in + let~ x : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + M.SubPointer.get_struct_record_field (| p, "p3_circle::point::Point", "x" |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| log_n |); Value.Integer IntegerKind.Usize 1 ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, b |) ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + b + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ F ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + b + |); + M.read (| i |) + ] + |) + |) + |); + M.read (| x |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + x, + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, b |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_n |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + b + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_circle_basis : + M.IsFunction.C "p3_circle::cfft::circle_basis" circle_basis. + Admitted. + Global Typeclasses Opaque circle_basis. +End cfft. diff --git a/CoqOfRust/plonky3/circle/src/deep_quotient.rs b/CoqOfRust/plonky3/circle/src/deep_quotient.rs new file mode 100644 index 000000000..4e4c80c0b --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/deep_quotient.rs @@ -0,0 +1,266 @@ +use alloc::vec::Vec; + +use itertools::{Itertools, izip}; +use p3_field::extension::ComplexExtendable; +use p3_field::{ExtensionField, PackedFieldExtension, batch_multiplicative_inverse, dot_product}; +use p3_matrix::Matrix; +use p3_maybe_rayon::prelude::*; +use p3_util::log2_strict_usize; +use tracing::instrument; + +use crate::domain::CircleDomain; +use crate::point::Point; +use crate::{CircleEvaluations, cfft_permute_slice}; + +/// Compute numerator and denominator of the "vanishing part" of the DEEP quotient +/// Section 6, Remark 21 of Circle Starks (page 30 of first edition PDF) +/// Re(1/v_gamma) + alpha^L Im(1/v_gamma) +/// (Other "part" is \bar g - \bar v_gamma) +pub(crate) fn deep_quotient_vanishing_part>( + x: Point, + zeta: Point, + alpha_pow_width: EF, +) -> (EF, EF) { + let (re_v_zeta, im_v_zeta) = x.v_p(zeta); + ( + re_v_zeta - alpha_pow_width * im_v_zeta, + re_v_zeta.square() + im_v_zeta.square(), + ) +} + +pub(crate) fn deep_quotient_reduce_row>( + alpha: EF, + x: Point, + zeta: Point, + ps_at_x: &[F], + ps_at_zeta: &[EF], +) -> EF { + let (vp_num, vp_denom) = + deep_quotient_vanishing_part(x, zeta, alpha.exp_u64(ps_at_x.len() as u64)); + (vp_num / vp_denom) + * dot_product::( + alpha.powers(), + izip!(ps_at_x, ps_at_zeta).map(|(&p_at_x, &p_at_zeta)| -p_at_zeta + p_at_x), + ) +} + +impl> CircleEvaluations { + /// Same as `deep_quotient_reduce_row`, but reduces a whole matrix into a column, taking advantage of batch inverses. + #[instrument(skip_all, fields(dims = %self.values.dimensions()))] + pub(crate) fn deep_quotient_reduce>( + &self, + alpha: EF, + zeta: Point, + ps_at_zeta: &[EF], + ) -> Vec { + let alpha_pow_width = alpha.exp_u64(self.values.width() as u64); + let points = cfft_permute_slice(&self.domain.points().collect_vec()); + let (vp_nums, vp_denoms): (Vec<_>, Vec<_>) = points + .into_iter() + .map(|x| deep_quotient_vanishing_part(x, zeta, alpha_pow_width)) + .unzip(); + let vp_denom_invs = batch_multiplicative_inverse(&vp_denoms); + + // TODO: packed_alpha_powers and alpha_powers should be passed into deep_quotient_reduce instead of being recomputed every time. + let packed_alpha_powers = + EF::ExtensionPacking::packed_ext_powers_capped(alpha, self.values.width()) + .collect_vec(); + let alpha_powers = + EF::ExtensionPacking::to_ext_iter(packed_alpha_powers.iter().copied()).collect_vec(); + + let alpha_reduced_ps_at_zeta: EF = + dot_product(alpha_powers.iter().copied(), ps_at_zeta.iter().copied()); + + self.values + .rowwise_packed_dot_product::(&packed_alpha_powers) + .zip(vp_nums.into_par_iter()) + .zip(vp_denom_invs.into_par_iter()) + .map(|((reduced_ps_at_x, vp_num), vp_denom_inv)| { + vp_num * vp_denom_inv * (reduced_ps_at_x - alpha_reduced_ps_at_zeta) + }) + .collect() + } +} + +/// Given evaluations over lde_domain, extract the multiple of the vanishing poly of orig_domain +/// See Section 4.3, Lemma 6: < v_n, f > = 0 for any f in FFT space +/// So, we find the "error" (a scalar multiple of v_n) and remove it +/// |lde_domain| > |orig_domain| +#[instrument(skip_all, fields(bits = log2_strict_usize(lde.len())))] +pub fn extract_lambda>( + lde: &mut [EF], + log_blowup: usize, +) -> EF { + let log_lde_size = log2_strict_usize(lde.len()); + // let num_cosets = 1 << (log_lde_size - orig_domain.log_n); + + // v_n is constant on cosets of the same size as orig_domain, so we only have + // as many unique values as we have cosets. + let v_d_init = CircleDomain::::standard(log_lde_size) + .points() + .take(1 << log_blowup) + .map(|p| p.v_n(log_lde_size - log_blowup)) + .collect_vec(); + + // The unique values are repeated over the rest of the domain like + // 0 1 2 .. n-1 n n n-1 .. 1 0 0 1 .. + let v_d = v_d_init + .iter() + .chain(v_d_init.iter().rev()) + .cycle() + .copied(); + + // < v_d, v_d > + // This formula was determined experimentally... + let v_d_2 = F::TWO.exp_u64(log_lde_size as u64 - 1); + + let v_d = v_d.take(lde.len()).collect_vec(); + let v_d = cfft_permute_slice(&v_d); + + let lambda = + dot_product::(lde.iter().copied(), v_d.iter().copied()) * v_d_2.inverse(); + + for (y, v_x) in izip!(lde, v_d) { + *y -= lambda * v_x; + } + + lambda +} + +#[cfg(test)] +mod tests { + use alloc::vec; + + use p3_field::PrimeCharacteristicRing; + use p3_field::extension::BinomialExtensionField; + use p3_matrix::dense::RowMajorMatrix; + use p3_mersenne_31::Mersenne31; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + + type F = Mersenne31; + type EF = BinomialExtensionField; + + #[test] + fn reduce_row_same_as_reduce_matrix() { + let mut rng = SmallRng::seed_from_u64(1); + let domain = CircleDomain::standard(5); + let evals = CircleEvaluations::from_cfft_order( + domain, + RowMajorMatrix::::rand(&mut rng, 1 << domain.log_n, 1 << 3), + ); + + let alpha: EF = rng.random(); + let zeta: Point = Point::from_projective_line(rng.random()); + let ps_at_zeta = evals.evaluate_at_point(zeta); + + let mat_reduced = evals.deep_quotient_reduce(alpha, zeta, &ps_at_zeta); + let row_reduced = evals + .to_natural_order() + .rows() + .zip(domain.points()) + .map(|(ps_at_x, x)| { + deep_quotient_reduce_row(alpha, x, zeta, &ps_at_x.collect_vec(), &ps_at_zeta) + }) + .collect_vec(); + assert_eq!(cfft_permute_slice(&mat_reduced), row_reduced); + } + + #[test] + fn reduce_evaluations_low_degree() { + let mut rng = SmallRng::seed_from_u64(1); + let log_n = 5; + let log_blowup = 1; + let evals = CircleEvaluations::from_cfft_order( + CircleDomain::standard(log_n), + RowMajorMatrix::::rand(&mut rng, 1 << log_n, 1 << 3), + ); + let lde = evals + .clone() + .extrapolate(CircleDomain::standard(log_n + log_blowup)); + assert!(lde.dim() <= (1 << log_n)); + + let alpha: EF = rng.random(); + let zeta: Point = Point::from_projective_line(rng.random()); + + let ps_at_zeta = evals.evaluate_at_point(zeta); + let reduced0 = CircleEvaluations::::from_cfft_order( + CircleDomain::standard(log_n + log_blowup), + RowMajorMatrix::new_col(lde.deep_quotient_reduce(alpha, zeta, &ps_at_zeta)) + .flatten_to_base(), + ); + assert!(reduced0.dim() <= (1 << log_n) + 1); + + let not_ps_at_zeta = evals.evaluate_at_point(zeta.double()); + let reduced1 = CircleEvaluations::::from_cfft_order( + CircleDomain::standard(log_n + log_blowup), + RowMajorMatrix::new_col(lde.deep_quotient_reduce(alpha, zeta, ¬_ps_at_zeta)) + .flatten_to_base(), + ); + assert!(reduced1.dim() > (1 << log_n) + 1); + } + + #[test] + fn reduce_multiple_evaluations() { + let mut rng = SmallRng::seed_from_u64(1); + let domain = CircleDomain::standard(5); + let lde_domain = CircleDomain::standard(8); + + let alpha: EF = rng.random(); + let zeta: Point = Point::from_projective_line(rng.random()); + + let mut alpha_offset = EF::ONE; + let mut ros = vec![EF::ZERO; 1 << lde_domain.log_n]; + + for _ in 0..4 { + let evals = CircleEvaluations::from_cfft_order( + domain, + RowMajorMatrix::::rand(&mut rng, 1 << domain.log_n, 1 << 3), + ); + let ps_at_zeta = evals.evaluate_at_point(zeta); + let lde = evals.extrapolate(lde_domain); + assert!(lde.dim() <= (1 << domain.log_n) + 1); + let mat_ros = lde.deep_quotient_reduce(alpha, zeta, &ps_at_zeta); + for (ro, mat_ro) in izip!(&mut ros, mat_ros) { + *ro += alpha_offset * mat_ro; + } + alpha_offset *= alpha.exp_u64(2 * lde.values.width() as u64); + } + + let ros = CircleEvaluations::from_cfft_order( + lde_domain, + RowMajorMatrix::new_col(ros).flatten_to_base(), + ); + assert!(ros.dim() <= (1 << domain.log_n) + 1); + } + + #[test] + fn test_extract_lambda() { + let mut rng = SmallRng::seed_from_u64(1); + let log_n = 5; + for log_blowup in [1, 2, 3] { + let mut coeffs = RowMajorMatrix::::rand(&mut rng, (1 << log_n) + 1, 1); + coeffs.pad_to_height(1 << (log_n + log_blowup), F::ZERO); + + let domain = CircleDomain::standard(log_n + log_blowup); + let mut lde = CircleEvaluations::evaluate(domain, coeffs.clone()).values; + + let lambda = extract_lambda(&mut lde.values, log_blowup); + assert_eq!(lambda, coeffs.get(1 << log_n, 0)); + + let coeffs2 = + CircleEvaluations::from_cfft_order(domain, RowMajorMatrix::new_col(lde.values)) + .interpolate() + .values; + assert_eq!(&coeffs2[..(1 << log_n)], &coeffs.values[..(1 << log_n)]); + assert_eq!(lambda, coeffs.values[1 << log_n]); + assert_eq!(coeffs2[1 << log_n], F::ZERO); + assert_eq!( + &coeffs2[(1 << log_n) + 1..], + &coeffs.values[(1 << log_n) + 1..] + ); + } + } +} diff --git a/CoqOfRust/plonky3/circle/src/deep_quotient.v b/CoqOfRust/plonky3/circle/src/deep_quotient.v new file mode 100644 index 000000000..4553fa709 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/deep_quotient.v @@ -0,0 +1,4308 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module deep_quotient. + (* + pub(crate) fn deep_quotient_vanishing_part>( + x: Point, + zeta: Point, + alpha_pow_width: EF, + ) -> (EF, EF) { + let (re_v_zeta, im_v_zeta) = x.v_p(zeta); + ( + re_v_zeta - alpha_pow_width * im_v_zeta, + re_v_zeta.square() + im_v_zeta.square(), + ) + } + *) + Definition deep_quotient_vanishing_part + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF ], [ x; zeta; alpha_pow_width ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let zeta := M.alloc (| zeta |) in + let alpha_pow_width := M.alloc (| alpha_pow_width |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [ EF; EF ] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ EF; EF ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "v_p", + [], + [ EF ] + |), + [ M.read (| x |); M.read (| zeta |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let re_v_zeta := M.copy (| γ0_0 |) in + let im_v_zeta := M.copy (| γ0_1 |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Sub", + EF, + [], + [ EF ], + "sub", + [], + [] + |), + [ + M.read (| re_v_zeta |); + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ EF ], + "mul", + [], + [] + |), + [ M.read (| alpha_pow_width |); M.read (| im_v_zeta |) ] + |) + ] + |); + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Add", + EF, + [], + [ EF ], + "add", + [], + [] + |), + [ + M.call_closure (| + EF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + EF, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, re_v_zeta |) ] + |); + M.call_closure (| + EF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + EF, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, im_v_zeta |) ] + |) + ] + |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_deep_quotient_vanishing_part : + M.IsFunction.C + "p3_circle::deep_quotient::deep_quotient_vanishing_part" + deep_quotient_vanishing_part. + Admitted. + Global Typeclasses Opaque deep_quotient_vanishing_part. + + (* + pub(crate) fn deep_quotient_reduce_row>( + alpha: EF, + x: Point, + zeta: Point, + ps_at_x: &[F], + ps_at_zeta: &[EF], + ) -> EF { + let (vp_num, vp_denom) = + deep_quotient_vanishing_part(x, zeta, alpha.exp_u64(ps_at_x.len() as u64)); + (vp_num / vp_denom) + * dot_product::( + alpha.powers(), + izip!(ps_at_x, ps_at_zeta).map(|(&p_at_x, &p_at_zeta)| -p_at_zeta + p_at_x), + ) + } + *) + Definition deep_quotient_reduce_row (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF ], [ alpha; x; zeta; ps_at_x; ps_at_zeta ] => + ltac:(M.monadic + (let alpha := M.alloc (| alpha |) in + let x := M.alloc (| x |) in + let zeta := M.alloc (| zeta |) in + let ps_at_x := M.alloc (| ps_at_x |) in + let ps_at_zeta := M.alloc (| ps_at_zeta |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ EF ], + M.alloc (| + M.call_closure (| + Ty.tuple [ EF; EF ], + M.get_function (| + "p3_circle::deep_quotient::deep_quotient_vanishing_part", + [], + [ F; EF ] + |), + [ + M.read (| x |); + M.read (| zeta |); + M.call_closure (| + EF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + EF, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, alpha |); + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| ps_at_x |) |) |) ] + |)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let vp_num := M.copy (| γ0_0 |) in + let vp_denom := M.copy (| γ0_1 |) in + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ EF ], + "mul", + [], + [] + |), + [ + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Div", + EF, + [], + [ EF ], + "div", + [], + [] + |), + [ M.read (| vp_num |); M.read (| vp_denom |) ] + |); + M.call_closure (| + EF, + M.get_function (| + "p3_field::helpers::dot_product", + [], + [ + EF; + Ty.apply (Ty.path "p3_field::field::Powers") [] [ EF ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ EF ] + ] + ] + ] + EF + ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ EF ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + EF, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, alpha |) ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ EF ] + ] + ] + ] + EF + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ], + [], + [], + "map", + [], + [ + EF; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ EF ] + ] + ] + ] + EF + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| ps_at_x |) ] + |); + M.read (| ps_at_zeta |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ EF ] + ] + ] + ] + EF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let p_at_x := M.copy (| γ0_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let p_at_zeta := M.copy (| γ0_1 |) in + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Add", + EF, + [], + [ F ], + "add", + [], + [] + |), + [ + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Neg", + EF, + [], + [], + "neg", + [], + [] + |), + [ M.read (| p_at_zeta |) ] + |); + M.read (| p_at_x |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_deep_quotient_reduce_row : + M.IsFunction.C "p3_circle::deep_quotient::deep_quotient_reduce_row" deep_quotient_reduce_row. + Admitted. + Global Typeclasses Opaque deep_quotient_reduce_row. + + Module Impl_p3_circle_cfft_CircleEvaluations_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::cfft::CircleEvaluations") [] [ F; M_ ]. + + (* #[instrument(skip_all, fields(dims = %self.values.dimensions()))] *) + Definition deep_quotient_reduce + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [ EF ], [ self; alpha; zeta; ps_at_zeta ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let alpha := M.alloc (| alpha |) in + let zeta := M.alloc (| zeta |) in + let ps_at_zeta := M.alloc (| ps_at_zeta |) in + M.catch_return + (Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::deep_quotient::deep_quotient_reduce::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::deep_quotient::deep_quotient_reduce::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::deep_quotient::deep_quotient_reduce::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + F + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::deep_quotient::deep_quotient_reduce::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ alpha_pow_width : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + EF, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, alpha |); + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "width", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |) + ] + |)) + ] + |) + |) in + let~ points : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_circle::ordering::cfft_permute_slice", + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_unknown, + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ F ], + "points", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::cfft::CircleEvaluations", + "domain" + |) + |) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + (Ty.tuple [ EF; EF ]) + ], + [], + [], + "unzip", + [], + [ + EF; + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + (Ty.tuple [ EF; EF ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.tuple [ EF; EF ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + (Ty.tuple [ EF; EF ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| points |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + (Ty.tuple [ EF; EF ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [ EF; EF ], + M.get_function (| + "p3_circle::deep_quotient::deep_quotient_vanishing_part", + [], + [ F; EF ] + |), + [ + M.read (| x |); + M.read (| zeta |); + M.read (| alpha_pow_width |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let vp_nums := M.copy (| γ0_0 |) in + let vp_denoms := M.copy (| γ0_1 |) in + let~ vp_denom_invs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse", + [], + [ EF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, vp_denoms |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ packed_alpha_powers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_in_trait + "p3_field::packed::PackedFieldExtension" + [] + [ F; EF ] + (Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking") + "{{synthetic}}'1", + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedFieldExtension" + [] + [ F; EF ] + (Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking") + "{{synthetic}}'1", + M.get_trait_method (| + "p3_field::packed::PackedFieldExtension", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking", + [], + [ F; EF ], + "packed_ext_powers_capped", + [], + [] + |), + [ + M.read (| alpha |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "width", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ alpha_powers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_in_trait + "p3_field::packed::PackedFieldExtension" + [] + [ + F; + EF; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking" + ] + ] + ] + (Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking") + "{{synthetic}}", + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedFieldExtension" + [] + [ + F; + EF; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking" + ] + ] + ] + (Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking") + "{{synthetic}}", + M.get_trait_method (| + "p3_field::packed::PackedFieldExtension", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking", + [], + [ F; EF ], + "to_ext_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking" + ], + [], + [], + "copied", + [], + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + packed_alpha_powers + |) + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ alpha_reduced_ps_at_zeta : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_function (| + "p3_field::helpers::dot_product", + [], + [ + EF; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] ]; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ], + [], + [], + "copied", + [], + [ EF ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ EF ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, alpha_powers |) ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ], + [], + [], + "copied", + [], + [ EF ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ EF ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| ps_at_zeta |) |) + |) + ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F; EF ] + M_ + "{{synthetic}}'12"; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.tuple [ EF; EF ]; EF ] ] ] + EF + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F; EF ] + M_ + "{{synthetic}}'12"; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.tuple [ EF; EF ]; EF ] ] ] + EF + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F; EF ] + M_ + "{{synthetic}}'12"; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "map", + [], + [ + EF; + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.tuple [ EF; EF ]; EF ] ] ] + EF + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F; EF ] + M_ + "{{synthetic}}'12"; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F; EF ] + M_ + "{{synthetic}}'12"; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F; EF ] + M_ + "{{synthetic}}'12"; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F; EF ] + M_ + "{{synthetic}}'12", + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F; EF ] + M_ + "{{synthetic}}'12", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "rowwise_packed_dot_product", + [], + [ EF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ F ] + EF + "ExtensionPacking"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + packed_alpha_powers + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_par_iter", + [], + [] + |), + [ M.read (| vp_nums |) ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_par_iter", + [], + [] + |), + [ M.read (| vp_denom_invs |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.tuple [ Ty.tuple [ EF; EF ]; EF ] ] + ] + EF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let reduced_ps_at_x := M.copy (| γ1_0 |) in + let vp_num := M.copy (| γ1_1 |) in + let vp_denom_inv := M.copy (| γ0_1 |) in + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ EF ], + "mul", + [], + [] + |), + [ + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ EF ], + "mul", + [], + [] + |), + [ + M.read (| vp_num |); + M.read (| vp_denom_inv |) + ] + |); + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Sub", + EF, + [], + [ EF ], + "sub", + [], + [] + |), + [ + M.read (| reduced_ps_at_x |); + M.read (| alpha_reduced_ps_at_zeta |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_deep_quotient_reduce : + forall (F M_ : Ty.t), + M.IsAssociatedFunction.C (Self F M_) "deep_quotient_reduce" (deep_quotient_reduce F M_). + Admitted. + Global Typeclasses Opaque deep_quotient_reduce. + End Impl_p3_circle_cfft_CircleEvaluations_F_M_. + + (* #[instrument(skip_all, fields(bits = log2_strict_usize(lde.len())))] *) + Definition extract_lambda (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF ], [ lde; log_blowup ] => + ltac:(M.monadic + (let lde := M.alloc (| lde |) in + let log_blowup := M.alloc (| log_blowup |) in + M.catch_return EF (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::deep_quotient::extract_lambda::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::deep_quotient::extract_lambda::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::deep_quotient::extract_lambda::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + EF + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + lde + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::deep_quotient::extract_lambda::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_lde_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ EF ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| lde |) |) |) ] + |) + ] + |) + |) in + let~ v_d_init : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.associated_unknown ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + F + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.associated_unknown ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.associated_unknown ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.associated_unknown ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "points", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ F ], + "standard", + [], + [] + |), + [ M.read (| log_lde_size |) ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_blowup |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let p := M.copy (| γ |) in + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ], + "v_n", + [], + [] + |), + [ + M.read (| p |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| log_lde_size |); + M.read (| log_blowup |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ v_d : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + ], + [], + [], + "copied", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ], + [], + [], + "cycle", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, v_d_init |) ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "rev", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, v_d_init |) ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ v_d_2 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", F |) + |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.cast (Ty.path "u64") (M.read (| log_lde_size |)); + Value.Integer IntegerKind.U64 1 + ] + |) + ] + |) + |) in + let~ v_d : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + ] + ] + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + ] + ], + [], + [], + "take", + [], + [] + |), + [ + M.read (| v_d |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ EF ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| lde |) |) |) ] + |) + ] + |) + ] + |) + |) in + let~ v_d : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_function (| "p3_circle::ordering::cfft_permute_slice", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, v_d |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ lambda : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + EF, + M.get_function (| + "p3_field::helpers::dot_product", + [], + [ + EF; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] ]; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ], + [], + [], + "copied", + [], + [ EF ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ EF ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| lde |) |) |) ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "copied", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, v_d |) ] + |) + |) + |) + ] + |) + ] + |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, v_d_2 |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ EF ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ EF ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ EF ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ EF ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ EF ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| lde |) ] + |); + M.read (| v_d |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ EF ]; F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ EF ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let y := M.copy (| γ1_0 |) in + let v_x := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + EF, + [], + [ EF ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| y |) |) + |); + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| lambda |); M.read (| v_x |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + lambda + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_extract_lambda : + M.IsFunction.C "p3_circle::deep_quotient::extract_lambda" extract_lambda. + Admitted. + Global Typeclasses Opaque extract_lambda. +End deep_quotient. diff --git a/CoqOfRust/plonky3/circle/src/domain.rs b/CoqOfRust/plonky3/circle/src/domain.rs new file mode 100644 index 000000000..4ee16d459 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/domain.rs @@ -0,0 +1,403 @@ +use alloc::vec; +use alloc::vec::Vec; + +use itertools::{Itertools, iterate}; +use p3_commit::{LagrangeSelectors, PolynomialSpace}; +use p3_field::ExtensionField; +use p3_field::extension::ComplexExtendable; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_util::{log2_ceil_usize, log2_strict_usize}; +use tracing::instrument; + +use crate::point::Point; + +/// A twin-coset of the circle group on F. It has a power-of-two size and an arbitrary shift. +/// +/// X is generator, O is the first coset, goes counterclockwise +/// ```text +/// O X . +/// . . +/// . O <- start = shift +/// . . - (1,0) +/// O . +/// . . +/// . . O +/// ``` +/// +/// For ordering reasons, the other half will start at gen / shift: +/// ```text +/// . X O <- start = gen/shift +/// . . +/// O . +/// . . - (1,0) +/// . O +/// . . +/// O . . +/// ``` +/// +/// The full domain is the interleaving of these two cosets +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +pub struct CircleDomain { + // log_n corresponds to the log size of the WHOLE domain + pub(crate) log_n: usize, + pub(crate) shift: Point, +} + +impl CircleDomain { + pub const fn new(log_n: usize, shift: Point) -> Self { + Self { log_n, shift } + } + pub fn standard(log_n: usize) -> Self { + Self { + log_n, + shift: Point::generator(log_n + 1), + } + } + fn is_standard(&self) -> bool { + self.shift == Point::generator(self.log_n + 1) + } + pub(crate) fn subgroup_generator(&self) -> Point { + Point::generator(self.log_n - 1) + } + pub(crate) fn coset0(&self) -> impl Iterator> { + let g = self.subgroup_generator(); + iterate(self.shift, move |&p| p + g).take(1 << (self.log_n - 1)) + } + fn coset1(&self) -> impl Iterator> { + let g = self.subgroup_generator(); + iterate(g - self.shift, move |&p| p + g).take(1 << (self.log_n - 1)) + } + pub(crate) fn points(&self) -> impl Iterator> { + self.coset0().interleave(self.coset1()) + } + pub(crate) fn nth_point(&self, idx: usize) -> Point { + let (idx, lsb) = (idx >> 1, idx & 1); + if lsb == 0 { + self.shift + self.subgroup_generator() * idx + } else { + -self.shift + self.subgroup_generator() * (idx + 1) + } + } + + pub(crate) fn vanishing_poly>(&self, at: Point) -> EF { + at.v_n(self.log_n) - self.shift.v_n(self.log_n) + } + + pub(crate) fn s_p>(&self, p: Point, at: Point) -> EF { + self.vanishing_poly(at) / p.v_tilde_p(at) + } + + pub(crate) fn s_p_normalized>(&self, p: Point, at: Point) -> EF { + self.vanishing_poly(at) / (p.v_tilde_p(at) * p.s_p_at_p(self.log_n)) + } +} + +impl PolynomialSpace for CircleDomain { + type Val = F; + + fn size(&self) -> usize { + 1 << self.log_n + } + + fn first_point(&self) -> Self::Val { + self.shift.to_projective_line().unwrap() + } + + fn next_point>(&self, x: Ext) -> Option { + // Only in standard position do we have an algebraic expression to access the next point. + if self.is_standard() { + (Point::from_projective_line(x) + Point::generator(self.log_n)).to_projective_line() + } else { + None + } + } + + fn create_disjoint_domain(&self, min_size: usize) -> Self { + // Right now we simply guarantee the domain is disjoint by returning a + // larger standard position coset, which is fine because we always ask for a larger + // domain. If we wanted good performance for a disjoint domain of the same size, + // we could change the shift. Also we could support nonstandard twin cosets. + assert!( + self.is_standard(), + "create_disjoint_domain not currently supported for nonstandard twin cosets" + ); + let log_n = log2_ceil_usize(min_size); + // Any standard position coset that is not the same size as us will be disjoint. + Self::standard(if log_n == self.log_n { + log_n + 1 + } else { + log_n + }) + } + + /// Decompose a domain into disjoint twin-cosets. + fn split_domains(&self, num_chunks: usize) -> Vec { + assert!(self.is_standard()); + let log_chunks = log2_strict_usize(num_chunks); + assert!(log_chunks <= self.log_n); + self.points() + .take(num_chunks) + .map(|shift| Self { + log_n: self.log_n - log_chunks, + shift, + }) + .collect() + } + + fn split_evals( + &self, + num_chunks: usize, + evals: RowMajorMatrix, + ) -> Vec> { + let log_chunks = log2_strict_usize(num_chunks); + assert!(evals.height() >> (log_chunks + 1) >= 1); + let width = evals.width(); + let mut values: Vec> = vec![vec![]; num_chunks]; + evals + .rows() + .enumerate() + .for_each(|(i, row)| values[forward_backward_index(i, num_chunks)].extend(row)); + values + .into_iter() + .map(|v| RowMajorMatrix::new(v, width)) + .collect() + } + + fn vanishing_poly_at_point>(&self, point: Ext) -> Ext { + self.vanishing_poly(Point::from_projective_line(point)) + } + + fn selectors_at_point>( + &self, + point: Ext, + ) -> LagrangeSelectors { + let point = Point::from_projective_line(point); + LagrangeSelectors { + is_first_row: self.s_p(self.shift, point), + is_last_row: self.s_p(-self.shift, point), + is_transition: Ext::ONE - self.s_p_normalized(-self.shift, point), + inv_vanishing: self.vanishing_poly(point).inverse(), + } + } + + /* + chunks=2: + + 1 . 1 + . . + 0 0 <-- start + . . - (1,0) + 0 0 + . . + 1 . 1 + + + idx -> which chunk to put it in: + chunks=2: 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 + chunks=4: 0 1 2 3 3 2 1 0 0 1 2 3 3 2 1 0 + */ + // wow, really slow! + // todo: batch inverses + #[instrument(skip_all, fields(log_n = %coset.log_n))] + fn selectors_on_coset(&self, coset: Self) -> LagrangeSelectors> { + let sels = coset + .points() + .map(|p| self.selectors_at_point(p.to_projective_line().unwrap())) + .collect_vec(); + LagrangeSelectors { + is_first_row: sels.iter().map(|s| s.is_first_row).collect(), + is_last_row: sels.iter().map(|s| s.is_last_row).collect(), + is_transition: sels.iter().map(|s| s.is_transition).collect(), + inv_vanishing: sels.iter().map(|s| s.inv_vanishing).collect(), + } + } +} + +// 0 1 2 .. len-1 len len len-1 .. 1 0 0 1 .. +const fn forward_backward_index(mut i: usize, len: usize) -> usize { + i %= 2 * len; + if i < len { i } else { 2 * len - 1 - i } +} + +#[cfg(test)] +mod tests { + use core::iter; + + use hashbrown::HashSet; + use itertools::izip; + use p3_field::{PrimeCharacteristicRing, batch_multiplicative_inverse}; + use p3_mersenne_31::Mersenne31; + use rand::SeedableRng; + use rand::rngs::SmallRng; + + use super::*; + use crate::CircleEvaluations; + + fn assert_is_twin_coset(d: CircleDomain) { + let pts = d.points().collect_vec(); + let half_n = pts.len() >> 1; + for (&l, &r) in izip!(&pts[..half_n], pts[half_n..].iter().rev()) { + assert_eq!(l, -r); + } + } + + fn do_test_circle_domain(log_n: usize, width: usize) { + let n = 1 << log_n; + + type F = Mersenne31; + let d = CircleDomain::::standard(log_n); + + // we can move around the circle and end up where we started + let p0 = d.first_point(); + let mut p1 = p0; + for i in 0..(n - 1) { + // nth_point is correct + assert_eq!(Point::from_projective_line(p1), d.nth_point(i)); + p1 = d.next_point(p1).unwrap(); + assert_ne!(p1, p0); + } + assert_eq!(d.next_point(p1).unwrap(), p0); + + // .points() is the same as first_point -> next_point + let mut uni_point = d.first_point(); + for p in d.points() { + assert_eq!(Point::from_projective_line(uni_point), p); + uni_point = d.next_point(uni_point).unwrap(); + } + + // disjoint domain is actually disjoint, and large enough + let seen: HashSet> = d.points().collect(); + for disjoint_size in [10, 100, n - 5, n + 15] { + let dd = d.create_disjoint_domain(disjoint_size); + assert!(dd.size() >= disjoint_size); + for pt in dd.points() { + assert!(!seen.contains(&pt)); + } + } + + // zp is zero + for p in d.points() { + assert_eq!( + d.vanishing_poly_at_point(p.to_projective_line().unwrap()), + F::ZERO + ); + } + + let mut rng = SmallRng::seed_from_u64(1); + + // split domains + let evals = RowMajorMatrix::rand(&mut rng, n, width); + let orig: Vec<(Point, Vec)> = d + .points() + .zip(evals.rows().map(|r| r.collect_vec())) + .collect(); + for num_chunks in [1, 2, 4, 8] { + let mut combined = vec![]; + + let sds = d.split_domains(num_chunks); + assert_eq!(sds.len(), num_chunks); + let ses = d.split_evals(num_chunks, evals.clone()); + assert_eq!(ses.len(), num_chunks); + for (sd, se) in izip!(sds, ses) { + // Split domains are twin cosets + assert_is_twin_coset(sd); + // Split domains have correct size wrt original domain + assert_eq!(sd.size() * num_chunks, d.size()); + assert_eq!(se.width(), evals.width()); + assert_eq!(se.height() * num_chunks, d.size()); + combined.extend(sd.points().zip(se.rows().map(|r| r.collect_vec()))); + } + // Union of split domains and evals is the original domain and evals + assert_eq!( + orig.iter().map(|x| x.0).collect::>(), + combined.iter().map(|x| x.0).collect::>(), + "union of split domains is orig domain" + ); + assert_eq!( + orig.iter().map(|x| &x.1).collect::>(), + combined.iter().map(|x| &x.1).collect::>(), + "union of split evals is orig evals" + ); + assert_eq!( + orig.iter().collect::>(), + combined.iter().collect::>(), + "split domains and evals correspond to orig domains and evals" + ); + } + } + + #[test] + fn selectors() { + type F = Mersenne31; + let log_n = 8; + let n = 1 << log_n; + + let d = CircleDomain::::standard(log_n); + let coset = d.create_disjoint_domain(n); + let sels = d.selectors_on_coset(coset); + + // selectors_on_coset matches selectors_at_point + let mut pt = coset.first_point(); + for i in 0..coset.size() { + let pt_sels = d.selectors_at_point(pt); + assert_eq!(sels.is_first_row[i], pt_sels.is_first_row); + assert_eq!(sels.is_last_row[i], pt_sels.is_last_row); + assert_eq!(sels.is_transition[i], pt_sels.is_transition); + assert_eq!(sels.inv_vanishing[i], pt_sels.inv_vanishing); + pt = coset.next_point(pt).unwrap(); + } + + let coset_to_d = |evals: &[F]| { + let evals = CircleEvaluations::from_natural_order( + coset, + RowMajorMatrix::new_col(evals.to_vec()), + ); + let coeffs = evals.interpolate().to_row_major_matrix(); + let (lo, hi) = coeffs.split_rows(n); + assert_eq!(hi.values, vec![F::ZERO; n]); + CircleEvaluations::evaluate(d, lo.to_row_major_matrix()) + .to_natural_order() + .to_row_major_matrix() + .values + }; + + // Nonzero at first point, zero everywhere else on domain + let is_first_row = coset_to_d(&sels.is_first_row); + assert_ne!(is_first_row[0], F::ZERO); + assert_eq!(&is_first_row[1..], &vec![F::ZERO; n - 1]); + + // Nonzero at last point, zero everywhere else on domain + let is_last_row = coset_to_d(&sels.is_last_row); + assert_eq!(&is_last_row[..n - 1], &vec![F::ZERO; n - 1]); + assert_ne!(is_last_row[n - 1], F::ZERO); + + // Nonzero everywhere on domain but last point + let is_transition = coset_to_d(&sels.is_transition); + assert_ne!(&is_transition[..n - 1], &vec![F::ZERO; n - 1]); + assert_eq!(is_transition[n - 1], F::ZERO); + + // Vanishing polynomial coefficients look like [0.. (n times), 1, 0.. (n-1 times)] + let z_coeffs = CircleEvaluations::from_natural_order( + coset, + RowMajorMatrix::new_col(batch_multiplicative_inverse(&sels.inv_vanishing)), + ) + .interpolate() + .to_row_major_matrix() + .values; + assert_eq!( + z_coeffs, + iter::empty() + .chain(iter::repeat_n(F::ZERO, n)) + .chain(iter::once(F::ONE)) + .chain(iter::repeat_n(F::ZERO, n - 1)) + .collect_vec() + ); + } + + #[test] + fn test_circle_domain() { + do_test_circle_domain(4, 8); + do_test_circle_domain(10, 32); + } +} diff --git a/CoqOfRust/plonky3/circle/src/domain.v b/CoqOfRust/plonky3/circle/src/domain.v new file mode 100644 index 000000000..f84559294 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/domain.v @@ -0,0 +1,4974 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module domain. + (* StructRecord + { + name := "CircleDomain"; + const_params := []; + ty_params := [ "F" ]; + fields := + [ + ("log_n", Ty.path "usize"); + ("shift", Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_F_for_p3_circle_domain_CircleDomain_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_F_for_p3_circle_domain_CircleDomain_F. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_circle_domain_CircleDomain_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_circle::domain::CircleDomain" + [ + ("log_n", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + |) + |) + ] + |)); + ("shift", + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_circle_domain_CircleDomain_F. + + Module Impl_core_marker_StructuralPartialEq_for_p3_circle_domain_CircleDomain_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_circle_domain_CircleDomain_F. + + Module Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_p3_circle_domain_CircleDomain_F_for_p3_circle_domain_CircleDomain_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]. + + (* PartialEq *) + Definition eq (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ] ] + (Self F) + (* Instance *) [ ("eq", InstanceField.Method (eq F)) ]. + End Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_p3_circle_domain_CircleDomain_F_for_p3_circle_domain_CircleDomain_F. + + Module Impl_core_cmp_Eq_where_core_cmp_Eq_F_for_p3_circle_domain_CircleDomain_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]. + + (* Eq *) + Definition assert_receiver_is_total_eq + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method (assert_receiver_is_total_eq F)) ]. + End Impl_core_cmp_Eq_where_core_cmp_Eq_F_for_p3_circle_domain_CircleDomain_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_circle_domain_CircleDomain_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "CircleDomain" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "log_n" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "shift" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_circle_domain_CircleDomain_F. + + Module Impl_p3_circle_domain_CircleDomain_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]. + + (* + pub const fn new(log_n: usize, shift: Point) -> Self { + Self { log_n, shift } + } + *) + Definition new (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ log_n; shift ] => + ltac:(M.monadic + (let log_n := M.alloc (| log_n |) in + let shift := M.alloc (| shift |) in + Value.StructRecord + "p3_circle::domain::CircleDomain" + [ ("log_n", M.read (| log_n |)); ("shift", M.read (| shift |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "new" (new F). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn standard(log_n: usize) -> Self { + Self { + log_n, + shift: Point::generator(log_n + 1), + } + } + *) + Definition standard (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ log_n ] => + ltac:(M.monadic + (let log_n := M.alloc (| log_n |) in + Value.StructRecord + "p3_circle::domain::CircleDomain" + [ + ("log_n", M.read (| log_n |)); + ("shift", + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "generator", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_n |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_standard : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "standard" (standard F). + Admitted. + Global Typeclasses Opaque standard. + + (* + fn is_standard(&self) -> bool { + self.shift == Point::generator(self.log_n + 1) + } + *) + Definition is_standard (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "generator", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_standard : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "is_standard" (is_standard F). + Admitted. + Global Typeclasses Opaque is_standard. + + (* + pub(crate) fn subgroup_generator(&self) -> Point { + Point::generator(self.log_n - 1) + } + *) + Definition subgroup_generator + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "generator", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_subgroup_generator : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "subgroup_generator" (subgroup_generator F). + Admitted. + Global Typeclasses Opaque subgroup_generator. + + (* + pub(crate) fn coset0(&self) -> impl Iterator> { + let g = self.subgroup_generator(); + iterate(self.shift, move |&p| p + g).take(1 << (self.log_n - 1)) + } + *) + Definition coset0 (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ g : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "subgroup_generator", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ], + M.get_function (| + "itertools::sources::iterate", + [], + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let p := M.copy (| γ |) in + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ], + "add", + [], + [] + |), + [ M.read (| p |); M.read (| g |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_coset0 : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "coset0" (coset0 F). + Admitted. + Global Typeclasses Opaque coset0. + + (* + fn coset1(&self) -> impl Iterator> { + let g = self.subgroup_generator(); + iterate(g - self.shift, move |&p| p + g).take(1 << (self.log_n - 1)) + } + *) + Definition coset1 (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ g : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "subgroup_generator", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::sources::Iterate") + [] + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ], + M.get_function (| + "itertools::sources::iterate", + [], + [ + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "sub", + [], + [] + |), + [ + M.read (| g |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + (Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let p := M.copy (| γ |) in + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ], + "add", + [], + [] + |), + [ M.read (| p |); M.read (| g |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_coset1 : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "coset1" (coset1 F). + Admitted. + Global Typeclasses Opaque coset1. + + (* + pub(crate) fn points(&self) -> impl Iterator> { + self.coset0().interleave(self.coset1()) + } + *) + Definition points (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "itertools::adaptors::Interleave") + [] + [ Ty.associated_unknown; Ty.associated_unknown ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_unknown, + [], + [], + "interleave", + [], + [ Ty.associated_unknown ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "coset0", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "coset1", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_points : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "points" (points F). + Admitted. + Global Typeclasses Opaque points. + + (* + pub(crate) fn nth_point(&self, idx: usize) -> Point { + let (idx, lsb) = (idx >> 1, idx & 1); + if lsb == 0 { + self.shift + self.subgroup_generator() * idx + } else { + -self.shift + self.subgroup_generator() * (idx + 1) + } + } + *) + Definition nth_point (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; idx ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let idx := M.alloc (| idx |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| idx |); Value.Integer IntegerKind.I32 1 ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ M.read (| idx |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let idx := M.copy (| γ0_0 |) in + let lsb := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| lsb |); Value.Integer IntegerKind.Usize 0 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |); + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.path "usize" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ F ], + "subgroup_generator", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |); + M.read (| idx |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Neg", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.path "usize" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ F ], + "subgroup_generator", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| idx |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + ] + |) + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_nth_point : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "nth_point" (nth_point F). + Admitted. + Global Typeclasses Opaque nth_point. + + (* + pub(crate) fn vanishing_poly>(&self, at: Point) -> EF { + at.v_n(self.log_n) - self.shift.v_n(self.log_n) + } + *) + Definition vanishing_poly + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ EF ], [ self; at_ ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let at_ := M.alloc (| at_ |) in + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Sub", EF, [], [ F ], "sub", [], [] |), + [ + M.call_closure (| + EF, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + "v_n", + [], + [] + |), + [ + M.read (| at_ |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |); + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "v_n", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_vanishing_poly : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "vanishing_poly" (vanishing_poly F). + Admitted. + Global Typeclasses Opaque vanishing_poly. + + (* + pub(crate) fn s_p>(&self, p: Point, at: Point) -> EF { + self.vanishing_poly(at) / p.v_tilde_p(at) + } + *) + Definition s_p (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ EF ], [ self; p; at_ ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let p := M.alloc (| p |) in + let at_ := M.alloc (| at_ |) in + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Div", EF, [], [ EF ], "div", [], [] |), + [ + M.call_closure (| + EF, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "vanishing_poly", + [], + [ EF ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); M.read (| at_ |) + ] + |); + M.call_closure (| + EF, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "v_tilde_p", + [], + [ EF ] + |), + [ M.read (| p |); M.read (| at_ |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_s_p : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "s_p" (s_p F). + Admitted. + Global Typeclasses Opaque s_p. + + (* + pub(crate) fn s_p_normalized>(&self, p: Point, at: Point) -> EF { + self.vanishing_poly(at) / (p.v_tilde_p(at) * p.s_p_at_p(self.log_n)) + } + *) + Definition s_p_normalized + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ EF ], [ self; p; at_ ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let p := M.alloc (| p |) in + let at_ := M.alloc (| at_ |) in + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Div", EF, [], [ EF ], "div", [], [] |), + [ + M.call_closure (| + EF, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "vanishing_poly", + [], + [ EF ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); M.read (| at_ |) + ] + |); + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + EF, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "v_tilde_p", + [], + [ EF ] + |), + [ M.read (| p |); M.read (| at_ |) ] + |); + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "s_p_at_p", + [], + [] + |), + [ + M.read (| p |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_s_p_normalized : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "s_p_normalized" (s_p_normalized F). + Admitted. + Global Typeclasses Opaque s_p_normalized. + End Impl_p3_circle_domain_CircleDomain_F. + + Module Impl_p3_commit_domain_PolynomialSpace_where_p3_field_extension_complex_ComplexExtendable_F_for_p3_circle_domain_CircleDomain_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]. + + (* type Val = F; *) + Definition _Val (F : Ty.t) : Ty.t := F. + + (* + fn size(&self) -> usize { + 1 << self.log_n + } + *) + Definition size (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn first_point(&self) -> Self::Val { + self.shift.to_projective_line().unwrap() + } + *) + Definition first_point (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "to_projective_line", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn next_point>(&self, x: Ext) -> Option { + // Only in standard position do we have an algebraic expression to access the next point. + if self.is_standard() { + (Point::from_projective_line(x) + Point::generator(self.log_n)).to_projective_line() + } else { + None + } + } + *) + Definition next_point (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ Ext ], [ self; x ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x := M.alloc (| x |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "core::option::Option") [] [ Ext ] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "is_standard", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ext ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ Ext ], + "to_projective_line", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ Ext ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ Ext ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ Ext ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ Ext ], + "from_projective_line", + [], + [] + |), + [ M.read (| x |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "generator", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn create_disjoint_domain(&self, min_size: usize) -> Self { + // Right now we simply guarantee the domain is disjoint by returning a + // larger standard position coset, which is fine because we always ask for a larger + // domain. If we wanted good performance for a disjoint domain of the same size, + // we could change the shift. Also we could support nonstandard twin cosets. + assert!( + self.is_standard(), + "create_disjoint_domain not currently supported for nonstandard twin cosets" + ); + let log_n = log2_ceil_usize(min_size); + // Any standard position coset that is not the same size as us will be disjoint. + Self::standard(if log_n == self.log_n { + log_n + 1 + } else { + log_n + }) + } + *) + Definition create_disjoint_domain + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; min_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let min_size := M.alloc (| min_size |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "is_standard", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "create_disjoint_domain not currently supported for nonstandard twin cosets" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_ceil_usize", [], [] |), + [ M.read (| min_size |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "standard", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| log_n |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_n |); Value.Integer IntegerKind.Usize 1 ] + |) + |))); + fun γ => ltac:(M.monadic log_n) + ] + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn split_domains(&self, num_chunks: usize) -> Vec { + assert!(self.is_standard()); + let log_chunks = log2_strict_usize(num_chunks); + assert!(log_chunks <= self.log_n); + self.points() + .take(num_chunks) + .map(|shift| Self { + log_n: self.log_n - log_chunks, + shift, + }) + .collect() + } + *) + Definition split_domains (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; num_chunks ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_chunks := M.alloc (| num_chunks |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "is_standard", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: self.is_standard()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_chunks : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| num_chunks |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| log_chunks |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: log_chunks <= self.log_n" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.associated_unknown ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + (Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.associated_unknown ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + (Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.associated_unknown ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + (Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.associated_unknown ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "points", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.read (| num_chunks |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ] + ] + (Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let shift := M.copy (| γ |) in + Value.StructRecord + "p3_circle::domain::CircleDomain" + [ + ("log_n", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + M.read (| log_chunks |) + ] + |)); + ("shift", M.read (| shift |)) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn split_evals( + &self, + num_chunks: usize, + evals: RowMajorMatrix, + ) -> Vec> { + let log_chunks = log2_strict_usize(num_chunks); + assert!(evals.height() >> (log_chunks + 1) >= 1); + let width = evals.width(); + let mut values: Vec> = vec![vec![]; num_chunks]; + evals + .rows() + .enumerate() + .for_each(|(i, row)| values[forward_backward_index(i, num_chunks)].extend(row)); + values + .into_iter() + .map(|v| RowMajorMatrix::new(v, width)) + .collect() + } + *) + Definition split_evals (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; num_chunks; evals ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_chunks := M.alloc (| num_chunks |) in + let evals := M.alloc (| evals |) in + M.read (| + let~ log_chunks : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| num_chunks |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_chunks |); Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: evals.height() >> (log_chunks + 1) >= 1" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |) + |) in + let~ values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "alloc::vec::from_elem", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |); + M.read (| num_chunks |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "rows", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let i := M.copy (| γ0_0 |) in + let row := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ F ], + "extend", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, values |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_circle::domain::forward_backward_index", + [], + [] + |), + [ M.read (| i |); M.read (| num_chunks |) ] + |) + ] + |) + |) + |); + M.read (| row |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| values |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let v := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| v |); M.read (| width |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn vanishing_poly_at_point>(&self, point: Ext) -> Ext { + self.vanishing_poly(Point::from_projective_line(point)) + } + *) + Definition vanishing_poly_at_point + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ Ext ], [ self; point ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let point := M.alloc (| point |) in + M.call_closure (| + Ext, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "vanishing_poly", + [], + [ Ext ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ Ext ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ Ext ], + "from_projective_line", + [], + [] + |), + [ M.read (| point |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn selectors_at_point>( + &self, + point: Ext, + ) -> LagrangeSelectors { + let point = Point::from_projective_line(point); + LagrangeSelectors { + is_first_row: self.s_p(self.shift, point), + is_last_row: self.s_p(-self.shift, point), + is_transition: Ext::ONE - self.s_p_normalized(-self.shift, point), + inv_vanishing: self.vanishing_poly(point).inverse(), + } + } + *) + Definition selectors_at_point + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ Ext ], [ self; point ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let point := M.alloc (| point |) in + M.read (| + let~ point : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ Ext ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ Ext ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ Ext ], + "from_projective_line", + [], + [] + |), + [ M.read (| point |) ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_commit::domain::LagrangeSelectors" + [ + ("is_first_row", + M.call_closure (| + Ext, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "s_p", + [], + [ Ext ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |); + M.read (| point |) + ] + |)); + ("is_last_row", + M.call_closure (| + Ext, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "s_p", + [], + [ Ext ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Neg", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |) + ] + |); + M.read (| point |) + ] + |)); + ("is_transition", + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Sub", + Ext, + [], + [ Ext ], + "sub", + [], + [] + |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Ext |) + |); + M.call_closure (| + Ext, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "s_p_normalized", + [], + [ Ext ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Neg", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::domain::CircleDomain", + "shift" + |) + |) + ] + |); + M.read (| point |) + ] + |) + ] + |)); + ("inv_vanishing", + M.call_closure (| + Ext, + M.get_trait_method (| + "p3_field::field::Field", + Ext, + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ext, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "vanishing_poly", + [], + [ Ext ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| point |) + ] + |) + |) + |) + ] + |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* #[instrument(skip_all, fields(log_n = %coset.log_n))] *) + Definition selectors_on_coset + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; coset ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let coset := M.alloc (| coset |) in + M.catch_return + (Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ]) + "Val"; + Ty.path "alloc::alloc::Global" + ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::domain::selectors_on_coset::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::domain::selectors_on_coset::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::domain::selectors_on_coset::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + coset, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::domain::selectors_on_coset::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ sels : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_commit::domain::LagrangeSelectors") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_commit::domain::LagrangeSelectors") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.associated_unknown; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] ] + (Ty.apply (Ty.path "p3_commit::domain::LagrangeSelectors") [] [ F ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.associated_unknown; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + (Ty.apply (Ty.path "p3_commit::domain::LagrangeSelectors") [] [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "p3_commit::domain::LagrangeSelectors") [] [ F ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + (Ty.apply (Ty.path "p3_commit::domain::LagrangeSelectors") [] [ F ]) + ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "points", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coset |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let p := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ], + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ F ], + [], + [], + "selectors_at_point", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ F ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ], + "to_projective_line", + [], + [] + |), + [ M.read (| p |) ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_commit::domain::LagrangeSelectors" + [ + ("is_first_row", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, sels |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let s := M.copy (| γ |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| s |) |), + "p3_commit::domain::LagrangeSelectors", + "is_first_row" + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |)); + ("is_last_row", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, sels |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let s := M.copy (| γ |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| s |) |), + "p3_commit::domain::LagrangeSelectors", + "is_last_row" + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |)); + ("is_transition", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, sels |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let s := M.copy (| γ |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| s |) |), + "p3_commit::domain::LagrangeSelectors", + "is_transition" + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |)); + ("inv_vanishing", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, sels |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_commit::domain::LagrangeSelectors") + [] + [ F ] + ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let s := M.copy (| γ |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| s |) |), + "p3_commit::domain::LagrangeSelectors", + "inv_vanishing" + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |)) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_commit::domain::PolynomialSpace" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ + ("Val", InstanceField.Ty (_Val F)); + ("size", InstanceField.Method (size F)); + ("first_point", InstanceField.Method (first_point F)); + ("next_point", InstanceField.Method (next_point F)); + ("create_disjoint_domain", InstanceField.Method (create_disjoint_domain F)); + ("split_domains", InstanceField.Method (split_domains F)); + ("split_evals", InstanceField.Method (split_evals F)); + ("vanishing_poly_at_point", InstanceField.Method (vanishing_poly_at_point F)); + ("selectors_at_point", InstanceField.Method (selectors_at_point F)); + ("selectors_on_coset", InstanceField.Method (selectors_on_coset F)) + ]. + End Impl_p3_commit_domain_PolynomialSpace_where_p3_field_extension_complex_ComplexExtendable_F_for_p3_circle_domain_CircleDomain_F. + + (* + const fn forward_backward_index(mut i: usize, len: usize) -> usize { + i %= 2 * len; + if i < len { i } else { 2 * len - 1 - i } + } + *) + Definition forward_backward_index (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ i; len ] => + ltac:(M.monadic + (let i := M.alloc (| i |) in + let len := M.alloc (| len |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.read (| β |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| len |) ] + |) + ] + |) + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| i |); M.read (| len |) ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + i)); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| len |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + M.read (| i |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_forward_backward_index : + M.IsFunction.C "p3_circle::domain::forward_backward_index" forward_backward_index. + Admitted. + Global Typeclasses Opaque forward_backward_index. +End domain. diff --git a/CoqOfRust/plonky3/circle/src/folding.rs b/CoqOfRust/plonky3/circle/src/folding.rs new file mode 100644 index 000000000..12917d4a0 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/folding.rs @@ -0,0 +1,192 @@ +use alloc::vec::Vec; +use core::fmt::Debug; +use core::marker::PhantomData; + +use itertools::Itertools; +use p3_commit::Mmcs; +use p3_field::extension::ComplexExtendable; +use p3_field::{ExtensionField, batch_multiplicative_inverse}; +use p3_fri::FriGenericConfig; +use p3_matrix::Matrix; +use p3_util::{log2_strict_usize, reverse_bits_len}; + +use crate::domain::CircleDomain; +use crate::{CircleInputProof, InputError}; + +pub(crate) struct CircleFriGenericConfig( + pub(crate) PhantomData<(F, InputProof, InputError)>, +); + +pub(crate) type CircleFriConfig = CircleFriGenericConfig< + Val, + CircleInputProof, + InputError<>::Error, >::Error>, +>; + +impl, InputProof, InputError: Debug> + FriGenericConfig for CircleFriGenericConfig +{ + type InputProof = InputProof; + type InputError = InputError; + + fn extra_query_index_bits(&self) -> usize { + 1 + } + + fn fold_row( + &self, + index: usize, + log_folded_height: usize, + beta: EF, + evals: impl Iterator, + ) -> EF { + fold_x_row(index, log_folded_height, beta, evals) + } + + fn fold_matrix>(&self, beta: EF, m: M) -> Vec { + fold_x(beta, m) + } +} + +fn fold>( + evals: impl Matrix, + beta: EF, + twiddles: &[F], +) -> Vec { + evals + .rows() + .zip(twiddles) + .map(|(mut row, &t)| { + let (lo, hi) = row.next_tuple().unwrap(); + let sum = lo + hi; + let diff = (lo - hi) * t; + (sum + beta * diff).halve() + }) + .collect_vec() +} + +pub(crate) fn fold_y>( + beta: EF, + evals: impl Matrix, +) -> Vec { + assert_eq!(evals.width(), 2); + let log_n = log2_strict_usize(evals.height()) + 1; + fold( + evals, + beta, + &batch_multiplicative_inverse(&CircleDomain::standard(log_n).y_twiddles()), + ) +} + +pub(crate) fn fold_y_row>( + index: usize, + log_folded_height: usize, + beta: EF, + evals: impl Iterator, +) -> EF { + let evals = evals.collect_vec(); + assert_eq!(evals.len(), 2); + let t = CircleDomain::::standard(log_folded_height + 1) + .nth_y_twiddle(index) + .inverse(); + let sum = evals[0] + evals[1]; + let diff = (evals[0] - evals[1]) * t; + (sum + beta * diff).halve() +} + +pub(crate) fn fold_x>( + beta: EF, + evals: impl Matrix, +) -> Vec { + let log_n = log2_strict_usize(evals.width() * evals.height()); + // +1 because twiddles after the first layer come from the x coordinates of the larger domain. + let domain = CircleDomain::standard(log_n + 1); + fold( + evals, + beta, + &batch_multiplicative_inverse(&domain.x_twiddles(0)), + ) +} + +pub(crate) fn fold_x_row>( + index: usize, + log_folded_height: usize, + beta: EF, + evals: impl Iterator, +) -> EF { + let evals = evals.collect_vec(); + assert_eq!(evals.len(), 2); + let log_arity = log2_strict_usize(evals.len()); + + let t = CircleDomain::::standard(log_folded_height + log_arity + 1) + .nth_x_twiddle(reverse_bits_len(index, log_folded_height)) + .inverse(); + + let sum = evals[0] + evals[1]; + let diff = (evals[0] - evals[1]) * t; + (sum + beta * diff).halve() +} + +#[cfg(test)] +mod tests { + use itertools::iproduct; + use p3_field::extension::BinomialExtensionField; + use p3_matrix::dense::RowMajorMatrix; + use p3_mersenne_31::Mersenne31; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + use crate::CircleEvaluations; + + type F = Mersenne31; + type EF = BinomialExtensionField; + + #[test] + fn fold_matrix_same_as_row() { + let mut rng = SmallRng::seed_from_u64(1); + let log_folded_height = 5; + let m = RowMajorMatrix::::rand(&mut rng, 1 << log_folded_height, 2); + let beta: EF = rng.random(); + + let mat_y_folded = fold_y::(beta, m.as_view()); + let row_y_folded = (0..(1 << log_folded_height)) + .map(|i| fold_y_row::(i, log_folded_height, beta, m.row(i))) + .collect_vec(); + assert_eq!(mat_y_folded, row_y_folded); + + let mat_x_folded = fold_x::(beta, m.as_view()); + let row_x_folded = (0..(1 << log_folded_height)) + .map(|i| fold_x_row::(i, log_folded_height, beta, m.row(i))) + .collect_vec(); + assert_eq!(mat_x_folded, row_x_folded); + } + + #[test] + fn folded_matrix_remains_low_degree() { + let vec_dim = |evals: &[F]| { + CircleEvaluations::from_cfft_order( + CircleDomain::standard(log2_strict_usize(evals.len())), + RowMajorMatrix::new_col(evals.to_vec()), + ) + .dim() + }; + + let mut rng = SmallRng::seed_from_u64(1); + for (log_n, log_blowup) in iproduct!(3..6, 1..4) { + let mut values = CircleEvaluations::evaluate( + CircleDomain::standard(log_n + log_blowup), + RowMajorMatrix::rand(&mut rng, 1 << log_n, 1), + ) + .to_cfft_order() + .values; + + values = fold_y(rng.random(), RowMajorMatrix::new(values, 2)); + assert_eq!(vec_dim(&values), values.len() >> log_blowup); + for _ in 0..(log_n - 1) { + values = fold_x(rng.random(), RowMajorMatrix::new(values, 2)); + assert_eq!(vec_dim(&values), values.len() >> log_blowup); + } + } + } +} diff --git a/CoqOfRust/plonky3/circle/src/folding.v b/CoqOfRust/plonky3/circle/src/folding.v new file mode 100644 index 000000000..7b859cf34 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/folding.v @@ -0,0 +1,1822 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module folding. + (* StructTuple + { + name := "CircleFriGenericConfig"; + const_params := []; + ty_params := [ "F"; "InputProof"; "InputError" ]; + fields := + [ + Ty.apply + (Ty.path "core::marker::PhantomData") + [] + [ Ty.tuple [ F; InputProof; InputError ] ] + ]; + } *) + + Axiom CircleFriConfig : + forall (Val Challenge InputMmcs FriMmcs : Ty.t), + (Ty.apply + (Ty.path "p3_circle::folding::CircleFriConfig") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]) = + (Ty.apply + (Ty.path "p3_circle::folding::CircleFriGenericConfig") + [] + [ + Val; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Error"; + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] FriMmcs "Error" + ] + ]). + + Module Impl_p3_fri_config_FriGenericConfig_where_p3_field_extension_complex_ComplexExtendable_F_where_p3_field_field_ExtensionField_EF_F_where_core_fmt_Debug_InputError_EF_for_p3_circle_folding_CircleFriGenericConfig_F_InputProof_InputError. + Definition Self (F EF InputProof InputError : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_circle::folding::CircleFriGenericConfig") + [] + [ F; InputProof; InputError ]. + + (* type InputProof = InputProof; *) + Definition _InputProof (F EF InputProof InputError : Ty.t) : Ty.t := InputProof. + + (* type InputError = InputError; *) + Definition _InputError (F EF InputProof InputError : Ty.t) : Ty.t := InputError. + + (* + fn extra_query_index_bits(&self) -> usize { + 1 + } + *) + Definition extra_query_index_bits + (F EF InputProof InputError : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF InputProof InputError in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Integer IntegerKind.Usize 1)) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn fold_row( + &self, + index: usize, + log_folded_height: usize, + beta: EF, + evals: impl Iterator, + ) -> EF { + fold_x_row(index, log_folded_height, beta, evals) + } + *) + Definition fold_row + (F EF InputProof InputError : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF InputProof InputError in + match ε, τ, α with + | [], [ impl_Iterator_Item___EF_ ], [ self; index; log_folded_height; beta; evals ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let index := M.alloc (| index |) in + let log_folded_height := M.alloc (| log_folded_height |) in + let beta := M.alloc (| beta |) in + let evals := M.alloc (| evals |) in + M.call_closure (| + EF, + M.get_function (| + "p3_circle::folding::fold_x_row", + [], + [ F; EF; impl_Iterator_Item___EF_ ] + |), + [ + M.read (| index |); + M.read (| log_folded_height |); + M.read (| beta |); + M.read (| evals |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn fold_matrix>(&self, beta: EF, m: M) -> Vec { + fold_x(beta, m) + } + *) + Definition fold_matrix + (F EF InputProof InputError : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF InputProof InputError in + match ε, τ, α with + | [], [ M_ ], [ self; beta; m ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let beta := M.alloc (| beta |) in + let m := M.alloc (| m |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| "p3_circle::folding::fold_x", [], [ F; EF; M_ ] |), + [ M.read (| beta |); M.read (| m |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F EF InputProof InputError : Ty.t), + M.IsTraitInstance + "p3_fri::config::FriGenericConfig" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ EF ] + (Self F EF InputProof InputError) + (* Instance *) + [ + ("InputProof", InstanceField.Ty (_InputProof F EF InputProof InputError)); + ("InputError", InstanceField.Ty (_InputError F EF InputProof InputError)); + ("extra_query_index_bits", + InstanceField.Method (extra_query_index_bits F EF InputProof InputError)); + ("fold_row", InstanceField.Method (fold_row F EF InputProof InputError)); + ("fold_matrix", InstanceField.Method (fold_matrix F EF InputProof InputError)) + ]. + End Impl_p3_fri_config_FriGenericConfig_where_p3_field_extension_complex_ComplexExtendable_F_where_p3_field_field_ExtensionField_EF_F_where_core_fmt_Debug_InputError_EF_for_p3_circle_folding_CircleFriGenericConfig_F_InputProof_InputError. + + (* + fn fold>( + evals: impl Matrix, + beta: EF, + twiddles: &[F], + ) -> Vec { + evals + .rows() + .zip(twiddles) + .map(|(mut row, &t)| { + let (lo, hi) = row.next_tuple().unwrap(); + let sum = lo + hi; + let diff = (lo - hi) * t; + (sum + beta * diff).halve() + }) + .collect_vec() + } + *) + Definition fold (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF; impl_Matrix_EF_ ], [ evals; beta; twiddles ] => + ltac:(M.monadic + (let evals := M.alloc (| evals |) in + let beta := M.alloc (| beta |) in + let twiddles := M.alloc (| twiddles |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "{{synthetic}}"; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "Row"; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + EF + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "{{synthetic}}"; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "Row"; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + EF + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "{{synthetic}}"; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "map", + [], + [ + EF; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "Row"; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + EF + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "{{synthetic}}"; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "{{synthetic}}", + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "{{synthetic}}", + M.get_trait_method (| + "p3_matrix::Matrix", + impl_Matrix_EF_, + [], + [ EF ], + "rows", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |); + M.read (| twiddles |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "Row"; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + EF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let row := M.copy (| γ0_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let t := M.copy (| γ0_1 |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ EF ], + M.alloc (| + M.call_closure (| + Ty.tuple [ EF; EF ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ EF; EF ] ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ EF; EF ] ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ EF ] + impl_Matrix_EF_ + "Row", + [], + [], + "next_tuple", + [], + [ Ty.tuple [ EF; EF ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, row |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let lo := M.copy (| γ0_0 |) in + let hi := M.copy (| γ0_1 |) in + let~ sum : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Add", + EF, + [], + [ EF ], + "add", + [], + [] + |), + [ M.read (| lo |); M.read (| hi |) ] + |) + |) in + let~ diff : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Sub", + EF, + [], + [ EF ], + "sub", + [], + [] + |), + [ M.read (| lo |); M.read (| hi |) ] + |); + M.read (| t |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "p3_field::field::Field", + EF, + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Add", + EF, + [], + [ EF ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ EF ], + "mul", + [], + [] + |), + [ M.read (| beta |); M.read (| diff |) ] + |) + ] + |) + |) + |) + ] + |) + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_fold : M.IsFunction.C "p3_circle::folding::fold" fold. + Admitted. + Global Typeclasses Opaque fold. + + (* + pub(crate) fn fold_y>( + beta: EF, + evals: impl Matrix, + ) -> Vec { + assert_eq!(evals.width(), 2); + let log_n = log2_strict_usize(evals.height()) + 1; + fold( + evals, + beta, + &batch_multiplicative_inverse(&CircleDomain::standard(log_n).y_twiddles()), + ) + } + *) + Definition fold_y (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF; impl_Matrix_EF_ ], [ beta; evals ] => + ltac:(M.monadic + (let beta := M.alloc (| beta |) in + let evals := M.alloc (| evals |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + impl_Matrix_EF_, + [], + [ EF ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.alloc (| Value.Integer IntegerKind.Usize 2 |) |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + impl_Matrix_EF_, + [], + [ EF ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| "p3_circle::folding::fold", [], [ F; EF; impl_Matrix_EF_ ] |), + [ + M.read (| evals |); + M.read (| beta |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ F ], + "y_twiddles", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ F ], + "standard", + [], + [] + |), + [ M.read (| log_n |) ] + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_fold_y : M.IsFunction.C "p3_circle::folding::fold_y" fold_y. + Admitted. + Global Typeclasses Opaque fold_y. + + (* + pub(crate) fn fold_y_row>( + index: usize, + log_folded_height: usize, + beta: EF, + evals: impl Iterator, + ) -> EF { + let evals = evals.collect_vec(); + assert_eq!(evals.len(), 2); + let t = CircleDomain::::standard(log_folded_height + 1) + .nth_y_twiddle(index) + .inverse(); + let sum = evals[0] + evals[1]; + let diff = (evals[0] - evals[1]) * t; + (sum + beta * diff).halve() + } + *) + Definition fold_y_row (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF; impl_Iterator_Item___EF_ ], [ index; log_folded_height; beta; evals ] => + ltac:(M.monadic + (let index := M.alloc (| index |) in + let log_folded_height := M.alloc (| log_folded_height |) in + let beta := M.alloc (| beta |) in + let evals := M.alloc (| evals |) in + M.read (| + let~ evals : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + impl_Iterator_Item___EF_, + [], + [], + "collect_vec", + [], + [] + |), + [ M.read (| evals |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.alloc (| Value.Integer IntegerKind.Usize 2 |) |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ t : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "nth_y_twiddle", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "standard", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| log_folded_height |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |); + M.read (| index |) + ] + |) + |) + |) + ] + |) + |) in + let~ sum : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Add", EF, [], [ EF ], "add", [], [] |), + [ + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ EF ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |); Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |); + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ EF ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |); Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) + ] + |) + |) in + let~ diff : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Sub", EF, [], [ EF ], "sub", [], [] |), + [ + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ EF ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, evals |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |); + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ EF ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, evals |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) + ] + |); + M.read (| t |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| "p3_field::field::Field", EF, [], [], "halve", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Add", + EF, + [], + [ EF ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ EF ], + "mul", + [], + [] + |), + [ M.read (| beta |); M.read (| diff |) ] + |) + ] + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_fold_y_row : + M.IsFunction.C "p3_circle::folding::fold_y_row" fold_y_row. + Admitted. + Global Typeclasses Opaque fold_y_row. + + (* + pub(crate) fn fold_x>( + beta: EF, + evals: impl Matrix, + ) -> Vec { + let log_n = log2_strict_usize(evals.width() * evals.height()); + // +1 because twiddles after the first layer come from the x coordinates of the larger domain. + let domain = CircleDomain::standard(log_n + 1); + fold( + evals, + beta, + &batch_multiplicative_inverse(&domain.x_twiddles(0)), + ) + } + *) + Definition fold_x (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF; impl_Matrix_EF_ ], [ beta; evals ] => + ltac:(M.monadic + (let beta := M.alloc (| beta |) in + let evals := M.alloc (| evals |) in + M.read (| + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + impl_Matrix_EF_, + [], + [ EF ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + impl_Matrix_EF_, + [], + [ EF ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |) + ] + |) + ] + |) + |) in + let~ domain : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "standard", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_n |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| "p3_circle::folding::fold", [], [ F; EF; impl_Matrix_EF_ ] |), + [ + M.read (| evals |); + M.read (| beta |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ F ], + "x_twiddles", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, domain |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_fold_x : M.IsFunction.C "p3_circle::folding::fold_x" fold_x. + Admitted. + Global Typeclasses Opaque fold_x. + + (* + pub(crate) fn fold_x_row>( + index: usize, + log_folded_height: usize, + beta: EF, + evals: impl Iterator, + ) -> EF { + let evals = evals.collect_vec(); + assert_eq!(evals.len(), 2); + let log_arity = log2_strict_usize(evals.len()); + + let t = CircleDomain::::standard(log_folded_height + log_arity + 1) + .nth_x_twiddle(reverse_bits_len(index, log_folded_height)) + .inverse(); + + let sum = evals[0] + evals[1]; + let diff = (evals[0] - evals[1]) * t; + (sum + beta * diff).halve() + } + *) + Definition fold_x_row (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF; impl_Iterator_Item___EF_ ], [ index; log_folded_height; beta; evals ] => + ltac:(M.monadic + (let index := M.alloc (| index |) in + let log_folded_height := M.alloc (| log_folded_height |) in + let beta := M.alloc (| beta |) in + let evals := M.alloc (| evals |) in + M.read (| + let~ evals : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + impl_Iterator_Item___EF_, + [], + [], + "collect_vec", + [], + [] + |), + [ M.read (| evals |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.alloc (| Value.Integer IntegerKind.Usize 2 |) |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ log_arity : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |) + ] + |) + |) in + let~ t : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "nth_x_twiddle", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ F ], + "standard", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_folded_height |); M.read (| log_arity |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::reverse_bits_len", [], [] |), + [ M.read (| index |); M.read (| log_folded_height |) ] + |) + ] + |) + |) + |) + ] + |) + |) in + let~ sum : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Add", EF, [], [ EF ], "add", [], [] |), + [ + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ EF ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |); Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |); + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ EF ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |); Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) + ] + |) + |) in + let~ diff : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Sub", EF, [], [ EF ], "sub", [], [] |), + [ + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ EF ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, evals |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |); + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ EF ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, evals |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) + ] + |); + M.read (| t |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| "p3_field::field::Field", EF, [], [], "halve", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Add", + EF, + [], + [ EF ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ EF ], + "mul", + [], + [] + |), + [ M.read (| beta |); M.read (| diff |) ] + |) + ] + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_fold_x_row : + M.IsFunction.C "p3_circle::folding::fold_x_row" fold_x_row. + Admitted. + Global Typeclasses Opaque fold_x_row. +End folding. diff --git a/CoqOfRust/plonky3/circle/src/lib.rs b/CoqOfRust/plonky3/circle/src/lib.rs new file mode 100644 index 000000000..9605646f2 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/lib.rs @@ -0,0 +1,23 @@ +//! A framework for operating over the unit circle of a finite field, +//! following the [Circle STARKs paper](https://eprint.iacr.org/2024/278) by Haböck, Levit and Papini. + +#![no_std] + +extern crate alloc; + +mod cfft; +mod deep_quotient; +mod domain; +mod folding; +mod ordering; +mod pcs; +mod point; +mod proof; +mod prover; +mod verifier; + +pub use cfft::*; +pub use domain::*; +pub use ordering::*; +pub use pcs::*; +pub use proof::*; diff --git a/CoqOfRust/plonky3/circle/src/ordering.rs b/CoqOfRust/plonky3/circle/src/ordering.rs new file mode 100644 index 000000000..d5a05ba7d --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/ordering.rs @@ -0,0 +1,118 @@ +use alloc::vec::Vec; + +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::row_index_mapped::{RowIndexMap, RowIndexMappedView}; +use p3_util::{log2_strict_usize, reverse_bits_len}; + +#[inline] +pub(crate) const fn cfft_permute_index(index: usize, log_n: usize) -> usize { + let (index, lsb) = (index >> 1, index & 1); + reverse_bits_len( + if lsb == 0 { + index + } else { + (1 << log_n) - index - 1 + }, + log_n, + ) +} + +pub(crate) fn cfft_permute_slice(xs: &[T]) -> Vec { + let log_n = log2_strict_usize(xs.len()); + (0..xs.len()) + .map(|i| xs[cfft_permute_index(i, log_n)].clone()) + .collect() +} + +pub(crate) fn cfft_permute_slice_chunked_in_place(xs: &mut [T], chunk_size: usize) { + assert_eq!(xs.len() % chunk_size, 0); + let n_chunks = xs.len() / chunk_size; + let log_n = log2_strict_usize(n_chunks); + for i in 0..n_chunks { + let j = cfft_permute_index(i, log_n); + if i < j { + // somehow this is slightly faster than the unsafe block below + for k in 0..chunk_size { + xs.swap(i * chunk_size + k, j * chunk_size + k); + } + /* + unsafe { + core::ptr::swap_nonoverlapping( + xs.as_mut_ptr().add(i * chunk_size), + xs.as_mut_ptr().add(j * chunk_size), + chunk_size, + ); + } + */ + } + } +} + +pub type CfftView = RowIndexMappedView; + +#[derive(Copy, Clone)] +pub struct CfftPerm { + log_height: usize, +} + +impl RowIndexMap for CfftPerm { + fn height(&self) -> usize { + 1 << self.log_height + } + fn map_row_index(&self, r: usize) -> usize { + cfft_permute_index(r, self.log_height) + } + fn to_row_major_matrix>( + &self, + inner: Inner, + ) -> RowMajorMatrix { + let mut inner = inner.to_row_major_matrix(); + cfft_permute_slice_chunked_in_place(&mut inner.values, inner.width); + inner + } +} + +pub(crate) trait CfftPermutable: Matrix + Sized { + fn cfft_perm_rows(self) -> CfftView; +} + +impl> CfftPermutable for M { + fn cfft_perm_rows(self) -> CfftView { + RowIndexMappedView { + index_map: CfftPerm { + log_height: log2_strict_usize(self.height()), + }, + inner: self, + } + } +} + +#[cfg(test)] +mod tests { + use itertools::Itertools; + + use super::*; + + #[test] + fn ordering() { + // reference ordering derived by hand + assert_eq!( + (0..8).map(|i| cfft_permute_index(i, 3)).collect_vec(), + &[0, 7, 4, 3, 2, 5, 6, 1], + ); + for log_n in 1..5 { + let n = 1 << log_n; + let sigma = |i| cfft_permute_index(i, log_n); + for i in 0..n { + // involution: σ(σ(i)) = i + assert_eq!(sigma(sigma(i)), i); + } + // perm_slice same as perm_idx + assert_eq!( + cfft_permute_slice(&(0..n).collect_vec()), + (0..n).map(sigma).collect_vec() + ); + } + } +} diff --git a/CoqOfRust/plonky3/circle/src/ordering.v b/CoqOfRust/plonky3/circle/src/ordering.v new file mode 100644 index 000000000..8f00a3b4a --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/ordering.v @@ -0,0 +1,1051 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module ordering. + (* + pub(crate) const fn cfft_permute_index(index: usize, log_n: usize) -> usize { + let (index, lsb) = (index >> 1, index & 1); + reverse_bits_len( + if lsb == 0 { + index + } else { + (1 << log_n) - index - 1 + }, + log_n, + ) + } + *) + Definition cfft_permute_index (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ index; log_n ] => + ltac:(M.monadic + (let index := M.alloc (| index |) in + let log_n := M.alloc (| log_n |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| index |); Value.Integer IntegerKind.I32 1 ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ M.read (| index |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let index := M.copy (| γ0_0 |) in + let lsb := M.copy (| γ0_1 |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::reverse_bits_len", [], [] |), + [ + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| lsb |); Value.Integer IntegerKind.Usize 0 ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + index)); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| log_n |) + ] + |); + M.read (| index |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |))) + ] + |) + |); + M.read (| log_n |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_cfft_permute_index : + M.IsFunction.C "p3_circle::ordering::cfft_permute_index" cfft_permute_index. + Admitted. + Global Typeclasses Opaque cfft_permute_index. + + (* + pub(crate) fn cfft_permute_slice(xs: &[T]) -> Vec { + let log_n = log2_strict_usize(xs.len()); + (0..xs.len()) + .map(|i| xs[cfft_permute_index(i, log_n)].clone()) + .collect() + } + *) + Definition cfft_permute_slice (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ xs ] => + ltac:(M.monadic + (let xs := M.alloc (| xs |) in + M.read (| + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| xs |) |) |) ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] T + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] T + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ T; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] T ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| xs |) |) |) ] + |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] T ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + T, + M.get_trait_method (| + "core::clone::Clone", + T, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| xs |) |), + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_circle::ordering::cfft_permute_index", + [], + [] + |), + [ M.read (| i |); M.read (| log_n |) ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_cfft_permute_slice : + M.IsFunction.C "p3_circle::ordering::cfft_permute_slice" cfft_permute_slice. + Admitted. + Global Typeclasses Opaque cfft_permute_slice. + + (* + pub(crate) fn cfft_permute_slice_chunked_in_place(xs: &mut [T], chunk_size: usize) { + assert_eq!(xs.len() % chunk_size, 0); + let n_chunks = xs.len() / chunk_size; + let log_n = log2_strict_usize(n_chunks); + for i in 0..n_chunks { + let j = cfft_permute_index(i, log_n); + if i < j { + // somehow this is slightly faster than the unsafe block below + for k in 0..chunk_size { + xs.swap(i * chunk_size + k, j * chunk_size + k); + } + /* + unsafe { + core::ptr::swap_nonoverlapping( + xs.as_mut_ptr().add(i * chunk_size), + xs.as_mut_ptr().add(j * chunk_size), + chunk_size, + ); + } + */ + } + } + } + *) + Definition cfft_permute_slice_chunked_in_place + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ T ], [ xs; chunk_size ] => + ltac:(M.monadic + (let xs := M.alloc (| xs |) in + let chunk_size := M.alloc (| chunk_size |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| xs |) |) |) ] + |); + M.read (| chunk_size |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.alloc (| Value.Integer IntegerKind.Usize 0 |) |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ n_chunks : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| xs |) |) |) ] + |); + M.read (| chunk_size |) + ] + |) + |) in + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| n_chunks |) ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| n_chunks |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ j : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_circle::ordering::cfft_permute_index", + [], + [] + |), + [ M.read (| i |); M.read (| log_n |) ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| i |); M.read (| j |) ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| chunk_size |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let k := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ T ], + "swap", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| xs |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| i |); + M.read (| + chunk_size + |) + ] + |); + M.read (| k |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| j |); + M.read (| + chunk_size + |) + ] + |); + M.read (| k |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_cfft_permute_slice_chunked_in_place : + M.IsFunction.C + "p3_circle::ordering::cfft_permute_slice_chunked_in_place" + cfft_permute_slice_chunked_in_place. + Admitted. + Global Typeclasses Opaque cfft_permute_slice_chunked_in_place. + + Axiom CfftView : + forall (M_ : Ty.t), + (Ty.apply (Ty.path "p3_circle::ordering::CfftView") [] [ M_ ]) = + (Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ Ty.path "p3_circle::ordering::CfftPerm"; M_ ]). + + (* StructRecord + { + name := "CfftPerm"; + const_params := []; + ty_params := []; + fields := [ ("log_height", Ty.path "usize") ]; + } *) + + Module Impl_core_marker_Copy_for_p3_circle_ordering_CfftPerm. + Definition Self : Ty.t := Ty.path "p3_circle::ordering::CfftPerm". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_circle_ordering_CfftPerm. + + Module Impl_core_clone_Clone_for_p3_circle_ordering_CfftPerm. + Definition Self : Ty.t := Ty.path "p3_circle::ordering::CfftPerm". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_circle::ordering::CfftPerm" ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_circle_ordering_CfftPerm. + + Module Impl_p3_matrix_row_index_mapped_RowIndexMap_for_p3_circle_ordering_CfftPerm. + Definition Self : Ty.t := Ty.path "p3_circle::ordering::CfftPerm". + + (* + fn height(&self) -> usize { + 1 << self.log_height + } + *) + Definition height (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::ordering::CfftPerm", + "log_height" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn map_row_index(&self, r: usize) -> usize { + cfft_permute_index(r, self.log_height) + } + *) + Definition map_row_index (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; r ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let r := M.alloc (| r |) in + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_circle::ordering::cfft_permute_index", [], [] |), + [ + M.read (| r |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::ordering::CfftPerm", + "log_height" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn to_row_major_matrix>( + &self, + inner: Inner, + ) -> RowMajorMatrix { + let mut inner = inner.to_row_major_matrix(); + cfft_permute_slice_chunked_in_place(&mut inner.values, inner.width); + inner + } + *) + Definition to_row_major_matrix (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T; Inner ], [ self; inner ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let inner := M.alloc (| inner |) in + M.read (| + let~ inner : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + T; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + T; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Inner, + [], + [ T ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| inner |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_circle::ordering::cfft_permute_slice_chunked_in_place", + [], + [ T ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + inner, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + inner, + "p3_matrix::dense::DenseMatrix", + "width" + |) + |) + ] + |) + |) in + inner + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_matrix::row_index_mapped::RowIndexMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("height", InstanceField.Method height); + ("map_row_index", InstanceField.Method map_row_index); + ("to_row_major_matrix", InstanceField.Method to_row_major_matrix) + ]. + End Impl_p3_matrix_row_index_mapped_RowIndexMap_for_p3_circle_ordering_CfftPerm. + + (* Trait *) + (* Empty module 'CfftPermutable' *) + + Module Impl_p3_circle_ordering_CfftPermutable_where_core_marker_Send_T_where_core_marker_Sync_T_where_p3_matrix_Matrix_M__T_T_for_M_. + Definition Self (T M_ : Ty.t) : Ty.t := M_. + + (* + fn cfft_perm_rows(self) -> CfftView { + RowIndexMappedView { + index_map: CfftPerm { + log_height: log2_strict_usize(self.height()), + }, + inner: self, + } + } + *) + Definition cfft_perm_rows + (T M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self T M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_matrix::row_index_mapped::RowIndexMappedView" + [ + ("index_map", + Value.StructRecord + "p3_circle::ordering::CfftPerm" + [ + ("log_height", + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ T ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |) + ] + |)) + ]); + ("inner", M.read (| self |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T M_ : Ty.t), + M.IsTraitInstance + "p3_circle::ordering::CfftPermutable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self T M_) + (* Instance *) [ ("cfft_perm_rows", InstanceField.Method (cfft_perm_rows T M_)) ]. + End Impl_p3_circle_ordering_CfftPermutable_where_core_marker_Send_T_where_core_marker_Sync_T_where_p3_matrix_Matrix_M__T_T_for_M_. +End ordering. diff --git a/CoqOfRust/plonky3/circle/src/pcs.rs b/CoqOfRust/plonky3/circle/src/pcs.rs new file mode 100644 index 000000000..f567c985a --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/pcs.rs @@ -0,0 +1,619 @@ +use alloc::borrow::Cow; +use alloc::collections::BTreeMap; +use alloc::vec; +use alloc::vec::Vec; +use core::marker::PhantomData; + +use itertools::{Itertools, izip}; +use p3_challenger::{CanObserve, FieldChallenger, GrindingChallenger}; +use p3_commit::{Mmcs, OpenedValues, Pcs, PolynomialSpace}; +use p3_field::extension::ComplexExtendable; +use p3_field::{ExtensionField, Field}; +use p3_fri::FriConfig; +use p3_fri::verifier::FriError; +use p3_matrix::dense::{DenseMatrix, RowMajorMatrix}; +use p3_matrix::row_index_mapped::RowIndexMappedView; +use p3_matrix::{Dimensions, Matrix}; +use p3_maybe_rayon::prelude::*; +use p3_util::log2_strict_usize; +use p3_util::zip_eq::zip_eq; +use serde::{Deserialize, Serialize}; +use tracing::info_span; + +use crate::deep_quotient::{deep_quotient_reduce_row, extract_lambda}; +use crate::domain::CircleDomain; +use crate::folding::{CircleFriConfig, CircleFriGenericConfig, fold_y, fold_y_row}; +use crate::point::Point; +use crate::prover::prove; +use crate::verifier::verify; +use crate::{CfftPerm, CfftPermutable, CircleEvaluations, CircleFriProof, cfft_permute_index}; + +#[derive(Debug)] +pub struct CirclePcs { + pub mmcs: InputMmcs, + pub fri_config: FriConfig, + pub _phantom: PhantomData, +} + +impl CirclePcs { + pub const fn new(mmcs: InputMmcs, fri_config: FriConfig) -> Self { + Self { + mmcs, + fri_config, + _phantom: PhantomData, + } + } +} + +#[derive(Serialize, Deserialize, Clone)] +#[serde(bound = "")] +pub struct BatchOpening> { + pub(crate) opened_values: Vec>, + pub(crate) opening_proof: >::Proof, +} + +#[derive(Serialize, Deserialize, Clone)] +#[serde(bound = "")] +pub struct CircleInputProof< + Val: Field, + Challenge: Field, + InputMmcs: Mmcs, + FriMmcs: Mmcs, +> { + input_openings: Vec>, + first_layer_siblings: Vec, + first_layer_proof: FriMmcs::Proof, +} + +#[derive(Debug)] +pub enum InputError { + InputMmcsError(InputMmcsError), + FirstLayerMmcsError(FriMmcsError), + InputShapeError, +} + +#[derive(Serialize, Deserialize, Clone)] +#[serde(bound( + serialize = "Witness: Serialize", + deserialize = "Witness: Deserialize<'de>" +))] +pub struct CirclePcsProof< + Val: Field, + Challenge: Field, + InputMmcs: Mmcs, + FriMmcs: Mmcs, + Witness, +> { + first_layer_commitment: FriMmcs::Commitment, + lambdas: Vec, + fri_proof: CircleFriProof< + Challenge, + FriMmcs, + Witness, + CircleInputProof, + >, +} + +impl Pcs + for CirclePcs +where + Val: ComplexExtendable, + Challenge: ExtensionField, + InputMmcs: Mmcs, + FriMmcs: Mmcs, + Challenger: FieldChallenger + GrindingChallenger + CanObserve, +{ + type Domain = CircleDomain; + type Commitment = InputMmcs::Commitment; + type ProverData = InputMmcs::ProverData>; + type EvaluationsOnDomain<'a> = RowIndexMappedView>>; + type Proof = CirclePcsProof; + type Error = FriError>; + + fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain { + CircleDomain::standard(log2_strict_usize(degree)) + } + + fn commit( + &self, + evaluations: Vec<(Self::Domain, RowMajorMatrix)>, + ) -> (Self::Commitment, Self::ProverData) { + let ldes = evaluations + .into_iter() + .map(|(domain, evals)| { + assert!( + domain.log_n >= 2, + "CirclePcs cannot commit to a matrix with fewer than 4 rows.", + // (because we bivariate fold one bit, and fri needs one more bit) + ); + CircleEvaluations::from_natural_order(domain, evals) + .extrapolate(CircleDomain::standard( + domain.log_n + self.fri_config.log_blowup, + )) + .to_cfft_order() + }) + .collect_vec(); + let (comm, mmcs_data) = self.mmcs.commit(ldes); + (comm, mmcs_data) + } + + fn get_evaluations_on_domain<'a>( + &self, + data: &'a Self::ProverData, + idx: usize, + domain: Self::Domain, + ) -> Self::EvaluationsOnDomain<'a> { + let mat = self.mmcs.get_matrices(data)[idx].as_view(); + let committed_domain = CircleDomain::standard(log2_strict_usize(mat.height())); + if domain == committed_domain { + mat.as_cow().cfft_perm_rows() + } else { + CircleEvaluations::from_cfft_order(committed_domain, mat) + .extrapolate(domain) + .to_cfft_order() + .as_cow() + .cfft_perm_rows() + } + } + + fn open( + &self, + // For each round, + rounds: Vec<( + &Self::ProverData, + // for each matrix, + Vec< + // points to open + Vec, + >, + )>, + challenger: &mut Challenger, + ) -> (OpenedValues, Self::Proof) { + // Open matrices at points + let values: OpenedValues = rounds + .iter() + .map(|(data, points_for_mats)| { + let mats = self.mmcs.get_matrices(data); + debug_assert_eq!( + mats.len(), + points_for_mats.len(), + "Mismatched number of matrices and points" + ); + izip!(mats, points_for_mats) + .map(|(mat, points_for_mat)| { + let log_height = log2_strict_usize(mat.height()); + // It was committed in cfft order. + let evals = CircleEvaluations::from_cfft_order( + CircleDomain::standard(log_height), + mat.as_view(), + ); + points_for_mat + .iter() + .map(|&zeta| { + let zeta = Point::from_projective_line(zeta); + let ps_at_zeta = + info_span!("compute opened values with Lagrange interpolation") + .in_scope(|| evals.evaluate_at_point(zeta)); + ps_at_zeta + .iter() + .for_each(|&p| challenger.observe_algebra_element(p)); + ps_at_zeta + }) + .collect() + }) + .collect() + }) + .collect(); + + // Batch combination challenge + let alpha: Challenge = challenger.sample_algebra_element(); + + /* + We are reducing columns ("ro" = reduced opening) with powers of alpha: + ro = .. + α^n c_n + α^(n+1) c_(n+1) + .. + But we want to precompute small powers of alpha, and batch the columns. So we can do: + ro = .. + α^n (α^0 c_n + α^1 c_(n+1) + ..) + .. + reusing the α^0, α^1, etc., then at the end of each column batch we multiply by the α^n. + (Due to circle stark specifics, we need 2 powers of α for each column, so actually α^(2n)). + We store this α^(2n), the running reducing factor per log_height, and call it the "alpha offset". + */ + + // log_height -> (alpha offset, reduced openings column) + let mut reduced_openings: BTreeMap)> = BTreeMap::new(); + + rounds + .iter() + .zip(values.iter()) + .for_each(|((data, points_for_mats), values)| { + let mats = self.mmcs.get_matrices(data); + izip!(mats, points_for_mats, values).for_each(|(mat, points_for_mat, values)| { + let log_height = log2_strict_usize(mat.height()); + // It was committed in cfft order. + let evals = CircleEvaluations::from_cfft_order( + CircleDomain::standard(log_height), + mat.as_view(), + ); + + let (alpha_offset, reduced_opening_for_log_height) = + reduced_openings.entry(log_height).or_insert_with(|| { + (Challenge::ONE, vec![Challenge::ZERO; 1 << log_height]) + }); + + points_for_mat + .iter() + .zip(values.iter()) + .for_each(|(&zeta, ps_at_zeta)| { + let zeta = Point::from_projective_line(zeta); + + // Reduce this matrix, as a deep quotient, into one column with powers of α. + let mat_ros = evals.deep_quotient_reduce(alpha, zeta, ps_at_zeta); + + // Fold it into our running reduction, offset by alpha_offset. + reduced_opening_for_log_height + .par_iter_mut() + .zip(mat_ros) + .for_each(|(ro, mat_ro)| { + *ro += *alpha_offset * mat_ro; + }); + + // Update alpha_offset from α^i -> α^(i + 2 * width) + *alpha_offset *= alpha.exp_u64(2 * evals.values.width() as u64); + }); + }); + }); + + // Iterate over our reduced columns and extract lambda - the multiple of the vanishing polynomial + // which may appear in the reduced quotient due to CFFT dimension gap. + + let mut lambdas = vec![]; + let mut log_heights = vec![]; + let first_layer_mats: Vec> = reduced_openings + .into_iter() + .map(|(log_height, (_, mut ro))| { + assert!(log_height > 0); + log_heights.push(log_height); + let lambda = extract_lambda(&mut ro, self.fri_config.log_blowup); + lambdas.push(lambda); + // Prepare for first layer fold with 2 siblings per leaf. + RowMajorMatrix::new(ro, 2) + }) + .collect(); + let log_max_height = log_heights.iter().max().copied().unwrap(); + + // Commit to reduced openings at each log_height, so we can challenge a global + // folding factor for all first layers, which we use for a "manual" (not part of p3-fri) fold. + // This is necessary because the first layer of folding uses different twiddles, so it's easiest + // to do it here, before p3-fri. + + let (first_layer_commitment, first_layer_data) = + self.fri_config.mmcs.commit(first_layer_mats); + challenger.observe(first_layer_commitment.clone()); + let bivariate_beta: Challenge = challenger.sample_algebra_element(); + + // Fold all first layers at bivariate_beta. + + let fri_input: Vec> = self + .fri_config + .mmcs + .get_matrices(&first_layer_data) + .into_iter() + .map(|m| fold_y(bivariate_beta, m.as_view())) + // Reverse, because FRI expects descending by height + .rev() + .collect(); + + let g: CircleFriConfig = + CircleFriGenericConfig(PhantomData); + + let fri_proof = prove(&g, &self.fri_config, fri_input, challenger, |index| { + // CircleFriFolder asks for an extra query index bit, so we use that here to index + // the first layer fold. + + // Open the input (big opening, lots of columns) at the full index... + let input_openings = rounds + .iter() + .map(|(data, _)| { + let log_max_batch_height = log2_strict_usize(self.mmcs.get_max_height(data)); + let reduced_index = index >> (log_max_height - log_max_batch_height); + let (opened_values, opening_proof) = self.mmcs.open_batch(reduced_index, data); + BatchOpening { + opened_values, + opening_proof, + } + }) + .collect(); + + // We committed to first_layer in pairs, so open the reduced index and include the sibling + // as part of the input proof. + let (first_layer_values, first_layer_proof) = self + .fri_config + .mmcs + .open_batch(index >> 1, &first_layer_data); + let first_layer_siblings = izip!(&first_layer_values, &log_heights) + .map(|(v, log_height)| { + let reduced_index = index >> (log_max_height - log_height); + let sibling_index = (reduced_index & 1) ^ 1; + v[sibling_index] + }) + .collect(); + CircleInputProof { + input_openings, + first_layer_siblings, + first_layer_proof, + } + }); + + ( + values, + CirclePcsProof { + first_layer_commitment, + lambdas, + fri_proof, + }, + ) + } + + fn verify( + &self, + // For each round: + rounds: Vec<( + Self::Commitment, + // for each matrix: + Vec<( + // its domain, + Self::Domain, + // for each point: + Vec<( + // the point, + Challenge, + // values at the point + Vec, + )>, + )>, + )>, + proof: &Self::Proof, + challenger: &mut Challenger, + ) -> Result<(), Self::Error> { + // Write evaluations to challenger + for (_, round) in &rounds { + for (_, mat) in round { + for (_, point) in mat { + point + .iter() + .for_each(|&opening| challenger.observe_algebra_element(opening)); + } + } + } + + // Batch combination challenge + let alpha: Challenge = challenger.sample_algebra_element(); + challenger.observe(proof.first_layer_commitment.clone()); + let bivariate_beta: Challenge = challenger.sample_algebra_element(); + + // +1 to account for first layer + let log_global_max_height = + proof.fri_proof.commit_phase_commits.len() + self.fri_config.log_blowup + 1; + + let g: CircleFriConfig = + CircleFriGenericConfig(PhantomData); + + verify( + &g, + &self.fri_config, + &proof.fri_proof, + challenger, + |index, input_proof| { + // log_height -> (alpha_offset, ro) + let mut reduced_openings = BTreeMap::new(); + + let CircleInputProof { + input_openings, + first_layer_siblings, + first_layer_proof, + } = input_proof; + + for (batch_opening, (batch_commit, mats)) in + zip_eq(input_openings, &rounds, InputError::InputShapeError)? + { + let batch_heights: Vec = mats + .iter() + .map(|(domain, _)| (domain.size() << self.fri_config.log_blowup)) + .collect_vec(); + let batch_dims: Vec = batch_heights + .iter() + // todo: mmcs doesn't really need width + .map(|&height| Dimensions { width: 0, height }) + .collect_vec(); + + let (dims, idx) = if let Some(log_batch_max_height) = + batch_heights.iter().max().map(|x| log2_strict_usize(*x)) + { + ( + &batch_dims[..], + index >> (log_global_max_height - log_batch_max_height), + ) + } else { + // Empty batch? + (&[][..], 0) + }; + + self.mmcs + .verify_batch( + batch_commit, + dims, + idx, + &batch_opening.opened_values, + &batch_opening.opening_proof, + ) + .map_err(InputError::InputMmcsError)?; + + for (ps_at_x, (mat_domain, mat_points_and_values)) in zip_eq( + &batch_opening.opened_values, + mats, + InputError::InputShapeError, + )? { + let log_height = mat_domain.log_n + self.fri_config.log_blowup; + let bits_reduced = log_global_max_height - log_height; + let orig_idx = cfft_permute_index(index >> bits_reduced, log_height); + + let committed_domain = CircleDomain::standard(log_height); + let x = committed_domain.nth_point(orig_idx); + + let (alpha_offset, ro) = reduced_openings + .entry(log_height) + .or_insert((Challenge::ONE, Challenge::ZERO)); + let alpha_pow_width_2 = alpha.exp_u64(ps_at_x.len() as u64).square(); + + for (zeta_uni, ps_at_zeta) in mat_points_and_values { + let zeta = Point::from_projective_line(*zeta_uni); + + *ro += *alpha_offset + * deep_quotient_reduce_row(alpha, x, zeta, ps_at_x, ps_at_zeta); + + *alpha_offset *= alpha_pow_width_2; + } + } + } + + // Verify bivariate fold and lambda correction + + let (mut fri_input, fl_dims, fl_leaves): (Vec<_>, Vec<_>, Vec<_>) = zip_eq( + zip_eq( + reduced_openings, + first_layer_siblings, + InputError::InputShapeError, + )?, + &proof.lambdas, + InputError::InputShapeError, + )? + .map(|(((log_height, (_, ro)), &fl_sib), &lambda)| { + assert!(log_height > 0); + + let orig_size = log_height - self.fri_config.log_blowup; + let bits_reduced = log_global_max_height - log_height; + let orig_idx = cfft_permute_index(index >> bits_reduced, log_height); + + let lde_domain = CircleDomain::standard(log_height); + let p: Point = lde_domain.nth_point(orig_idx); + + let lambda_corrected = ro - lambda * p.v_n(orig_size); + + let mut fl_values = vec![lambda_corrected; 2]; + fl_values[((index >> bits_reduced) & 1) ^ 1] = fl_sib; + + let fri_input = ( + // - 1 here is because we have already folded a layer. + log_height - 1, + fold_y_row( + index >> (bits_reduced + 1), + // - 1 here is log_arity. + log_height - 1, + bivariate_beta, + fl_values.iter().copied(), + ), + ); + + let fl_dims = Dimensions { + width: 0, + height: 1 << (log_height - 1), + }; + + (fri_input, fl_dims, fl_values) + }) + .multiunzip(); + + // sort descending + fri_input.reverse(); + + self.fri_config + .mmcs + .verify_batch( + &proof.first_layer_commitment, + &fl_dims, + index >> 1, + &fl_leaves, + first_layer_proof, + ) + .map_err(InputError::FirstLayerMmcsError)?; + + Ok(fri_input) + }, + ) + } +} + +#[cfg(test)] +mod tests { + use p3_challenger::{HashChallenger, SerializingChallenger32}; + use p3_commit::ExtensionMmcs; + use p3_field::extension::BinomialExtensionField; + use p3_fri::create_test_fri_config; + use p3_keccak::Keccak256Hash; + use p3_merkle_tree::MerkleTreeMmcs; + use p3_mersenne_31::Mersenne31; + use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher32}; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + + #[test] + fn circle_pcs() { + // Very simple pcs test. More rigorous tests in p3_fri/tests/pcs. + + let mut rng = SmallRng::seed_from_u64(0); + + type Val = Mersenne31; + type Challenge = BinomialExtensionField; + + type ByteHash = Keccak256Hash; + type FieldHash = SerializingHasher32; + let byte_hash = ByteHash {}; + let field_hash = FieldHash::new(byte_hash); + + type MyCompress = CompressionFunctionFromHasher; + let compress = MyCompress::new(byte_hash); + + type ValMmcs = MerkleTreeMmcs; + let val_mmcs = ValMmcs::new(field_hash, compress); + + type ChallengeMmcs = ExtensionMmcs; + let challenge_mmcs = ChallengeMmcs::new(val_mmcs.clone()); + + type Challenger = SerializingChallenger32>; + + let fri_config = create_test_fri_config(challenge_mmcs, 0); + + type Pcs = CirclePcs; + let pcs = Pcs { + mmcs: val_mmcs, + fri_config, + _phantom: PhantomData, + }; + + let log_n = 10; + + let d = >::natural_domain_for_degree( + &pcs, + 1 << log_n, + ); + + let evals = RowMajorMatrix::rand(&mut rng, 1 << log_n, 1); + + let (comm, data) = + >::commit(&pcs, vec![(d, evals)]); + + let zeta: Challenge = rng.random(); + + let mut chal = Challenger::from_hasher(vec![], byte_hash); + let (values, proof) = pcs.open(vec![(&data, vec![vec![zeta]])], &mut chal); + + let mut chal = Challenger::from_hasher(vec![], byte_hash); + pcs.verify( + vec![(comm, vec![(d, vec![(zeta, values[0][0][0].clone())])])], + &proof, + &mut chal, + ) + .expect("verify err"); + } +} diff --git a/CoqOfRust/plonky3/circle/src/pcs.v b/CoqOfRust/plonky3/circle/src/pcs.v new file mode 100644 index 000000000..4bf9e560d --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/pcs.v @@ -0,0 +1,25198 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module pcs. + (* StructRecord + { + name := "CirclePcs"; + const_params := []; + ty_params := [ "Val"; "InputMmcs"; "FriMmcs" ]; + fields := + [ + ("mmcs", InputMmcs); + ("fri_config", Ty.apply (Ty.path "p3_fri::config::FriConfig") [] [ FriMmcs ]); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ Val ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Val_where_p3_field_field_Field_Val_where_core_fmt_Debug_InputMmcs_where_core_fmt_Debug_FriMmcs_for_p3_circle_pcs_CirclePcs_Val_InputMmcs_FriMmcs. + Definition Self (Val InputMmcs FriMmcs : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::pcs::CirclePcs") [] [ Val; InputMmcs; FriMmcs ]. + + (* Debug *) + Definition fmt + (Val InputMmcs FriMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs FriMmcs in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "CirclePcs" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "mmcs" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "mmcs" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "fri_config" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val InputMmcs FriMmcs : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val InputMmcs FriMmcs) + (* Instance *) [ ("fmt", InstanceField.Method (fmt Val InputMmcs FriMmcs)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Val_where_p3_field_field_Field_Val_where_core_fmt_Debug_InputMmcs_where_core_fmt_Debug_FriMmcs_for_p3_circle_pcs_CirclePcs_Val_InputMmcs_FriMmcs. + + Module Impl_p3_circle_pcs_CirclePcs_Val_InputMmcs_FriMmcs. + Definition Self (Val InputMmcs FriMmcs : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::pcs::CirclePcs") [] [ Val; InputMmcs; FriMmcs ]. + + (* + pub const fn new(mmcs: InputMmcs, fri_config: FriConfig) -> Self { + Self { + mmcs, + fri_config, + _phantom: PhantomData, + } + } + *) + Definition new + (Val InputMmcs FriMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs FriMmcs in + match ε, τ, α with + | [], [], [ mmcs; fri_config ] => + ltac:(M.monadic + (let mmcs := M.alloc (| mmcs |) in + let fri_config := M.alloc (| fri_config |) in + Value.StructRecord + "p3_circle::pcs::CirclePcs" + [ + ("mmcs", M.read (| mmcs |)); + ("fri_config", M.read (| fri_config |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (Val InputMmcs FriMmcs : Ty.t), + M.IsAssociatedFunction.C (Self Val InputMmcs FriMmcs) "new" (new Val InputMmcs FriMmcs). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_circle_pcs_CirclePcs_Val_InputMmcs_FriMmcs. + + (* StructRecord + { + name := "BatchOpening"; + const_params := []; + ty_params := [ "Val"; "InputMmcs" ]; + fields := + [ + ("opened_values", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]); + ("opening_proof", + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Proof") + ]; + } *) + + Module underscore. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_circle_pcs_BatchOpening_Val_InputMmcs. + Definition Self (Val InputMmcs : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::pcs::BatchOpening") [] [ Val; InputMmcs ]. + + (* Serialize *) + Definition serialize + (Val InputMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "BatchOpening" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "opened_values" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::BatchOpening", + "opened_values" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Proof" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "opening_proof" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::BatchOpening", + "opening_proof" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val InputMmcs : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val InputMmcs) + (* Instance *) [ ("serialize", InstanceField.Method (serialize Val InputMmcs)) ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_circle_pcs_BatchOpening_Val_InputMmcs. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_circle_pcs_BatchOpening_Val_InputMmcs. + Definition Self (Val InputMmcs : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::pcs::BatchOpening") [] [ Val; InputMmcs ]. + + (* Deserialize *) + Definition deserialize + (Val InputMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_circle::pcs::BatchOpening") [] [ Val; InputMmcs ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_circle::pcs::_'1::deserialize::__Visitor") + [] + [ Val; InputMmcs ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "BatchOpening" |); + M.read (| + get_constant (| + "p3_circle::pcs::_'1::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_circle::pcs::_'1::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val InputMmcs : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val InputMmcs) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize Val InputMmcs)) ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_circle_pcs_BatchOpening_Val_InputMmcs. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_Val_where_p3_field_field_Field_Challenge_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_for_p3_circle_pcs_CircleInputProof_Val_Challenge_InputMmcs_FriMmcs. + Definition Self (Val Challenge InputMmcs FriMmcs : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]. + + (* Serialize *) + Definition serialize + (Val Challenge InputMmcs FriMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Challenge InputMmcs FriMmcs in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "CircleInputProof" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "input_openings" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CircleInputProof", + "input_openings" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "first_layer_siblings" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CircleInputProof", + "first_layer_siblings" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Proof" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "first_layer_proof" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CircleInputProof", + "first_layer_proof" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Challenge InputMmcs FriMmcs : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val Challenge InputMmcs FriMmcs) + (* Instance *) + [ ("serialize", InstanceField.Method (serialize Val Challenge InputMmcs FriMmcs)) ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_Val_where_p3_field_field_Field_Challenge_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_for_p3_circle_pcs_CircleInputProof_Val_Challenge_InputMmcs_FriMmcs. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_Val_where_p3_field_field_Field_Challenge_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_for_p3_circle_pcs_CircleInputProof_Val_Challenge_InputMmcs_FriMmcs. + Definition Self (Val Challenge InputMmcs FriMmcs : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]. + + (* Deserialize *) + Definition deserialize + (Val Challenge InputMmcs FriMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Challenge InputMmcs FriMmcs in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_circle::pcs::_'3::deserialize::__Visitor") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "CircleInputProof" |); + M.read (| + get_constant (| + "p3_circle::pcs::_'3::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_circle::pcs::_'3::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Challenge InputMmcs FriMmcs : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val Challenge InputMmcs FriMmcs) + (* Instance *) + [ ("deserialize", InstanceField.Method (deserialize Val Challenge InputMmcs FriMmcs)) ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_Val_where_p3_field_field_Field_Challenge_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_for_p3_circle_pcs_CircleInputProof_Val_Challenge_InputMmcs_FriMmcs. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_Val_where_p3_field_field_Field_Challenge_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_serde_ser_Serialize_Witness_for_p3_circle_pcs_CirclePcsProof_Val_Challenge_InputMmcs_FriMmcs_Witness. + Definition Self (Val Challenge InputMmcs FriMmcs Witness : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcsProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs; Witness ]. + + (* Serialize *) + Definition serialize + (Val Challenge InputMmcs FriMmcs Witness : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Challenge InputMmcs FriMmcs Witness in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "CirclePcsProof" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "first_layer_commitment" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcsProof", + "first_layer_commitment" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "lambdas" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcsProof", + "lambdas" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleFriProof") + [] + [ + Challenge; + FriMmcs; + Witness; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "fri_proof" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcsProof", + "fri_proof" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Challenge InputMmcs FriMmcs Witness : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val Challenge InputMmcs FriMmcs Witness) + (* Instance *) + [ ("serialize", InstanceField.Method (serialize Val Challenge InputMmcs FriMmcs Witness)) + ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_Val_where_p3_field_field_Field_Challenge_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_serde_ser_Serialize_Witness_for_p3_circle_pcs_CirclePcsProof_Val_Challenge_InputMmcs_FriMmcs_Witness. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_Val_where_p3_field_field_Field_Challenge_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_serde_de_Deserialize_Witness_for_p3_circle_pcs_CirclePcsProof_Val_Challenge_InputMmcs_FriMmcs_Witness. + Definition Self (Val Challenge InputMmcs FriMmcs Witness : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcsProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs; Witness ]. + + (* Deserialize *) + Definition deserialize + (Val Challenge InputMmcs FriMmcs Witness : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Challenge InputMmcs FriMmcs Witness in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcsProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs; Witness ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_circle::pcs::_'5::deserialize::__Visitor") + [] + [ Val; Challenge; InputMmcs; FriMmcs; Witness ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "CirclePcsProof" |); + M.read (| + get_constant (| + "p3_circle::pcs::_'5::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_circle::pcs::_'5::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Challenge InputMmcs FriMmcs Witness : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val Challenge InputMmcs FriMmcs Witness) + (* Instance *) + [ + ("deserialize", + InstanceField.Method (deserialize Val Challenge InputMmcs FriMmcs Witness)) + ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_Val_where_p3_field_field_Field_Challenge_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_serde_de_Deserialize_Witness_for_p3_circle_pcs_CirclePcsProof_Val_Challenge_InputMmcs_FriMmcs_Witness. + End underscore. + + + Module Impl_core_clone_Clone_where_core_clone_Clone_Val_where_p3_field_field_Field_Val_where_core_clone_Clone_InputMmcs_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_circle_pcs_BatchOpening_Val_InputMmcs. + Definition Self (Val InputMmcs : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::pcs::BatchOpening") [] [ Val; InputMmcs ]. + + (* Clone *) + Definition clone + (Val InputMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_circle::pcs::BatchOpening" + [ + ("opened_values", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::BatchOpening", + "opened_values" + |) + |) + |) + |) + ] + |)); + ("opening_proof", + M.call_closure (| + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Proof", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Proof", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::BatchOpening", + "opening_proof" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val InputMmcs : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val InputMmcs) + (* Instance *) [ ("clone", InstanceField.Method (clone Val InputMmcs)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_Val_where_p3_field_field_Field_Val_where_core_clone_Clone_InputMmcs_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_circle_pcs_BatchOpening_Val_InputMmcs. + + (* StructRecord + { + name := "CircleInputProof"; + const_params := []; + ty_params := [ "Val"; "Challenge"; "InputMmcs"; "FriMmcs" ]; + fields := + [ + ("input_openings", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::pcs::BatchOpening") [] [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ]); + ("first_layer_siblings", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Challenge; Ty.path "alloc::alloc::Global" ]); + ("first_layer_proof", + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] FriMmcs "Proof") + ]; + } *) + + + + Module Impl_core_clone_Clone_where_core_clone_Clone_Val_where_p3_field_field_Field_Val_where_core_clone_Clone_Challenge_where_p3_field_field_Field_Challenge_where_core_clone_Clone_InputMmcs_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_core_clone_Clone_FriMmcs_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__Challenge_FriMmcs_Proof_for_p3_circle_pcs_CircleInputProof_Val_Challenge_InputMmcs_FriMmcs. + Definition Self (Val Challenge InputMmcs FriMmcs : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]. + + (* Clone *) + Definition clone + (Val Challenge InputMmcs FriMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Challenge InputMmcs FriMmcs in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_circle::pcs::CircleInputProof" + [ + ("input_openings", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::pcs::BatchOpening") [] [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::pcs::BatchOpening") [] [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CircleInputProof", + "input_openings" + |) + |) + |) + |) + ] + |)); + ("first_layer_siblings", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CircleInputProof", + "first_layer_siblings" + |) + |) + |) + |) + ] + |)); + ("first_layer_proof", + M.call_closure (| + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] FriMmcs "Proof", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] FriMmcs "Proof", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CircleInputProof", + "first_layer_proof" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Challenge InputMmcs FriMmcs : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val Challenge InputMmcs FriMmcs) + (* Instance *) [ ("clone", InstanceField.Method (clone Val Challenge InputMmcs FriMmcs)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_Val_where_p3_field_field_Field_Val_where_core_clone_Clone_Challenge_where_p3_field_field_Field_Challenge_where_core_clone_Clone_InputMmcs_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_core_clone_Clone_FriMmcs_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__Challenge_FriMmcs_Proof_for_p3_circle_pcs_CircleInputProof_Val_Challenge_InputMmcs_FriMmcs. + + (* + Enum InputError + { + const_params := []; + ty_params := [ "InputMmcsError"; "FriMmcsError" ]; + variants := + [ + { + name := "InputMmcsError"; + item := StructTuple [ InputMmcsError ]; + }; + { + name := "FirstLayerMmcsError"; + item := StructTuple [ FriMmcsError ]; + }; + { + name := "InputShapeError"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_InputError_InputMmcsError : + M.IsDiscriminant "p3_circle::pcs::InputError::InputMmcsError" 0. + Axiom IsDiscriminant_InputError_FirstLayerMmcsError : + M.IsDiscriminant "p3_circle::pcs::InputError::FirstLayerMmcsError" 1. + Axiom IsDiscriminant_InputError_InputShapeError : + M.IsDiscriminant "p3_circle::pcs::InputError::InputShapeError" 2. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_InputMmcsError_where_core_fmt_Debug_FriMmcsError_for_p3_circle_pcs_InputError_InputMmcsError_FriMmcsError. + Definition Self (InputMmcsError FriMmcsError : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::pcs::InputError") [] [ InputMmcsError; FriMmcsError ]. + + (* Debug *) + Definition fmt + (InputMmcsError FriMmcsError : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self InputMmcsError FriMmcsError in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_circle::pcs::InputError::InputMmcsError", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "InputMmcsError" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_circle::pcs::InputError::FirstLayerMmcsError", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "FirstLayerMmcsError" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| γ, "p3_circle::pcs::InputError::InputShapeError" |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "InputShapeError" |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (InputMmcsError FriMmcsError : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self InputMmcsError FriMmcsError) + (* Instance *) [ ("fmt", InstanceField.Method (fmt InputMmcsError FriMmcsError)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_InputMmcsError_where_core_fmt_Debug_FriMmcsError_for_p3_circle_pcs_InputError_InputMmcsError_FriMmcsError. + + (* StructRecord + { + name := "CirclePcsProof"; + const_params := []; + ty_params := [ "Val"; "Challenge"; "InputMmcs"; "FriMmcs"; "Witness" ]; + fields := + [ + ("first_layer_commitment", + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] FriMmcs "Commitment"); + ("lambdas", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Challenge; Ty.path "alloc::alloc::Global" ]); + ("fri_proof", + Ty.apply + (Ty.path "p3_circle::proof::CircleFriProof") + [] + [ + Challenge; + FriMmcs; + Witness; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ]) + ]; + } *) + + + + Module Impl_core_clone_Clone_where_core_clone_Clone_Val_where_p3_field_field_Field_Val_where_core_clone_Clone_Challenge_where_p3_field_field_Field_Challenge_where_core_clone_Clone_InputMmcs_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_core_clone_Clone_FriMmcs_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_core_clone_Clone_Witness_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__Challenge_FriMmcs_Commitment_for_p3_circle_pcs_CirclePcsProof_Val_Challenge_InputMmcs_FriMmcs_Witness. + Definition Self (Val Challenge InputMmcs FriMmcs Witness : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcsProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs; Witness ]. + + (* Clone *) + Definition clone + (Val Challenge InputMmcs FriMmcs Witness : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Challenge InputMmcs FriMmcs Witness in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_circle::pcs::CirclePcsProof" + [ + ("first_layer_commitment", + M.call_closure (| + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcsProof", + "first_layer_commitment" + |) + |) + |) + |) + ] + |)); + ("lambdas", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcsProof", + "lambdas" + |) + |) + |) + |) + ] + |)); + ("fri_proof", + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::proof::CircleFriProof") + [] + [ + Challenge; + FriMmcs; + Witness; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_circle::proof::CircleFriProof") + [] + [ + Challenge; + FriMmcs; + Witness; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcsProof", + "fri_proof" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Challenge InputMmcs FriMmcs Witness : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val Challenge InputMmcs FriMmcs Witness) + (* Instance *) + [ ("clone", InstanceField.Method (clone Val Challenge InputMmcs FriMmcs Witness)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_Val_where_p3_field_field_Field_Val_where_core_clone_Clone_Challenge_where_p3_field_field_Field_Challenge_where_core_clone_Clone_InputMmcs_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_core_clone_Clone_FriMmcs_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_core_clone_Clone_Witness_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__Challenge_FriMmcs_Commitment_for_p3_circle_pcs_CirclePcsProof_Val_Challenge_InputMmcs_FriMmcs_Witness. + + Module Impl_p3_commit_pcs_Pcs_where_p3_field_extension_complex_ComplexExtendable_Val_where_p3_field_field_ExtensionField_Challenge_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_p3_challenger_FieldChallenger_Challenger_Val_where_p3_challenger_grinding_challenger_GrindingChallenger_Challenger_where_p3_challenger_CanObserve_Challenger_associated_in_trait_p3_commit_mmcs_Mmcs__Challenge_FriMmcs_Commitment_Challenge_Challenger_for_p3_circle_pcs_CirclePcs_Val_InputMmcs_FriMmcs. + Definition Self (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::pcs::CirclePcs") [] [ Val; InputMmcs; FriMmcs ]. + + (* type Domain = CircleDomain; *) + Definition _Domain (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ]. + + (* type Commitment = InputMmcs::Commitment; *) + Definition _Commitment (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Commitment". + + (* type ProverData = InputMmcs::ProverData>; *) + Definition _ProverData (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ] ] + ] + InputMmcs + "ProverData". + + (* type EvaluationsOnDomain<'a> = RowIndexMappedView>>; *) + Definition _EvaluationsOnDomain (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_circle::ordering::CfftPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply (Ty.path "alloc::borrow::Cow") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ]. + + (* type Proof = CirclePcsProof; *) + Definition _Proof (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcsProof") + [] + [ + Val; + Challenge; + InputMmcs; + FriMmcs; + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness" + ]. + + (* type Error = FriError>; *) + Definition _Error (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] FriMmcs "Error"; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Error"; + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] FriMmcs "Error" + ] + ]. + + (* + fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain { + CircleDomain::standard(log2_strict_usize(degree)) + } + *) + Definition natural_domain_for_degree + (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs FriMmcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; degree ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let degree := M.alloc (| degree |) in + M.call_closure (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ], + "standard", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| degree |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn commit( + &self, + evaluations: Vec<(Self::Domain, RowMajorMatrix)>, + ) -> (Self::Commitment, Self::ProverData) { + let ldes = evaluations + .into_iter() + .map(|(domain, evals)| { + assert!( + domain.log_n >= 2, + "CirclePcs cannot commit to a matrix with fewer than 4 rows.", + // (because we bivariate fold one bit, and fri needs one more bit) + ); + CircleEvaluations::from_natural_order(domain, evals) + .extrapolate(CircleDomain::standard( + domain.log_n + self.fri_config.log_blowup, + )) + .to_cfft_order() + }) + .collect_vec(); + let (comm, mmcs_data) = self.mmcs.commit(ldes); + (comm, mmcs_data) + } + *) + Definition commit + (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs FriMmcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; evaluations ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let evaluations := M.alloc (| evaluations |) in + M.read (| + let~ ldes : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| evaluations |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let domain := M.copy (| γ0_0 |) in + let evals := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "CirclePcs cannot commit to a matrix with fewer than 4 rows." + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ], + "to_cfft_order", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path + "p3_circle::ordering::CfftPerm"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + "extrapolate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path + "p3_circle::ordering::CfftPerm"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "from_natural_order", + [], + [] + |), + [ M.read (| domain |); M.read (| evals |) ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ], + "standard", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + domain, + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + ] + |) + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "commit", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "mmcs" + |) + |); + M.read (| ldes |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let comm := M.copy (| γ0_0 |) in + let mmcs_data := M.copy (| γ0_1 |) in + M.alloc (| Value.Tuple [ M.read (| comm |); M.read (| mmcs_data |) ] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn get_evaluations_on_domain<'a>( + &self, + data: &'a Self::ProverData, + idx: usize, + domain: Self::Domain, + ) -> Self::EvaluationsOnDomain<'a> { + let mat = self.mmcs.get_matrices(data)[idx].as_view(); + let committed_domain = CircleDomain::standard(log2_strict_usize(mat.height())); + if domain == committed_domain { + mat.as_cow().cfft_perm_rows() + } else { + CircleEvaluations::from_cfft_order(committed_domain, mat) + .extrapolate(domain) + .to_cfft_order() + .as_cow() + .cfft_perm_rows() + } + } + *) + Definition get_evaluations_on_domain + (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs FriMmcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; data; idx; domain ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let data := M.alloc (| data |) in + let idx := M.alloc (| idx |) in + let domain := M.alloc (| domain |) in + M.read (| + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + "as_view", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "get_matrices", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| data |) |) + |) + ] + |) + |) + |); + M.read (| idx |) + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ committed_domain : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ], + "standard", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ], + [], + [ Val ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_circle::ordering::CfftPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::borrow::Cow") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ], + [], + [ Ty.apply (Ty.path "p3_circle::domain::CircleDomain") [] [ Val ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, domain |); + M.borrow (| Pointer.Kind.Ref, committed_domain |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_circle::ordering::CfftPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::borrow::Cow") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ], + M.get_trait_method (| + "p3_circle::ordering::CfftPermutable", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::borrow::Cow") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ], + [], + [ Val ], + "cfft_perm_rows", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::borrow::Cow") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ], + "as_cow", + [], + [] + |), + [ M.read (| mat |) ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_circle::ordering::CfftPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::borrow::Cow") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ], + M.get_trait_method (| + "p3_circle::ordering::CfftPermutable", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::borrow::Cow") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ], + [], + [ Val ], + "cfft_perm_rows", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::borrow::Cow") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + "as_cow", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ], + "to_cfft_order", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ], + "extrapolate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ], + "from_cfft_order", + [], + [] + |), + [ M.read (| committed_domain |); M.read (| mat |) ] + |); + M.read (| domain |) + ] + |) + ] + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn open( + &self, + // For each round, + rounds: Vec<( + &Self::ProverData, + // for each matrix, + Vec< + // points to open + Vec, + >, + )>, + challenger: &mut Challenger, + ) -> (OpenedValues, Self::Proof) { + // Open matrices at points + let values: OpenedValues = rounds + .iter() + .map(|(data, points_for_mats)| { + let mats = self.mmcs.get_matrices(data); + debug_assert_eq!( + mats.len(), + points_for_mats.len(), + "Mismatched number of matrices and points" + ); + izip!(mats, points_for_mats) + .map(|(mat, points_for_mat)| { + let log_height = log2_strict_usize(mat.height()); + // It was committed in cfft order. + let evals = CircleEvaluations::from_cfft_order( + CircleDomain::standard(log_height), + mat.as_view(), + ); + points_for_mat + .iter() + .map(|&zeta| { + let zeta = Point::from_projective_line(zeta); + let ps_at_zeta = + info_span!("compute opened values with Lagrange interpolation") + .in_scope(|| evals.evaluate_at_point(zeta)); + ps_at_zeta + .iter() + .for_each(|&p| challenger.observe_algebra_element(p)); + ps_at_zeta + }) + .collect() + }) + .collect() + }) + .collect(); + + // Batch combination challenge + let alpha: Challenge = challenger.sample_algebra_element(); + + /* + We are reducing columns ("ro" = reduced opening) with powers of alpha: + ro = .. + α^n c_n + α^(n+1) c_(n+1) + .. + But we want to precompute small powers of alpha, and batch the columns. So we can do: + ro = .. + α^n (α^0 c_n + α^1 c_(n+1) + ..) + .. + reusing the α^0, α^1, etc., then at the end of each column batch we multiply by the α^n. + (Due to circle stark specifics, we need 2 powers of α for each column, so actually α^(2n)). + We store this α^(2n), the running reducing factor per log_height, and call it the "alpha offset". + */ + + // log_height -> (alpha offset, reduced openings column) + let mut reduced_openings: BTreeMap)> = BTreeMap::new(); + + rounds + .iter() + .zip(values.iter()) + .for_each(|((data, points_for_mats), values)| { + let mats = self.mmcs.get_matrices(data); + izip!(mats, points_for_mats, values).for_each(|(mat, points_for_mat, values)| { + let log_height = log2_strict_usize(mat.height()); + // It was committed in cfft order. + let evals = CircleEvaluations::from_cfft_order( + CircleDomain::standard(log_height), + mat.as_view(), + ); + + let (alpha_offset, reduced_opening_for_log_height) = + reduced_openings.entry(log_height).or_insert_with(|| { + (Challenge::ONE, vec![Challenge::ZERO; 1 << log_height]) + }); + + points_for_mat + .iter() + .zip(values.iter()) + .for_each(|(&zeta, ps_at_zeta)| { + let zeta = Point::from_projective_line(zeta); + + // Reduce this matrix, as a deep quotient, into one column with powers of α. + let mat_ros = evals.deep_quotient_reduce(alpha, zeta, ps_at_zeta); + + // Fold it into our running reduction, offset by alpha_offset. + reduced_opening_for_log_height + .par_iter_mut() + .zip(mat_ros) + .for_each(|(ro, mat_ro)| { + *ro += *alpha_offset * mat_ro; + }); + + // Update alpha_offset from α^i -> α^(i + 2 * width) + *alpha_offset *= alpha.exp_u64(2 * evals.values.width() as u64); + }); + }); + }); + + // Iterate over our reduced columns and extract lambda - the multiple of the vanishing polynomial + // which may appear in the reduced quotient due to CFFT dimension gap. + + let mut lambdas = vec![]; + let mut log_heights = vec![]; + let first_layer_mats: Vec> = reduced_openings + .into_iter() + .map(|(log_height, (_, mut ro))| { + assert!(log_height > 0); + log_heights.push(log_height); + let lambda = extract_lambda(&mut ro, self.fri_config.log_blowup); + lambdas.push(lambda); + // Prepare for first layer fold with 2 siblings per leaf. + RowMajorMatrix::new(ro, 2) + }) + .collect(); + let log_max_height = log_heights.iter().max().copied().unwrap(); + + // Commit to reduced openings at each log_height, so we can challenge a global + // folding factor for all first layers, which we use for a "manual" (not part of p3-fri) fold. + // This is necessary because the first layer of folding uses different twiddles, so it's easiest + // to do it here, before p3-fri. + + let (first_layer_commitment, first_layer_data) = + self.fri_config.mmcs.commit(first_layer_mats); + challenger.observe(first_layer_commitment.clone()); + let bivariate_beta: Challenge = challenger.sample_algebra_element(); + + // Fold all first layers at bivariate_beta. + + let fri_input: Vec> = self + .fri_config + .mmcs + .get_matrices(&first_layer_data) + .into_iter() + .map(|m| fold_y(bivariate_beta, m.as_view())) + // Reverse, because FRI expects descending by height + .rev() + .collect(); + + let g: CircleFriConfig = + CircleFriGenericConfig(PhantomData); + + let fri_proof = prove(&g, &self.fri_config, fri_input, challenger, |index| { + // CircleFriFolder asks for an extra query index bit, so we use that here to index + // the first layer fold. + + // Open the input (big opening, lots of columns) at the full index... + let input_openings = rounds + .iter() + .map(|(data, _)| { + let log_max_batch_height = log2_strict_usize(self.mmcs.get_max_height(data)); + let reduced_index = index >> (log_max_height - log_max_batch_height); + let (opened_values, opening_proof) = self.mmcs.open_batch(reduced_index, data); + BatchOpening { + opened_values, + opening_proof, + } + }) + .collect(); + + // We committed to first_layer in pairs, so open the reduced index and include the sibling + // as part of the input proof. + let (first_layer_values, first_layer_proof) = self + .fri_config + .mmcs + .open_batch(index >> 1, &first_layer_data); + let first_layer_siblings = izip!(&first_layer_values, &log_heights) + .map(|(v, log_height)| { + let reduced_index = index >> (log_max_height - log_height); + let sibling_index = (reduced_index & 1) ^ 1; + v[sibling_index] + }) + .collect(); + CircleInputProof { + input_openings, + first_layer_siblings, + first_layer_proof, + } + }); + + ( + values, + CirclePcsProof { + first_layer_commitment, + lambdas, + fri_proof, + }, + ) + } + *) + Definition open + (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs FriMmcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; rounds; challenger ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rounds := M.alloc (| rounds |) in + let challenger := M.alloc (| challenger |) in + M.read (| + let~ values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rounds |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let data := M.alloc (| γ1_0 |) in + let points_for_mats := M.alloc (| γ1_1 |) in + M.read (| + let~ mats : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "get_matrices", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| M.deref (| M.read (| data |) |) |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + mats + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + points_for_mats + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path + "usize"; + Ty.path + "usize" + ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Mismatched number of matrices and points" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| mats |) ] + |); + M.read (| points_for_mats |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let mat := + M.copy (| γ0_0 |) in + let points_for_mat := + M.copy (| γ0_1 |) in + M.read (| + let~ log_height : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ Val ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |) + ] + |) + ] + |) + |) in + let~ evals : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ], + "from_cfft_order", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ], + "standard", + [], + [] + |), + [ + M.read (| + log_height + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ], + "as_view", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + points_for_mat + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ + with + | [ α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + zeta := + M.copy (| + γ + |) in + M.read (| + let~ + zeta : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Challenge + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Challenge + ], + "from_projective_line", + [], + [] + |), + [ + M.read (| + zeta + |) + ] + |) + |) in + let~ + ps_at_zeta : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.path + "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ + Ty.tuple + [] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]); + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ + interest : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing_core::subscriber::Interest" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing::span::Span" + ], + M.alloc (| + Value.Tuple + [] + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::pcs::open::{{closure}}::{{closure}}::{{closure}}::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path + "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::pcs::open::{{closure}}::{{closure}}::{{closure}}::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| + interest + |) + ] + |))) + |) + |)) in + let + _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + let~ + meta : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::pcs::open::{{closure}}::{{closure}}::{{closure}}::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::Span", + M.get_associated_function (| + Ty.path + "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun + γ => + ltac:(M.monadic + (let~ + span : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing::span::Span" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::pcs::open::{{closure}}::{{closure}}::{{closure}}::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + Value.Tuple + [] + |) in + span)) + ] + |) + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ], + "evaluate_at_point", + [], + [ + Challenge + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + evals + |); + M.read (| + zeta + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.tuple + []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + ps_at_zeta + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.tuple + []) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + p := + M.copy (| + γ + |) in + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ + Val + ], + "observe_algebra_element", + [], + [ + Challenge + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + challenger + |) + |) + |); + M.read (| + p + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + ps_at_zeta + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ alpha : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "sample_algebra_element", + [], + [ Challenge ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |) ] + |) + |) in + let~ reduced_openings : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rounds |) ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, values |) ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let data := M.alloc (| γ2_0 |) in + let points_for_mats := M.alloc (| γ2_1 |) in + let values := M.copy (| γ0_1 |) in + M.read (| + let~ mats : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "get_matrices", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| M.deref (| M.read (| data |) |) |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]) + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| mats |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| points_for_mats |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ M.read (| iter |); M.read (| values |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := + M.copy (| γ1_0 |) in + let b := + M.copy (| γ1_1 |) in + let b := + M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let mat := M.copy (| γ0_0 |) in + let points_for_mat := + M.copy (| γ0_1 |) in + let values := M.copy (| γ0_2 |) in + M.read (| + let~ log_height : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ Val ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| mat |) + |) + |) + ] + |) + ] + |) + |) in + let~ evals : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ], + "from_cfft_order", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ], + "standard", + [], + [] + |), + [ + M.read (| + log_height + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ], + "as_view", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| mat |) + |) + |) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + "or_insert_with", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + "entry", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + reduced_openings + |); + M.read (| + log_height + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [] + ] + (Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]) + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (Value.Tuple + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Challenge + |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_function (| + "alloc::vec::from_elem", + [], + [ + Challenge + ] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Challenge + |) + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shl, + [ + Value.Integer + IntegerKind.Usize + 1; + M.read (| + log_height + |) + ] + |) + ] + |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let alpha_offset := + M.alloc (| γ1_0 |) in + let + reduced_opening_for_log_height := + M.alloc (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + points_for_mat + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + values + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ + with + | [ α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + []) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + γ0_0 := + M.read (| + γ0_0 + |) in + let + zeta := + M.copy (| + γ0_0 + |) in + let + ps_at_zeta := + M.copy (| + γ0_1 + |) in + M.read (| + let~ + zeta : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Challenge + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Challenge + ], + "from_projective_line", + [], + [] + |), + [ + M.read (| + zeta + |) + ] + |) + |) in + let~ + mat_ros : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::cfft::CircleEvaluations") + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ], + "deep_quotient_reduce", + [], + [ + Challenge + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + evals + |); + M.read (| + alpha + |); + M.read (| + zeta + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + ps_at_zeta + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Challenge + ]; + Challenge + ] + ] + ] + (Ty.tuple + []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Challenge + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Challenge + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelRefMutIterator", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "par_iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + reduced_opening_for_log_height + |) + |) + |) + ] + |); + M.read (| + mat_ros + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Challenge + ]; + Challenge + ] + ] + ] + (Ty.tuple + []) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + ro := + M.copy (| + γ0_0 + |) in + let + mat_ro := + M.copy (| + γ0_1 + |) in + M.read (| + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Challenge, + [], + [ + Challenge + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + ro + |) + |) + |); + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Mul", + Challenge, + [], + [ + Challenge + ], + "mul", + [], + [] + |), + [ + M.read (| + M.deref (| + M.read (| + alpha_offset + |) + |) + |); + M.read (| + mat_ro + |) + ] + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Challenge, + [], + [ + Challenge + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + alpha_offset + |) + |) + |); + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Challenge, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + alpha + |); + M.call_closure (| + Ty.path + "u64", + BinOp.Wrap.mul, + [ + Value.Integer + IntegerKind.U64 + 2; + M.cast + (Ty.path + "u64") + (M.call_closure (| + Ty.path + "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ], + [], + [ + Val + ], + "width", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + evals, + "p3_circle::cfft::CircleEvaluations", + "values" + |) + |) + ] + |)) + ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |) + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ lambdas : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) in + let~ log_heights : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "usize"; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "usize"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "usize"; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) in + let~ first_layer_mats : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| reduced_openings |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let log_height := M.copy (| γ0_0 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_1, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_1, 1 |) in + let ro := M.copy (| γ1_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.read (| log_height |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic", + [], + [] + |), + [ + mk_str (| + "assertion failed: log_height > 0" + |) + ] + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "usize"; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, log_heights |); + M.read (| log_height |) + ] + |) + |) in + let~ lambda : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_function (| + "p3_circle::deep_quotient::extract_lambda", + [], + [ Val; Challenge ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Challenge ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + ro + |) + |) + |) + ] + |) + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, lambdas |); + M.read (| lambda |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ M.read (| ro |); Value.Integer IntegerKind.Usize 2 + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ log_max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "usize" ] ], + "copied", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "usize" ], + [], + [], + "max", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "usize" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "usize" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "usize"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, log_heights |) ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcsProof") + [] + [ + Val; + Challenge; + InputMmcs; + FriMmcs; + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness" + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + FriMmcs + "ProverData" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + FriMmcs, + [], + [ Challenge ], + "commit", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.read (| first_layer_mats |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let first_layer_commitment := M.copy (| γ0_0 |) in + let first_layer_data := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Challenger, + [], + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment" + ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, first_layer_commitment |) ] + |) + ] + |) + |) in + let~ bivariate_beta : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "sample_algebra_element", + [], + [ Challenge ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |) + ] + |) + |) in + let~ fri_input : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]) + ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]) + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]) + ], + [], + [], + "rev", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + FriMmcs, + [], + [ Challenge ], + "get_matrices", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, first_layer_data |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_circle::folding::fold_y", + [], + [ + Val; + Challenge; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Challenge ] + ] + ] + ] + |), + [ + M.read (| bivariate_beta |); + M.call_closure (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Challenge ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ], + "as_view", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| m |) |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + |) + |) in + let~ g : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::folding::CircleFriGenericConfig") + [] + [ + Val; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ] + ] := + M.alloc (| + Value.StructTuple + "p3_circle::folding::CircleFriGenericConfig" + [ Value.StructTuple "core::marker::PhantomData" [] ] + |) in + let~ fri_proof : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleFriProof") + [] + [ + Challenge; + FriMmcs; + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness"; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::proof::CircleFriProof") + [] + [ + Challenge; + FriMmcs; + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness"; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ], + M.get_function (| + "p3_circle::prover::prove", + [], + [ + Ty.apply + (Ty.path "p3_circle::folding::CircleFriGenericConfig") + [] + [ + Val; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ]; + Val; + Challenge; + FriMmcs; + Challenger; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]) + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, g |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |) + |) + |) + |); + M.read (| fri_input |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let index := M.copy (| γ |) in + M.read (| + let~ input_openings : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + rounds + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let data := + M.alloc (| + γ1_0 + |) in + M.read (| + let~ + log_max_batch_height : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "usize", + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "get_max_height", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_circle::pcs::CirclePcs", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| + data + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) in + let~ reduced_index : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_max_height + |); + M.read (| + log_max_batch_height + |) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Proof" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "open_batch", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_circle::pcs::CirclePcs", + "mmcs" + |) + |); + M.read (| + reduced_index + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| + data + |) + |) + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + opened_values := + M.copy (| + γ0_0 + |) in + let + opening_proof := + M.copy (| + γ0_1 + |) in + M.alloc (| + Value.StructRecord + "p3_circle::pcs::BatchOpening" + [ + ("opened_values", + M.read (| + opened_values + |)); + ("opening_proof", + M.read (| + opening_proof + |)) + ] + |))) + ] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Proof" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + FriMmcs, + [], + [ Challenge ], + "open_batch", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.read (| index |); + Value.Integer IntegerKind.I32 1 + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + first_layer_data + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let first_layer_values := + M.copy (| γ0_0 |) in + let first_layer_proof := + M.copy (| γ0_1 |) in + let~ first_layer_siblings : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "usize" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "usize" + ] + ] + ] + ] + Challenge + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "usize" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + ] + Challenge + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "usize" ] + ], + [], + [], + "map", + [], + [ + Challenge; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + ] + Challenge + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path "usize"; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + first_layer_values + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + log_heights + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + ] + Challenge + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let v := + M.copy (| + γ0_0 + |) in + let + log_height := + M.copy (| + γ0_1 + |) in + M.read (| + let~ + reduced_index : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + M.call_closure (| + Ty.path + "usize", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.path + "usize", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ], + "sub", + [], + [] + |), + [ + M.read (| + log_max_height + |); + M.read (| + log_height + |) + ] + |) + ] + |) + |) in + let~ + sibling_index : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.bit_xor, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.bit_and, + [ + M.read (| + reduced_index + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + |) in + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.path + "usize" + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + v + |) + |) + |); + M.read (| + sibling_index + |) + ] + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_circle::pcs::CircleInputProof" + [ + ("input_openings", + M.read (| input_openings |)); + ("first_layer_siblings", + M.read (| first_layer_siblings |)); + ("first_layer_proof", + M.read (| first_layer_proof |)) + ] + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.read (| values |); + Value.StructRecord + "p3_circle::pcs::CirclePcsProof" + [ + ("first_layer_commitment", M.read (| first_layer_commitment |)); + ("lambdas", M.read (| lambdas |)); + ("fri_proof", M.read (| fri_proof |)) + ] + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn verify( + &self, + // For each round: + rounds: Vec<( + Self::Commitment, + // for each matrix: + Vec<( + // its domain, + Self::Domain, + // for each point: + Vec<( + // the point, + Challenge, + // values at the point + Vec, + )>, + )>, + )>, + proof: &Self::Proof, + challenger: &mut Challenger, + ) -> Result<(), Self::Error> { + // Write evaluations to challenger + for (_, round) in &rounds { + for (_, mat) in round { + for (_, point) in mat { + point + .iter() + .for_each(|&opening| challenger.observe_algebra_element(opening)); + } + } + } + + // Batch combination challenge + let alpha: Challenge = challenger.sample_algebra_element(); + challenger.observe(proof.first_layer_commitment.clone()); + let bivariate_beta: Challenge = challenger.sample_algebra_element(); + + // +1 to account for first layer + let log_global_max_height = + proof.fri_proof.commit_phase_commits.len() + self.fri_config.log_blowup + 1; + + let g: CircleFriConfig = + CircleFriGenericConfig(PhantomData); + + verify( + &g, + &self.fri_config, + &proof.fri_proof, + challenger, + |index, input_proof| { + // log_height -> (alpha_offset, ro) + let mut reduced_openings = BTreeMap::new(); + + let CircleInputProof { + input_openings, + first_layer_siblings, + first_layer_proof, + } = input_proof; + + for (batch_opening, (batch_commit, mats)) in + zip_eq(input_openings, &rounds, InputError::InputShapeError)? + { + let batch_heights: Vec = mats + .iter() + .map(|(domain, _)| (domain.size() << self.fri_config.log_blowup)) + .collect_vec(); + let batch_dims: Vec = batch_heights + .iter() + // todo: mmcs doesn't really need width + .map(|&height| Dimensions { width: 0, height }) + .collect_vec(); + + let (dims, idx) = if let Some(log_batch_max_height) = + batch_heights.iter().max().map(|x| log2_strict_usize( *x)) + { + ( + &batch_dims[..], + index >> (log_global_max_height - log_batch_max_height), + ) + } else { + // Empty batch? + (&[][..], 0) + }; + + self.mmcs + .verify_batch( + batch_commit, + dims, + idx, + &batch_opening.opened_values, + &batch_opening.opening_proof, + ) + .map_err(InputError::InputMmcsError)?; + + for (ps_at_x, (mat_domain, mat_points_and_values)) in zip_eq( + &batch_opening.opened_values, + mats, + InputError::InputShapeError, + )? { + let log_height = mat_domain.log_n + self.fri_config.log_blowup; + let bits_reduced = log_global_max_height - log_height; + let orig_idx = cfft_permute_index(index >> bits_reduced, log_height); + + let committed_domain = CircleDomain::standard(log_height); + let x = committed_domain.nth_point(orig_idx); + + let (alpha_offset, ro) = reduced_openings + .entry(log_height) + .or_insert((Challenge::ONE, Challenge::ZERO)); + let alpha_pow_width_2 = alpha.exp_u64(ps_at_x.len() as u64).square(); + + for (zeta_uni, ps_at_zeta) in mat_points_and_values { + let zeta = Point::from_projective_line( *zeta_uni); + + *ro += *alpha_offset + * deep_quotient_reduce_row(alpha, x, zeta, ps_at_x, ps_at_zeta); + + *alpha_offset *= alpha_pow_width_2; + } + } + } + + // Verify bivariate fold and lambda correction + + let (mut fri_input, fl_dims, fl_leaves): (Vec<_>, Vec<_>, Vec<_>) = zip_eq( + zip_eq( + reduced_openings, + first_layer_siblings, + InputError::InputShapeError, + )?, + &proof.lambdas, + InputError::InputShapeError, + )? + .map(|(((log_height, (_, ro)), &fl_sib), &lambda)| { + assert!(log_height > 0); + + let orig_size = log_height - self.fri_config.log_blowup; + let bits_reduced = log_global_max_height - log_height; + let orig_idx = cfft_permute_index(index >> bits_reduced, log_height); + + let lde_domain = CircleDomain::standard(log_height); + let p: Point = lde_domain.nth_point(orig_idx); + + let lambda_corrected = ro - lambda * p.v_n(orig_size); + + let mut fl_values = vec![lambda_corrected; 2]; + fl_values[((index >> bits_reduced) & 1) ^ 1] = fl_sib; + + let fri_input = ( + // - 1 here is because we have already folded a layer. + log_height - 1, + fold_y_row( + index >> (bits_reduced + 1), + // - 1 here is log_arity. + log_height - 1, + bivariate_beta, + fl_values.iter().copied(), + ), + ); + + let fl_dims = Dimensions { + width: 0, + height: 1 << (log_height - 1), + }; + + (fri_input, fl_dims, fl_values) + }) + .multiunzip(); + + // sort descending + fri_input.reverse(); + + self.fri_config + .mmcs + .verify_batch( + &proof.first_layer_commitment, + &fl_dims, + index >> 1, + &fl_leaves, + first_layer_proof, + ) + .map_err(InputError::FirstLayerMmcsError)?; + + Ok(fri_input) + }, + ) + } + *) + Definition verify + (Val InputMmcs FriMmcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs FriMmcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; rounds; proof; challenger ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rounds := M.alloc (| rounds |) in + let proof := M.alloc (| proof |) in + let challenger := M.alloc (| challenger |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rounds |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let round := M.alloc (| γ2_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| round |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let mat := M.alloc (| γ2_1 |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| mat |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := + M.read (| + γ0_0 + |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let point := + M.alloc (| + γ2_1 + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.tuple + []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + point + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.tuple + []) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + opening := + M.copy (| + γ + |) in + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ + Val + ], + "observe_algebra_element", + [], + [ + Challenge + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + challenger + |) + |) + |); + M.read (| + opening + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ alpha : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "sample_algebra_element", + [], + [ Challenge ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Challenger, + [], + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment" + ], + "observe", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_circle::pcs::CirclePcsProof", + "first_layer_commitment" + |) + |) + ] + |) + ] + |) + |) in + let~ bivariate_beta : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "sample_algebra_element", + [], + [ Challenge ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |) ] + |) + |) in + let~ log_global_max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_circle::pcs::CirclePcsProof", + "fri_proof" + |), + "p3_circle::proof::CircleFriProof", + "commit_phase_commits" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ g : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::folding::CircleFriGenericConfig") + [] + [ + Val; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ] + ] := + M.alloc (| + Value.StructTuple + "p3_circle::folding::CircleFriGenericConfig" + [ Value.StructTuple "core::marker::PhantomData" [] ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ] + ], + M.get_function (| + "p3_circle::verifier::verify", + [], + [ + Ty.apply + (Ty.path "p3_circle::folding::CircleFriGenericConfig") + [] + [ + Val; + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ]; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ]; + Val; + Challenge; + FriMmcs; + Challenger; + Ty.function + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ] + ] + ] + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ]) + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.borrow (| Pointer.Kind.Ref, g |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_circle::pcs::CirclePcsProof", + "fri_proof" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ] + ] + ] + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let index := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CircleInputProof") + [] + [ Val; Challenge; InputMmcs; FriMmcs ] + ] + ] + ] + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let input_proof := M.copy (| γ |) in + M.read (| + let~ reduced_openings : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple [ Challenge; Challenge ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple [ Challenge; Challenge ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple [ Challenge; Challenge ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ] + ], + input_proof, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_circle::pcs::CircleInputProof", + "input_openings" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_circle::pcs::CircleInputProof", + "first_layer_siblings" + |) in + let γ1_2 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_circle::pcs::CircleInputProof", + "first_layer_proof" + |) in + let input_openings := M.alloc (| γ1_0 |) in + let first_layer_siblings := + M.alloc (| γ1_1 |) in + let first_layer_proof := M.alloc (| γ1_2 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ Val; InputMmcs + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge + ] + FriMmcs + "Error" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge + ] + FriMmcs + "Error" + ] + ] + |), + [ + M.read (| + input_openings + |); + M.borrow (| + Pointer.Kind.Ref, + rounds + |); + Value.StructTuple + "p3_circle::pcs::InputError::InputShapeError" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := + M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := + M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let batch_opening := + M.copy (| + γ1_0 + |) in + let γ1_1 := + M.read (| + γ1_1 + |) in + let γ3_0 := + M.SubPointer.get_tuple_field (| + γ1_1, + 0 + |) in + let γ3_1 := + M.SubPointer.get_tuple_field (| + γ1_1, + 1 + |) in + let batch_commit := + M.alloc (| + γ3_0 + |) in + let mats := + M.alloc (| + γ3_1 + |) in + let~ batch_heights : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "usize"; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "usize"; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path + "usize") + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path + "usize") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.path + "usize"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path + "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mats + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path + "usize") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + domain := + M.alloc (| + γ1_0 + |) in + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shl, + [ + M.call_closure (| + Ty.path + "usize", + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ], + [], + [], + "size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + domain + |) + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ batch_dims : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ], + [], + [], + "map", + [], + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "usize" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "usize" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "usize"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + batch_heights + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + height := + M.copy (| + γ + |) in + Value.StructRecord + "p3_matrix::Dimensions" + [ + ("width", + Value.Integer + IntegerKind.Usize + 0); + ("height", + M.read (| + height + |)) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ]; + Ty.path + "usize" + ] + ], + M.alloc (| + Value.Tuple [] + |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ], + "map", + [], + [ + Ty.path + "usize"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path + "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ], + [], + [], + "max", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "usize" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "usize" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "usize"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + batch_heights + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path + "usize") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + x := + M.copy (| + γ + |) in + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.read (| + M.deref (| + M.read (| + x + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + log_batch_max_height := + M.copy (| + γ0_0 + |) in + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.path + "core::ops::range::RangeFull" + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + batch_dims + |); + Value.StructTuple + "core::ops::range::RangeFull" + [] + ] + |) + |) + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_global_max_height + |); + M.read (| + log_batch_max_height + |) + ] + |) + ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 0 + ] + [ + Ty.path + "p3_matrix::Dimensions" + ], + [], + [ + Ty.path + "core::ops::range::RangeFull" + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [] + |) + |); + Value.StructTuple + "core::ops::range::RangeFull" + [] + ] + |) + |) + |); + Value.Integer + IntegerKind.Usize + 0 + ] + |))) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let dims := + M.copy (| + γ0_0 + |) in + let idx := + M.copy (| + γ0_1 + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ]; + Ty.tuple + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ], + "map_err", + [], + [ + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ]; + Ty.function + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + (Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ + Val + ], + "verify_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_circle::pcs::CirclePcs", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + batch_commit + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + dims + |) + |) + |); + M.read (| + idx + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + batch_opening + |) + |), + "p3_circle::pcs::BatchOpening", + "opened_values" + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + batch_opening + |) + |), + "p3_circle::pcs::BatchOpening", + "opening_proof" + |) + |) + |) + |) + ] + |); + M.constructor_as_closure + "p3_circle::pcs::InputError::InputMmcsError'1" + ] + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let + residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let + val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + batch_opening + |) + |), + "p3_circle::pcs::BatchOpening", + "opened_values" + |) + |); + M.read (| + mats + |); + Value.StructTuple + "p3_circle::pcs::InputError::InputShapeError" + [] + ] + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let + residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let + val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + iter := + M.copy (| + γ + |) in + M.loop (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + ltac:(M.monadic + (let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let + ps_at_x := + M.copy (| + γ1_0 + |) in + let + γ1_1 := + M.read (| + γ1_1 + |) in + let + γ3_0 := + M.SubPointer.get_tuple_field (| + γ1_1, + 0 + |) in + let + γ3_1 := + M.SubPointer.get_tuple_field (| + γ1_1, + 1 + |) in + let + mat_domain := + M.alloc (| + γ3_0 + |) in + let + mat_points_and_values := + M.alloc (| + γ3_1 + |) in + let~ + log_height : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + mat_domain + |) + |), + "p3_circle::domain::CircleDomain", + "log_n" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + |) in + let~ + bits_reduced : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_global_max_height + |); + M.read (| + log_height + |) + ] + |) + |) in + let~ + orig_idx : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_circle::ordering::cfft_permute_index", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + M.read (| + bits_reduced + |) + ] + |); + M.read (| + log_height + |) + ] + |) + |) in + let~ + committed_domain : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ], + "standard", + [], + [] + |), + [ + M.read (| + log_height + |) + ] + |) + |) in + let~ + x : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Val + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Val + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ], + "nth_point", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + committed_domain + |); + M.read (| + orig_idx + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.tuple + [ + Challenge; + Challenge + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + "or_insert", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + "entry", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + reduced_openings + |); + M.read (| + log_height + |) + ] + |); + Value.Tuple + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Challenge + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Challenge + |) + |) + ] + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + alpha_offset := + M.alloc (| + γ1_0 + |) in + let + ro := + M.alloc (| + γ1_1 + |) in + let~ + alpha_pow_width_2 : + Ty.apply + (Ty.path + "*") + [] + [ + Challenge + ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Challenge, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Challenge, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + alpha + |); + M.cast + (Ty.path + "u64") + (M.call_closure (| + Ty.path + "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + ps_at_x + |) + |) + |) + ] + |)) + ] + |) + |) + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + mat_points_and_values + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + iter := + M.copy (| + γ + |) in + M.loop (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + ltac:(M.monadic + (let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + γ0_0 := + M.read (| + γ0_0 + |) in + let + γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let + zeta_uni := + M.alloc (| + γ2_0 + |) in + let + ps_at_zeta := + M.alloc (| + γ2_1 + |) in + let~ + zeta : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Challenge + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Challenge + ], + "from_projective_line", + [], + [] + |), + [ + M.read (| + M.deref (| + M.read (| + zeta_uni + |) + |) + |) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Challenge, + [], + [ + Challenge + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + ro + |) + |) + |); + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Mul", + Challenge, + [], + [ + Challenge + ], + "mul", + [], + [] + |), + [ + M.read (| + M.deref (| + M.read (| + alpha_offset + |) + |) + |); + M.call_closure (| + Challenge, + M.get_function (| + "p3_circle::deep_quotient::deep_quotient_reduce_row", + [], + [ + Val; + Challenge + ] + |), + [ + M.read (| + alpha + |); + M.read (| + x + |); + M.read (| + zeta + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + ps_at_x + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + ps_at_zeta + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Challenge, + [], + [ + Challenge + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + alpha_offset + |) + |) + |); + M.read (| + alpha_pow_width_2 + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + |))) + ] + |)))) + ] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + |))) + ] + |)))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ Ty.path "usize"; Challenge + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ Ty.path "usize"; Challenge + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_matrix::Dimensions"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Challenge ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Challenge ] + ] + ] + ] + (Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Challenge + ]; + Ty.path + "p3_matrix::Dimensions"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]) + ], + [], + [], + "multiunzip", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Challenge ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Challenge ] + ] + ] + ] + (Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Challenge + ]; + Ty.path + "p3_matrix::Dimensions"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Challenge + ]; + Ty.path + "p3_matrix::Dimensions"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Challenge ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Challenge ] + ] + ] + ] + (Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Challenge + ]; + Ty.path + "p3_matrix::Dimensions"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]) + ] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge + ] + FriMmcs + "Error" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ] + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ] + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge + ] + FriMmcs + "Error" + ] + ] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ] + |), + [ + M.read (| + reduced_openings + |); + M.read (| + first_layer_siblings + |); + Value.StructTuple + "p3_circle::pcs::InputError::InputShapeError" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let + residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + proof + |) + |), + "p3_circle::pcs::CirclePcsProof", + "lambdas" + |) + |); + Value.StructTuple + "p3_circle::pcs::InputError::InputShapeError" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := + M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := + M.copy (| γ0_0 |) in + val)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + ] + (Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "p3_matrix::Dimensions"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ1_0, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ1_0, + 1 + |) in + let + log_height := + M.copy (| + γ2_0 + |) in + let γ3_0 := + M.SubPointer.get_tuple_field (| + γ2_1, + 0 + |) in + let γ3_1 := + M.SubPointer.get_tuple_field (| + γ2_1, + 1 + |) in + let ro := + M.copy (| + γ3_1 + |) in + let γ1_1 := + M.read (| + γ1_1 + |) in + let fl_sib := + M.copy (| + γ1_1 + |) in + let γ0_1 := + M.read (| + γ0_1 + |) in + let lambda := + M.copy (| + γ0_1 + |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + Value.Tuple + [] + |), + [ + fun γ => + ltac:(M.monadic + (let + γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + BinOp.gt, + [ + M.read (| + log_height + |); + Value.Integer + IntegerKind.Usize + 0 + ] + |) + |) + |)) in + let + _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::panic", + [], + [] + |), + [ + mk_str (| + "assertion failed: log_height > 0" + |) + ] + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + let~ + orig_size : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_height + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + |) in + let~ + bits_reduced : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_global_max_height + |); + M.read (| + log_height + |) + ] + |) + |) in + let~ + orig_idx : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_circle::ordering::cfft_permute_index", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + M.read (| + bits_reduced + |) + ] + |); + M.read (| + log_height + |) + ] + |) + |) in + let~ + lde_domain : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ Val + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ], + "standard", + [], + [] + |), + [ + M.read (| + log_height + |) + ] + |) + |) in + let~ p : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Val + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ Val + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::domain::CircleDomain") + [] + [ + Val + ], + "nth_point", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + lde_domain + |); + M.read (| + orig_idx + |) + ] + |) + |) in + let~ + lambda_corrected : + Ty.apply + (Ty.path + "*") + [] + [ + Challenge + ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Sub", + Challenge, + [], + [ + Challenge + ], + "sub", + [], + [] + |), + [ + M.read (| + ro + |); + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Mul", + Challenge, + [], + [ + Val + ], + "mul", + [], + [] + |), + [ + M.read (| + lambda + |); + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_circle::point::Point") + [] + [ + Val + ], + "v_n", + [], + [] + |), + [ + M.read (| + p + |); + M.read (| + orig_size + |) + ] + |) + ] + |) + ] + |) + |) in + let~ + fl_values : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_function (| + "alloc::vec::from_elem", + [], + [ + Challenge + ] + |), + [ + M.read (| + lambda_corrected + |); + Value.Integer + IntegerKind.Usize + 2 + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&mut") + [] + [ + Challenge + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.path + "usize" + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + fl_values + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.bit_xor, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + M.read (| + bits_reduced + |) + ] + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + ] + |) + |), + M.read (| + fl_sib + |) + |) + |) in + let~ + fri_input : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] := + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_height + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + M.call_closure (| + Challenge, + M.get_function (| + "p3_circle::folding::fold_y_row", + [], + [ + Val; + Challenge; + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ] + ] + |), + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + bits_reduced + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + ] + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_height + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + M.read (| + bivariate_beta + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + [], + [], + "copied", + [], + [ + Challenge + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + fl_values + |) + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + ] + |) in + let~ fl_dims : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] := + M.alloc (| + Value.StructRecord + "p3_matrix::Dimensions" + [ + ("width", + Value.Integer + IntegerKind.Usize + 0); + ("height", + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shl, + [ + Value.Integer + IntegerKind.Usize + 1; + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_height + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + ] + |)) + ] + |) in + M.alloc (| + Value.Tuple + [ + M.read (| + fri_input + |); + M.read (| + fl_dims + |); + M.read (| + fl_values + |) + ] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let fri_input := M.copy (| γ0_0 |) in + let fl_dims := M.copy (| γ0_1 |) in + let fl_leaves := M.copy (| γ0_2 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Challenge + ] + ], + "reverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + fri_input + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ], + "map_err", + [], + [ + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ]; + Ty.function + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ] + (Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + FriMmcs, + [], + [ Challenge ], + "verify_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_circle::pcs::CirclePcs", + "fri_config" + |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + proof + |) + |), + "p3_circle::pcs::CirclePcsProof", + "first_layer_commitment" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + fl_dims + |) + |) + |) + ] + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + Value.Integer + IntegerKind.I32 + 1 + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + fl_leaves + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + first_layer_proof + |) + |) + |) + ] + |); + M.constructor_as_closure + "p3_circle::pcs::InputError::FirstLayerMmcsError" + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := + M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_circle::pcs::InputError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := + M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ M.read (| fri_input |) ] + |))) + ] + |))) + ] + |) + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val InputMmcs FriMmcs Challenge Challenger : Ty.t), + M.IsTraitInstance + "p3_commit::pcs::Pcs" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Challenge; Challenger ] + (Self Val InputMmcs FriMmcs Challenge Challenger) + (* Instance *) + [ + ("Domain", InstanceField.Ty (_Domain Val InputMmcs FriMmcs Challenge Challenger)); + ("Commitment", InstanceField.Ty (_Commitment Val InputMmcs FriMmcs Challenge Challenger)); + ("ProverData", InstanceField.Ty (_ProverData Val InputMmcs FriMmcs Challenge Challenger)); + ("EvaluationsOnDomain", + InstanceField.Ty (_EvaluationsOnDomain Val InputMmcs FriMmcs Challenge Challenger)); + ("Proof", InstanceField.Ty (_Proof Val InputMmcs FriMmcs Challenge Challenger)); + ("Error", InstanceField.Ty (_Error Val InputMmcs FriMmcs Challenge Challenger)); + ("natural_domain_for_degree", + InstanceField.Method + (natural_domain_for_degree Val InputMmcs FriMmcs Challenge Challenger)); + ("commit", InstanceField.Method (commit Val InputMmcs FriMmcs Challenge Challenger)); + ("get_evaluations_on_domain", + InstanceField.Method + (get_evaluations_on_domain Val InputMmcs FriMmcs Challenge Challenger)); + ("open", InstanceField.Method (open Val InputMmcs FriMmcs Challenge Challenger)); + ("verify", InstanceField.Method (verify Val InputMmcs FriMmcs Challenge Challenger)) + ]. + End Impl_p3_commit_pcs_Pcs_where_p3_field_extension_complex_ComplexExtendable_Val_where_p3_field_field_ExtensionField_Challenge_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_p3_challenger_FieldChallenger_Challenger_Val_where_p3_challenger_grinding_challenger_GrindingChallenger_Challenger_where_p3_challenger_CanObserve_Challenger_associated_in_trait_p3_commit_mmcs_Mmcs__Challenge_FriMmcs_Commitment_Challenge_Challenger_for_p3_circle_pcs_CirclePcs_Val_InputMmcs_FriMmcs. +End pcs. diff --git a/CoqOfRust/plonky3/circle/src/point.rs b/CoqOfRust/plonky3/circle/src/point.rs new file mode 100644 index 000000000..e1cc14a35 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/point.rs @@ -0,0 +1,219 @@ +use alloc::vec::Vec; +use core::ops::{Add, AddAssign, Mul, Neg, Sub}; + +use p3_field::extension::ComplexExtendable; +use p3_field::{ExtensionField, Field, batch_multiplicative_inverse}; + +/// Affine representation of a point on the circle. +/// x^2 + y^2 == 1 +// _private is to prevent construction so we can debug assert the invariant +#[allow(clippy::manual_non_exhaustive)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] +pub struct Point { + pub x: F, + pub y: F, + _private: (), +} + +impl Point { + #[inline] + pub fn new(x: F, y: F) -> Self { + debug_assert_eq!(x.square() + y.square(), F::ONE); + Self { x, y, _private: () } + } + + const ZERO: Self = Self { + x: F::ONE, + y: F::ZERO, + _private: (), + }; + + /// Circle STARKs, Section 3, Lemma 1: (page 4 of the first revision PDF) + /// ```ignore + /// (x, y) = ((1-t^2)/(1+t^2), 2t/(1+t^2)) + /// ``` + /// Panics if t^2 = -1, corresponding to either of the points at infinity + /// (on the projective *circle*) (1 : ±i : 0) + pub fn from_projective_line(t: F) -> Self { + let t2 = t.square(); + let inv_denom = (F::ONE + t2).try_inverse().expect("t^2 = -1"); + Self::new((F::ONE - t2) * inv_denom, t.double() * inv_denom) + } + + /// Circle STARKs, Section 3, Lemma 1: (page 4 of the first revision PDF) + /// ```ignore + /// t = y / (x + 1) + /// ``` + /// Returns None if self.x = -1, corresponding to Inf on the projective line + /// + /// This is also used as a selector polynomial, with a simple zero at (1,0) + /// and a simple pole at (-1,0), which in the paper is called v_0 + /// Circle STARKs, Section 5.1, Lemma 11 (page 21 of the first revision PDF) + pub fn to_projective_line(self) -> Option { + (self.x + F::ONE).try_inverse().map(|x| x * self.y) + } + + /// The "squaring map", or doubling in additive notation, denoted π(x,y) + /// Circle STARKs, Section 3.1, Equation 1: (page 5 of the first revision PDF) + pub fn double(self) -> Self { + Self::new(self.x.square().double() - F::ONE, self.x.double() * self.y) + } + + /// Evaluate the vanishing polynomial for the standard position coset of size 2^log_n + /// at this point + /// Circle STARKs, Section 3.3, Equation 8 (page 10 of the first revision PDF) + pub fn v_n(mut self, log_n: usize) -> F { + for _ in 0..(log_n - 1) { + self.x = self.x.square().double() - F::ONE; // TODO: replace this by a custom field impl. + } + self.x + } + + /// Compute a product of successive `v_n`'s. + /// + /// More explicitly this computes `(1..log_n).map(|i| self.v_n(i)).product()` + /// but uses far fewer `self.x.square().double() - F::ONE` steps compared to the naive implementation. + pub fn v_n_prod(mut self, log_n: usize) -> F { + let mut output = self.x; + for _ in 0..(log_n - 2) { + self.x = self.x.square().double() - F::ONE; // TODO: replace this by a custom field impl. + output *= self.x; + } + output + } + + /// Evaluate the selector function which is zero at `self` and nonzero elsewhere, at `at`. + /// Called v_0 . T_p⁻¹ or ṽ_p(x,y) in the paper, used for constraint selectors. + /// Panics if p = -self, the pole. + /// Section 5.1, Lemma 11 of Circle Starks (page 21 of first edition PDF) + pub fn v_tilde_p>(self, at: Point) -> EF { + (at - self).to_projective_line().unwrap() + } + + /// The concrete value of the selector s_P = v_n / (v_0 . T_p⁻¹) at P=self, used for normalization. + /// Circle STARKs, Section 5.1, Remark 16 (page 22 of the first revision PDF) + pub fn s_p_at_p(self, log_n: usize) -> F { + -self.v_n_prod(log_n).mul_2exp_u64((2 * log_n - 1) as u64) * self.y + } + + /// Evaluate the alternate single-point vanishing function v_p(x), used for DEEP quotient. + /// Returns (a, b), representing the complex number a + bi. + /// Simple zero at p, simple pole at +-infinity. + /// Circle STARKs, Section 3.3, Equation 11 (page 11 of the first edition PDF). + pub fn v_p>(self, at: Point) -> (EF, EF) { + let diff = -at + self; + (EF::ONE - diff.x, -diff.y) + } +} + +/// Compute (ṽ_P(x,y) * s_p)^{-1} for each element in the list. +/// This takes advantage of batched inversion. +pub fn compute_lagrange_den_batched>( + points: &[Point], + at: Point, + log_n: usize, +) -> Vec { + // This following line costs about 2% of the runtime for example prove_poseidon2_m31_keccak. + // Would be nice to find further speedups. + // Maybe modify to use packed fields here? + let (numer, denom): (Vec<_>, Vec<_>) = points + .iter() + .map(|&pt| { + let diff = at - pt; + let numer = diff.x + F::ONE; + let denom = diff.y * pt.s_p_at_p(log_n); + (numer, denom) + }) + .unzip(); + + let inv_d = batch_multiplicative_inverse(&denom); + + numer + .iter() + .zip(inv_d.iter()) + .map(|(&num, &inv_d)| num * inv_d) + .collect() +} + +impl Point { + pub fn generator(log_n: usize) -> Self { + let g = F::circle_two_adic_generator(log_n); + Self::new(g.real(), g.imag()) + } +} + +/// Circle STARKs, Section 3.1, Equation 2: (page 5 of the first revision PDF) +/// The inverse map J(x,y) = (x,-y) +impl Neg for Point { + type Output = Self; + fn neg(mut self) -> Self::Output { + self.y = -self.y; + self + } +} + +impl> Add> for Point { + type Output = Self; + fn add(self, rhs: Point) -> Self::Output { + Self::new( + self.x * rhs.x - self.y * rhs.y, + self.x * rhs.y + self.y * rhs.x, + ) + } +} + +impl AddAssign for Point { + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} + +impl> Sub> for Point { + type Output = Self; + fn sub(self, rhs: Point) -> Self::Output { + Self::new( + self.x * rhs.x + self.y * rhs.y, + self.y * rhs.x - self.x * rhs.y, + ) + } +} + +impl Mul for Point { + type Output = Self; + fn mul(mut self, mut rhs: usize) -> Self::Output { + let mut res = Self::ZERO; + while rhs != 0 { + if rhs & 1 == 1 { + res += self; + } + rhs >>= 1; + self = self.double(); + } + res + } +} + +#[cfg(test)] +mod tests { + use p3_mersenne_31::Mersenne31; + + use super::*; + + type F = Mersenne31; + type Pt = Point; + + #[test] + fn test_arithmetic() { + let one = Pt::generator(3); + assert_eq!(one - one, Pt::ZERO); + assert_eq!(one + one, one * 2); + assert_eq!(one + one + one, one * 3); + assert_eq!(one * 7, -one); + assert_eq!(one * 8, Pt::ZERO); + + let generator = Pt::generator(10); + let log_n = 10; + let vn_prod_gen = (1..log_n).map(|i| generator.v_n(i)).product(); + assert_eq!(generator.v_n_prod(log_n), vn_prod_gen); + } +} diff --git a/CoqOfRust/plonky3/circle/src/point.v b/CoqOfRust/plonky3/circle/src/point.v new file mode 100644 index 000000000..88ab7d50a --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/point.v @@ -0,0 +1,2988 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module point. + (* StructRecord + { + name := "Point"; + const_params := []; + ty_params := [ "F" ]; + fields := [ ("x", F); ("y", F); ("_private", Ty.tuple []) ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_F_for_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_F_for_p3_circle_point_Point_F. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_circle::point::Point" + [ + ("x", + M.call_closure (| + F, + M.get_trait_method (| "core::clone::Clone", F, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "x" + |) + |) + |) + |) + ] + |)); + ("y", + M.call_closure (| + F, + M.get_trait_method (| "core::clone::Clone", F, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "y" + |) + |) + |) + |) + ] + |)); + ("_private", + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::clone::Clone", + Ty.tuple [], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "_private" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_circle_point_Point_F. + + Module Impl_core_marker_StructuralPartialEq_for_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_circle_point_Point_F. + + Module Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_p3_circle_point_Point_F_for_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* PartialEq *) + Definition eq (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| "core::cmp::PartialEq", F, [], [ F ], "eq", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "x" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_circle::point::Point", + "x" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| "core::cmp::PartialEq", F, [], [ F ], "eq", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "y" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_circle::point::Point", + "y" + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.tuple [], + [], + [ Ty.tuple [] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "_private" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_circle::point::Point", + "_private" + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + (Self F) + (* Instance *) [ ("eq", InstanceField.Method (eq F)) ]. + End Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_p3_circle_point_Point_F_for_p3_circle_point_Point_F. + + Module Impl_core_cmp_Eq_where_core_cmp_Eq_F_for_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* Eq *) + Definition assert_receiver_is_total_eq + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method (assert_receiver_is_total_eq F)) ]. + End Impl_core_cmp_Eq_where_core_cmp_Eq_F_for_p3_circle_point_Point_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Point" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "x" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "x" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "y" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "y" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_private" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "_private" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_circle_point_Point_F. + + Module Impl_core_hash_Hash_where_core_hash_Hash_F_for_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* Hash *) + Definition hash (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| "core::hash::Hash", F, [], [], "hash", [], [ __H ] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "x" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| "core::hash::Hash", F, [], [], "hash", [], [ __H ] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "y" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.tuple [], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::point::Point", + "_private" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("hash", InstanceField.Method (hash F)) ]. + End Impl_core_hash_Hash_where_core_hash_Hash_F_for_p3_circle_point_Point_F. + + Module Impl_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* + pub fn new(x: F, y: F) -> Self { + debug_assert_eq!(x.square() + y.square(), F::ONE); + Self { x, y, _private: () } + } + *) + Definition new (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ x; y ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, y |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructRecord + "p3_circle::point::Point" + [ ("x", M.read (| x |)); ("y", M.read (| y |)); ("_private", Value.Tuple []) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "new" (new F). + Admitted. + Global Typeclasses Opaque new. + + (* + const ZERO: Self = Self { + x: F::ONE, + y: F::ZERO, + _private: (), + }; + *) + (* Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] *) + Definition value_ZERO (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + ltac:(M.monadic + (M.alloc (| + Value.StructRecord + "p3_circle::point::Point" + [ + ("x", + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) |)); + ("y", + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) + |)); + ("_private", Value.Tuple []) + ] + |))). + + Global Instance AssociatedConstant_value_ZERO : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "ZERO" (value_ZERO F). + Admitted. + Global Typeclasses Opaque value_ZERO. + + (* + pub fn from_projective_line(t: F) -> Self { + let t2 = t.square(); + let inv_denom = (F::ONE + t2).try_inverse().expect("t^2 = -1"); + Self::new((F::ONE - t2) * inv_denom, t.double() * inv_denom) + } + *) + Definition from_projective_line + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ t ] => + ltac:(M.monadic + (let t := M.alloc (| t |) in + M.read (| + let~ t2 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, t |) ] + |) + |) in + let~ inv_denom : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "try_inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |); + M.read (| t2 |) + ] + |) + |) + |) + ] + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "t^2 = -1" |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "new", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) + |); + M.read (| t2 |) + ] + |); + M.read (| inv_denom |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "double", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, t |) ] + |); + M.read (| inv_denom |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_projective_line : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "from_projective_line" (from_projective_line F). + Admitted. + Global Typeclasses Opaque from_projective_line. + + (* + pub fn to_projective_line(self) -> Option { + (self.x + F::ONE).try_inverse().map(|x| x * self.y) + } + *) + Definition to_projective_line + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "map", + [], + [ F; Ty.function [ Ty.tuple [ F ] ] F ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| "p3_field::field::Field", F, [], [], "try_inverse", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |) + |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ F ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "y" + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_projective_line : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "to_projective_line" (to_projective_line F). + Admitted. + Global Typeclasses Opaque to_projective_line. + + (* + pub fn double(self) -> Self { + Self::new(self.x.square().double() - F::ONE, self.x.double() * self.y) + } + *) + Definition double (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "new", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Sub", F, [], [ F ], "sub", [], [] |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |) + |) + ] + |) + |) + |) + ] + |); + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| self, "p3_circle::point::Point", "y" |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_double : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "double" (double F). + Admitted. + Global Typeclasses Opaque double. + + (* + pub fn v_n(mut self, log_n: usize) -> F { + for _ in 0..(log_n - 1) { + self.x = self.x.square().double() - F::ONE; // TODO: replace this by a custom field impl. + } + self.x + } + *) + Definition v_n (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; log_n ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let log_n := M.alloc (| log_n |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| log_n |); Value.Integer IntegerKind.Usize 1 ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |), + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |) + |) + ] + |) + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.SubPointer.get_struct_record_field (| self, "p3_circle::point::Point", "x" |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_v_n : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "v_n" (v_n F). + Admitted. + Global Typeclasses Opaque v_n. + + (* + pub fn v_n_prod(mut self, log_n: usize) -> F { + let mut output = self.x; + for _ in 0..(log_n - 2) { + self.x = self.x.square().double() - F::ONE; // TODO: replace this by a custom field impl. + output *= self.x; + } + output + } + *) + Definition v_n_prod (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; log_n ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let log_n := M.alloc (| log_n |) in + M.read (| + let~ output : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + M.SubPointer.get_struct_record_field (| self, "p3_circle::point::Point", "x" |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| log_n |); Value.Integer IntegerKind.Usize 2 ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |), + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |) + |) + ] + |) + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + F, + [], + [ F ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, output |); + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_v_n_prod : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "v_n_prod" (v_n_prod F). + Admitted. + Global Typeclasses Opaque v_n_prod. + + (* + pub fn v_tilde_p>(self, at: Point) -> EF { + (at - self).to_projective_line().unwrap() + } + *) + Definition v_tilde_p (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ EF ], [ self; at_ ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let at_ := M.alloc (| at_ |) in + M.call_closure (| + EF, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ EF ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ EF ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + "to_projective_line", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "sub", + [], + [] + |), + [ M.read (| at_ |); M.read (| self |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_v_tilde_p : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "v_tilde_p" (v_tilde_p F). + Admitted. + Global Typeclasses Opaque v_tilde_p. + + (* + pub fn s_p_at_p(self, log_n: usize) -> F { + -self.v_n_prod(log_n).mul_2exp_u64((2 * log_n - 1) as u64) * self.y + } + *) + Definition s_p_at_p (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; log_n ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let log_n := M.alloc (| log_n |) in + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Neg", F, [], [], "neg", [], [] |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "mul_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "v_n_prod", + [], + [] + |), + [ M.read (| self |); M.read (| log_n |) ] + |) + |) + |); + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| log_n |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |)) + ] + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| self, "p3_circle::point::Point", "y" |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_s_p_at_p : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "s_p_at_p" (s_p_at_p F). + Admitted. + Global Typeclasses Opaque s_p_at_p. + + (* + pub fn v_p>(self, at: Point) -> (EF, EF) { + let diff = -at + self; + (EF::ONE - diff.x, -diff.y) + } + *) + Definition v_p (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ EF ], [ self; at_ ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let at_ := M.alloc (| at_ |) in + M.read (| + let~ diff : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + M.get_trait_method (| + "core::ops::arith::Neg", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + [], + [], + "neg", + [], + [] + |), + [ M.read (| at_ |) ] + |); + M.read (| self |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Sub", EF, [], [ EF ], "sub", [], [] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", EF |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + diff, + "p3_circle::point::Point", + "x" + |) + |) + ] + |); + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Neg", EF, [], [], "neg", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + diff, + "p3_circle::point::Point", + "y" + |) + |) + ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_v_p : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "v_p" (v_p F). + Admitted. + Global Typeclasses Opaque v_p. + (* + pub fn generator(log_n: usize) -> Self { + let g = F::circle_two_adic_generator(log_n); + Self::new(g.real(), g.imag()) + } + *) + Definition generator (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ log_n ] => + ltac:(M.monadic + (let log_n := M.alloc (| log_n |) in + M.read (| + let~ g : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ], + M.get_trait_method (| + "p3_field::extension::complex::ComplexExtendable", + F, + [], + [], + "circle_two_adic_generator", + [], + [] + |), + [ M.read (| log_n |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "new", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ], + "real", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, g |) ] + |); + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ], + "imag", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, g |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_generator : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "generator" (generator F). + Admitted. + Global Typeclasses Opaque generator. + End Impl_p3_circle_point_Point_F. + + (* + pub fn compute_lagrange_den_batched>( + points: &[Point], + at: Point, + log_n: usize, + ) -> Vec { + // This following line costs about 2% of the runtime for example prove_poseidon2_m31_keccak. + // Would be nice to find further speedups. + // Maybe modify to use packed fields here? + let (numer, denom): (Vec<_>, Vec<_>) = points + .iter() + .map(|&pt| { + let diff = at - pt; + let numer = diff.x + F::ONE; + let denom = diff.y * pt.s_p_at_p(log_n); + (numer, denom) + }) + .unzip(); + + let inv_d = batch_multiplicative_inverse(&denom); + + numer + .iter() + .zip(inv_d.iter()) + .map(|(&num, &inv_d)| num * inv_d) + .collect() + } + *) + Definition compute_lagrange_den_batched + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF ], [ points; at_; log_n ] => + ltac:(M.monadic + (let points := M.alloc (| points |) in + let at_ := M.alloc (| at_ |) in + let log_n := M.alloc (| log_n |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.tuple [ EF; EF ]) + ], + [], + [], + "unzip", + [], + [ + EF; + EF; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.tuple [ EF; EF ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + [], + [], + "map", + [], + [ + Ty.tuple [ EF; EF ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + ] + ] + (Ty.tuple [ EF; EF ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| points |) |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ] + ] + ] + (Ty.tuple [ EF; EF ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let pt := M.copy (| γ |) in + M.read (| + let~ diff : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ EF ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ EF ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ EF ], + [], + [ + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ] + ], + "sub", + [], + [] + |), + [ M.read (| at_ |); M.read (| pt |) ] + |) + |) in + let~ numer : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Add", + EF, + [], + [ F ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + diff, + "p3_circle::point::Point", + "x" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |) + ] + |) + |) in + let~ denom : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + diff, + "p3_circle::point::Point", + "y" + |) + |); + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::point::Point") + [] + [ F ], + "s_p_at_p", + [], + [] + |), + [ M.read (| pt |); M.read (| log_n |) ] + |) + ] + |) + |) in + M.alloc (| + Value.Tuple [ M.read (| numer |); M.read (| denom |) ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let numer := M.copy (| γ0_0 |) in + let denom := M.copy (| γ0_1 |) in + let~ inv_d : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse", + [], + [ EF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ EF ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, denom |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ EF ]; + Ty.apply (Ty.path "&") [] [ EF ] + ] + ] + ] + EF + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ EF ]; + Ty.apply (Ty.path "&") [] [ EF ] + ] + ] + ] + EF + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ], + [], + [], + "map", + [], + [ + EF; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ EF ]; + Ty.apply (Ty.path "&") [] [ EF ] + ] + ] + ] + EF + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ EF ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, numer |) ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ EF ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inv_d |) ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ EF ]; + Ty.apply (Ty.path "&") [] [ EF ] + ] + ] + ] + EF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let num := M.copy (| γ0_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let inv_d := M.copy (| γ0_1 |) in + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ EF ], + "mul", + [], + [] + |), + [ M.read (| num |); M.read (| inv_d |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_compute_lagrange_den_batched : + M.IsFunction.C "p3_circle::point::compute_lagrange_den_batched" compute_lagrange_den_batched. + Admitted. + Global Typeclasses Opaque compute_lagrange_den_batched. + + + Module Impl_core_ops_arith_Neg_where_p3_field_field_Field_F_for_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* type Output = Self; *) + Definition _Output (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* + fn neg(mut self) -> Self::Output { + self.y = -self.y; + self + } + *) + Definition neg (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| self, "p3_circle::point::Point", "y" |), + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Neg", F, [], [], "neg", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "y" + |) + |) + ] + |) + |) + |) in + self + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F)); ("neg", InstanceField.Method (neg F)) ]. + End Impl_core_ops_arith_Neg_where_p3_field_field_Field_F_for_p3_circle_point_Point_F. + + Module Impl_core_ops_arith_Add_where_p3_field_field_Field_F_where_p3_field_field_ExtensionField_EF_F_p3_circle_point_Point_F_for_p3_circle_point_Point_EF. + Definition Self (F EF : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ]. + + (* type Output = Self; *) + Definition _Output (F EF : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ]. + + (* + fn add(self, rhs: Point) -> Self::Output { + Self::new( + self.x * rhs.x - self.y * rhs.y, + self.x * rhs.y + self.y * rhs.x, + ) + } + *) + Definition add (F EF : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F EF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + "new", + [], + [] + |), + [ + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Sub", EF, [], [ EF ], "sub", [], [] |), + [ + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_circle::point::Point", + "x" + |) + |) + ] + |); + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "y" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_circle::point::Point", + "y" + |) + |) + ] + |) + ] + |); + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Add", EF, [], [ EF ], "add", [], [] |), + [ + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_circle::point::Point", + "y" + |) + |) + ] + |); + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "y" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_circle::point::Point", + "x" + |) + |) + ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F EF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + (Self F EF) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F EF)); ("add", InstanceField.Method (add F EF)) ]. + End Impl_core_ops_arith_Add_where_p3_field_field_Field_F_where_p3_field_field_ExtensionField_EF_F_p3_circle_point_Point_F_for_p3_circle_point_Point_EF. + + Module Impl_core_ops_arith_AddAssign_where_p3_field_field_Field_F_p3_circle_point_Point_F_for_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } + *) + Definition add_assign (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ], + "add", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + (Self F) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign F)) ]. + End Impl_core_ops_arith_AddAssign_where_p3_field_field_Field_F_p3_circle_point_Point_F_for_p3_circle_point_Point_F. + + Module Impl_core_ops_arith_Sub_where_p3_field_field_Field_F_where_p3_field_field_ExtensionField_EF_F_p3_circle_point_Point_F_for_p3_circle_point_Point_EF. + Definition Self (F EF : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ]. + + (* type Output = Self; *) + Definition _Output (F EF : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ]. + + (* + fn sub(self, rhs: Point) -> Self::Output { + Self::new( + self.x * rhs.x + self.y * rhs.y, + self.y * rhs.x - self.x * rhs.y, + ) + } + *) + Definition sub (F EF : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F EF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ EF ], + "new", + [], + [] + |), + [ + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Add", EF, [], [ EF ], "add", [], [] |), + [ + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_circle::point::Point", + "x" + |) + |) + ] + |); + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "y" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_circle::point::Point", + "y" + |) + |) + ] + |) + ] + |); + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Sub", EF, [], [ EF ], "sub", [], [] |), + [ + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "y" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_circle::point::Point", + "x" + |) + |) + ] + |); + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_circle::point::Point", + "x" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_circle::point::Point", + "y" + |) + |) + ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F EF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] + (Self F EF) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F EF)); ("sub", InstanceField.Method (sub F EF)) ]. + End Impl_core_ops_arith_Sub_where_p3_field_field_Field_F_where_p3_field_field_ExtensionField_EF_F_p3_circle_point_Point_F_for_p3_circle_point_Point_EF. + + Module Impl_core_ops_arith_Mul_where_p3_field_field_Field_F_usize_for_p3_circle_point_Point_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* type Output = Self; *) + Definition _Output (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ]. + + (* + fn mul(mut self, mut rhs: usize) -> Self::Output { + let mut res = Self::ZERO; + while rhs != 0 { + if rhs & 1 == 1 { + res += self; + } + rhs >>= 1; + self = self.double(); + } + res + } + *) + Definition mul (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] ] := + M.copy (| + get_associated_constant (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "ZERO", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ M.read (| rhs |); Value.Integer IntegerKind.Usize 0 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ + M.read (| rhs |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, res |); + M.read (| self |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := rhs in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| β |); Value.Integer IntegerKind.I32 1 ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + self, + M.call_closure (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_circle::point::Point") [] [ F ], + "double", + [], + [] + |), + [ M.read (| self |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + res + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + (Self F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F)); ("mul", InstanceField.Method (mul F)) ]. + End Impl_core_ops_arith_Mul_where_p3_field_field_Field_F_usize_for_p3_circle_point_Point_F. +End point. diff --git a/CoqOfRust/plonky3/circle/src/proof.rs b/CoqOfRust/plonky3/circle/src/proof.rs new file mode 100644 index 000000000..bcb22c2f2 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/proof.rs @@ -0,0 +1,42 @@ +use alloc::vec::Vec; + +use p3_commit::Mmcs; +use p3_field::Field; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone)] +#[serde(bound( + serialize = "Witness: Serialize, InputProof: Serialize", + deserialize = "Witness: Deserialize<'de>, InputProof: Deserialize<'de>" +))] +pub struct CircleFriProof, Witness, InputProof> { + pub commit_phase_commits: Vec, + pub query_proofs: Vec>, + // This could become Vec if this library was generalized to support non-constant + // final polynomials. + pub final_poly: F, + pub pow_witness: Witness, +} + +#[derive(Serialize, Deserialize, Clone)] +#[serde(bound( + serialize = "InputProof: Serialize", + deserialize = "InputProof: Deserialize<'de>", +))] +pub struct CircleQueryProof, InputProof> { + pub input_proof: InputProof, + /// For each commit phase commitment, this contains openings of a commit phase codeword at the + /// queried location, along with an opening proof. + pub commit_phase_openings: Vec>, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(bound = "")] +pub struct CircleCommitPhaseProofStep> { + /// The opening of the commit phase codeword at the sibling location. + // This may change to Vec if the library is generalized to support other FRI + // folding arities besides 2, meaning that there can be multiple siblings. + pub sibling_value: F, + + pub opening_proof: M::Proof, +} diff --git a/CoqOfRust/plonky3/circle/src/proof.v b/CoqOfRust/plonky3/circle/src/proof.v new file mode 100644 index 000000000..660bc9ebb --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/proof.v @@ -0,0 +1,2929 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module proof. + (* StructRecord + { + name := "CircleFriProof"; + const_params := []; + ty_params := [ "F"; "M_"; "Witness"; "InputProof" ]; + fields := + [ + ("commit_phase_commits", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Commitment"; + Ty.path "alloc::alloc::Global" + ]); + ("query_proofs", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::proof::CircleQueryProof") [] [ F; M_; InputProof ]; + Ty.path "alloc::alloc::Global" + ]); + ("final_poly", F); + ("pow_witness", Witness) + ]; + } *) + + Module underscore. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_ser_Serialize_Witness_where_serde_ser_Serialize_InputProof_for_p3_circle_proof_CircleFriProof_F_M__Witness_InputProof. + Definition Self (F M_ Witness InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::proof::CircleFriProof") [] [ F; M_; Witness; InputProof ]. + + (* Serialize *) + Definition serialize + (F M_ Witness InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ Witness InputProof in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "CircleFriProof" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "commit_phase_commits" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleFriProof", + "commit_phase_commits" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ F; M_; InputProof ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "query_proofs" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleFriProof", + "query_proofs" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "final_poly" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleFriProof", + "final_poly" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Witness ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "pow_witness" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleFriProof", + "pow_witness" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ Witness InputProof : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ Witness InputProof) + (* Instance *) + [ ("serialize", InstanceField.Method (serialize F M_ Witness InputProof)) ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_ser_Serialize_Witness_where_serde_ser_Serialize_InputProof_for_p3_circle_proof_CircleFriProof_F_M__Witness_InputProof. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_de_Deserialize_Witness_where_serde_de_Deserialize_InputProof_for_p3_circle_proof_CircleFriProof_F_M__Witness_InputProof. + Definition Self (F M_ Witness InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::proof::CircleFriProof") [] [ F; M_; Witness; InputProof ]. + + (* Deserialize *) + Definition deserialize + (F M_ Witness InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ Witness InputProof in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleFriProof") + [] + [ F; M_; Witness; InputProof ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_circle::proof::_'1::deserialize::__Visitor") + [] + [ F; M_; Witness; InputProof ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "CircleFriProof" |); + M.read (| + get_constant (| + "p3_circle::proof::_'1::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_circle::proof::_'1::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ Witness InputProof : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ Witness InputProof) + (* Instance *) + [ ("deserialize", InstanceField.Method (deserialize F M_ Witness InputProof)) ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_de_Deserialize_Witness_where_serde_de_Deserialize_InputProof_for_p3_circle_proof_CircleFriProof_F_M__Witness_InputProof. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_ser_Serialize_InputProof_for_p3_circle_proof_CircleQueryProof_F_M__InputProof. + Definition Self (F M_ InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::proof::CircleQueryProof") [] [ F; M_; InputProof ]. + + (* Serialize *) + Definition serialize + (F M_ InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ InputProof in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "CircleQueryProof" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ InputProof ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "input_proof" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleQueryProof", + "input_proof" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "commit_phase_openings" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleQueryProof", + "commit_phase_openings" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ InputProof : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ InputProof) + (* Instance *) [ ("serialize", InstanceField.Method (serialize F M_ InputProof)) ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_ser_Serialize_InputProof_for_p3_circle_proof_CircleQueryProof_F_M__InputProof. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_de_Deserialize_InputProof_for_p3_circle_proof_CircleQueryProof_F_M__InputProof. + Definition Self (F M_ InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::proof::CircleQueryProof") [] [ F; M_; InputProof ]. + + (* Deserialize *) + Definition deserialize + (F M_ InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ InputProof in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_circle::proof::CircleQueryProof") [] [ F; M_; InputProof ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_circle::proof::_'3::deserialize::__Visitor") + [] + [ F; M_; InputProof ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "CircleQueryProof" |); + M.read (| + get_constant (| + "p3_circle::proof::_'3::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_circle::proof::_'3::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ InputProof : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ InputProof) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize F M_ InputProof)) ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_de_Deserialize_InputProof_for_p3_circle_proof_CircleQueryProof_F_M__InputProof. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_for_p3_circle_proof_CircleCommitPhaseProofStep_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]. + + (* Serialize *) + Definition serialize + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "CircleCommitPhaseProofStep" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "sibling_value" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleCommitPhaseProofStep", + "sibling_value" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Proof" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "opening_proof" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleCommitPhaseProofStep", + "opening_proof" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_) + (* Instance *) [ ("serialize", InstanceField.Method (serialize F M_)) ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_for_p3_circle_proof_CircleCommitPhaseProofStep_F_M_. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_for_p3_circle_proof_CircleCommitPhaseProofStep_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]. + + (* Deserialize *) + Definition deserialize + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ Ty.apply (Ty.path "p3_circle::proof::_'5::deserialize::__Visitor") [] [ F; M_ ] ] + |), + [ + M.read (| __deserializer |); + mk_str (| "CircleCommitPhaseProofStep" |); + M.read (| + get_constant (| + "p3_circle::proof::_'5::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_circle::proof::_'5::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize F M_)) ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_for_p3_circle_proof_CircleCommitPhaseProofStep_F_M_. + End underscore. + + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_Witness_where_core_clone_Clone_InputProof_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Commitment_for_p3_circle_proof_CircleFriProof_F_M__Witness_InputProof. + Definition Self (F M_ Witness InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::proof::CircleFriProof") [] [ F; M_; Witness; InputProof ]. + + (* Clone *) + Definition clone + (F M_ Witness InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ Witness InputProof in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_circle::proof::CircleFriProof" + [ + ("commit_phase_commits", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Commitment"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Commitment"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleFriProof", + "commit_phase_commits" + |) + |) + |) + |) + ] + |)); + ("query_proofs", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ F; M_; InputProof ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ F; M_; InputProof ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleFriProof", + "query_proofs" + |) + |) + |) + |) + ] + |)); + ("final_poly", + M.call_closure (| + F, + M.get_trait_method (| "core::clone::Clone", F, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleFriProof", + "final_poly" + |) + |) + |) + |) + ] + |)); + ("pow_witness", + M.call_closure (| + Witness, + M.get_trait_method (| "core::clone::Clone", Witness, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleFriProof", + "pow_witness" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ Witness InputProof : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ Witness InputProof) + (* Instance *) [ ("clone", InstanceField.Method (clone F M_ Witness InputProof)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_Witness_where_core_clone_Clone_InputProof_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Commitment_for_p3_circle_proof_CircleFriProof_F_M__Witness_InputProof. + + (* StructRecord + { + name := "CircleQueryProof"; + const_params := []; + ty_params := [ "F"; "M_"; "InputProof" ]; + fields := + [ + ("input_proof", InputProof); + ("commit_phase_openings", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ]) + ]; + } *) + + + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_InputProof_for_p3_circle_proof_CircleQueryProof_F_M__InputProof. + Definition Self (F M_ InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::proof::CircleQueryProof") [] [ F; M_; InputProof ]. + + (* Clone *) + Definition clone + (F M_ InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ InputProof in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_circle::proof::CircleQueryProof" + [ + ("input_proof", + M.call_closure (| + InputProof, + M.get_trait_method (| + "core::clone::Clone", + InputProof, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleQueryProof", + "input_proof" + |) + |) + |) + |) + ] + |)); + ("commit_phase_openings", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleQueryProof", + "commit_phase_openings" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ InputProof : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ InputProof) + (* Instance *) [ ("clone", InstanceField.Method (clone F M_ InputProof)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_InputProof_for_p3_circle_proof_CircleQueryProof_F_M__InputProof. + + (* StructRecord + { + name := "CircleCommitPhaseProofStep"; + const_params := []; + ty_params := [ "F"; "M_" ]; + fields := + [ + ("sibling_value", F); + ("opening_proof", Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Proof") + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_where_core_fmt_Debug_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_fmt_Debug_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Proof_for_p3_circle_proof_CircleCommitPhaseProofStep_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]. + + (* Debug *) + Definition fmt (F M_ : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "CircleCommitPhaseProofStep" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "sibling_value" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleCommitPhaseProofStep", + "sibling_value" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "opening_proof" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleCommitPhaseProofStep", + "opening_proof" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F M_)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_where_core_fmt_Debug_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_fmt_Debug_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Proof_for_p3_circle_proof_CircleCommitPhaseProofStep_F_M_. + + + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Proof_for_p3_circle_proof_CircleCommitPhaseProofStep_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]. + + (* Clone *) + Definition clone (F M_ : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_circle::proof::CircleCommitPhaseProofStep" + [ + ("sibling_value", + M.call_closure (| + F, + M.get_trait_method (| "core::clone::Clone", F, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleCommitPhaseProofStep", + "sibling_value" + |) + |) + |) + |) + ] + |)); + ("opening_proof", + M.call_closure (| + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Proof", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Proof", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_circle::proof::CircleCommitPhaseProofStep", + "opening_proof" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_) + (* Instance *) [ ("clone", InstanceField.Method (clone F M_)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Proof_for_p3_circle_proof_CircleCommitPhaseProofStep_F_M_. +End proof. diff --git a/CoqOfRust/plonky3/circle/src/prover.rs b/CoqOfRust/plonky3/circle/src/prover.rs new file mode 100644 index 000000000..0ea652196 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/prover.rs @@ -0,0 +1,154 @@ +use alloc::vec; +use alloc::vec::Vec; +use core::iter; + +use itertools::{Itertools, izip}; +use p3_challenger::{CanObserve, FieldChallenger, GrindingChallenger}; +use p3_commit::Mmcs; +use p3_field::{ExtensionField, Field}; +use p3_fri::{FriConfig, FriGenericConfig}; +use p3_matrix::dense::RowMajorMatrix; +use p3_util::log2_strict_usize; +use tracing::{info_span, instrument}; + +use crate::{CircleCommitPhaseProofStep, CircleFriProof, CircleQueryProof}; + +#[instrument(name = "FRI prover", skip_all)] +pub fn prove( + g: &G, + config: &FriConfig, + inputs: Vec>, + challenger: &mut Challenger, + open_input: impl Fn(usize) -> G::InputProof, +) -> CircleFriProof +where + Val: Field, + Challenge: ExtensionField, + M: Mmcs, + Challenger: FieldChallenger + GrindingChallenger + CanObserve, + G: FriGenericConfig, +{ + // check sorted descending + assert!( + inputs + .iter() + .tuple_windows() + .all(|(l, r)| l.len() >= r.len()) + ); + + let log_max_height = log2_strict_usize(inputs[0].len()); + + let commit_phase_result = commit_phase(g, config, inputs, challenger); + + let pow_witness = challenger.grind(config.proof_of_work_bits); + + let query_proofs = info_span!("query phase").in_scope(|| { + iter::repeat_with(|| challenger.sample_bits(log_max_height + g.extra_query_index_bits())) + .take(config.num_queries) + .map(|index| CircleQueryProof { + input_proof: open_input(index), + commit_phase_openings: answer_query( + config, + &commit_phase_result.data, + index >> g.extra_query_index_bits(), + ), + }) + .collect() + }); + + CircleFriProof { + commit_phase_commits: commit_phase_result.commits, + query_proofs, + final_poly: commit_phase_result.final_poly, + pow_witness, + } +} + +struct CommitPhaseResult> { + commits: Vec, + data: Vec>>, + final_poly: F, +} + +#[instrument(name = "commit phase", skip_all)] +fn commit_phase( + g: &G, + config: &FriConfig, + inputs: Vec>, + challenger: &mut Challenger, +) -> CommitPhaseResult +where + Val: Field, + Challenge: ExtensionField, + M: Mmcs, + Challenger: FieldChallenger + CanObserve, + G: FriGenericConfig, +{ + let mut inputs_iter = inputs.into_iter().peekable(); + let mut folded = inputs_iter.next().unwrap(); + let mut commits = vec![]; + let mut data = vec![]; + + while folded.len() > config.blowup() { + let leaves = RowMajorMatrix::new(folded, 2); + let (commit, prover_data) = config.mmcs.commit_matrix(leaves); + challenger.observe(commit.clone()); + + let beta: Challenge = challenger.sample_algebra_element(); + // We passed ownership of `current` to the MMCS, so get a reference to it + let leaves = config.mmcs.get_matrices(&prover_data).pop().unwrap(); + folded = g.fold_matrix(beta, leaves.as_view()); + + commits.push(commit); + data.push(prover_data); + + if let Some(v) = inputs_iter.next_if(|v| v.len() == folded.len()) { + izip!(&mut folded, v).for_each(|(c, x)| *c += x); + } + } + + // We should be left with `blowup` evaluations of a constant polynomial. + assert_eq!(folded.len(), config.blowup()); + let final_poly = folded[0]; + for x in folded { + assert_eq!(x, final_poly); + } + challenger.observe_algebra_element(final_poly); + + CommitPhaseResult { + commits, + data, + final_poly, + } +} + +fn answer_query( + config: &FriConfig, + commit_phase_commits: &[M::ProverData>], + index: usize, +) -> Vec> +where + F: Field, + M: Mmcs, +{ + commit_phase_commits + .iter() + .enumerate() + .map(|(i, commit)| { + let index_i = index >> i; + let index_i_sibling = index_i ^ 1; + let index_pair = index_i >> 1; + + let (mut opened_rows, opening_proof) = config.mmcs.open_batch(index_pair, commit); + assert_eq!(opened_rows.len(), 1); + let opened_row = opened_rows.pop().unwrap(); + assert_eq!(opened_row.len(), 2, "Committed data should be in pairs"); + let sibling_value = opened_row[index_i_sibling % 2]; + + CircleCommitPhaseProofStep { + sibling_value, + opening_proof, + } + }) + .collect() +} diff --git a/CoqOfRust/plonky3/circle/src/prover.v b/CoqOfRust/plonky3/circle/src/prover.v new file mode 100644 index 000000000..b2a89ae38 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/prover.v @@ -0,0 +1,5641 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module prover. + (* #[instrument(name = "FRI prover", skip_all)] *) + Definition prove (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], + [ G; Val; Challenge; M_; Challenger; impl_Fn_usize__arrow_G_InputProof ], + [ g; config; inputs; challenger; open_input ] => + ltac:(M.monadic + (let g := M.alloc (| g |) in + let config := M.alloc (| config |) in + let inputs := M.alloc (| inputs |) in + let challenger := M.alloc (| challenger |) in + let open_input := M.alloc (| open_input |) in + M.catch_return + (Ty.apply + (Ty.path "p3_circle::proof::CircleFriProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleFriProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ], + [], + [], + "all", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "tuple_windows", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inputs |) ] + |) + |) + |) + ] + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let l := M.copy (| γ0_0 |) in + let r := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| l |) |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| r |) |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: inputs.iter().tuple_windows().all(|(l, r)| l.len() >= r.len())" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, inputs |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ commit_phase_result : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_circle::prover::CommitPhaseResult") [] [ Challenge; M_ ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_circle::prover::CommitPhaseResult") [] [ Challenge; M_ ], + M.get_function (| + "p3_circle::prover::commit_phase", + [], + [ G; Val; Challenge; M_; Challenger ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| g |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| config |) |) |); + M.read (| inputs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |) + ] + |) + |) in + let~ pow_witness : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Challenger, + [], + [], + "grind", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "proof_of_work_bits" + |) + |) + ] + |) + |) in + let~ query_proofs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ]); + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ] + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ] + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ], + M.get_function (| + "core::iter::sources::repeat_with::repeat_with", + [], + [ + Ty.path "usize"; + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_challenger::CanSampleBits", + Challenger, + [], + [ Ty.path "usize" ], + "sample_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + challenger + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + log_max_height + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ Challenge ], + "extra_query_index_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + g + |) + |) + |) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "num_queries" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let index := M.copy (| γ |) in + Value.StructRecord + "p3_circle::proof::CircleQueryProof" + [ + ("input_proof", + M.call_closure (| + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof", + M.get_trait_method (| + "core::ops::function::Fn", + impl_Fn_usize__arrow_G_InputProof, + [], + [ + Ty.tuple + [ Ty.path "usize" ] + ], + "call", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + open_input + |); + Value.Tuple + [ M.read (| index |) ] + ] + |)); + ("commit_phase_openings", + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ Challenge; M_ ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_function (| + "p3_circle::prover::answer_query", + [], + [ Challenge; M_ ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| config |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + M_ + "ProverData" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + M_ + "ProverData"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + commit_phase_result, + "p3_circle::prover::CommitPhaseResult", + "data" + |) + |) + |) + |) + ] + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.read (| index |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ Challenge ], + "extra_query_index_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + g + |) + |) + |) + ] + |) + ] + |) + ] + |)) + ])) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_circle::proof::CircleFriProof" + [ + ("commit_phase_commits", + M.read (| + M.SubPointer.get_struct_record_field (| + commit_phase_result, + "p3_circle::prover::CommitPhaseResult", + "commits" + |) + |)); + ("query_proofs", M.read (| query_proofs |)); + ("final_poly", + M.read (| + M.SubPointer.get_struct_record_field (| + commit_phase_result, + "p3_circle::prover::CommitPhaseResult", + "final_poly" + |) + |)); + ("pow_witness", M.read (| pow_witness |)) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_prove : M.IsFunction.C "p3_circle::prover::prove" prove. + Admitted. + Global Typeclasses Opaque prove. + + (* StructRecord + { + name := "CommitPhaseResult"; + const_params := []; + ty_params := [ "F"; "M_" ]; + fields := + [ + ("commits", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Commitment"; + Ty.path "alloc::alloc::Global" + ]); + ("data", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData"; + Ty.path "alloc::alloc::Global" + ]); + ("final_poly", F) + ]; + } *) + + (* #[instrument(name = "commit phase", skip_all)] *) + Definition commit_phase (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ G; Val; Challenge; M_; Challenger ], [ g; config; inputs; challenger ] => + ltac:(M.monadic + (let g := M.alloc (| g |) in + let config := M.alloc (| config |) in + let inputs := M.alloc (| inputs |) in + let challenger := M.alloc (| challenger |) in + M.catch_return + (Ty.apply (Ty.path "p3_circle::prover::CommitPhaseResult") [] [ Challenge; M_ ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::commit_phase::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::commit_phase::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::commit_phase::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_circle::prover::commit_phase::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::prover::CommitPhaseResult") + [] + [ Challenge; M_ ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ inputs_iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "peekable", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| inputs |) ] + |) + ] + |) + |) in + let~ folded : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "next", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, inputs_iter |) ] + |) + ] + |) + |) in + let~ commits : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + let~ data : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData"; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData"; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, folded |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "p3_fri::config::FriConfig") [] [ M_ ], + "blowup", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| config |) |) + |) + ] + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ leaves : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| folded |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + M_, + [], + [ Challenge ], + "commit_matrix", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.read (| leaves |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let commit := M.copy (| γ0_0 |) in + let prover_data := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Challenger, + [], + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, commit |) ] + |) + ] + |) + |) in + let~ beta : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "sample_algebra_element", + [], + [ Challenge ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |) + ] + |) + |) in + let~ leaves : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "pop", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + M_, + [], + [ Challenge ], + "get_matrices", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + prover_data + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + folded, + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ Challenge ], + "fold_matrix", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Challenge ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| g |) |) + |); + M.read (| beta |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Challenge ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ], + "as_view", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| leaves |) |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, commits |); + M.read (| commit |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + M_ + "ProverData"; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, data |); + M.read (| prover_data |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "next_if", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, inputs_iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let v := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| v |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + folded + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let v := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Challenge ]; + Challenge + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Challenge ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Challenge ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + folded + |) + ] + |); + M.read (| v |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Challenge ]; + Challenge + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let c := M.copy (| γ0_0 |) in + let x := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Challenge, + [], + [ Challenge ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| c |) + |) + |); + M.read (| x |) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, folded |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "p3_fri::config::FriConfig") [] [ M_ ], + "blowup", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| config |) |) |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ final_poly : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Challenge ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, folded |); Value.Integer IntegerKind.Usize 0 ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| folded |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Challenge ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.borrow (| Pointer.Kind.Ref, final_poly |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Challenge, + [], + [ Challenge ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Challenge; Challenge ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "observe_algebra_element", + [], + [ Challenge ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |); + M.read (| final_poly |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_circle::prover::CommitPhaseResult" + [ + ("commits", M.read (| commits |)); + ("data", M.read (| data |)); + ("final_poly", M.read (| final_poly |)) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_commit_phase : + M.IsFunction.C "p3_circle::prover::commit_phase" commit_phase. + Admitted. + Global Typeclasses Opaque commit_phase. + + (* + fn answer_query( + config: &FriConfig, + commit_phase_commits: &[M::ProverData>], + index: usize, + ) -> Vec> + where + F: Field, + M: Mmcs, + { + commit_phase_commits + .iter() + .enumerate() + .map(|(i, commit)| { + let index_i = index >> i; + let index_i_sibling = index_i ^ 1; + let index_pair = index_i >> 1; + + let (mut opened_rows, opening_proof) = config.mmcs.open_batch(index_pair, commit); + assert_eq!(opened_rows.len(), 1); + let opened_row = opened_rows.pop().unwrap(); + assert_eq!(opened_row.len(), 2, "Committed data should be in pairs"); + let sibling_value = opened_row[index_i_sibling % 2]; + + CircleCommitPhaseProofStep { + sibling_value, + opening_proof, + } + }) + .collect() + } + *) + Definition answer_query (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; M_ ], [ config; commit_phase_commits; index ] => + ltac:(M.monadic + (let config := M.alloc (| config |) in + let commit_phase_commits := M.alloc (| commit_phase_commits |) in + let index := M.alloc (| index |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ] + ] + ] + (Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ] + ] + ] + (Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ] + ] + ] + (Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| commit_phase_commits |) |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ F; M_ ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let i := M.copy (| γ0_0 |) in + let commit := M.copy (| γ0_1 |) in + M.read (| + let~ index_i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| index |); M.read (| i |) ] + |) + |) in + let~ index_i_sibling : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_xor, + [ M.read (| index_i |); Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ index_pair : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| index_i |); Value.Integer IntegerKind.I32 1 ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ F; M_ ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Proof" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + M_, + [], + [ F ], + "open_batch", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.read (| index_pair |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| commit |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let opened_rows := M.copy (| γ0_0 |) in + let opening_proof := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + opened_rows + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ opened_row : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + "pop", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + opened_rows + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + opened_row + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Committed data should be in pairs" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ sibling_value : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ F ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, opened_row |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.read (| index_i_sibling |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |) + |) in + M.alloc (| + Value.StructRecord + "p3_circle::proof::CircleCommitPhaseProofStep" + [ + ("sibling_value", M.read (| sibling_value |)); + ("opening_proof", M.read (| opening_proof |)) + ] + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_answer_query : + M.IsFunction.C "p3_circle::prover::answer_query" answer_query. + Admitted. + Global Typeclasses Opaque answer_query. +End prover. diff --git a/CoqOfRust/plonky3/circle/src/twiddles.rs b/CoqOfRust/plonky3/circle/src/twiddles.rs new file mode 100644 index 000000000..6cdb9ec5a --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/twiddles.rs @@ -0,0 +1,78 @@ +use alloc::vec::Vec; +use core::mem; + +use itertools::Itertools; +use p3_field::extension::{Complex, ComplexExtendable}; +use p3_field::{batch_multiplicative_inverse, Field}; +use p3_util::linear_map::LinearMap; +use tracing::instrument; + +use crate::domain::CircleDomain; + +#[derive(Debug, Default)] +pub(crate) struct TwiddleCache( + // (log_n, shift) -> (twiddles, inverse_twiddles) + #[allow(clippy::type_complexity)] + LinearMap<(usize, Complex), (Vec>, Option>>)>, +); + +impl TwiddleCache { + pub(crate) fn get_twiddles( + &mut self, + log_n: usize, + shift: Complex, + inv: bool, + ) -> &Vec> { + let cache = self + .0 + .get_or_insert_with((log_n, shift), || (compute_twiddles(log_n, shift), None)); + if !inv { + &cache.0 + } else { + cache.1.get_or_insert_with(|| { + cache + .0 + .iter() + .map(|xs| batch_multiplicative_inverse(xs)) + .collect() + }) + } + } +} + +/// Computes all (non-inverted) twiddles for the FFT over a circle domain of size 2^log_n, for all layers of the FFT. +#[instrument(skip(shift))] +fn compute_twiddles(log_n: usize, shift: Complex) -> Vec> { + let size = 1 << (log_n - 1); + + let init_domain = CircleDomain::new(log_n, shift) + .points() + .take(size) + .collect_vec(); + + // After the first step we only need the real part. + let mut working_domain: Vec<_> = init_domain + .iter() + .take(size / 2) + .map(|x| x.real()) + .collect(); + + (0..log_n) + .map(|i| { + let size = working_domain.len(); + let output = if i == 0 { + // The twiddles in step one are the inverse imaginary parts. + init_domain.iter().map(|x| x.imag()).collect_vec() + } else { + let new_working_domain = working_domain + .iter() + .take(size / 2) + // When we square a point, the real part changes as x -> 2x^2 - 1. + .map(|x| x.square().double() - F::ONE) + .collect(); + mem::replace(&mut working_domain, new_working_domain) + }; + output + }) + .collect() +} diff --git a/CoqOfRust/plonky3/circle/src/verifier.rs b/CoqOfRust/plonky3/circle/src/verifier.rs new file mode 100644 index 000000000..1eabc5cf0 --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/verifier.rs @@ -0,0 +1,169 @@ +use alloc::vec; +use alloc::vec::Vec; + +use itertools::Itertools; +use p3_challenger::{CanObserve, FieldChallenger, GrindingChallenger}; +use p3_commit::Mmcs; +use p3_field::{ExtensionField, Field}; +use p3_fri::verifier::FriError; +use p3_fri::{FriConfig, FriGenericConfig}; +use p3_matrix::Dimensions; +use p3_util::zip_eq::zip_eq; + +use crate::{CircleCommitPhaseProofStep, CircleFriProof}; + +pub fn verify( + g: &G, + config: &FriConfig, + proof: &CircleFriProof, + challenger: &mut Challenger, + open_input: impl Fn(usize, &G::InputProof) -> Result, G::InputError>, +) -> Result<(), FriError> +where + Val: Field, + Challenge: ExtensionField, + M: Mmcs, + Challenger: FieldChallenger + GrindingChallenger + CanObserve, + G: FriGenericConfig, +{ + let betas: Vec = proof + .commit_phase_commits + .iter() + .map(|comm| { + challenger.observe(comm.clone()); + challenger.sample_algebra_element() + }) + .collect(); + + // Observe the claimed final polynomial. + challenger.observe_algebra_element(proof.final_poly); + + if proof.query_proofs.len() != config.num_queries { + return Err(FriError::InvalidProofShape); + } + + // Check PoW. + if !challenger.check_witness(config.proof_of_work_bits, proof.pow_witness) { + return Err(FriError::InvalidPowWitness); + } + + // The log of the maximum domain size. + let log_max_height = proof.commit_phase_commits.len() + config.log_blowup; + + for qp in &proof.query_proofs { + let index = challenger.sample_bits(log_max_height + g.extra_query_index_bits()); + let ro = open_input(index, &qp.input_proof).map_err(FriError::InputError)?; + + debug_assert!( + ro.iter().tuple_windows().all(|((l, _), (r, _))| l > r), + "reduced openings sorted by height descending" + ); + + // Starting at the evaluation at `index` of the initial domain, + // perform fri folds until the domain size reaches the final domain size. + // Check after each fold that the pair of sibling evaluations at the current + // node match the commitment. + let folded_eval = verify_query( + g, + config, + index >> g.extra_query_index_bits(), + zip_eq( + zip_eq( + &betas, + &proof.commit_phase_commits, + FriError::InvalidProofShape, + )?, + &qp.commit_phase_openings, + FriError::InvalidProofShape, + )?, + ro, + log_max_height, + )?; + + // As we fold until the polynomial is constant, proof.final_poly should be a constant value and + // we do not need to do any polynomial evaluations. + if folded_eval != proof.final_poly { + return Err(FriError::FinalPolyMismatch); + } + } + + Ok(()) +} + +type CommitStep<'a, F, M> = ( + ( + &'a F, // The challenge point beta used for the next fold of Circle-FRI evaluations. + &'a >::Commitment, // A commitment to the Circle-FRI evaluations on the current domain. + ), + &'a CircleCommitPhaseProofStep, // The sibling and opening proof for the current Circle-FRI node. +); + +/// Verifies a single query chain in the Circle-FRI proof. +/// +/// Given an initial `index` corresponding to a point in the initial domain +/// and a series of `reduced_openings` corresponding to evaluations of +/// polynomials to be added in at specific domain sizes, perform the standard +/// sequence of Circle-FRI folds, checking at each step that the pair of sibling evaluations +/// match the commitment. +fn verify_query<'a, G, F, M>( + g: &G, + config: &FriConfig, + mut index: usize, + steps: impl ExactSizeIterator>, + reduced_openings: Vec<(usize, F)>, + log_max_height: usize, +) -> Result> +where + F: Field, + M: Mmcs + 'a, + G: FriGenericConfig, +{ + let mut folded_eval = F::ZERO; + let mut ro_iter = reduced_openings.into_iter().peekable(); + + // We start with evaluations over a domain of size (1 << log_max_height). We fold + // using FRI until the domain size reaches (1 << log_final_height). This is equal to 1 << log_blowup + // currently as we have not yet implemented early stopping. + for (log_folded_height, ((&beta, comm), opening)) in zip_eq( + (config.log_blowup..log_max_height).rev(), + steps, + FriError::InvalidProofShape, + )? { + // If there are new polynomials to roll in at this height, do so. + if let Some((_, ro)) = ro_iter.next_if(|(lh, _)| *lh == log_folded_height + 1) { + folded_eval += ro; + } + + // Get the index of the other sibling of the current fri node. + let index_sibling = index ^ 1; + + let mut evals = vec![folded_eval; 2]; + evals[index_sibling % 2] = opening.sibling_value; + + let dims = &[Dimensions { + width: 2, + height: 1 << log_folded_height, + }]; + + // Replace index with the index of the parent fri node. + index >>= 1; + + // Verify the commitment to the evaluations of the sibling nodes. + config + .mmcs + .verify_batch(comm, dims, index, &[evals.clone()], &opening.opening_proof) + .map_err(FriError::CommitPhaseMmcsError)?; + + // Fold the pair of evaluations of sibling nodes into the evaluation of the parent fri node. + folded_eval = g.fold_row(index, log_folded_height, beta, evals.into_iter()); + } + + // If ro_iter is not empty, we failed to fold in some polynomial evaluations. + if ro_iter.next().is_some() { + return Err(FriError::InvalidProofShape); + } + + // If we reached this point, we have verified that, starting at the initial index, + // the chain of folds has produced folded_eval. + Ok(folded_eval) +} diff --git a/CoqOfRust/plonky3/circle/src/verifier.v b/CoqOfRust/plonky3/circle/src/verifier.v new file mode 100644 index 000000000..3cb56f0ac --- /dev/null +++ b/CoqOfRust/plonky3/circle/src/verifier.v @@ -0,0 +1,4660 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module verifier. + (* + pub fn verify( + g: &G, + config: &FriConfig, + proof: &CircleFriProof, + challenger: &mut Challenger, + open_input: impl Fn(usize, &G::InputProof) -> Result, G::InputError>, + ) -> Result<(), FriError> + where + Val: Field, + Challenge: ExtensionField, + M: Mmcs, + Challenger: FieldChallenger + GrindingChallenger + CanObserve, + G: FriGenericConfig, + { + let betas: Vec = proof + .commit_phase_commits + .iter() + .map(|comm| { + challenger.observe(comm.clone()); + challenger.sample_algebra_element() + }) + .collect(); + + // Observe the claimed final polynomial. + challenger.observe_algebra_element(proof.final_poly); + + if proof.query_proofs.len() != config.num_queries { + return Err(FriError::InvalidProofShape); + } + + // Check PoW. + if !challenger.check_witness(config.proof_of_work_bits, proof.pow_witness) { + return Err(FriError::InvalidPowWitness); + } + + // The log of the maximum domain size. + let log_max_height = proof.commit_phase_commits.len() + config.log_blowup; + + for qp in &proof.query_proofs { + let index = challenger.sample_bits(log_max_height + g.extra_query_index_bits()); + let ro = open_input(index, &qp.input_proof).map_err(FriError::InputError)?; + + debug_assert!( + ro.iter().tuple_windows().all(|((l, _), (r, _))| l > r), + "reduced openings sorted by height descending" + ); + + // Starting at the evaluation at `index` of the initial domain, + // perform fri folds until the domain size reaches the final domain size. + // Check after each fold that the pair of sibling evaluations at the current + // node match the commitment. + let folded_eval = verify_query( + g, + config, + index >> g.extra_query_index_bits(), + zip_eq( + zip_eq( + &betas, + &proof.commit_phase_commits, + FriError::InvalidProofShape, + )?, + &qp.commit_phase_openings, + FriError::InvalidProofShape, + )?, + ro, + log_max_height, + )?; + + // As we fold until the polynomial is constant, proof.final_poly should be a constant value and + // we do not need to do any polynomial evaluations. + if folded_eval != proof.final_poly { + return Err(FriError::FinalPolyMismatch); + } + } + + Ok(()) + } + *) + Definition verify (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], + [ + G; + Val; + Challenge; + M_; + Challenger; + impl_Fn_usize___G_InputProof__arrow_Result_Vec__usize__Challenge____G_InputError_ + ], + [ g; config; proof; challenger; open_input ] => + ltac:(M.monadic + (let g := M.alloc (| g |) in + let config := M.alloc (| config |) in + let proof := M.alloc (| proof |) in + let challenger := M.alloc (| challenger |) in + let open_input := M.alloc (| open_input |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] M_ "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ betas : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ] + ] + Challenge + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ] + ] + Challenge + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ], + [], + [], + "map", + [], + [ + Challenge; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ] + ] + Challenge + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_circle::proof::CircleFriProof", + "commit_phase_commits" + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ] + ] + Challenge + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let comm := M.copy (| γ |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Challenger, + [], + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| comm |) |) + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "sample_algebra_element", + [], + [ Challenge ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "observe_algebra_element", + [], + [ Challenge ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_circle::proof::CircleFriProof", + "final_poly" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_circle::proof::CircleFriProof", + "query_proofs" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "num_queries" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Challenger, + [], + [], + "check_witness", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "proof_of_work_bits" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_circle::proof::CircleFriProof", + "pow_witness" + |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_fri::verifier::FriError::InvalidPowWitness" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_circle::proof::CircleFriProof", + "commit_phase_commits" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_circle::proof::CircleFriProof", + "query_proofs" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_circle::proof::CircleQueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let qp := M.copy (| γ0_0 |) in + let~ index : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_challenger::CanSampleBits", + Challenger, + [], + [ Ty.path "usize" ], + "sample_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| log_max_height |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ Challenge ], + "extra_query_index_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| g |) |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ ro : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ], + "map_err", + [], + [ + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ]; + Ty.function + [ + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + (Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ], + M.get_trait_method (| + "core::ops::function::Fn", + impl_Fn_usize___G_InputProof__arrow_Result_Vec__usize__Challenge____G_InputError_, + [], + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + open_input + |); + Value.Tuple + [ + M.read (| index |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| qp |) + |), + "p3_circle::proof::CircleQueryProof", + "input_proof" + |) + |) + |) + |) + ] + ] + |); + M.constructor_as_closure + "p3_fri::verifier::FriError::InputError'1" + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Challenge + ] + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ] + ], + [], + [], + "all", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ] + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ], + [], + [], + "tuple_windows", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + ro + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ] + ] + ] + (Ty.path + "bool") + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + γ0_0 := + M.read (| + γ0_0 + |) in + let + γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let l := + M.alloc (| + γ2_0 + |) in + let + γ0_1 := + M.read (| + γ0_1 + |) in + let + γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_1, + 0 + |) in + let + γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_1, + 1 + |) in + let r := + M.alloc (| + γ2_0 + |) in + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ], + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ], + "gt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + l + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + r + |) + |) + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "reduced openings sorted by height descending" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ folded_eval : + Ty.apply (Ty.path "*") [] [ Challenge ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Challenge ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ]; + Challenge + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_function (| + "p3_circle::verifier::verify_query", + [], + [ + G; + Challenge; + M_; + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ Challenge; M_ ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| g |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| config |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.read (| index |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ Challenge ], + "extra_query_index_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| g |) |) + |) + ] + |) + ] + |); + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ Challenge; M_ ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ Challenge; M_ ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ Challenge; M_ ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ Challenge; M_ ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ Challenge; M_ ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ Challenge; M_ ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge + ] + M_ + "Commitment" + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Commitment" + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Commitment"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Commitment" + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + betas + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + proof + |) + |), + "p3_circle::proof::CircleFriProof", + "commit_phase_commits" + |) + |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| qp |) + |), + "p3_circle::proof::CircleQueryProof", + "commit_phase_openings" + |) + |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := + M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge + ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |); + M.read (| ro |); + M.read (| log_max_height |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Challenge, + [], + [ Challenge ], + "ne", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + folded_eval + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_circle::proof::CircleFriProof", + "final_poly" + |) + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_fri::verifier::FriError::FinalPolyMismatch" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| Value.StructTuple "core::result::Result::Ok" [ Value.Tuple [] ] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_verify : M.IsFunction.C "p3_circle::verifier::verify" verify. + Admitted. + Global Typeclasses Opaque verify. + + Axiom CommitStep : + forall (F M_ : Ty.t), + (Ty.apply (Ty.path "p3_circle::verifier::CommitStep") [] [ F; M_ ]) = + (Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Commitment" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_circle::proof::CircleCommitPhaseProofStep") [] [ F; M_ ] ] + ]). + + (* + fn verify_query<'a, G, F, M>( + g: &G, + config: &FriConfig, + mut index: usize, + steps: impl ExactSizeIterator>, + reduced_openings: Vec<(usize, F)>, + log_max_height: usize, + ) -> Result> + where + F: Field, + M: Mmcs + 'a, + G: FriGenericConfig, + { + let mut folded_eval = F::ZERO; + let mut ro_iter = reduced_openings.into_iter().peekable(); + + // We start with evaluations over a domain of size (1 << log_max_height). We fold + // using FRI until the domain size reaches (1 << log_final_height). This is equal to 1 << log_blowup + // currently as we have not yet implemented early stopping. + for (log_folded_height, ((&beta, comm), opening)) in zip_eq( + (config.log_blowup..log_max_height).rev(), + steps, + FriError::InvalidProofShape, + )? { + // If there are new polynomials to roll in at this height, do so. + if let Some((_, ro)) = ro_iter.next_if(|(lh, _)| *lh == log_folded_height + 1) { + folded_eval += ro; + } + + // Get the index of the other sibling of the current fri node. + let index_sibling = index ^ 1; + + let mut evals = vec![folded_eval; 2]; + evals[index_sibling % 2] = opening.sibling_value; + + let dims = &[Dimensions { + width: 2, + height: 1 << log_folded_height, + }]; + + // Replace index with the index of the parent fri node. + index >>= 1; + + // Verify the commitment to the evaluations of the sibling nodes. + config + .mmcs + .verify_batch(comm, dims, index, &[evals.clone()], &opening.opening_proof) + .map_err(FriError::CommitPhaseMmcsError)?; + + // Fold the pair of evaluations of sibling nodes into the evaluation of the parent fri node. + folded_eval = g.fold_row(index, log_folded_height, beta, evals.into_iter()); + } + + // If ro_iter is not empty, we failed to fold in some polynomial evaluations. + if ro_iter.next().is_some() { + return Err(FriError::InvalidProofShape); + } + + // If we reached this point, we have verified that, starting at the initial index, + // the chain of folds has produced folded_eval. + Ok(folded_eval) + } + *) + Definition verify_query (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], + [ G; F; M_; impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ ], + [ g; config; index; steps; reduced_openings; log_max_height ] => + ltac:(M.monadic + (let g := M.alloc (| g |) in + let config := M.alloc (| config |) in + let index := M.alloc (| index |) in + let steps := M.alloc (| steps |) in + let reduced_openings := M.alloc (| reduced_openings |) in + let log_max_height := M.alloc (| log_max_height |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + F; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Error"; + Ty.associated_in_trait "p3_fri::config::FriGenericConfig" [] [ F ] G "InputError" + ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ folded_eval : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) + |) in + let~ ro_iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ Ty.path "usize"; F ]; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ Ty.path "usize"; F ]; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ Ty.path "usize"; F ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "peekable", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ Ty.path "usize"; F ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ Ty.path "usize"; F ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| reduced_openings |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ]; + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |)); + ("end_", M.read (| log_max_height |)) + ] + ] + |); + M.read (| steps |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + F; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + F; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_circle::proof::CircleCommitPhaseProofStep") + [] + [ F; M_ ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let log_folded_height := M.copy (| γ1_0 |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ1_1, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ1_1, 1 |) in + let γ3_0 := M.SubPointer.get_tuple_field (| γ2_0, 0 |) in + let γ3_1 := M.SubPointer.get_tuple_field (| γ2_0, 1 |) in + let γ3_0 := M.read (| γ3_0 |) in + let beta := M.copy (| γ3_0 |) in + let comm := M.copy (| γ3_1 |) in + let opening := M.copy (| γ2_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.path "alloc::alloc::Global" + ] + ], + "next_if", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ Ty.path "usize"; F ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + ro_iter + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + F + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lh := + M.alloc (| γ1_0 |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| lh |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + log_folded_height + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let ro := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + folded_eval + |); + M.read (| ro |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ index_sibling : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_xor, + [ + M.read (| index |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ evals : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "alloc::vec::from_elem", + [], + [ F ] + |), + [ + M.read (| folded_eval |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, evals |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.read (| index_sibling |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| opening |) |), + "p3_circle::proof::CircleCommitPhaseProofStep", + "sibling_value" + |) + |) + |) + |) in + let~ dims : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.StructRecord + "p3_matrix::Dimensions" + [ + ("width", + Value.Integer IntegerKind.Usize 2); + ("height", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| log_folded_height |) + ] + |)) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := index in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| β |); Value.Integer IntegerKind.I32 1 ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error" + ], + "map_err", + [], + [ + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ]; + Ty.function + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error" + ] + (Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + M_, + [], + [ F ], + "verify_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| comm |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| dims |) |) + |)); + M.read (| index |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + evals + |) + ] + |) + ] + |) + |) + |) + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| opening |) + |), + "p3_circle::proof::CircleCommitPhaseProofStep", + "opening_proof" + |) + |) + |) + |) + ] + |); + M.constructor_as_closure + "p3_fri::verifier::FriError::CommitPhaseMmcsError" + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + F; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + F; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + folded_eval, + M.call_closure (| + F, + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ F ], + "fold_row", + [], + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| g |) |) + |); + M.read (| index |); + M.read (| log_folded_height |); + M.read (| beta |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| evals |) ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + "is_some", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "next", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, ro_iter |) ] + |) + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple "core::result::Result::Ok" [ M.read (| folded_eval |) ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_verify_query : + M.IsFunction.C "p3_circle::verifier::verify_query" verify_query. + Admitted. + Global Typeclasses Opaque verify_query. +End verifier. diff --git a/CoqOfRust/plonky3/commit/src/adapters/extension_mmcs.rs b/CoqOfRust/plonky3/commit/src/adapters/extension_mmcs.rs new file mode 100644 index 000000000..63dd74240 --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/adapters/extension_mmcs.rs @@ -0,0 +1,98 @@ +use alloc::vec::Vec; +use core::marker::PhantomData; +use core::ops::Deref; + +use p3_field::{ExtensionField, Field}; +use p3_matrix::extension::FlatMatrixView; +use p3_matrix::{Dimensions, Matrix}; + +use crate::Mmcs; + +#[derive(Clone, Debug)] +pub struct ExtensionMmcs { + inner: InnerMmcs, + _phantom: PhantomData<(F, EF)>, +} + +impl ExtensionMmcs { + pub const fn new(inner: InnerMmcs) -> Self { + Self { + inner, + _phantom: PhantomData, + } + } +} + +impl Mmcs for ExtensionMmcs +where + F: Field, + EF: ExtensionField, + InnerMmcs: Mmcs, +{ + type ProverData = InnerMmcs::ProverData>; + type Commitment = InnerMmcs::Commitment; + type Proof = InnerMmcs::Proof; + type Error = InnerMmcs::Error; + + fn commit>(&self, inputs: Vec) -> (Self::Commitment, Self::ProverData) { + self.inner + .commit(inputs.into_iter().map(FlatMatrixView::new).collect()) + } + + fn open_batch>( + &self, + index: usize, + prover_data: &Self::ProverData, + ) -> (Vec>, Self::Proof) { + let (opened_base_values, proof) = self.inner.open_batch(index, prover_data); + let opened_ext_values = opened_base_values + .into_iter() + .map(|row| { + // By construction, the width of the row is a multiple of EF::DIMENSION. + // So there will be no remainder when we call chunks_exact. + row.chunks_exact(EF::DIMENSION) + // As each chunk has length EF::DIMENSION, from_basis_coefficients_slice + // will produce some(elem) which into_iter converts to the iterator once(elem). + .flat_map(EF::from_basis_coefficients_slice) + .collect() + }) + .collect(); + (opened_ext_values, proof) + } + + fn get_matrices<'a, M: Matrix>(&self, prover_data: &'a Self::ProverData) -> Vec<&'a M> { + self.inner + .get_matrices(prover_data) + .into_iter() + .map(|mat| mat.deref()) + .collect() + } + + fn verify_batch( + &self, + commit: &Self::Commitment, + dimensions: &[Dimensions], + index: usize, + opened_values: &[Vec], + proof: &Self::Proof, + ) -> Result<(), Self::Error> { + let opened_base_values: Vec> = opened_values + .iter() + .map(|row| { + row.iter() + .flat_map(|el| el.as_basis_coefficients_slice()) + .copied() + .collect() + }) + .collect(); + let base_dimensions = dimensions + .iter() + .map(|dim| Dimensions { + width: dim.width * EF::DIMENSION, + height: dim.height, + }) + .collect::>(); + self.inner + .verify_batch(commit, &base_dimensions, index, &opened_base_values, proof) + } +} diff --git a/CoqOfRust/plonky3/commit/src/adapters/extension_mmcs.v b/CoqOfRust/plonky3/commit/src/adapters/extension_mmcs.v new file mode 100644 index 000000000..e406107aa --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/adapters/extension_mmcs.v @@ -0,0 +1,2121 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module adapters. + Module extension_mmcs. + (* StructRecord + { + name := "ExtensionMmcs"; + const_params := []; + ty_params := [ "F"; "EF"; "InnerMmcs" ]; + fields := + [ + ("inner", InnerMmcs); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ Ty.tuple [ F; EF ] ]) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_EF_where_core_clone_Clone_InnerMmcs_for_p3_commit_adapters_extension_mmcs_ExtensionMmcs_F_EF_InnerMmcs. + Definition Self (F EF InnerMmcs : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ F; EF; InnerMmcs ]. + + (* Clone *) + Definition clone + (F EF InnerMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF InnerMmcs in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_commit::adapters::extension_mmcs::ExtensionMmcs" + [ + ("inner", + M.call_closure (| + InnerMmcs, + M.get_trait_method (| + "core::clone::Clone", + InnerMmcs, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::adapters::extension_mmcs::ExtensionMmcs", + "inner" + |) + |) + |) + |) + ] + |)); + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ Ty.tuple [ F; EF ] ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ Ty.tuple [ F; EF ] ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::adapters::extension_mmcs::ExtensionMmcs", + "_phantom" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F EF InnerMmcs : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F EF InnerMmcs) + (* Instance *) [ ("clone", InstanceField.Method (clone F EF InnerMmcs)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_EF_where_core_clone_Clone_InnerMmcs_for_p3_commit_adapters_extension_mmcs_ExtensionMmcs_F_EF_InnerMmcs. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_EF_where_core_fmt_Debug_InnerMmcs_for_p3_commit_adapters_extension_mmcs_ExtensionMmcs_F_EF_InnerMmcs. + Definition Self (F EF InnerMmcs : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ F; EF; InnerMmcs ]. + + (* Debug *) + Definition fmt + (F EF InnerMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF InnerMmcs in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "ExtensionMmcs" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inner" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::adapters::extension_mmcs::ExtensionMmcs", + "inner" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::adapters::extension_mmcs::ExtensionMmcs", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F EF InnerMmcs : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F EF InnerMmcs) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F EF InnerMmcs)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_EF_where_core_fmt_Debug_InnerMmcs_for_p3_commit_adapters_extension_mmcs_ExtensionMmcs_F_EF_InnerMmcs. + + Module Impl_p3_commit_adapters_extension_mmcs_ExtensionMmcs_F_EF_InnerMmcs. + Definition Self (F EF InnerMmcs : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ F; EF; InnerMmcs ]. + + (* + pub const fn new(inner: InnerMmcs) -> Self { + Self { + inner, + _phantom: PhantomData, + } + } + *) + Definition new + (F EF InnerMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF InnerMmcs in + match ε, τ, α with + | [], [], [ inner ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + Value.StructRecord + "p3_commit::adapters::extension_mmcs::ExtensionMmcs" + [ + ("inner", M.read (| inner |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (F EF InnerMmcs : Ty.t), + M.IsAssociatedFunction.C (Self F EF InnerMmcs) "new" (new F EF InnerMmcs). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_commit_adapters_extension_mmcs_ExtensionMmcs_F_EF_InnerMmcs. + + Module Impl_p3_commit_mmcs_Mmcs_where_p3_field_field_Field_F_where_p3_field_field_ExtensionField_EF_F_where_p3_commit_mmcs_Mmcs_InnerMmcs_F_EF_for_p3_commit_adapters_extension_mmcs_ExtensionMmcs_F_EF_InnerMmcs. + Definition Self (F EF InnerMmcs : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ F; EF; InnerMmcs ]. + + (* type ProverData = InnerMmcs::ProverData>; *) + Definition _ProverData (F EF InnerMmcs : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F; Ty.apply (Ty.path "p3_matrix::extension::FlatMatrixView") [] [ F; EF; M_ ] ] + InnerMmcs + "ProverData". + + (* type Commitment = InnerMmcs::Commitment; *) + Definition _Commitment (F EF InnerMmcs : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] InnerMmcs "Commitment". + + (* type Proof = InnerMmcs::Proof; *) + Definition _Proof (F EF InnerMmcs : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] InnerMmcs "Proof". + + (* type Error = InnerMmcs::Error; *) + Definition _Error (F EF InnerMmcs : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] InnerMmcs "Error". + + (* + fn commit>(&self, inputs: Vec) -> (Self::Commitment, Self::ProverData) { + self.inner + .commit(inputs.into_iter().map(FlatMatrixView::new).collect()) + } + *) + Definition commit + (F EF InnerMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF InnerMmcs in + match ε, τ, α with + | [], [ M_ ], [ self; inputs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let inputs := M.alloc (| inputs |) in + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] InnerMmcs "Commitment"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F; Ty.apply (Ty.path "p3_matrix::extension::FlatMatrixView") [] [ F; EF; M_ ] + ] + InnerMmcs + "ProverData" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InnerMmcs, + [], + [ F ], + "commit", + [], + [ Ty.apply (Ty.path "p3_matrix::extension::FlatMatrixView") [] [ F; EF; M_ ] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::adapters::extension_mmcs::ExtensionMmcs", + "inner" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_matrix::extension::FlatMatrixView") [] [ F; EF; M_ ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ M_; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ M_ ] + (Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ M_; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ M_ ] + (Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ M_; Ty.path "alloc::alloc::Global" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ]; + Ty.function + [ M_ ] + (Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ M_; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| inputs |) ] + |); + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ], + "new", + [], + [] + |) + ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn open_batch>( + &self, + index: usize, + prover_data: &Self::ProverData, + ) -> (Vec>, Self::Proof) { + let (opened_base_values, proof) = self.inner.open_batch(index, prover_data); + let opened_ext_values = opened_base_values + .into_iter() + .map(|row| { + // By construction, the width of the row is a multiple of EF::DIMENSION. + // So there will be no remainder when we call chunks_exact. + row.chunks_exact(EF::DIMENSION) + // As each chunk has length EF::DIMENSION, from_basis_coefficients_slice + // will produce some(elem) which into_iter converts to the iterator once(elem). + .flat_map(EF::from_basis_coefficients_slice) + .collect() + }) + .collect(); + (opened_ext_values, proof) + } + *) + Definition open_batch + (F EF InnerMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF InnerMmcs in + match ε, τ, α with + | [], [ M_ ], [ self; index; prover_data ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let index := M.alloc (| index |) in + let prover_data := M.alloc (| prover_data |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] InnerMmcs "Proof" + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] InnerMmcs "Proof" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InnerMmcs, + [], + [ F ], + "open_batch", + [], + [ Ty.apply (Ty.path "p3_matrix::extension::FlatMatrixView") [] [ F; EF; M_ ] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::adapters::extension_mmcs::ExtensionMmcs", + "inner" + |) + |); + M.read (| index |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| prover_data |) |) |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let opened_base_values := M.copy (| γ0_0 |) in + let proof := M.copy (| γ0_1 |) in + let~ opened_ext_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| opened_base_values |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let row := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksExact") + [] + [ F ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ EF ]; + Ty.function + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path "core::option::Option") + [] + [ EF ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksExact") + [] + [ F ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ EF ]; + Ty.function + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path "core::option::Option") + [] + [ EF ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::ChunksExact") + [] + [ F ], + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ EF ]; + Ty.function + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path "core::option::Option") + [] + [ EF ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::ChunksExact") + [] + [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "chunks_exact", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + row + |) + ] + |) + |) + |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |); + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + EF, + [], + [ F ], + "from_basis_coefficients_slice", + [], + [] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + Value.Tuple [ M.read (| opened_ext_values |); M.read (| proof |) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn get_matrices<'a, M: Matrix>(&self, prover_data: &'a Self::ProverData) -> Vec<&'a M> { + self.inner + .get_matrices(prover_data) + .into_iter() + .map(|mat| mat.deref()) + .collect() + } + *) + Definition get_matrices + (F EF InnerMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF InnerMmcs in + match ε, τ, α with + | [], [ M_ ], [ self; prover_data ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let prover_data := M.alloc (| prover_data |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ] + ] + ] + (Ty.apply (Ty.path "&") [] [ M_ ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ] + ] + ] + (Ty.apply (Ty.path "&") [] [ M_ ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ] + ] + ] + (Ty.apply (Ty.path "&") [] [ M_ ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InnerMmcs, + [], + [ F ], + "get_matrices", + [], + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::adapters::extension_mmcs::ExtensionMmcs", + "inner" + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| prover_data |) |) |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ] + ] + ] + ] + (Ty.apply (Ty.path "&") [] [ M_ ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let mat := M.copy (| γ |) in + M.call_closure (| + Ty.apply (Ty.path "&") [] [ M_ ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "p3_matrix::extension::FlatMatrixView") + [] + [ F; EF; M_ ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| mat |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn verify_batch( + &self, + commit: &Self::Commitment, + dimensions: &[Dimensions], + index: usize, + opened_values: &[Vec], + proof: &Self::Proof, + ) -> Result<(), Self::Error> { + let opened_base_values: Vec> = opened_values + .iter() + .map(|row| { + row.iter() + .flat_map(|el| el.as_basis_coefficients_slice()) + .copied() + .collect() + }) + .collect(); + let base_dimensions = dimensions + .iter() + .map(|dim| Dimensions { + width: dim.width * EF::DIMENSION, + height: dim.height, + }) + .collect::>(); + self.inner + .verify_batch(commit, &base_dimensions, index, &opened_base_values, proof) + } + *) + Definition verify_batch + (F EF InnerMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F EF InnerMmcs in + match ε, τ, α with + | [], [], [ self; commit; dimensions; index; opened_values; proof ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let commit := M.alloc (| commit |) in + let dimensions := M.alloc (| dimensions |) in + let index := M.alloc (| index |) in + let opened_values := M.alloc (| opened_values |) in + let proof := M.alloc (| proof |) in + M.read (| + let~ opened_base_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| opened_values |) |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let row := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ EF ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ EF ] ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]) + ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ EF ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ EF ] ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] + ]) + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ EF ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ EF ] ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]) + ], + [], + [], + "copied", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ EF ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ EF ] ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ EF ], + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ EF ] ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ EF ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ EF ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ EF ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| row |) |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ EF ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let el := + M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + EF, + [], + [ F ], + "as_basis_coefficients_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| el |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ base_dimensions : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_matrix::Dimensions"; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_matrix::Dimensions"; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_matrix::Dimensions" ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.path "p3_matrix::Dimensions" ] ] + ] + (Ty.path "p3_matrix::Dimensions") + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_matrix::Dimensions"; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_matrix::Dimensions" ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.path "p3_matrix::Dimensions" ] ] + ] + (Ty.path "p3_matrix::Dimensions") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_matrix::Dimensions" ], + [], + [], + "map", + [], + [ + Ty.path "p3_matrix::Dimensions"; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.path "p3_matrix::Dimensions" ] ] + ] + (Ty.path "p3_matrix::Dimensions") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_matrix::Dimensions" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "p3_matrix::Dimensions" ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| dimensions |) |) |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + (Ty.path "p3_matrix::Dimensions") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let dim := M.copy (| γ |) in + Value.StructRecord + "p3_matrix::Dimensions" + [ + ("width", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| dim |) |), + "p3_matrix::Dimensions", + "width" + |) + |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |)); + ("height", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| dim |) |), + "p3_matrix::Dimensions", + "height" + |) + |)) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] InnerMmcs "Error" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InnerMmcs, + [], + [ F ], + "verify_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::adapters::extension_mmcs::ExtensionMmcs", + "inner" + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| commit |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "p3_matrix::Dimensions" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_matrix::Dimensions"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, base_dimensions |) |) + |) + ] + |) + |) + |); + M.read (| index |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, opened_base_values |) |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| proof |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F EF InnerMmcs : Ty.t), + M.IsTraitInstance + "p3_commit::mmcs::Mmcs" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ EF ] + (Self F EF InnerMmcs) + (* Instance *) + [ + ("ProverData", InstanceField.Ty (_ProverData F EF InnerMmcs)); + ("Commitment", InstanceField.Ty (_Commitment F EF InnerMmcs)); + ("Proof", InstanceField.Ty (_Proof F EF InnerMmcs)); + ("Error", InstanceField.Ty (_Error F EF InnerMmcs)); + ("commit", InstanceField.Method (commit F EF InnerMmcs)); + ("open_batch", InstanceField.Method (open_batch F EF InnerMmcs)); + ("get_matrices", InstanceField.Method (get_matrices F EF InnerMmcs)); + ("verify_batch", InstanceField.Method (verify_batch F EF InnerMmcs)) + ]. + End Impl_p3_commit_mmcs_Mmcs_where_p3_field_field_Field_F_where_p3_field_field_ExtensionField_EF_F_where_p3_commit_mmcs_Mmcs_InnerMmcs_F_EF_for_p3_commit_adapters_extension_mmcs_ExtensionMmcs_F_EF_InnerMmcs. + End extension_mmcs. +End adapters. diff --git a/CoqOfRust/plonky3/commit/src/adapters/mod.rs b/CoqOfRust/plonky3/commit/src/adapters/mod.rs new file mode 100644 index 000000000..a09886456 --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/adapters/mod.rs @@ -0,0 +1,4 @@ +//! Adapters for converting between different types of commitment schemes. + +mod extension_mmcs; +pub use extension_mmcs::*; diff --git a/CoqOfRust/plonky3/commit/src/domain.rs b/CoqOfRust/plonky3/commit/src/domain.rs new file mode 100644 index 000000000..945b30380 --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/domain.rs @@ -0,0 +1,283 @@ +use alloc::vec::Vec; + +use itertools::Itertools; +use p3_field::coset::TwoAdicMultiplicativeCoset; +use p3_field::{ + ExtensionField, Field, TwoAdicField, batch_multiplicative_inverse, + cyclic_subgroup_coset_known_order, +}; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_util::{log2_ceil_usize, log2_strict_usize}; + +/// Given a `PolynomialSpace`, `S`, and a subset `R`, a Lagrange selector `P_R` is +/// a polynomial which is not equal to `0` for every element in `R` but is equal +/// to `0` for every element of `S` not in `R`. +/// +/// This struct contains evaluations of several Lagrange selectors for a fixed +/// `PolynomialSpace` over some collection of points disjoint from that +/// `PolynomialSpace`. +/// +/// The Lagrange selector is normalized if it is equal to `1` for every element in `R`. +/// The LagrangeSelectors given here are not normalized. +#[derive(Debug)] +pub struct LagrangeSelectors { + /// A Lagrange selector corresponding to the first point in the space. + pub is_first_row: T, + /// A Lagrange selector corresponding to the last point in the space. + pub is_last_row: T, + /// A Lagrange selector corresponding the subset of all but the last point. + pub is_transition: T, + /// The inverse of the vanishing polynomial which is a Lagrange selector corresponding to the empty set + pub inv_vanishing: T, +} + +/// Fixing a field, `F`, `PolynomialSpace` denotes an indexed subset of `F^n` +/// with some additional algebraic structure. +/// +/// We do not expect `PolynomialSpace` to store this subset, instead it usually contains +/// some associated data which allows it to generate the subset or pieces of it. +/// +/// Each `PolynomialSpace` should be part of a family of similar spaces for some +/// collection of sizes (usually powers of two). Any space other than at the smallest size +/// should be decomposable into a disjoint collection of smaller spaces. Additionally, the +/// set of all `PolynomialSpace` of a given size should form a disjoint partition of some +/// subset of `F^n` which supports a group structure. +/// +/// The canonical example of a `PolynomialSpace` is a coset `gH` of +/// a two-adic subgroup `H` of the multiplicative group `F*`. This satisfies the properties +/// above as cosets partition the group and decompose as `gH = g(H^2) u gh(H^2)` for `h` any +/// generator of `H`. +/// +/// The other example in this code base is twin cosets which are sets of the form `gH u g^{-1}H`. +/// The decomposition above extends easily to this case as `h` is a generator if and only if `h^{-1}` +/// is and so `gH u g^{-1}H = (g(H^2) u g^{-1}(H^2)) u (gh(H^2) u (gh)^{-1}(H^2))`. +pub trait PolynomialSpace: Copy { + /// The base field `F`. + type Val: Field; + + /// The number of elements of the space. + fn size(&self) -> usize; + + /// The first point in the space. + fn first_point(&self) -> Self::Val; + + /// An algebraic function which takes the i'th element of the space and returns + /// the (i+1)'th evaluated on the given point. + /// + /// When `PolynomialSpace` corresponds to a coset, `gH` this + /// function is multiplication by `h` for a chosen generator `h` of `H`. + /// + /// This function may not exist for other classes of `PolynomialSpace` in which + /// case this will return `None`. + fn next_point>(&self, x: Ext) -> Option; + + /// Return another `PolynomialSpace` with size at least `min_size` disjoint from this space. + /// + /// When working with spaces of power of two size, this will return a space of size `2^ceil(log_2(min_size))`. + /// This will fail if `min_size` is too large. In particular, `log_2(min_size)` should be + /// smaller than the `2`-adicity of the field. + /// + /// This fixes a canonical choice for prover/verifier determinism and LDE caching. + fn create_disjoint_domain(&self, min_size: usize) -> Self; + + /// Split the `PolynomialSpace` into `num_chunks` smaller `PolynomialSpaces` of equal size. + /// + /// `num_chunks` must divide `self.size()` (which usually forces it to be a power of 2.) or + /// this function will panic. + fn split_domains(&self, num_chunks: usize) -> Vec; + + /// Split a set of polynomial evaluations over this `PolynomialSpace` into a vector + /// of polynomial evaluations over each `PolynomialSpace` generated from `split_domains`. + /// + /// `evals.height()` must equal `self.size()` and `num_chunks` must divide `self.size()`. + fn split_evals( + &self, + num_chunks: usize, + evals: RowMajorMatrix, + ) -> Vec>; + + /// Compute the vanishing polynomial of the space, evaluated at the given point. + /// + /// This is a polynomial which evaluates to `0` on every point of the + /// space `self` and has degree equal to `self.size()`. In other words it is + /// a choice of element of the defining ideal of the given set with this extra + /// degree property. + /// + /// In the univariate case, it is equal, up to a linear factor, to the product over + /// all elements `x`, of `(X - x)`. In particular this implies it will not evaluate + /// to `0` at any point not in `self`. + fn vanishing_poly_at_point>(&self, point: Ext) -> Ext; + + /// Compute several Lagrange selectors at a given point. + /// - The Lagrange selector of the first point. + /// - The Lagrange selector of the last point. + /// - The Lagrange selector of everything but the last point. + /// - The inverse of the vanishing polynomial. + /// + /// Note that these may not be normalized. + fn selectors_at_point>( + &self, + point: Ext, + ) -> LagrangeSelectors; + + /// Compute several Lagrange selectors at all points of the given disjoint `PolynomialSpace`. + /// - The Lagrange selector of the first point. + /// - The Lagrange selector of the last point. + /// - The Lagrange selector of everything but the last point. + /// - The inverse of the vanishing polynomial. + /// + /// Note that these may not be normalized. + fn selectors_on_coset(&self, coset: Self) -> LagrangeSelectors>; +} + +impl PolynomialSpace for TwoAdicMultiplicativeCoset { + type Val = Val; + + fn size(&self) -> usize { + self.size() + } + + fn first_point(&self) -> Self::Val { + self.shift() + } + + /// Getting the next point corresponds to multiplication by the generator. + fn next_point>(&self, x: Ext) -> Option { + Some(x * self.subgroup_generator()) + } + + /// Given the coset `gH`, return the disjoint coset `gfK` where `f` + /// is a fixed generator of `F^*` and `K` is the unique two-adic subgroup + /// of with size `2^(ceil(log_2(min_size)))`. + /// + /// # Panics + /// + /// This will panic if `min_size` > `1 << Val::TWO_ADICITY`. + fn create_disjoint_domain(&self, min_size: usize) -> Self { + // We provide a short proof that these cosets are always disjoint: + // + // Assume without loss of generality that `|H| <= min_size <= |K|`. + // Then we know that `gH` is entirely contained in `gK`. As cosets are + // either equal or disjoint, this means that `gH` is disjoint from `g'K` + // for every `g'` not contained in `gK`. As `f` is a generator of `F^*` + // it does not lie in `K` and so `gf` cannot lie in `gK`. + // + // Thus `gH` and `gfK` are disjoint. + + // This panics if (and only if) `min_size` > `1 << Val::TWO_ADICITY`. + Self::new(self.shift() * Val::GENERATOR, log2_ceil_usize(min_size)).unwrap() + } + + /// Given the coset `gH` and generator `h` of `H`, let `K = H^{num_chunks}` + /// be the unique group of order `|H|/num_chunks`. + /// + /// Then we decompose `gH` into `gK, ghK, gh^2K, ..., gh^{num_chunks}K`. + fn split_domains(&self, num_chunks: usize) -> Vec { + let log_chunks = log2_strict_usize(num_chunks); + debug_assert!(log_chunks <= self.log_size()); + (0..num_chunks) + .map(|i| { + Self::new( + self.shift() * self.subgroup_generator().exp_u64(i as u64), + self.log_size() - log_chunks, + ) + .unwrap() // This won't panic as `self.log_size() - log_chunks < self.log_size() < Val::TWO_ADICITY` + }) + .collect() + } + + fn split_evals( + &self, + num_chunks: usize, + evals: RowMajorMatrix, + ) -> Vec> { + debug_assert_eq!(evals.height(), self.size()); + debug_assert!(log2_strict_usize(num_chunks) <= self.log_size()); + // todo less copy + (0..num_chunks) + .map(|i| { + evals + .as_view() + .vertically_strided(num_chunks, i) + .to_row_major_matrix() + }) + .collect() + } + + /// Compute the vanishing polynomial at the given point: + /// + /// `Z_{gH}(X) = g^{-|H|}\prod_{h \in H} (X - gh) = (g^{-1}X)^|H| - 1` + fn vanishing_poly_at_point>(&self, point: Ext) -> Ext { + (point * self.shift().inverse()).exp_power_of_2(self.log_size()) - Ext::ONE + } + + /// Compute several Lagrange selectors at the given point: + /// + /// Defining the vanishing polynomial by `Z_{gH}(X) = g^{-|H|}\prod_{h \in H} (X - gh) = (g^{-1}X)^|H| - 1` return: + /// - `Z_{gH}(X)/(g^{-1}X - 1)`: The Lagrange selector of the point `g`. + /// - `Z_{gH}(X)/(g^{-1}X - h^{-1})`: The Lagrange selector of the point `gh^{-1}` where `h` is the generator of `H`. + /// - `(g^{-1}X - h^{-1})`: The Lagrange selector of the subset consisting of everything but the point `gh^{-1}`. + /// - `1/Z_{gH}(X)`: The inverse of the vanishing polynomial. + fn selectors_at_point>(&self, point: Ext) -> LagrangeSelectors { + let unshifted_point = point * self.shift().inverse(); + let z_h = unshifted_point.exp_power_of_2(self.log_size()) - Ext::ONE; + LagrangeSelectors { + is_first_row: z_h / (unshifted_point - Ext::ONE), + is_last_row: z_h / (unshifted_point - self.subgroup_generator().inverse()), + is_transition: unshifted_point - self.subgroup_generator().inverse(), + inv_vanishing: z_h.inverse(), + } + } + + /// Compute the Lagrange selectors of our space at every point in the coset. + /// + /// This will error if our space is not the group `H` and if the given + /// coset is not disjoint from `H`. + fn selectors_on_coset(&self, coset: Self) -> LagrangeSelectors> { + assert_eq!(self.shift(), Val::ONE); + assert_ne!(coset.shift(), Val::ONE); + assert!(coset.log_size() >= self.log_size()); + let rate_bits = coset.log_size() - self.log_size(); + + let s_pow_n = coset.shift().exp_power_of_2(self.log_size()); + // evals of Z_H(X) = X^n - 1 + let evals = Val::two_adic_generator(rate_bits) + .powers() + .take(1 << rate_bits) + .map(|x| s_pow_n * x - Val::ONE) + .collect_vec(); + + let xs = cyclic_subgroup_coset_known_order( + coset.subgroup_generator(), + coset.shift(), + coset.size(), + ) + .collect_vec(); + + let single_point_selector = |i: u64| { + let coset_i = self.subgroup_generator().exp_u64(i); + let denoms = xs.iter().map(|&x| x - coset_i).collect_vec(); + let invs = batch_multiplicative_inverse(&denoms); + evals + .iter() + .cycle() + .zip(invs) + .map(|(&z_h, inv)| z_h * inv) + .collect_vec() + }; + + let subgroup_last = self.subgroup_generator().inverse(); + + LagrangeSelectors { + is_first_row: single_point_selector(0), + is_last_row: single_point_selector(self.size() as u64 - 1), + is_transition: xs.into_iter().map(|x| x - subgroup_last).collect(), + inv_vanishing: batch_multiplicative_inverse(&evals) + .into_iter() + .cycle() + .take(coset.size()) + .collect(), + } + } +} diff --git a/CoqOfRust/plonky3/commit/src/domain.v b/CoqOfRust/plonky3/commit/src/domain.v new file mode 100644 index 000000000..2622077cc --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/domain.v @@ -0,0 +1,3324 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module domain. + (* StructRecord + { + name := "LagrangeSelectors"; + const_params := []; + ty_params := [ "T" ]; + fields := + [ ("is_first_row", T); ("is_last_row", T); ("is_transition", T); ("inv_vanishing", T) ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_T_for_p3_commit_domain_LagrangeSelectors_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_commit::domain::LagrangeSelectors") [] [ T ]. + + (* Debug *) + Definition fmt (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field4_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "LagrangeSelectors" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "is_first_row" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::domain::LagrangeSelectors", + "is_first_row" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "is_last_row" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::domain::LagrangeSelectors", + "is_last_row" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "is_transition" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::domain::LagrangeSelectors", + "is_transition" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inv_vanishing" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::domain::LagrangeSelectors", + "inv_vanishing" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("fmt", InstanceField.Method (fmt T)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_T_for_p3_commit_domain_LagrangeSelectors_T. + + (* Trait *) + (* Empty module 'PolynomialSpace' *) + + Module Impl_p3_commit_domain_PolynomialSpace_where_p3_field_field_TwoAdicField_Val_for_p3_field_coset_TwoAdicMultiplicativeCoset_Val. + Definition Self (Val : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ]. + + (* type Val = Val; *) + Definition _Val (Val : Ty.t) : Ty.t := Val. + + (* + fn size(&self) -> usize { + self.size() + } + *) + Definition size (Val : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Val in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn first_point(&self) -> Self::Val { + self.shift() + } + *) + Definition first_point (Val : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Val in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "shift", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn next_point>(&self, x: Ext) -> Option { + Some(x * self.subgroup_generator()) + } + *) + Definition next_point (Val : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Val in + match ε, τ, α with + | [], [ Ext ], [ self; x ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x := M.alloc (| x |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ext, + M.get_trait_method (| "core::ops::arith::Mul", Ext, [], [ Val ], "mul", [], [] |), + [ + M.read (| x |); + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "subgroup_generator", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn create_disjoint_domain(&self, min_size: usize) -> Self { + // We provide a short proof that these cosets are always disjoint: + // + // Assume without loss of generality that `|H| <= min_size <= |K|`. + // Then we know that `gH` is entirely contained in `gK`. As cosets are + // either equal or disjoint, this means that `gH` is disjoint from `g'K` + // for every `g'` not contained in `gK`. As `f` is a generator of `F^*` + // it does not lie in `K` and so `gf` cannot lie in `gK`. + // + // Thus `gH` and `gfK` are disjoint. + + // This panics if (and only if) `min_size` > `1 << Val::TWO_ADICITY`. + Self::new(self.shift() * Val::GENERATOR, log2_ceil_usize(min_size)).unwrap() + } + *) + Definition create_disjoint_domain + (Val : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val in + match ε, τ, α with + | [], [], [ self; min_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let min_size := M.alloc (| min_size |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ] ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ] ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "new", + [], + [] + |), + [ + M.call_closure (| + Val, + M.get_trait_method (| + "core::ops::arith::Mul", + Val, + [], + [ Val ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.read (| get_constant (| "p3_field::field::Field::GENERATOR", Val |) |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_ceil_usize", [], [] |), + [ M.read (| min_size |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn split_domains(&self, num_chunks: usize) -> Vec { + let log_chunks = log2_strict_usize(num_chunks); + debug_assert!(log_chunks <= self.log_size()); + (0..num_chunks) + .map(|i| { + Self::new( + self.shift() * self.subgroup_generator().exp_u64(i as u64), + self.log_size() - log_chunks, + ) + .unwrap() // This won't panic as `self.log_size() - log_chunks < self.log_size() < Val::TWO_ADICITY` + }) + .collect() + } + *) + Definition split_domains + (Val : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val in + match ε, τ, α with + | [], [], [ self; num_chunks ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_chunks := M.alloc (| num_chunks |) in + M.read (| + let~ log_chunks : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| num_chunks |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| log_chunks |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "log_size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: log_chunks <= self.log_size()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| num_chunks |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "new", + [], + [] + |), + [ + M.call_closure (| + Val, + M.get_trait_method (| + "core::ops::arith::Mul", + Val, + [], + [ Val ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |); + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Val, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "subgroup_generator", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |); + M.cast (Ty.path "u64") (M.read (| i |)) + ] + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "log_size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |); + M.read (| log_chunks |) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn split_evals( + &self, + num_chunks: usize, + evals: RowMajorMatrix, + ) -> Vec> { + debug_assert_eq!(evals.height(), self.size()); + debug_assert!(log2_strict_usize(num_chunks) <= self.log_size()); + // todo less copy + (0..num_chunks) + .map(|i| { + evals + .as_view() + .vertically_strided(num_chunks, i) + .to_row_major_matrix() + }) + .collect() + } + *) + Definition split_evals (Val : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Val in + match ε, τ, α with + | [], [], [ self; num_chunks; evals ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_chunks := M.alloc (| num_chunks |) in + let evals := M.alloc (| evals |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + [], + [ Val ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ M.read (| num_chunks |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "log_size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: log2_strict_usize(num_chunks) <= self.log_size()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| num_chunks |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path + "p3_matrix::strided::VerticallyStridedRowIndexMap"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ], + [], + [ Val ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path + "p3_matrix::strided::VerticallyStridedRowIndexMap"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ], + [], + [ Val ], + "vertically_strided", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + "as_view", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) ] + |); + M.read (| num_chunks |); + M.read (| i |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn vanishing_poly_at_point>(&self, point: Ext) -> Ext { + (point * self.shift().inverse()).exp_power_of_2(self.log_size()) - Ext::ONE + } + *) + Definition vanishing_poly_at_point + (Val : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val in + match ε, τ, α with + | [], [ Ext ], [ self; point ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let point := M.alloc (| point |) in + M.call_closure (| + Ext, + M.get_trait_method (| "core::ops::arith::Sub", Ext, [], [ Ext ], "sub", [], [] |), + [ + M.call_closure (| + Ext, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ext, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Mul", + Ext, + [], + [ Val ], + "mul", + [], + [] + |), + [ + M.read (| point |); + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::Field", + Val, + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "log_size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |); + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Ext |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn selectors_at_point>(&self, point: Ext) -> LagrangeSelectors { + let unshifted_point = point * self.shift().inverse(); + let z_h = unshifted_point.exp_power_of_2(self.log_size()) - Ext::ONE; + LagrangeSelectors { + is_first_row: z_h / (unshifted_point - Ext::ONE), + is_last_row: z_h / (unshifted_point - self.subgroup_generator().inverse()), + is_transition: unshifted_point - self.subgroup_generator().inverse(), + inv_vanishing: z_h.inverse(), + } + } + *) + Definition selectors_at_point + (Val : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val in + match ε, τ, α with + | [], [ Ext ], [ self; point ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let point := M.alloc (| point |) in + M.read (| + let~ unshifted_point : Ty.apply (Ty.path "*") [] [ Ext ] := + M.alloc (| + M.call_closure (| + Ext, + M.get_trait_method (| "core::ops::arith::Mul", Ext, [], [ Val ], "mul", [], [] |), + [ + M.read (| point |); + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::Field", + Val, + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ z_h : Ty.apply (Ty.path "*") [] [ Ext ] := + M.alloc (| + M.call_closure (| + Ext, + M.get_trait_method (| "core::ops::arith::Sub", Ext, [], [ Ext ], "sub", [], [] |), + [ + M.call_closure (| + Ext, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ext, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, unshifted_point |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "log_size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Ext |) + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_commit::domain::LagrangeSelectors" + [ + ("is_first_row", + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Div", + Ext, + [], + [ Ext ], + "div", + [], + [] + |), + [ + M.read (| z_h |); + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Sub", + Ext, + [], + [ Ext ], + "sub", + [], + [] + |), + [ + M.read (| unshifted_point |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ext + |) + |) + ] + |) + ] + |)); + ("is_last_row", + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Div", + Ext, + [], + [ Ext ], + "div", + [], + [] + |), + [ + M.read (| z_h |); + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Sub", + Ext, + [], + [ Val ], + "sub", + [], + [] + |), + [ + M.read (| unshifted_point |); + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::Field", + Val, + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "subgroup_generator", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + ] + |)); + ("is_transition", + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Sub", + Ext, + [], + [ Val ], + "sub", + [], + [] + |), + [ + M.read (| unshifted_point |); + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::Field", + Val, + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "subgroup_generator", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) + ] + |) + |) + |) + ] + |) + ] + |)); + ("inv_vanishing", + M.call_closure (| + Ext, + M.get_trait_method (| + "p3_field::field::Field", + Ext, + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, z_h |) ] + |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn selectors_on_coset(&self, coset: Self) -> LagrangeSelectors> { + assert_eq!(self.shift(), Val::ONE); + assert_ne!(coset.shift(), Val::ONE); + assert!(coset.log_size() >= self.log_size()); + let rate_bits = coset.log_size() - self.log_size(); + + let s_pow_n = coset.shift().exp_power_of_2(self.log_size()); + // evals of Z_H(X) = X^n - 1 + let evals = Val::two_adic_generator(rate_bits) + .powers() + .take(1 << rate_bits) + .map(|x| s_pow_n * x - Val::ONE) + .collect_vec(); + + let xs = cyclic_subgroup_coset_known_order( + coset.subgroup_generator(), + coset.shift(), + coset.size(), + ) + .collect_vec(); + + let single_point_selector = |i: u64| { + let coset_i = self.subgroup_generator().exp_u64(i); + let denoms = xs.iter().map(|&x| x - coset_i).collect_vec(); + let invs = batch_multiplicative_inverse(&denoms); + evals + .iter() + .cycle() + .zip(invs) + .map(|(&z_h, inv)| z_h * inv) + .collect_vec() + }; + + let subgroup_last = self.subgroup_generator().inverse(); + + LagrangeSelectors { + is_first_row: single_point_selector(0), + is_last_row: single_point_selector(self.size() as u64 - 1), + is_transition: xs.into_iter().map(|x| x - subgroup_last).collect(), + inv_vanishing: batch_multiplicative_inverse(&evals) + .into_iter() + .cycle() + .take(coset.size()) + .collect(), + } + } + *) + Definition selectors_on_coset + (Val : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val in + match ε, τ, α with + | [], [], [ self; coset ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let coset := M.alloc (| coset |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Val |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Val, + [], + [ Val ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Val; Val ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coset |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Val |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Val, + [], + [ Val ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Ne" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Val; Val ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "log_size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coset |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "log_size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: coset.log_size() >= self.log_size()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ rate_bits : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "log_size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coset |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "log_size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + |) in + let~ s_pow_n : Ty.apply (Ty.path "*") [] [ Val ] := + M.alloc (| + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Val, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coset |) ] + |) + |) + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "log_size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + |) in + let~ evals : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ Val ] ]; + Ty.function [ Ty.tuple [ Val ] ] Val + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ Val ] ]; + Ty.function [ Ty.tuple [ Val ] ] Val + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ Val ] ], + [], + [], + "map", + [], + [ Val; Ty.function [ Ty.tuple [ Val ] ] Val ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ Val ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ Val ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ Val ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Val, + [], + [], + "powers", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Val, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| rate_bits |) ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| rate_bits |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Val ] ] Val ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Val, + M.get_trait_method (| + "core::ops::arith::Sub", + Val, + [], + [ Val ], + "sub", + [], + [] + |), + [ + M.call_closure (| + Val, + M.get_trait_method (| + "core::ops::arith::Mul", + Val, + [], + [ Val ], + "mul", + [], + [] + |), + [ M.read (| s_pow_n |); M.read (| x |) ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Val + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ xs : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_unknown, + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_function (| + "p3_field::helpers::cyclic_subgroup_coset_known_order", + [], + [ Val ] + |), + [ + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "subgroup_generator", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coset |) ] + |); + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coset |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coset |) ] + |) + ] + |) + ] + |) + |) in + let~ single_point_selector : + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "u64" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]) + ] := + M.alloc (| + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "u64" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + let~ coset_i : Ty.apply (Ty.path "*") [] [ Val ] := + M.alloc (| + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Val, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "subgroup_generator", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |); + M.read (| i |) + ] + |) + |) in + let~ denoms : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Val ] ] ] + Val + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Val ] ] + ] + Val + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ], + [], + [], + "map", + [], + [ + Val; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Val ] ] + ] + Val + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Val ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, xs |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Val ] + ] + ] + Val + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let x := M.copy (| γ |) in + M.call_closure (| + Val, + M.get_trait_method (| + "core::ops::arith::Sub", + Val, + [], + [ Val ], + "sub", + [], + [] + |), + [ + M.read (| x |); + M.read (| coset_i |) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ invs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse", + [], + [ Val ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, denoms |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Val ]; Val ] + ] + ] + Val + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Val ]; Val ] + ] + ] + Val + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "map", + [], + [ + Val; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Val ]; Val ] + ] + ] + Val + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ], + [], + [], + "cycle", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Val ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Val ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + evals + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.read (| invs |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Val ]; + Val + ] + ] + ] + Val + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let z_h := M.copy (| γ0_0 |) in + let inv := M.copy (| γ0_1 |) in + M.call_closure (| + Val, + M.get_trait_method (| + "core::ops::arith::Mul", + Val, + [], + [ Val ], + "mul", + [], + [] + |), + [ + M.read (| z_h |); + M.read (| inv |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + |) in + let~ subgroup_last : Ty.apply (Ty.path "*") [] [ Val ] := + M.alloc (| + M.call_closure (| + Val, + M.get_trait_method (| "p3_field::field::Field", Val, [], [], "inverse", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "subgroup_generator", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_commit::domain::LagrangeSelectors" + [ + ("is_first_row", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ Ty.tuple [ Ty.path "u64" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]), + [], + [ Ty.tuple [ Ty.path "u64" ] ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, single_point_selector |); + Value.Tuple [ Value.Integer IntegerKind.U64 0 ] + ] + |)); + ("is_last_row", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ Ty.tuple [ Ty.path "u64" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]), + [], + [ Ty.tuple [ Ty.path "u64" ] ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, single_point_selector |); + Value.Tuple + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |)); + Value.Integer IntegerKind.U64 1 + ] + |) + ] + ] + |)); + ("is_transition", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.function [ Ty.tuple [ Val ] ] Val + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.function [ Ty.tuple [ Val ] ] Val + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + [], + [], + "map", + [], + [ Val; Ty.function [ Ty.tuple [ Val ] ] Val ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| xs |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Val ] ] Val ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Val, + M.get_trait_method (| + "core::ops::arith::Sub", + Val, + [], + [ Val ], + "sub", + [], + [] + |), + [ M.read (| x |); M.read (| subgroup_last |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |)); + ("inv_vanishing", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cycle::Cycle") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + [], + [], + "cycle", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse", + [], + [ Val ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, evals |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coset |) ] + |) + ] + |) + ] + |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val : Ty.t), + M.IsTraitInstance + "p3_commit::domain::PolynomialSpace" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val) + (* Instance *) + [ + ("Val", InstanceField.Ty (_Val Val)); + ("size", InstanceField.Method (size Val)); + ("first_point", InstanceField.Method (first_point Val)); + ("next_point", InstanceField.Method (next_point Val)); + ("create_disjoint_domain", InstanceField.Method (create_disjoint_domain Val)); + ("split_domains", InstanceField.Method (split_domains Val)); + ("split_evals", InstanceField.Method (split_evals Val)); + ("vanishing_poly_at_point", InstanceField.Method (vanishing_poly_at_point Val)); + ("selectors_at_point", InstanceField.Method (selectors_at_point Val)); + ("selectors_on_coset", InstanceField.Method (selectors_on_coset Val)) + ]. + End Impl_p3_commit_domain_PolynomialSpace_where_p3_field_field_TwoAdicField_Val_for_p3_field_coset_TwoAdicMultiplicativeCoset_Val. +End domain. diff --git a/CoqOfRust/plonky3/commit/src/lib.rs b/CoqOfRust/plonky3/commit/src/lib.rs new file mode 100644 index 000000000..2a2f6b97d --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/lib.rs @@ -0,0 +1,18 @@ +//! A framework for various (not necessarily hiding) cryptographic commitment schemes. + +#![no_std] + +extern crate alloc; + +mod adapters; +mod domain; +mod mmcs; +mod pcs; + +#[cfg(any(test, feature = "test-utils"))] +pub mod testing; + +pub use adapters::*; +pub use domain::*; +pub use mmcs::*; +pub use pcs::*; diff --git a/CoqOfRust/plonky3/commit/src/mmcs.rs b/CoqOfRust/plonky3/commit/src/mmcs.rs new file mode 100644 index 000000000..7002ec2b3 --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/mmcs.rs @@ -0,0 +1,82 @@ +use alloc::vec; +use alloc::vec::Vec; +use core::fmt::Debug; + +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::{Dimensions, Matrix}; +use serde::Serialize; +use serde::de::DeserializeOwned; + +/// A "Mixed Matrix Commitment Scheme" (MMCS) is a generalization of a vector commitment scheme. +/// +/// It supports committing to matrices and then opening rows. It is also batch-oriented; one can commit +/// to a batch of matrices at once even if their widths and heights differ. +/// +/// When a particular row index is opened, it is interpreted directly as a row index for matrices +/// with the largest height. For matrices with smaller heights, some bits of the row index are +/// removed (from the least-significant side) to get the effective row index. These semantics are +/// useful in the FRI protocol. See the documentation for `open_batch` for more details. +pub trait Mmcs: Clone { + type ProverData; + type Commitment: Clone + Serialize + DeserializeOwned; + type Proof: Clone + Serialize + DeserializeOwned; + type Error: Debug; + + fn commit>(&self, inputs: Vec) -> (Self::Commitment, Self::ProverData); + + fn commit_matrix>(&self, input: M) -> (Self::Commitment, Self::ProverData) { + self.commit(vec![input]) + } + + fn commit_vec(&self, input: Vec) -> (Self::Commitment, Self::ProverData>) + where + T: Clone + Send + Sync, + { + self.commit_matrix(RowMajorMatrix::new_col(input)) + } + + /// Opens a batch of rows from committed matrices + /// returns `(openings, proof)` + /// where `openings` is a vector whose `i`th element is the `j`th row of the ith matrix `M[i]`, + /// and `j = index >> (log2_ceil(max_height) - log2_ceil(M[i].height))`. + fn open_batch>( + &self, + index: usize, + prover_data: &Self::ProverData, + ) -> (Vec>, Self::Proof); + + /// Get the matrices that were committed to. + fn get_matrices<'a, M: Matrix>(&self, prover_data: &'a Self::ProverData) -> Vec<&'a M>; + + fn get_matrix_heights>(&self, prover_data: &Self::ProverData) -> Vec { + self.get_matrices(prover_data) + .iter() + .map(|matrix| matrix.height()) + .collect() + } + + /// Get the largest height of any committed matrix. + /// + /// # Panics + /// This may panic if there are no committed matrices. + fn get_max_height>(&self, prover_data: &Self::ProverData) -> usize { + self.get_matrix_heights(prover_data) + .into_iter() + .max() + .unwrap_or_else(|| panic!("No committed matrices?")) + } + + /// Verify a batch opening. + /// `index` is the row index we're opening for each matrix, following the same + /// semantics as `open_batch`. + /// `dimensions` is a slice whose ith element is the dimensions of the matrix being opened + /// in the ith opening + fn verify_batch( + &self, + commit: &Self::Commitment, + dimensions: &[Dimensions], + index: usize, + opened_values: &[Vec], + proof: &Self::Proof, + ) -> Result<(), Self::Error>; +} diff --git a/CoqOfRust/plonky3/commit/src/mmcs.v b/CoqOfRust/plonky3/commit/src/mmcs.v new file mode 100644 index 000000000..f0a32d8e3 --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/mmcs.v @@ -0,0 +1,500 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module mmcs. + (* Trait *) + Module Mmcs. + Definition commit_matrix + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ M_ ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ T ] Self "Commitment"; + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ T; M_ ] Self "ProverData" + ], + M.get_trait_method (| "p3_commit::mmcs::Mmcs", Self, [], [ T ], "commit", [], [ M_ ] |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ M_; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ M_ ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 1 ] [ M_ ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ M_ ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ M.alloc (| Value.Array [ M.read (| input |) ] |) ] + |) + |)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_commit_matrix : + forall (T : Ty.t), + M.IsProvidedMethod "p3_commit::mmcs::Mmcs" "commit_matrix" (commit_matrix T). + Definition commit_vec + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ T ] Self "Commitment"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + T; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + T; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ] + ] + ] + Self + "ProverData" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + Self, + [], + [ T ], + "commit_matrix", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ T; Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ T; Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + T; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] + ], + "new_col", + [], + [] + |), + [ M.read (| input |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_commit_vec : + forall (T : Ty.t), + M.IsProvidedMethod "p3_commit::mmcs::Mmcs" "commit_vec" (commit_vec T). + Definition get_matrix_heights + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ M_ ], [ self; prover_data ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let prover_data := M.alloc (| prover_data |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "usize"; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ] ] ] + (Ty.path "usize") + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "usize"; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ] ] + ] + (Ty.path "usize") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + [], + [], + "map", + [], + [ + Ty.path "usize"; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ] ] + ] + (Ty.path "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + Self, + [], + [ T ], + "get_matrices", + [], + [ M_ ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prover_data |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.path "usize") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let matrix := M.copy (| γ |) in + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ T ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| M.deref (| M.read (| matrix |) |) |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_get_matrix_heights : + forall (T : Ty.t), + M.IsProvidedMethod "p3_commit::mmcs::Mmcs" "get_matrix_heights" (get_matrix_heights T). + Definition get_max_height + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ M_ ], [ self; prover_data ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let prover_data := M.alloc (| prover_data |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + "unwrap_or_else", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.path "usize") ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.path "usize"; Ty.path "alloc::alloc::Global" ], + [], + [], + "max", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.path "usize"; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "usize"; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "usize"; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + Self, + [], + [ T ], + "get_matrix_heights", + [], + [ M_ ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| prover_data |) |) |) + ] + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.path "usize") ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "No committed matrices?" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_get_max_height : + forall (T : Ty.t), + M.IsProvidedMethod "p3_commit::mmcs::Mmcs" "get_max_height" (get_max_height T). + End Mmcs. +End mmcs. diff --git a/CoqOfRust/plonky3/commit/src/pcs.rs b/CoqOfRust/plonky3/commit/src/pcs.rs new file mode 100644 index 000000000..88532dcce --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/pcs.rs @@ -0,0 +1,95 @@ +//! Traits for polynomial commitment schemes. + +use alloc::vec::Vec; +use core::fmt::Debug; + +use p3_field::ExtensionField; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use serde::Serialize; +use serde::de::DeserializeOwned; + +use crate::PolynomialSpace; + +pub type Val = ::Val; + +/// A (not necessarily hiding) polynomial commitment scheme, for committing to (batches of) polynomials +// TODO: Should we have a super-trait for weakly-binding PCSs, like FRI outside unique decoding radius? +pub trait Pcs +where + Challenge: ExtensionField>, +{ + type Domain: PolynomialSpace; + + /// The commitment that's sent to the verifier. + type Commitment: Clone + Serialize + DeserializeOwned; + + /// Data that the prover stores for committed polynomials, to help the prover with opening. + type ProverData; + + /// Type of the output of `get_evaluations_on_domain`. + type EvaluationsOnDomain<'a>: Matrix> + 'a; + + /// The opening argument. + type Proof: Clone + Serialize + DeserializeOwned; + + type Error: Debug; + + /// This should return a coset domain (s.t. Domain::next_point returns Some) + fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain; + + #[allow(clippy::type_complexity)] + fn commit( + &self, + evaluations: Vec<(Self::Domain, RowMajorMatrix>)>, + ) -> (Self::Commitment, Self::ProverData); + + fn get_evaluations_on_domain<'a>( + &self, + prover_data: &'a Self::ProverData, + idx: usize, + domain: Self::Domain, + ) -> Self::EvaluationsOnDomain<'a>; + + fn open( + &self, + // For each round, + rounds: Vec<( + &Self::ProverData, + // for each matrix, + Vec< + // points to open + Vec, + >, + )>, + challenger: &mut Challenger, + ) -> (OpenedValues, Self::Proof); + + #[allow(clippy::type_complexity)] + fn verify( + &self, + // For each round: + rounds: Vec<( + Self::Commitment, + // for each matrix: + Vec<( + // its domain, + Self::Domain, + // for each point: + Vec<( + // the point, + Challenge, + // values at the point + Vec, + )>, + )>, + )>, + proof: &Self::Proof, + challenger: &mut Challenger, + ) -> Result<(), Self::Error>; +} + +pub type OpenedValues = Vec>; +pub type OpenedValuesForRound = Vec>; +pub type OpenedValuesForMatrix = Vec>; +pub type OpenedValuesForPoint = Vec; diff --git a/CoqOfRust/plonky3/commit/src/pcs.v b/CoqOfRust/plonky3/commit/src/pcs.v new file mode 100644 index 000000000..c62466a8b --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/pcs.v @@ -0,0 +1,68 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module pcs. + Axiom Val : + forall (D : Ty.t), + (Ty.apply (Ty.path "p3_commit::pcs::Val") [] [ D ]) = + (Ty.associated_in_trait "p3_commit::domain::PolynomialSpace" [] [] D "Val"). + + (* Trait *) + (* Empty module 'Pcs' *) + + Axiom OpenedValues : + forall (F : Ty.t), + (Ty.apply (Ty.path "p3_commit::pcs::OpenedValues") [] [ F ]) = + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]). + + Axiom OpenedValuesForRound : + forall (F : Ty.t), + (Ty.apply (Ty.path "p3_commit::pcs::OpenedValuesForRound") [] [ F ]) = + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]). + + Axiom OpenedValuesForMatrix : + forall (F : Ty.t), + (Ty.apply (Ty.path "p3_commit::pcs::OpenedValuesForMatrix") [] [ F ]) = + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]). + + Axiom OpenedValuesForPoint : + forall (F : Ty.t), + (Ty.apply (Ty.path "p3_commit::pcs::OpenedValuesForPoint") [] [ F ]) = + (Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]). +End pcs. diff --git a/CoqOfRust/plonky3/commit/src/testing.rs b/CoqOfRust/plonky3/commit/src/testing.rs new file mode 100644 index 000000000..7c13dfca6 --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/testing.rs @@ -0,0 +1,176 @@ +use alloc::vec; +use alloc::vec::Vec; +use core::marker::PhantomData; + +use p3_challenger::CanSample; +use p3_dft::TwoAdicSubgroupDft; +use p3_field::coset::TwoAdicMultiplicativeCoset; +use p3_field::{ExtensionField, Field, TwoAdicField}; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_util::log2_strict_usize; +use p3_util::zip_eq::zip_eq; +use serde::{Deserialize, Serialize}; + +use crate::{OpenedValues, Pcs}; + +/// A trivial PCS: its commitment is simply the coefficients of each poly. +#[derive(Debug)] +pub struct TrivialPcs> { + pub dft: Dft, + // degree bound + pub log_n: usize, + pub _phantom: PhantomData, +} + +pub fn eval_coeffs_at_pt>( + coeffs: &RowMajorMatrix, + x: EF, +) -> Vec { + let mut acc = vec![EF::ZERO; coeffs.width()]; + for r in (0..coeffs.height()).rev() { + let row = coeffs.row_slice(r); + for (acc_c, row_c) in acc.iter_mut().zip(row.iter()) { + *acc_c *= x; + *acc_c += *row_c; + } + } + acc +} + +impl Pcs for TrivialPcs +where + Val: TwoAdicField, + Challenge: ExtensionField, + Challenger: CanSample, + Dft: TwoAdicSubgroupDft, + Vec>: Serialize + for<'de> Deserialize<'de>, +{ + type Domain = TwoAdicMultiplicativeCoset; + type Commitment = Vec>; + type ProverData = Vec>; + type EvaluationsOnDomain<'a> = Dft::Evaluations; + type Proof = (); + type Error = (); + + fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain { + // This panics if (and only if) `degree` is not a power of 2 or `degree` + // > `1 << Val::TWO_ADICITY`. + TwoAdicMultiplicativeCoset::new(Val::ONE, log2_strict_usize(degree)).unwrap() + } + + fn commit( + &self, + evaluations: Vec<(Self::Domain, RowMajorMatrix)>, + ) -> (Self::Commitment, Self::ProverData) { + let coeffs: Vec<_> = evaluations + .into_iter() + .map(|(domain, evals)| { + let log_domain_size = log2_strict_usize(domain.size()); + // for now, only commit on larger domain than natural + assert!(log_domain_size >= self.log_n); + assert_eq!(domain.size(), evals.height()); + // coset_idft_batch + let mut coeffs = self.dft.idft_batch(evals); + coeffs + .rows_mut() + .zip(domain.shift().inverse().powers()) + .for_each(|(row, weight)| { + row.iter_mut().for_each(|coeff| { + *coeff *= weight; + }) + }); + coeffs + }) + .collect(); + ( + coeffs.clone().into_iter().map(|m| m.values).collect(), + coeffs, + ) + } + + fn get_evaluations_on_domain<'a>( + &self, + prover_data: &'a Self::ProverData, + idx: usize, + domain: Self::Domain, + ) -> Self::EvaluationsOnDomain<'a> { + let mut coeffs = prover_data[idx].clone(); + assert!(domain.log_size() >= self.log_n); + coeffs.values.resize( + coeffs.values.len() << (domain.log_size() - self.log_n), + Val::ZERO, + ); + self.dft.coset_dft_batch(coeffs, domain.shift()) + } + + fn open( + &self, + // For each round, + rounds: Vec<( + &Self::ProverData, + // for each matrix, + Vec< + // points to open + Vec, + >, + )>, + _challenger: &mut Challenger, + ) -> (OpenedValues, Self::Proof) { + ( + rounds + .into_iter() + .map(|(coeffs_for_round, points_for_round)| { + // ensure that each matrix corresponds to a set of opening points + debug_assert_eq!(coeffs_for_round.len(), points_for_round.len()); + coeffs_for_round + .iter() + .zip(points_for_round) + .map(|(coeffs_for_mat, points_for_mat)| { + points_for_mat + .into_iter() + .map(|pt| eval_coeffs_at_pt(coeffs_for_mat, pt)) + .collect() + }) + .collect() + }) + .collect(), + (), + ) + } + + // This is a testing function, so we allow panics for convenience. + #[allow(clippy::panic_in_result_fn)] + fn verify( + &self, + // For each round: + rounds: Vec<( + Self::Commitment, + // for each matrix: + Vec<( + // its domain, + Self::Domain, + // for each point: + Vec<( + Challenge, + // values at this point + Vec, + )>, + )>, + )>, + _proof: &Self::Proof, + _challenger: &mut Challenger, + ) -> Result<(), Self::Error> { + for (comm, round_opening) in rounds { + for (coeff_vec, (domain, points_and_values)) in zip_eq(comm, round_opening, ())? { + let width = coeff_vec.len() / domain.size(); + assert_eq!(width * domain.size(), coeff_vec.len()); + let coeffs = RowMajorMatrix::new(coeff_vec, width); + for (pt, values) in points_and_values { + assert_eq!(eval_coeffs_at_pt(&coeffs, pt), values); + } + } + } + Ok(()) + } +} diff --git a/CoqOfRust/plonky3/commit/src/testing.v b/CoqOfRust/plonky3/commit/src/testing.v new file mode 100644 index 000000000..c108d2579 --- /dev/null +++ b/CoqOfRust/plonky3/commit/src/testing.v @@ -0,0 +1,6221 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module testing. + (* StructRecord + { + name := "TrivialPcs"; + const_params := []; + ty_params := [ "Val"; "Dft" ]; + fields := + [ + ("dft", Dft); + ("log_n", Ty.path "usize"); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ Val ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Val_where_p3_field_field_TwoAdicField_Val_where_core_fmt_Debug_Dft_where_p3_dft_traits_TwoAdicSubgroupDft_Dft_Val_for_p3_commit_testing_TrivialPcs_Val_Dft. + Definition Self (Val Dft : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_commit::testing::TrivialPcs") [] [ Val; Dft ]. + + (* Debug *) + Definition fmt (Val Dft : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Val Dft in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "TrivialPcs" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "dft" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::testing::TrivialPcs", + "dft" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "log_n" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::testing::TrivialPcs", + "log_n" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::testing::TrivialPcs", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Dft : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val Dft) + (* Instance *) [ ("fmt", InstanceField.Method (fmt Val Dft)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Val_where_p3_field_field_TwoAdicField_Val_where_core_fmt_Debug_Dft_where_p3_dft_traits_TwoAdicSubgroupDft_Dft_Val_for_p3_commit_testing_TrivialPcs_Val_Dft. + + (* + pub fn eval_coeffs_at_pt>( + coeffs: &RowMajorMatrix, + x: EF, + ) -> Vec { + let mut acc = vec![EF::ZERO; coeffs.width()]; + for r in (0..coeffs.height()).rev() { + let row = coeffs.row_slice(r); + for (acc_c, row_c) in acc.iter_mut().zip(row.iter()) { + *acc_c *= x; + *acc_c += *row_c; + } + } + acc + } + *) + Definition eval_coeffs_at_pt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF ], [ coeffs; x ] => + ltac:(M.monadic + (let coeffs := M.alloc (| coeffs |) in + let x := M.alloc (| x |) in + M.read (| + let~ acc : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloc::vec::from_elem", [], [ EF ] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", EF |) + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| coeffs |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| coeffs |) |) + |) + ] + |)) + ] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let r := M.copy (| γ0_0 |) in + let~ row : + Ty.apply (Ty.path "*") [] [ Ty.associated_unknown ] := + M.alloc (| + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "row_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| coeffs |) |) + |); + M.read (| r |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ EF ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ EF ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ EF ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ EF ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ EF ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ EF ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + acc + |) + ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.associated_unknown, + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, row |) ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ EF ]; + Ty.apply (Ty.path "&") [] [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ EF ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let acc_c := M.copy (| γ1_0 |) in + let row_c := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + EF, + [], + [ EF ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| acc_c |) + |) + |); + M.read (| x |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + EF, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| acc_c |) + |) + |); + M.read (| + M.deref (| + M.read (| row_c |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + acc + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_eval_coeffs_at_pt : + M.IsFunction.C "p3_commit::testing::eval_coeffs_at_pt" eval_coeffs_at_pt. + Admitted. + Global Typeclasses Opaque eval_coeffs_at_pt. + + Module Impl_p3_commit_pcs_Pcs_where_p3_field_field_TwoAdicField_Val_where_p3_field_field_ExtensionField_Challenge_Val_where_p3_challenger_CanSample_Challenger_Challenge_where_p3_dft_traits_TwoAdicSubgroupDft_Dft_Val_where_serde_ser_Serialize_alloc_vec_Vec_alloc_vec_Vec_Val_alloc_alloc_Global_alloc_alloc_Global_where_serde_de_Deserialize_alloc_vec_Vec_alloc_vec_Vec_Val_alloc_alloc_Global_alloc_alloc_Global_Challenge_Challenger_for_p3_commit_testing_TrivialPcs_Val_Dft. + Definition Self (Val Dft Challenge Challenger : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_commit::testing::TrivialPcs") [] [ Val; Dft ]. + + (* type Domain = TwoAdicMultiplicativeCoset; *) + Definition _Domain (Val Dft Challenge Challenger : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ]. + + (* type Commitment = Vec>; *) + Definition _Commitment (Val Dft Challenge Challenger : Ty.t) : Ty.t := + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]. + + (* type ProverData = Vec>; *) + Definition _ProverData (Val Dft Challenge Challenger : Ty.t) : Ty.t := + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ]. + + (* type EvaluationsOnDomain<'a> = Dft::Evaluations; *) + Definition _EvaluationsOnDomain (Val Dft Challenge Challenger : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_dft::traits::TwoAdicSubgroupDft" [] [ Val ] Dft "Evaluations". + + (* type Proof = (); *) + Definition _Proof (Val Dft Challenge Challenger : Ty.t) : Ty.t := Ty.tuple []. + + (* type Error = (); *) + Definition _Error (Val Dft Challenge Challenger : Ty.t) : Ty.t := Ty.tuple []. + + (* + fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain { + // This panics if (and only if) `degree` is not a power of 2 or `degree` + // > `1 << Val::TWO_ADICITY`. + TwoAdicMultiplicativeCoset::new(Val::ONE, log2_strict_usize(degree)).unwrap() + } + *) + Definition natural_domain_for_degree + (Val Dft Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft Challenge Challenger in + match ε, τ, α with + | [], [], [ self; degree ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let degree := M.alloc (| degree |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ] ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ] ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "new", + [], + [] + |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Val |) + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| degree |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn commit( + &self, + evaluations: Vec<(Self::Domain, RowMajorMatrix)>, + ) -> (Self::Commitment, Self::ProverData) { + let coeffs: Vec<_> = evaluations + .into_iter() + .map(|(domain, evals)| { + let log_domain_size = log2_strict_usize(domain.size()); + // for now, only commit on larger domain than natural + assert!(log_domain_size >= self.log_n); + assert_eq!(domain.size(), evals.height()); + // coset_idft_batch + let mut coeffs = self.dft.idft_batch(evals); + coeffs + .rows_mut() + .zip(domain.shift().inverse().powers()) + .for_each(|(row, weight)| { + row.iter_mut().for_each(|coeff| { + *coeff *= weight; + }) + }); + coeffs + }) + .collect(); + ( + coeffs.clone().into_iter().map(|m| m.values).collect(), + coeffs, + ) + } + *) + Definition commit + (Val Dft Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft Challenge Challenger in + match ε, τ, α with + | [], [], [ self; evaluations ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let evaluations := M.alloc (| evaluations |) in + M.read (| + let~ coeffs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| evaluations |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let domain := M.copy (| γ0_0 |) in + let evals := M.copy (| γ0_1 |) in + M.read (| + let~ log_domain_size : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, domain |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| log_domain_size |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_commit::testing::TrivialPcs", + "log_n" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic", + [], + [] + |), + [ + mk_str (| + "assertion failed: log_domain_size >= self.log_n" + |) + ] + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + domain + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Val ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ coeffs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ Val ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::testing::TrivialPcs", + "dft" + |) + |); + M.read (| evals |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ Val ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ]; + Val + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ Val ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ Val ] + ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ], + "rows_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + coeffs + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ Val ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Val, + [], + [], + "powers", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::Field", + Val, + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + domain + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ]; + Val + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let row := + M.copy (| γ0_0 |) in + let weight := + M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ Val ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ Val ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ Val ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Val ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| row |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Val + ] + ] + ] + (Ty.tuple + []) + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + coeff := + M.copy (| + γ + |) in + M.read (| + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Val, + [], + [ + Val + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + coeff + |) + |) + |); + M.read (| + weight + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + coeffs + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, coeffs |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := M.copy (| γ |) in + M.read (| + M.SubPointer.get_struct_record_field (| + m, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |); + M.read (| coeffs |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn get_evaluations_on_domain<'a>( + &self, + prover_data: &'a Self::ProverData, + idx: usize, + domain: Self::Domain, + ) -> Self::EvaluationsOnDomain<'a> { + let mut coeffs = prover_data[idx].clone(); + assert!(domain.log_size() >= self.log_n); + coeffs.values.resize( + coeffs.values.len() << (domain.log_size() - self.log_n), + Val::ZERO, + ); + self.dft.coset_dft_batch(coeffs, domain.shift()) + } + *) + Definition get_evaluations_on_domain + (Val Dft Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft Challenge Challenger in + match ε, τ, α with + | [], [], [ self; prover_data; idx; domain ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let prover_data := M.alloc (| prover_data |) in + let idx := M.alloc (| idx |) in + let domain := M.alloc (| domain |) in + M.read (| + let~ coeffs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| prover_data |) |) |); + M.read (| idx |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "log_size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, domain |) ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::testing::TrivialPcs", + "log_n" + |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: domain.log_size() >= self.log_n" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ], + "resize", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + coeffs, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + coeffs, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "log_size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, domain |) ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::testing::TrivialPcs", + "log_n" + |) + |) + ] + |) + ] + |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", Val |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ Val ] + Dft + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ Val ], + "coset_dft_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_commit::testing::TrivialPcs", + "dft" + |) + |); + M.read (| coeffs |); + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "shift", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, domain |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn open( + &self, + // For each round, + rounds: Vec<( + &Self::ProverData, + // for each matrix, + Vec< + // points to open + Vec, + >, + )>, + _challenger: &mut Challenger, + ) -> (OpenedValues, Self::Proof) { + ( + rounds + .into_iter() + .map(|(coeffs_for_round, points_for_round)| { + // ensure that each matrix corresponds to a set of opening points + debug_assert_eq!(coeffs_for_round.len(), points_for_round.len()); + coeffs_for_round + .iter() + .zip(points_for_round) + .map(|(coeffs_for_mat, points_for_mat)| { + points_for_mat + .into_iter() + .map(|pt| eval_coeffs_at_pt(coeffs_for_mat, pt)) + .collect() + }) + .collect() + }) + .collect(), + (), + ) + } + *) + Definition open + (Val Dft Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft Challenge Challenger in + match ε, τ, α with + | [], [], [ self; rounds; _challenger ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rounds := M.alloc (| rounds |) in + let _challenger := M.alloc (| _challenger |) in + Value.Tuple + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| rounds |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let coeffs_for_round := M.copy (| γ0_0 |) in + let points_for_round := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + coeffs_for_round + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + points_for_round + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + coeffs_for_round + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.read (| points_for_round |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let coeffs_for_mat := + M.copy (| γ0_0 |) in + let points_for_mat := + M.copy (| γ0_1 |) in + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ Challenge ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ Challenge ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ Challenge ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + points_for_mat + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Challenge + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + pt := + M.copy (| + γ + |) in + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_function (| + "p3_commit::testing::eval_coeffs_at_pt", + [], + [ + Val; + Challenge + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + coeffs_for_mat + |) + |) + |); + M.read (| + pt + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |); + Value.Tuple [] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn verify( + &self, + // For each round: + rounds: Vec<( + Self::Commitment, + // for each matrix: + Vec<( + // its domain, + Self::Domain, + // for each point: + Vec<( + Challenge, + // values at this point + Vec, + )>, + )>, + )>, + _proof: &Self::Proof, + _challenger: &mut Challenger, + ) -> Result<(), Self::Error> { + for (comm, round_opening) in rounds { + for (coeff_vec, (domain, points_and_values)) in zip_eq(comm, round_opening, ())? { + let width = coeff_vec.len() / domain.size(); + assert_eq!(width * domain.size(), coeff_vec.len()); + let coeffs = RowMajorMatrix::new(coeff_vec, width); + for (pt, values) in points_and_values { + assert_eq!(eval_coeffs_at_pt(&coeffs, pt), values); + } + } + } + Ok(()) + } + *) + Definition verify + (Val Dft Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft Challenge Challenger in + match ε, τ, α with + | [], [], [ self; rounds; _proof; _challenger ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rounds := M.alloc (| rounds |) in + let _proof := M.alloc (| _proof |) in + let _challenger := M.alloc (| _challenger |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ Challenge; Challenger ] + (Ty.apply (Ty.path "p3_commit::testing::TrivialPcs") [] [ Val; Dft ]) + "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| rounds |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let comm := M.copy (| γ1_0 |) in + let round_opening := M.copy (| γ1_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.tuple [] + ]; + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.tuple [] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.tuple [] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.tuple [] + ] + |), + [ + M.read (| comm |); + M.read (| round_opening |); + Value.Tuple [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ Ty.tuple []; Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.tuple [] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.tuple [] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let coeff_vec := + M.copy (| γ1_0 |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ1_1, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ1_1, + 1 + |) in + let domain := M.copy (| γ2_0 |) in + let points_and_values := + M.copy (| γ2_1 |) in + let~ width : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + coeff_vec + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + domain + |) + ] + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| + width + |); + M.call_closure (| + Ty.path + "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + domain + |) + ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + coeff_vec + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple [] + |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ + kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path + "usize"; + Ty.path + "usize" + ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + let~ coeffs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ + M.read (| coeff_vec |); + M.read (| width |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + points_and_values + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] + ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let pt := + M.copy (| + γ1_0 + |) in + let + values := + M.copy (| + γ1_1 + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_function (| + "p3_commit::testing::eval_coeffs_at_pt", + [], + [ + Val; + Challenge + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + coeffs + |) + |) + |); + M.read (| + pt + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + values + |) + ] + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + left_val := + M.copy (| + γ0_0 + |) in + let + right_val := + M.copy (| + γ0_1 + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + Value.Tuple + [] + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let + _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ + kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [] + |))) + ] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| Value.StructTuple "core::result::Result::Ok" [ Value.Tuple [] ] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Dft Challenge Challenger : Ty.t), + M.IsTraitInstance + "p3_commit::pcs::Pcs" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Challenge; Challenger ] + (Self Val Dft Challenge Challenger) + (* Instance *) + [ + ("Domain", InstanceField.Ty (_Domain Val Dft Challenge Challenger)); + ("Commitment", InstanceField.Ty (_Commitment Val Dft Challenge Challenger)); + ("ProverData", InstanceField.Ty (_ProverData Val Dft Challenge Challenger)); + ("EvaluationsOnDomain", + InstanceField.Ty (_EvaluationsOnDomain Val Dft Challenge Challenger)); + ("Proof", InstanceField.Ty (_Proof Val Dft Challenge Challenger)); + ("Error", InstanceField.Ty (_Error Val Dft Challenge Challenger)); + ("natural_domain_for_degree", + InstanceField.Method (natural_domain_for_degree Val Dft Challenge Challenger)); + ("commit", InstanceField.Method (commit Val Dft Challenge Challenger)); + ("get_evaluations_on_domain", + InstanceField.Method (get_evaluations_on_domain Val Dft Challenge Challenger)); + ("open", InstanceField.Method (open Val Dft Challenge Challenger)); + ("verify", InstanceField.Method (verify Val Dft Challenge Challenger)) + ]. + End Impl_p3_commit_pcs_Pcs_where_p3_field_field_TwoAdicField_Val_where_p3_field_field_ExtensionField_Challenge_Val_where_p3_challenger_CanSample_Challenger_Challenge_where_p3_dft_traits_TwoAdicSubgroupDft_Dft_Val_where_serde_ser_Serialize_alloc_vec_Vec_alloc_vec_Vec_Val_alloc_alloc_Global_alloc_alloc_Global_where_serde_de_Deserialize_alloc_vec_Vec_alloc_vec_Vec_Val_alloc_alloc_Global_alloc_alloc_Global_Challenge_Challenger_for_p3_commit_testing_TrivialPcs_Val_Dft. +End testing. diff --git a/CoqOfRust/plonky3/dft/src/butterflies.rs b/CoqOfRust/plonky3/dft/src/butterflies.rs new file mode 100644 index 000000000..cf75e7c4e --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/butterflies.rs @@ -0,0 +1,87 @@ +use core::mem::MaybeUninit; + +use itertools::izip; +use p3_field::{Field, PackedField, PackedValue}; + +pub trait Butterfly: Copy + Send + Sync { + fn apply>(&self, x_1: PF, x_2: PF) -> (PF, PF); + + #[inline] + fn apply_in_place>(&self, x_1: &mut PF, x_2: &mut PF) { + (*x_1, *x_2) = self.apply(*x_1, *x_2); + } + + #[inline] + fn apply_to_rows(&self, row_1: &mut [F], row_2: &mut [F]) { + let (shorts_1, suffix_1) = F::Packing::pack_slice_with_suffix_mut(row_1); + let (shorts_2, suffix_2) = F::Packing::pack_slice_with_suffix_mut(row_2); + debug_assert_eq!(shorts_1.len(), shorts_2.len()); + debug_assert_eq!(suffix_1.len(), suffix_2.len()); + for (x_1, x_2) in shorts_1.iter_mut().zip(shorts_2) { + self.apply_in_place(x_1, x_2); + } + for (x_1, x_2) in suffix_1.iter_mut().zip(suffix_2) { + self.apply_in_place(x_1, x_2); + } + } + + /// Like `apply_to_rows`, but out-of-place. + #[inline] + fn apply_to_rows_oop( + &self, + src_1: &[F], + dst_1: &mut [MaybeUninit], + src_2: &[F], + dst_2: &mut [MaybeUninit], + ) { + let (src_shorts_1, src_suffix_1) = F::Packing::pack_slice_with_suffix(src_1); + let (src_shorts_2, src_suffix_2) = F::Packing::pack_slice_with_suffix(src_2); + let (dst_shorts_1, dst_suffix_1) = + F::Packing::pack_maybe_uninit_slice_with_suffix_mut(dst_1); + let (dst_shorts_2, dst_suffix_2) = + F::Packing::pack_maybe_uninit_slice_with_suffix_mut(dst_2); + debug_assert_eq!(src_shorts_1.len(), src_shorts_2.len()); + debug_assert_eq!(src_suffix_1.len(), src_suffix_2.len()); + debug_assert_eq!(dst_shorts_1.len(), dst_shorts_2.len()); + debug_assert_eq!(dst_suffix_1.len(), dst_suffix_2.len()); + for (s_1, s_2, d_1, d_2) in izip!(src_shorts_1, src_shorts_2, dst_shorts_1, dst_shorts_2) { + let (res_1, res_2) = self.apply(*s_1, *s_2); + d_1.write(res_1); + d_2.write(res_2); + } + for (s_1, s_2, d_1, d_2) in izip!(src_suffix_1, src_suffix_2, dst_suffix_1, dst_suffix_2) { + let (res_1, res_2) = self.apply(*s_1, *s_2); + d_1.write(res_1); + d_2.write(res_2); + } + } +} + +#[derive(Copy, Clone)] +pub struct DifButterfly(pub F); +impl Butterfly for DifButterfly { + #[inline] + fn apply>(&self, x_1: PF, x_2: PF) -> (PF, PF) { + (x_1 + x_2, (x_1 - x_2) * self.0) + } +} + +#[derive(Copy, Clone)] +pub struct DitButterfly(pub F); +impl Butterfly for DitButterfly { + #[inline] + fn apply>(&self, x_1: PF, x_2: PF) -> (PF, PF) { + let x_2_twiddle = x_2 * self.0; + (x_1 + x_2_twiddle, x_1 - x_2_twiddle) + } +} + +/// Butterfly with twiddle factor 1 (works in either DIT or DIF). +#[derive(Copy, Clone)] +pub struct TwiddleFreeButterfly; +impl Butterfly for TwiddleFreeButterfly { + #[inline] + fn apply>(&self, x_1: PF, x_2: PF) -> (PF, PF) { + (x_1 + x_2, x_1 - x_2) + } +} diff --git a/CoqOfRust/plonky3/dft/src/butterflies.v b/CoqOfRust/plonky3/dft/src/butterflies.v new file mode 100644 index 000000000..5a7f7fdd7 --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/butterflies.v @@ -0,0 +1,6476 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module butterflies. + (* Trait *) + Module Butterfly. + Definition apply_in_place + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ PF ], [ self; x_1; x_2 ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x_1 := M.alloc (| x_1 |) in + let x_2 := M.alloc (| x_2 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ PF; PF ], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Self, + [], + [ F ], + "apply", + [], + [ PF ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| x_1 |) |) |); + M.read (| M.deref (| M.read (| x_2 |) |) |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let lhs := M.copy (| γ0_0 |) in + let lhs := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| M.deref (| M.read (| x_1 |) |), M.read (| lhs |) |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| M.deref (| M.read (| x_2 |) |), M.read (| lhs |) |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_apply_in_place : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::butterflies::Butterfly" "apply_in_place" (apply_in_place F). + Definition apply_to_rows + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; row_1; row_2 ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let row_1 := M.alloc (| row_1 |) in + let row_2 := M.alloc (| row_2 |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ] + ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing", + [], + [], + "pack_slice_with_suffix_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| row_1 |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let shorts_1 := M.copy (| γ0_0 |) in + let suffix_1 := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing", + [], + [], + "pack_slice_with_suffix_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| row_2 |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let shorts_2 := M.copy (| γ0_0 |) in + let suffix_2 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shorts_1 |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shorts_2 |) |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix_1 |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix_2 |) |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| shorts_1 |) |) + |) + ] + |); + M.read (| shorts_2 |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let x_1 := M.copy (| γ1_0 |) in + let x_2 := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Self, + [], + [ F ], + "apply_in_place", + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x_1 |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x_2 |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| suffix_1 |) |) + |) + ] + |); + M.read (| suffix_2 |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ F ]; + Ty.apply (Ty.path "&mut") [] [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let x_1 := M.copy (| γ1_0 |) in + let x_2 := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Self, + [], + [ F ], + "apply_in_place", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x_1 |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x_2 |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_apply_to_rows : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::butterflies::Butterfly" "apply_to_rows" (apply_to_rows F). + Definition apply_to_rows_oop + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; src_1; dst_1; src_2; dst_2 ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let src_1 := M.alloc (| src_1 |) in + let dst_1 := M.alloc (| dst_1 |) in + let src_2 := M.alloc (| src_2 |) in + let dst_2 := M.alloc (| dst_2 |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing", + [], + [], + "pack_slice_with_suffix", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| src_1 |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let src_shorts_1 := M.copy (| γ0_0 |) in + let src_suffix_1 := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing", + [], + [], + "pack_slice_with_suffix", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| src_2 |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let src_shorts_2 := M.copy (| γ0_0 |) in + let src_suffix_2 := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing", + [], + [], + "pack_maybe_uninit_slice_with_suffix_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| dst_1 |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let dst_shorts_1 := M.copy (| γ0_0 |) in + let dst_suffix_1 := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing", + [], + [], + "pack_maybe_uninit_slice_with_suffix_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| dst_2 |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let dst_shorts_2 := M.copy (| γ0_0 |) in + let dst_suffix_2 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + src_shorts_1 + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + src_shorts_2 + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path + "usize"; + Ty.path + "usize" + ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ F ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + src_suffix_1 + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ F ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + src_suffix_2 + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path + "usize"; + Ty.path + "usize" + ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + dst_shorts_1 + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + dst_shorts_2 + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path + "usize"; + Ty.path + "usize" + ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + dst_suffix_1 + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + dst_suffix_2 + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path + "usize"; + Ty.path + "usize" + ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| src_shorts_1 |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| src_shorts_2 |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| dst_shorts_1 |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| dst_shorts_2 |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ1_0, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ1_0, + 1 + |) in + let a := + M.copy (| + γ2_0 + |) in + let b := + M.copy (| + γ2_1 + |) in + let b := + M.copy (| + γ1_1 + |) in + let b := + M.copy (| + γ0_1 + |) in + Value.Tuple + [ + M.read (| + a + |); + M.read (| + b + |); + M.read (| + b + |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ1_2 := + M.SubPointer.get_tuple_field (| + γ0_0, + 2 + |) in + let γ1_3 := + M.SubPointer.get_tuple_field (| + γ0_0, + 3 + |) in + let s_1 := + M.copy (| γ1_0 |) in + let s_2 := + M.copy (| γ1_1 |) in + let d_1 := + M.copy (| γ1_2 |) in + let d_2 := + M.copy (| γ1_3 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Self, + [], + [ F ], + "apply", + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| self |) + |) + |); + M.read (| + M.deref (| + M.read (| s_1 |) + |) + |); + M.read (| + M.deref (| + M.read (| s_2 |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let res_1 := + M.copy (| γ0_0 |) in + let res_2 := + M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + d_1 + |) + |) + |); + M.read (| + res_1 + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + d_2 + |) + |) + |); + M.read (| + res_2 + |) + ] + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| src_suffix_1 |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| src_suffix_2 |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| dst_suffix_1 |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| dst_suffix_2 |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + F + ]; + Ty.apply + (Ty.path + "&") + [] + [ + F + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ1_0, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ1_0, + 1 + |) in + let a := + M.copy (| + γ2_0 + |) in + let b := + M.copy (| + γ2_1 + |) in + let b := + M.copy (| + γ1_1 + |) in + let b := + M.copy (| + γ0_1 + |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ F ]; + Ty.apply + (Ty.path + "&") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ1_2 := + M.SubPointer.get_tuple_field (| + γ0_0, + 2 + |) in + let γ1_3 := + M.SubPointer.get_tuple_field (| + γ0_0, + 3 + |) in + let s_1 := M.copy (| γ1_0 |) in + let s_2 := M.copy (| γ1_1 |) in + let d_1 := M.copy (| γ1_2 |) in + let d_2 := M.copy (| γ1_3 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ F; F ], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Self, + [], + [ F ], + "apply", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| self |) + |) + |); + M.read (| + M.deref (| + M.read (| s_1 |) + |) + |); + M.read (| + M.deref (| + M.read (| s_2 |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let res_1 := + M.copy (| γ0_0 |) in + let res_2 := + M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "&mut") + [] + [ F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + d_1 + |) + |) + |); + M.read (| + res_1 + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "&mut") + [] + [ F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + d_2 + |) + |) + |); + M.read (| + res_2 + |) + ] + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |))) + ] + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_apply_to_rows_oop : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::butterflies::Butterfly" "apply_to_rows_oop" (apply_to_rows_oop F). + End Butterfly. + + (* StructTuple + { + name := "DifButterfly"; + const_params := []; + ty_params := [ "F" ]; + fields := [ F ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_F_for_p3_dft_butterflies_DifButterfly_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_F_for_p3_dft_butterflies_DifButterfly_F. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_dft_butterflies_DifButterfly_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "p3_dft::butterflies::DifButterfly" + [ + M.call_closure (| + F, + M.get_trait_method (| "core::clone::Clone", F, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_dft::butterflies::DifButterfly", + 0 + |) + |) + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_dft_butterflies_DifButterfly_F. + + Module Impl_p3_dft_butterflies_Butterfly_where_p3_field_field_Field_F_F_for_p3_dft_butterflies_DifButterfly_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]. + + (* + fn apply>(&self, x_1: PF, x_2: PF) -> (PF, PF) { + (x_1 + x_2, (x_1 - x_2) * self.0) + } + *) + Definition apply (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ PF ], [ self; x_1; x_2 ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x_1 := M.alloc (| x_1 |) in + let x_2 := M.alloc (| x_2 |) in + Value.Tuple + [ + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Add", PF, [], [ PF ], "add", [], [] |), + [ M.read (| x_1 |); M.read (| x_2 |) ] + |); + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Mul", PF, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Sub", PF, [], [ PF ], "sub", [], [] |), + [ M.read (| x_1 |); M.read (| x_2 |) ] + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_dft::butterflies::DifButterfly", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_dft::butterflies::Butterfly" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) [ ("apply", InstanceField.Method (apply F)) ]. + End Impl_p3_dft_butterflies_Butterfly_where_p3_field_field_Field_F_F_for_p3_dft_butterflies_DifButterfly_F. + + (* StructTuple + { + name := "DitButterfly"; + const_params := []; + ty_params := [ "F" ]; + fields := [ F ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_F_for_p3_dft_butterflies_DitButterfly_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_F_for_p3_dft_butterflies_DitButterfly_F. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_dft_butterflies_DitButterfly_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "p3_dft::butterflies::DitButterfly" + [ + M.call_closure (| + F, + M.get_trait_method (| "core::clone::Clone", F, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_dft::butterflies::DitButterfly", + 0 + |) + |) + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_dft_butterflies_DitButterfly_F. + + Module Impl_p3_dft_butterflies_Butterfly_where_p3_field_field_Field_F_F_for_p3_dft_butterflies_DitButterfly_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]. + + (* + fn apply>(&self, x_1: PF, x_2: PF) -> (PF, PF) { + let x_2_twiddle = x_2 * self.0; + (x_1 + x_2_twiddle, x_1 - x_2_twiddle) + } + *) + Definition apply (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ PF ], [ self; x_1; x_2 ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x_1 := M.alloc (| x_1 |) in + let x_2 := M.alloc (| x_2 |) in + M.read (| + let~ x_2_twiddle : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Mul", PF, [], [ F ], "mul", [], [] |), + [ + M.read (| x_2 |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_dft::butterflies::DitButterfly", + 0 + |) + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Add", PF, [], [ PF ], "add", [], [] |), + [ M.read (| x_1 |); M.read (| x_2_twiddle |) ] + |); + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Sub", PF, [], [ PF ], "sub", [], [] |), + [ M.read (| x_1 |); M.read (| x_2_twiddle |) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_dft::butterflies::Butterfly" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) [ ("apply", InstanceField.Method (apply F)) ]. + End Impl_p3_dft_butterflies_Butterfly_where_p3_field_field_Field_F_F_for_p3_dft_butterflies_DitButterfly_F. + + (* StructTuple + { + name := "TwiddleFreeButterfly"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_marker_Copy_for_p3_dft_butterflies_TwiddleFreeButterfly. + Definition Self : Ty.t := Ty.path "p3_dft::butterflies::TwiddleFreeButterfly". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_dft_butterflies_TwiddleFreeButterfly. + + Module Impl_core_clone_Clone_for_p3_dft_butterflies_TwiddleFreeButterfly. + Definition Self : Ty.t := Ty.path "p3_dft::butterflies::TwiddleFreeButterfly". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_dft_butterflies_TwiddleFreeButterfly. + + Module Impl_p3_dft_butterflies_Butterfly_where_p3_field_field_Field_F_F_for_p3_dft_butterflies_TwiddleFreeButterfly. + Definition Self (F : Ty.t) : Ty.t := Ty.path "p3_dft::butterflies::TwiddleFreeButterfly". + + (* + fn apply>(&self, x_1: PF, x_2: PF) -> (PF, PF) { + (x_1 + x_2, x_1 - x_2) + } + *) + Definition apply (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ PF ], [ self; x_1; x_2 ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x_1 := M.alloc (| x_1 |) in + let x_2 := M.alloc (| x_2 |) in + Value.Tuple + [ + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Add", PF, [], [ PF ], "add", [], [] |), + [ M.read (| x_1 |); M.read (| x_2 |) ] + |); + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Sub", PF, [], [ PF ], "sub", [], [] |), + [ M.read (| x_1 |); M.read (| x_2 |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_dft::butterflies::Butterfly" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) [ ("apply", InstanceField.Method (apply F)) ]. + End Impl_p3_dft_butterflies_Butterfly_where_p3_field_field_Field_F_F_for_p3_dft_butterflies_TwiddleFreeButterfly. +End butterflies. diff --git a/CoqOfRust/plonky3/dft/src/lib.rs b/CoqOfRust/plonky3/dft/src/lib.rs new file mode 100644 index 000000000..0c4cba06b --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/lib.rs @@ -0,0 +1,21 @@ +//! This crate contains some DFT implementations. + +#![no_std] + +extern crate alloc; + +mod butterflies; +mod naive; +mod radix_2_bowers; +mod radix_2_dit; +mod radix_2_dit_parallel; +mod traits; +mod util; + +pub use butterflies::*; +pub use naive::*; +pub use radix_2_bowers::*; +pub use radix_2_dit::*; +pub use radix_2_dit_parallel::*; +pub use traits::*; +pub use util::*; diff --git a/CoqOfRust/plonky3/dft/src/naive.rs b/CoqOfRust/plonky3/dft/src/naive.rs new file mode 100644 index 000000000..2822506a6 --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/naive.rs @@ -0,0 +1,108 @@ +use alloc::vec; + +use p3_field::TwoAdicField; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_util::log2_strict_usize; + +use crate::TwoAdicSubgroupDft; + +#[derive(Default, Clone, Debug)] +pub struct NaiveDft; + +impl TwoAdicSubgroupDft for NaiveDft { + type Evaluations = RowMajorMatrix; + fn dft_batch(&self, mat: RowMajorMatrix) -> RowMajorMatrix { + let w = mat.width(); + let h = mat.height(); + let log_h = log2_strict_usize(h); + let g = F::two_adic_generator(log_h); + + let mut res = RowMajorMatrix::new(vec![F::ZERO; w * h], w); + for (res_r, point) in g.powers().take(h).enumerate() { + for (src_r, point_power) in point.powers().take(h).enumerate() { + for c in 0..w { + res.values[res_r * w + c] += point_power * mat.values[src_r * w + c] + } + } + } + + res + } +} + +#[cfg(test)] +mod tests { + use alloc::vec; + + use p3_baby_bear::BabyBear; + use p3_field::{Field, PrimeCharacteristicRing}; + use p3_goldilocks::Goldilocks; + use p3_matrix::dense::RowMajorMatrix; + use rand::SeedableRng; + use rand::rngs::SmallRng; + + use crate::{NaiveDft, TwoAdicSubgroupDft}; + + #[test] + fn basic() { + type F = BabyBear; + + // A few polynomials: + // 5 + 4x + // 2 + 3x + // 0 + let mat = RowMajorMatrix::new( + vec![ + F::from_u8(5), + F::from_u8(2), + F::ZERO, + F::from_u8(4), + F::from_u8(3), + F::ZERO, + ], + 3, + ); + + let dft = NaiveDft.dft_batch(mat); + // Expected evaluations on {1, -1}: + // 9, 1 + // 5, -1 + // 0, 0 + assert_eq!( + dft, + RowMajorMatrix::new( + vec![ + F::from_u8(9), + F::from_u8(5), + F::ZERO, + F::ONE, + F::NEG_ONE, + F::ZERO, + ], + 3, + ) + ) + } + + #[test] + fn dft_idft_consistency() { + type F = Goldilocks; + let mut rng = SmallRng::seed_from_u64(1); + let original = RowMajorMatrix::::rand(&mut rng, 8, 3); + let dft = NaiveDft.dft_batch(original.clone()); + let idft = NaiveDft.idft_batch(dft); + assert_eq!(original, idft); + } + + #[test] + fn coset_dft_idft_consistency() { + type F = Goldilocks; + let generator = F::GENERATOR; + let mut rng = SmallRng::seed_from_u64(1); + let original = RowMajorMatrix::::rand(&mut rng, 8, 3); + let dft = NaiveDft.coset_dft_batch(original.clone(), generator); + let idft = NaiveDft.coset_idft_batch(dft, generator); + assert_eq!(original, idft); + } +} diff --git a/CoqOfRust/plonky3/dft/src/naive.v b/CoqOfRust/plonky3/dft/src/naive.v new file mode 100644 index 000000000..e59a74e0f --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/naive.v @@ -0,0 +1,957 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module naive. + (* StructTuple + { + name := "NaiveDft"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_default_Default_for_p3_dft_naive_NaiveDft. + Definition Self : Ty.t := Ty.path "p3_dft::naive::NaiveDft". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => ltac:(M.monadic (Value.StructTuple "p3_dft::naive::NaiveDft" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_dft_naive_NaiveDft. + + Module Impl_core_clone_Clone_for_p3_dft_naive_NaiveDft. + Definition Self : Ty.t := Ty.path "p3_dft::naive::NaiveDft". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_dft::naive::NaiveDft" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_dft_naive_NaiveDft. + + Module Impl_core_fmt_Debug_for_p3_dft_naive_NaiveDft. + Definition Self : Ty.t := Ty.path "p3_dft::naive::NaiveDft". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "NaiveDft" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_dft_naive_NaiveDft. + + Module Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_field_field_TwoAdicField_F_F_for_p3_dft_naive_NaiveDft. + Definition Self (F : Ty.t) : Ty.t := Ty.path "p3_dft::naive::NaiveDft". + + (* type Evaluations = RowMajorMatrix; *) + Definition _Evaluations (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ]. + + (* + fn dft_batch(&self, mat: RowMajorMatrix) -> RowMajorMatrix { + let w = mat.width(); + let h = mat.height(); + let log_h = log2_strict_usize(h); + let g = F::two_adic_generator(log_h); + + let mut res = RowMajorMatrix::new(vec![F::ZERO; w * h], w); + for (res_r, point) in g.powers().take(h).enumerate() { + for (src_r, point_power) in point.powers().take(h).enumerate() { + for c in 0..w { + res.values[res_r * w + c] += point_power * mat.values[src_r * w + c] + } + } + } + + res + } + *) + Definition dft_batch (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.read (| + let~ w : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ g : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_h |) ] + |) + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloc::vec::from_elem", [], [ F ] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| w |); M.read (| h |) ] + |) + ] + |); + M.read (| w |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, g |) ] + |); + M.read (| h |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let res_r := M.copy (| γ1_0 |) in + let point := M.copy (| γ1_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, point |) ] + |); + M.read (| h |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "p3_field::field::Powers") + [] + [ F ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let src_r := M.copy (| γ1_0 |) in + let point_power := + M.copy (| γ1_1 |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", M.read (| w |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let c := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&mut") + [] + [ + F + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.path + "usize" + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + res, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + M.read (| + res_r + |); + M.read (| + w + |) + ] + |); + M.read (| + c + |) + ] + |) + ] + |) + |) + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F + ], + "mul", + [], + [] + |), + [ + M.read (| + point_power + |); + M.read (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + F + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.path + "usize" + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + M.read (| + src_r + |); + M.read (| + w + |) + ] + |); + M.read (| + c + |) + ] + |) + ] + |) + |) + |) + ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + res + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_dft::traits::TwoAdicSubgroupDft" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) + [ + ("Evaluations", InstanceField.Ty (_Evaluations F)); + ("dft_batch", InstanceField.Method (dft_batch F)) + ]. + End Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_field_field_TwoAdicField_F_F_for_p3_dft_naive_NaiveDft. +End naive. diff --git a/CoqOfRust/plonky3/dft/src/radix_2_bowers.rs b/CoqOfRust/plonky3/dft/src/radix_2_bowers.rs new file mode 100644 index 000000000..9bd62e4f4 --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/radix_2_bowers.rs @@ -0,0 +1,132 @@ +use alloc::vec::Vec; + +use p3_field::{Field, Powers, PrimeCharacteristicRing, TwoAdicField}; +use p3_matrix::Matrix; +use p3_matrix::dense::{RowMajorMatrix, RowMajorMatrixViewMut}; +use p3_matrix::util::reverse_matrix_index_bits; +use p3_maybe_rayon::prelude::*; +use p3_util::{log2_strict_usize, reverse_bits, reverse_slice_index_bits}; +use tracing::instrument; + +use crate::TwoAdicSubgroupDft; +use crate::butterflies::{Butterfly, DifButterfly, DitButterfly, TwiddleFreeButterfly}; +use crate::util::divide_by_height; + +/// The Bowers G FFT algorithm. +/// See: "Improved Twiddle Access for Fast Fourier Transforms" +#[derive(Default, Clone)] +pub struct Radix2Bowers; + +impl TwoAdicSubgroupDft for Radix2Bowers { + type Evaluations = RowMajorMatrix; + + fn dft_batch(&self, mut mat: RowMajorMatrix) -> RowMajorMatrix { + reverse_matrix_index_bits(&mut mat); + bowers_g(&mut mat.as_view_mut()); + mat + } + + /// Compute the inverse DFT of each column in `mat`. + fn idft_batch(&self, mut mat: RowMajorMatrix) -> RowMajorMatrix { + bowers_g_t(&mut mat.as_view_mut()); + divide_by_height(&mut mat); + reverse_matrix_index_bits(&mut mat); + mat + } + + fn lde_batch(&self, mut mat: RowMajorMatrix, added_bits: usize) -> RowMajorMatrix { + bowers_g_t(&mut mat.as_view_mut()); + divide_by_height(&mut mat); + mat = mat.bit_reversed_zero_pad(added_bits); + bowers_g(&mut mat.as_view_mut()); + mat + } + + #[instrument(skip_all, fields(dims = %mat.dimensions(), added_bits))] + fn coset_lde_batch( + &self, + mut mat: RowMajorMatrix, + added_bits: usize, + shift: F, + ) -> RowMajorMatrix { + let h = mat.height(); + let log_h = log2_strict_usize(h); + // It's cheaper to use div_2exp_u64 as this usually avoids an inversion. + // It's also cheaper to work in the PrimeSubfield whenever possible. + let h_inv_subfield = F::PrimeSubfield::ONE.div_2exp_u64(log_h as u64); + let h_inv = F::from_prime_subfield(h_inv_subfield); + + bowers_g_t(&mut mat.as_view_mut()); + + // Rescale coefficients in two ways: + // - divide by height (since we're doing an inverse DFT) + // - multiply by powers of the coset shift (see default coset LDE impl for an explanation) + let weights = Powers { + base: shift, + current: h_inv, + } + .take(h); + for (row, weight) in weights.enumerate() { + // reverse_bits because mat is encoded in bit-reversed order + mat.scale_row(reverse_bits(row, h), weight); + } + + mat = mat.bit_reversed_zero_pad(added_bits); + + bowers_g(&mut mat.as_view_mut()); + + mat + } +} + +/// Executes the Bowers G network. This is like a DFT, except it assumes the input is in +/// bit-reversed order. +fn bowers_g(mat: &mut RowMajorMatrixViewMut) { + let h = mat.height(); + let log_h = log2_strict_usize(h); + + let root = F::two_adic_generator(log_h); + let mut twiddles: Vec<_> = root.powers().take(h / 2).map(DifButterfly).collect(); + reverse_slice_index_bits(&mut twiddles); + + for log_half_block_size in 0..log_h { + butterfly_layer(mat, 1 << log_half_block_size, &twiddles) + } +} + +/// Executes the Bowers G^T network. This is like an inverse DFT, except we skip rescaling by +/// 1/height, and the output is bit-reversed. +fn bowers_g_t(mat: &mut RowMajorMatrixViewMut) { + let h = mat.height(); + let log_h = log2_strict_usize(h); + + let root_inv = F::two_adic_generator(log_h).inverse(); + let mut twiddles: Vec<_> = root_inv.powers().take(h / 2).map(DitButterfly).collect(); + reverse_slice_index_bits(&mut twiddles); + + for log_half_block_size in (0..log_h).rev() { + butterfly_layer(mat, 1 << log_half_block_size, &twiddles) + } +} + +fn butterfly_layer>( + mat: &mut RowMajorMatrixViewMut, + half_block_size: usize, + twiddles: &[B], +) { + mat.par_row_chunks_exact_mut(2 * half_block_size) + .enumerate() + .for_each(|(block, mut chunks)| { + let (mut hi_chunks, mut lo_chunks) = chunks.split_rows_mut(half_block_size); + hi_chunks + .par_rows_mut() + .zip(lo_chunks.par_rows_mut()) + .for_each(|(hi_chunk, lo_chunk)| { + if block == 0 { + TwiddleFreeButterfly.apply_to_rows(hi_chunk, lo_chunk) + } else { + twiddles[block].apply_to_rows(hi_chunk, lo_chunk); + } + }); + }); +} diff --git a/CoqOfRust/plonky3/dft/src/radix_2_bowers.v b/CoqOfRust/plonky3/dft/src/radix_2_bowers.v new file mode 100644 index 000000000..60f412998 --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/radix_2_bowers.v @@ -0,0 +1,3249 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module radix_2_bowers. + (* StructTuple + { + name := "Radix2Bowers"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_default_Default_for_p3_dft_radix_2_bowers_Radix2Bowers. + Definition Self : Ty.t := Ty.path "p3_dft::radix_2_bowers::Radix2Bowers". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => ltac:(M.monadic (Value.StructTuple "p3_dft::radix_2_bowers::Radix2Bowers" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_dft_radix_2_bowers_Radix2Bowers. + + Module Impl_core_clone_Clone_for_p3_dft_radix_2_bowers_Radix2Bowers. + Definition Self : Ty.t := Ty.path "p3_dft::radix_2_bowers::Radix2Bowers". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_dft::radix_2_bowers::Radix2Bowers" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_dft_radix_2_bowers_Radix2Bowers. + + Module Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_field_field_TwoAdicField_F_F_for_p3_dft_radix_2_bowers_Radix2Bowers. + Definition Self (F : Ty.t) : Ty.t := Ty.path "p3_dft::radix_2_bowers::Radix2Bowers". + + (* type Evaluations = RowMajorMatrix; *) + Definition _Evaluations (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ]. + + (* + fn dft_batch(&self, mut mat: RowMajorMatrix) -> RowMajorMatrix { + reverse_matrix_index_bits(&mut mat); + bowers_g(&mut mat.as_view_mut()); + mat + } + *) + Definition dft_batch (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::reverse_matrix_index_bits", + [], + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_bowers::bowers_g", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "as_view_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, mat |) ] + |) + |) + |) + |) + |) + ] + |) + |) in + mat + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn idft_batch(&self, mut mat: RowMajorMatrix) -> RowMajorMatrix { + bowers_g_t(&mut mat.as_view_mut()); + divide_by_height(&mut mat); + reverse_matrix_index_bits(&mut mat); + mat + } + *) + Definition idft_batch (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_bowers::bowers_g_t", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "as_view_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, mat |) ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::util::divide_by_height", + [], + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::reverse_matrix_index_bits", + [], + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |) + ] + |) + |) in + mat + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn lde_batch(&self, mut mat: RowMajorMatrix, added_bits: usize) -> RowMajorMatrix { + bowers_g_t(&mut mat.as_view_mut()); + divide_by_height(&mut mat); + mat = mat.bit_reversed_zero_pad(added_bits); + bowers_g(&mut mat.as_view_mut()); + mat + } + *) + Definition lde_batch (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat; added_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let added_bits := M.alloc (| added_bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_bowers::bowers_g_t", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "as_view_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, mat |) ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::util::divide_by_height", + [], + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + mat, + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "bit_reversed_zero_pad", + [], + [] + |), + [ M.read (| mat |); M.read (| added_bits |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_bowers::bowers_g", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "as_view_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, mat |) ] + |) + |) + |) + |) + |) + ] + |) + |) in + mat + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* #[instrument(skip_all, fields(dims = %mat.dimensions(), added_bits))] *) + Definition coset_lde_batch + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat; added_bits; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let added_bits := M.alloc (| added_bits |) in + let shift := M.alloc (| shift |) in + M.catch_return + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_bowers::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_bowers::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_bowers::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + F + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + mat + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "tracing_core::field::Empty" + [] + |) + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_bowers::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ h_inv_subfield : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + M.get_trait_method (| + "p3_field::field::Field", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield" + |) + |); + M.cast (Ty.path "u64") (M.read (| log_h |)) + ] + |) + |) in + let~ h_inv : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ M.read (| h_inv_subfield |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_bowers::bowers_g_t", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "as_view_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, mat |) ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ weights : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + Value.StructRecord + "p3_field::field::Powers" + [ ("base", M.read (| shift |)); ("current", M.read (| h_inv |)) ]; + M.read (| h |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "enumerate", + [], + [] + |), + [ M.read (| weights |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let row := M.copy (| γ1_0 |) in + let weight := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "scale_row", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, mat |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::reverse_bits", + [], + [] + |), + [ M.read (| row |); M.read (| h |) ] + |); + M.read (| weight |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + mat, + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "bit_reversed_zero_pad", + [], + [] + |), + [ M.read (| mat |); M.read (| added_bits |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_bowers::bowers_g", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "as_view_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, mat |) ] + |) + |) + |) + |) + |) + ] + |) + |) in + mat + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_dft::traits::TwoAdicSubgroupDft" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) + [ + ("Evaluations", InstanceField.Ty (_Evaluations F)); + ("dft_batch", InstanceField.Method (dft_batch F)); + ("idft_batch", InstanceField.Method (idft_batch F)); + ("lde_batch", InstanceField.Method (lde_batch F)); + ("coset_lde_batch", InstanceField.Method (coset_lde_batch F)) + ]. + End Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_field_field_TwoAdicField_F_F_for_p3_dft_radix_2_bowers_Radix2Bowers. + + (* + fn bowers_g(mat: &mut RowMajorMatrixViewMut) { + let h = mat.height(); + let log_h = log2_strict_usize(h); + + let root = F::two_adic_generator(log_h); + let mut twiddles: Vec<_> = root.powers().take(h / 2).map(DifButterfly).collect(); + reverse_slice_index_bits(&mut twiddles); + + for log_half_block_size in 0..log_h { + butterfly_layer(mat, 1 << log_half_block_size, &twiddles) + } + } + *) + Definition bowers_g (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ mat ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + M.read (| + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ root : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_h |) ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ]; + Ty.function + [ F ] + (Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ]; + Ty.function + [ F ] + (Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]; + Ty.function + [ F ] + (Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, root |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| h |); Value.Integer IntegerKind.Usize 2 ] + |) + ] + |); + M.constructor_as_closure "p3_dft::butterflies::DifButterfly" + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::reverse_slice_index_bits", + [], + [ Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ] ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ] ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_dft::butterflies::DifButterfly") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, twiddles |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", M.read (| log_h |)) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_half_block_size := M.copy (| γ0_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_bowers::butterfly_layer", + [], + [ + F; + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| mat |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| log_half_block_size |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DifButterfly") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DifButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, twiddles |) + |) + |) + ] + |) + |) + |) + ] + |) + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_bowers_g : + M.IsFunction.C "p3_dft::radix_2_bowers::bowers_g" bowers_g. + Admitted. + Global Typeclasses Opaque bowers_g. + + (* + fn bowers_g_t(mat: &mut RowMajorMatrixViewMut) { + let h = mat.height(); + let log_h = log2_strict_usize(h); + + let root_inv = F::two_adic_generator(log_h).inverse(); + let mut twiddles: Vec<_> = root_inv.powers().take(h / 2).map(DitButterfly).collect(); + reverse_slice_index_bits(&mut twiddles); + + for log_half_block_size in (0..log_h).rev() { + butterfly_layer(mat, 1 << log_half_block_size, &twiddles) + } + } + *) + Definition bowers_g_t (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ mat ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + M.read (| + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ root_inv : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_h |) ] + |) + |) + |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ]; + Ty.function + [ F ] + (Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ]; + Ty.function + [ F ] + (Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]; + Ty.function + [ F ] + (Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, root_inv |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| h |); Value.Integer IntegerKind.Usize 2 ] + |) + ] + |); + M.constructor_as_closure "p3_dft::butterflies::DitButterfly" + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::reverse_slice_index_bits", + [], + [ Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ] ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ] ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_dft::butterflies::DitButterfly") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, twiddles |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| log_h |)) + ] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_half_block_size := M.copy (| γ0_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_bowers::butterfly_layer", + [], + [ + F; + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| mat |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| log_half_block_size |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_dft::butterflies::DitButterfly") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, twiddles |) + |) + |) + ] + |) + |) + |) + ] + |) + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_bowers_g_t : + M.IsFunction.C "p3_dft::radix_2_bowers::bowers_g_t" bowers_g_t. + Admitted. + Global Typeclasses Opaque bowers_g_t. + + (* + fn butterfly_layer>( + mat: &mut RowMajorMatrixViewMut, + half_block_size: usize, + twiddles: &[B], + ) { + mat.par_row_chunks_exact_mut(2 * half_block_size) + .enumerate() + .for_each(|(block, mut chunks)| { + let (mut hi_chunks, mut lo_chunks) = chunks.split_rows_mut(half_block_size); + hi_chunks + .par_rows_mut() + .zip(lo_chunks.par_rows_mut()) + .for_each(|(hi_chunk, lo_chunk)| { + if block == 0 { + TwiddleFreeButterfly.apply_to_rows(hi_chunk, lo_chunk) + } else { + twiddles[block].apply_to_rows(hi_chunk, lo_chunk); + } + }); + }); + } + *) + Definition butterfly_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; B ], [ mat; half_block_size; twiddles ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let half_block_size := M.alloc (| half_block_size |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + "par_row_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| half_block_size |) ] + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let block := M.copy (| γ0_0 |) in + let chunks := M.copy (| γ0_1 |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + "split_rows_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, chunks |); + M.read (| half_block_size |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let hi_chunks := M.copy (| γ0_0 |) in + let lo_chunks := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.associated_unknown + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.associated_unknown + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "zip", + [], + [ Ty.associated_unknown ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ], + "par_rows_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + hi_chunks + |) + ] + |); + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ], + "par_rows_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + lo_chunks + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let hi_chunk := + M.copy (| γ0_0 |) in + let lo_chunk := + M.copy (| γ0_1 |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple [] + |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path + "bool", + BinOp.eq, + [ + M.read (| + block + |); + Value.Integer + IntegerKind.Usize + 0 + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Ty.path + "p3_dft::butterflies::TwiddleFreeButterfly", + [], + [ F ], + "apply_to_rows", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "p3_dft::butterflies::TwiddleFreeButterfly" + [] + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + hi_chunk + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + lo_chunk + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + B, + [], + [ F ], + "apply_to_rows", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + twiddles + |) + |), + M.read (| + block + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + hi_chunk + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + lo_chunk + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_butterfly_layer : + M.IsFunction.C "p3_dft::radix_2_bowers::butterfly_layer" butterfly_layer. + Admitted. + Global Typeclasses Opaque butterfly_layer. +End radix_2_bowers. diff --git a/CoqOfRust/plonky3/dft/src/radix_2_dit.rs b/CoqOfRust/plonky3/dft/src/radix_2_dit.rs new file mode 100644 index 000000000..02c1f6518 --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/radix_2_dit.rs @@ -0,0 +1,69 @@ +use alloc::collections::BTreeMap; +use alloc::vec::Vec; +use core::cell::RefCell; + +use p3_field::{Field, TwoAdicField}; +use p3_matrix::Matrix; +use p3_matrix::dense::{RowMajorMatrix, RowMajorMatrixViewMut}; +use p3_matrix::util::reverse_matrix_index_bits; +use p3_maybe_rayon::prelude::*; +use p3_util::log2_strict_usize; + +use crate::TwoAdicSubgroupDft; +use crate::butterflies::{Butterfly, DitButterfly, TwiddleFreeButterfly}; + +/// The DIT FFT algorithm. +#[derive(Default, Clone, Debug)] +pub struct Radix2Dit { + /// Memoized twiddle factors for each length log_n. + twiddles: RefCell>>, +} + +impl TwoAdicSubgroupDft for Radix2Dit { + type Evaluations = RowMajorMatrix; + + fn dft_batch(&self, mut mat: RowMajorMatrix) -> RowMajorMatrix { + let h = mat.height(); + let log_h = log2_strict_usize(h); + + // Compute twiddle factors, or take memoized ones if already available. + let mut twiddles_ref_mut = self.twiddles.borrow_mut(); + let twiddles = twiddles_ref_mut.entry(log_h).or_insert_with(|| { + let root = F::two_adic_generator(log_h); + root.powers().take(1 << log_h).collect() + }); + + // DIT butterfly + reverse_matrix_index_bits(&mut mat); + for layer in 0..log_h { + dit_layer(&mut mat.as_view_mut(), layer, twiddles); + } + mat + } +} + +/// One layer of a DIT butterfly network. +fn dit_layer(mat: &mut RowMajorMatrixViewMut<'_, F>, layer: usize, twiddles: &[F]) { + let h = mat.height(); + let log_h = log2_strict_usize(h); + let layer_rev = log_h - 1 - layer; + + let half_block_size = 1 << layer; + let block_size = half_block_size * 2; + + mat.par_row_chunks_exact_mut(block_size) + .for_each(|mut block_chunks| { + let (mut hi_chunks, mut lo_chunks) = block_chunks.split_rows_mut(half_block_size); + hi_chunks + .par_rows_mut() + .zip(lo_chunks.par_rows_mut()) + .enumerate() + .for_each(|(ind, (hi_chunk, lo_chunk))| { + if ind == 0 { + TwiddleFreeButterfly.apply_to_rows(hi_chunk, lo_chunk) + } else { + DitButterfly(twiddles[ind << layer_rev]).apply_to_rows(hi_chunk, lo_chunk) + } + }); + }); +} diff --git a/CoqOfRust/plonky3/dft/src/radix_2_dit.v b/CoqOfRust/plonky3/dft/src/radix_2_dit.v new file mode 100644 index 000000000..e3b932648 --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/radix_2_dit.v @@ -0,0 +1,1516 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module radix_2_dit. + (* StructRecord + { + name := "Radix2Dit"; + const_params := []; + ty_params := [ "F" ]; + fields := + [ + ("twiddles", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]) + ]; + } *) + + Module Impl_core_default_Default_where_core_default_Default_F_where_p3_field_field_TwoAdicField_F_for_p3_dft_radix_2_dit_Radix2Dit_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit::Radix2Dit") [] [ F ]. + + (* Default *) + Definition default (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_dft::radix_2_dit::Radix2Dit" + [ + ("twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("default", InstanceField.Method (default F)) ]. + End Impl_core_default_Default_where_core_default_Default_F_where_p3_field_field_TwoAdicField_F_for_p3_dft_radix_2_dit_Radix2Dit_F. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_TwoAdicField_F_for_p3_dft_radix_2_dit_Radix2Dit_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit::Radix2Dit") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_dft::radix_2_dit::Radix2Dit" + [ + ("twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit::Radix2Dit", + "twiddles" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_TwoAdicField_F_for_p3_dft_radix_2_dit_Radix2Dit_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_TwoAdicField_F_for_p3_dft_radix_2_dit_Radix2Dit_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit::Radix2Dit") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Radix2Dit" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit::Radix2Dit", + "twiddles" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_TwoAdicField_F_for_p3_dft_radix_2_dit_Radix2Dit_F. + + Module Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_field_field_TwoAdicField_F_F_for_p3_dft_radix_2_dit_Radix2Dit_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit::Radix2Dit") [] [ F ]. + + (* type Evaluations = RowMajorMatrix; *) + Definition _Evaluations (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ]. + + (* + fn dft_batch(&self, mut mat: RowMajorMatrix) -> RowMajorMatrix { + let h = mat.height(); + let log_h = log2_strict_usize(h); + + // Compute twiddle factors, or take memoized ones if already available. + let mut twiddles_ref_mut = self.twiddles.borrow_mut(); + let twiddles = twiddles_ref_mut.entry(log_h).or_insert_with(|| { + let root = F::two_adic_generator(log_h); + root.powers().take(1 << log_h).collect() + }); + + // DIT butterfly + reverse_matrix_index_bits(&mut mat); + for layer in 0..log_h { + dit_layer(&mut mat.as_view_mut(), layer, twiddles); + } + mat + } + *) + Definition dft_batch (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.read (| + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ twiddles_ref_mut : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit::Radix2Dit", + "twiddles" + |) + |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + "or_insert_with", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + "entry", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, twiddles_ref_mut |) ] + |) + |) + |); + M.read (| log_h |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ root : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_h |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, root |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| log_h |) + ] + |) + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::reverse_matrix_index_bits", + [], + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| log_h |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let layer := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit::dit_layer", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ] + ], + "as_view_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, mat |) ] + |) + |) + |) + |) + |); + M.read (| layer |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + mat + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_dft::traits::TwoAdicSubgroupDft" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) + [ + ("Evaluations", InstanceField.Ty (_Evaluations F)); + ("dft_batch", InstanceField.Method (dft_batch F)) + ]. + End Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_field_field_TwoAdicField_F_F_for_p3_dft_radix_2_dit_Radix2Dit_F. + + (* + fn dit_layer(mat: &mut RowMajorMatrixViewMut<'_, F>, layer: usize, twiddles: &[F]) { + let h = mat.height(); + let log_h = log2_strict_usize(h); + let layer_rev = log_h - 1 - layer; + + let half_block_size = 1 << layer; + let block_size = half_block_size * 2; + + mat.par_row_chunks_exact_mut(block_size) + .for_each(|mut block_chunks| { + let (mut hi_chunks, mut lo_chunks) = block_chunks.split_rows_mut(half_block_size); + hi_chunks + .par_rows_mut() + .zip(lo_chunks.par_rows_mut()) + .enumerate() + .for_each(|(ind, (hi_chunk, lo_chunk))| { + if ind == 0 { + TwiddleFreeButterfly.apply_to_rows(hi_chunk, lo_chunk) + } else { + DitButterfly(twiddles[ind << layer_rev]).apply_to_rows(hi_chunk, lo_chunk) + } + }); + }); + } + *) + Definition dit_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ mat; layer; twiddles ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let layer := M.alloc (| layer |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ layer_rev : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| log_h |); Value.Integer IntegerKind.Usize 1 ] + |); + M.read (| layer |) + ] + |) + |) in + let~ half_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| layer |) ] + |) + |) in + let~ block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| half_block_size |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ], + "par_row_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.read (| block_size |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let block_chunks := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + "split_rows_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, block_chunks |); + M.read (| half_block_size |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let hi_chunks := M.copy (| γ0_0 |) in + let lo_chunks := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.associated_unknown + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.associated_unknown + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.associated_unknown + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.associated_unknown + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "zip", + [], + [ Ty.associated_unknown ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ], + "par_rows_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + hi_chunks + |) + ] + |); + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ], + "par_rows_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + lo_chunks + |) + ] + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let ind := + M.copy (| γ0_0 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_1, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_1, + 1 + |) in + let hi_chunk := + M.copy (| γ1_0 |) in + let lo_chunk := + M.copy (| γ1_1 |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple [] + |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path + "bool", + BinOp.eq, + [ + M.read (| + ind + |); + Value.Integer + IntegerKind.Usize + 0 + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Ty.path + "p3_dft::butterflies::TwiddleFreeButterfly", + [], + [ F ], + "apply_to_rows", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "p3_dft::butterflies::TwiddleFreeButterfly" + [] + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + hi_chunk + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + lo_chunk + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ], + [], + [ F ], + "apply_to_rows", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "p3_dft::butterflies::DitButterfly" + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + twiddles + |) + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shl, + [ + M.read (| + ind + |); + M.read (| + layer_rev + |) + ] + |) + |) + |) + ] + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + hi_chunk + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + lo_chunk + |) + |) + |) + ] + |) + |))) + ] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dit_layer : + M.IsFunction.C "p3_dft::radix_2_dit::dit_layer" dit_layer. + Admitted. + Global Typeclasses Opaque dit_layer. +End radix_2_dit. diff --git a/CoqOfRust/plonky3/dft/src/radix_2_dit_parallel.rs b/CoqOfRust/plonky3/dft/src/radix_2_dit_parallel.rs new file mode 100644 index 000000000..f6506c4ab --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/radix_2_dit_parallel.rs @@ -0,0 +1,523 @@ +use alloc::collections::BTreeMap; +use alloc::slice; +use alloc::vec::Vec; +use core::cell::RefCell; +use core::mem::{MaybeUninit, transmute}; + +use itertools::{Itertools, izip}; +use p3_field::integers::QuotientMap; +use p3_field::{Field, Powers, TwoAdicField}; +use p3_matrix::Matrix; +use p3_matrix::bitrev::{BitReversalPerm, BitReversedMatrixView, BitReversibleMatrix}; +use p3_matrix::dense::{RowMajorMatrix, RowMajorMatrixView, RowMajorMatrixViewMut}; +use p3_matrix::util::reverse_matrix_index_bits; +use p3_maybe_rayon::prelude::*; +use p3_util::{log2_strict_usize, reverse_bits_len, reverse_slice_index_bits}; +use tracing::{debug_span, instrument}; + +use crate::TwoAdicSubgroupDft; +use crate::butterflies::{Butterfly, DitButterfly}; + +/// A parallel FFT algorithm which divides a butterfly network's layers into two halves. +/// +/// For the first half, we apply a butterfly network with smaller blocks in earlier layers, +/// i.e. either DIT or Bowers G. Then we bit-reverse, and for the second half, we continue executing +/// the same network but in bit-reversed order. This way we're always working with small blocks, +/// so within each half, we can have a certain amount of parallelism with no cross-thread +/// communication. +#[derive(Default, Clone, Debug)] +pub struct Radix2DitParallel { + /// Twiddles based on roots of unity, used in the forward DFT. + twiddles: RefCell>>, + + /// A map from `(log_h, shift)` to forward DFT twiddles with that coset shift baked in. + #[allow(clippy::type_complexity)] + coset_twiddles: RefCell>>>, + + /// Twiddles based on inverse roots of unity, used in the inverse DFT. + inverse_twiddles: RefCell>>, +} + +/// A pair of vectors, one with twiddle factors in their natural order, the other bit-reversed. +#[derive(Default, Clone, Debug)] +struct VectorPair { + twiddles: Vec, + bitrev_twiddles: Vec, +} + +#[instrument(level = "debug", skip_all)] +fn compute_twiddles(log_h: usize) -> VectorPair { + let half_h = (1 << log_h) >> 1; + let root = F::two_adic_generator(log_h); + let twiddles: Vec = root.powers().take(half_h).collect(); + let mut bit_reversed_twiddles = twiddles.clone(); + reverse_slice_index_bits(&mut bit_reversed_twiddles); + VectorPair { + twiddles, + bitrev_twiddles: bit_reversed_twiddles, + } +} + +#[instrument(level = "debug", skip_all)] +fn compute_coset_twiddles(log_h: usize, shift: F) -> Vec> { + // In general either div_floor or div_ceil would work, but here we prefer div_ceil because it + // lets us assume below that the "first half" of the network has at least one layer of + // butterflies, even in the case of log_h = 1. + let mid = log_h.div_ceil(2); + let h = 1 << log_h; + let root = F::two_adic_generator(log_h); + + (0..log_h) + .map(|layer| { + let shift_power = shift.exp_power_of_2(layer); + let powers = Powers { + base: root.exp_power_of_2(layer), + current: shift_power, + }; + let mut twiddles: Vec<_> = powers.take(h >> (layer + 1)).collect(); + let layer_rev = log_h - 1 - layer; + if layer_rev >= mid { + reverse_slice_index_bits(&mut twiddles); + } + twiddles + }) + .collect() +} + +#[instrument(level = "debug", skip_all)] +fn compute_inverse_twiddles(log_h: usize) -> VectorPair { + let half_h = (1 << log_h) >> 1; + let root_inv = F::two_adic_generator(log_h).inverse(); + let twiddles: Vec = root_inv.powers().take(half_h).collect(); + let mut bit_reversed_twiddles = twiddles.clone(); + + // In the middle of the coset LDE, we're in bit-reversed order. + reverse_slice_index_bits(&mut bit_reversed_twiddles); + + VectorPair { + twiddles, + bitrev_twiddles: bit_reversed_twiddles, + } +} + +impl TwoAdicSubgroupDft for Radix2DitParallel { + type Evaluations = BitReversedMatrixView>; + + fn dft_batch(&self, mut mat: RowMajorMatrix) -> Self::Evaluations { + let h = mat.height(); + let log_h = log2_strict_usize(h); + + // Compute twiddle factors, or take memoized ones if already available. + let mut twiddles_ref_mut = self.twiddles.borrow_mut(); + let twiddles = twiddles_ref_mut + .entry(log_h) + .or_insert_with(|| compute_twiddles(log_h)); + + let mid = log_h.div_ceil(2); + + // The first half looks like a normal DIT. + reverse_matrix_index_bits(&mut mat); + first_half(&mut mat, mid, &twiddles.twiddles); + + // For the second half, we flip the DIT, working in bit-reversed order. + reverse_matrix_index_bits(&mut mat); + second_half(&mut mat, mid, &twiddles.bitrev_twiddles, None); + + mat.bit_reverse_rows() + } + + #[instrument(skip_all, fields(dims = %mat.dimensions(), added_bits = added_bits))] + fn coset_lde_batch( + &self, + mut mat: RowMajorMatrix, + added_bits: usize, + shift: F, + ) -> Self::Evaluations { + let w = mat.width; + let h = mat.height(); + let log_h = log2_strict_usize(h); + let mid = log_h.div_ceil(2); + + let mut inverse_twiddles_ref_mut = self.inverse_twiddles.borrow_mut(); + let inverse_twiddles = inverse_twiddles_ref_mut + .entry(log_h) + .or_insert_with(|| compute_inverse_twiddles(log_h)); + + // The first half looks like a normal DIT. + reverse_matrix_index_bits(&mut mat); + first_half(&mut mat, mid, &inverse_twiddles.twiddles); + + // For the second half, we flip the DIT, working in bit-reversed order. + reverse_matrix_index_bits(&mut mat); + // We'll also scale by 1/h, as per the usual inverse DFT algorithm. + // If F isn't a PrimeField, (and is thus an extension field) it's much cheaper to + // invert in F::PrimeSubfield. + let h_inv_subfield = F::PrimeSubfield::from_int(h).try_inverse(); + let scale = h_inv_subfield.map(F::from_prime_subfield); + second_half(&mut mat, mid, &inverse_twiddles.bitrev_twiddles, scale); + // We skip the final bit-reversal, since the next FFT expects bit-reversed input. + + let lde_elems = w * (h << added_bits); + let elems_to_add = lde_elems - w * h; + debug_span!("reserve_exact").in_scope(|| mat.values.reserve_exact(elems_to_add)); + + let g_big = F::two_adic_generator(log_h + added_bits); + + let mat_ptr = mat.values.as_mut_ptr(); + let rest_ptr = unsafe { (mat_ptr as *mut MaybeUninit).add(w * h) }; + let first_slice: &mut [F] = unsafe { slice::from_raw_parts_mut(mat_ptr, w * h) }; + let rest_slice: &mut [MaybeUninit] = + unsafe { slice::from_raw_parts_mut(rest_ptr, lde_elems - w * h) }; + let mut first_coset_mat = RowMajorMatrixViewMut::new(first_slice, w); + let mut rest_cosets_mat = rest_slice + .chunks_exact_mut(w * h) + .map(|slice| RowMajorMatrixViewMut::new(slice, w)) + .collect_vec(); + + for coset_idx in 1..(1 << added_bits) { + let total_shift = g_big.exp_u64(coset_idx as u64) * shift; + let coset_idx = reverse_bits_len(coset_idx, added_bits); + let dest = &mut rest_cosets_mat[coset_idx - 1]; // - 1 because we removed the first matrix. + coset_dft_oop(self, &first_coset_mat.as_view(), dest, total_shift); + } + + // Now run a forward DFT on the very first coset, this time in-place. + coset_dft(self, &mut first_coset_mat.as_view_mut(), shift); + + // SAFETY: We wrote all values above. + unsafe { + mat.values.set_len(lde_elems); + } + BitReversalPerm::new_view(mat) + } +} + +#[instrument(level = "debug", skip_all)] +fn coset_dft( + dft: &Radix2DitParallel, + mat: &mut RowMajorMatrixViewMut, + shift: F, +) { + let log_h = log2_strict_usize(mat.height()); + let mid = log_h.div_ceil(2); + + let mut twiddles_ref_mut = dft.coset_twiddles.borrow_mut(); + let twiddles = twiddles_ref_mut + .entry((log_h, shift)) + .or_insert_with(|| compute_coset_twiddles(log_h, shift)); + + // The first half looks like a normal DIT. + first_half_general(mat, mid, twiddles); + + // For the second half, we flip the DIT, working in bit-reversed order. + reverse_matrix_index_bits(mat); + + second_half_general(mat, mid, twiddles); +} + +/// Like `coset_dft`, except out-of-place. +#[instrument(level = "debug", skip_all)] +fn coset_dft_oop( + dft: &Radix2DitParallel, + src: &RowMajorMatrixView, + dst_maybe: &mut RowMajorMatrixViewMut>, + shift: F, +) { + assert_eq!(src.dimensions(), dst_maybe.dimensions()); + + let log_h = log2_strict_usize(dst_maybe.height()); + + if log_h == 0 { + // This is an edge case where first_half_general_oop doesn't work, as it expects there to be + // at least one layer in the network, so we just copy instead. + let src_maybe = unsafe { + transmute::<&RowMajorMatrixView, &RowMajorMatrixView>>(src) + }; + dst_maybe.copy_from(src_maybe); + return; + } + + let mid = log_h.div_ceil(2); + + let mut twiddles_ref_mut = dft.coset_twiddles.borrow_mut(); + let twiddles = twiddles_ref_mut + .entry((log_h, shift)) + .or_insert_with(|| compute_coset_twiddles(log_h, shift)); + + // The first half looks like a normal DIT. + first_half_general_oop(src, dst_maybe, mid, twiddles); + + // dst is now initialized. + let dst = unsafe { + transmute::<&mut RowMajorMatrixViewMut>, &mut RowMajorMatrixViewMut>( + dst_maybe, + ) + }; + + // For the second half, we flip the DIT, working in bit-reversed order. + reverse_matrix_index_bits(dst); + + second_half_general(dst, mid, twiddles); +} + +/// This can be used as the first half of a DIT butterfly network. +#[instrument(level = "debug", skip_all)] +fn first_half(mat: &mut RowMajorMatrix, mid: usize, twiddles: &[F]) { + let log_h = log2_strict_usize(mat.height()); + + // max block size: 2^mid + mat.par_row_chunks_exact_mut(1 << mid) + .for_each(|mut submat| { + let mut backwards = false; + for layer in 0..mid { + let layer_rev = log_h - 1 - layer; + let layer_pow = 1 << layer_rev; + dit_layer( + &mut submat, + layer, + twiddles.iter().copied().step_by(layer_pow), + backwards, + ); + backwards = !backwards; + } + }); +} + +/// Like `first_half`, except supporting different twiddle factors per layer, enabling coset shifts +/// to be baked into them. +#[instrument(level = "debug", skip_all)] +fn first_half_general( + mat: &mut RowMajorMatrixViewMut, + mid: usize, + twiddles: &[Vec], +) { + let log_h = log2_strict_usize(mat.height()); + mat.par_row_chunks_exact_mut(1 << mid) + .for_each(|mut submat| { + let mut backwards = false; + for layer in 0..mid { + let layer_rev = log_h - 1 - layer; + dit_layer( + &mut submat, + layer, + twiddles[layer_rev].iter().copied(), + backwards, + ); + backwards = !backwards; + } + }); +} + +/// Like `first_half_general`, except out-of-place. +/// +/// Assumes there's at least one layer in the network, i.e. `src.height() > 1`. +/// Undefined behavior otherwise. +#[instrument(level = "debug", skip_all)] +fn first_half_general_oop( + src: &RowMajorMatrixView, + dst_maybe: &mut RowMajorMatrixViewMut>, + mid: usize, + twiddles: &[Vec], +) { + let log_h = log2_strict_usize(src.height()); + src.par_row_chunks_exact(1 << mid) + .zip(dst_maybe.par_row_chunks_exact_mut(1 << mid)) + .for_each(|(src_submat, mut dst_submat_maybe)| { + debug_assert_eq!(src_submat.dimensions(), dst_submat_maybe.dimensions()); + + // The first layer is special, done out-of-place. + // (Recall from the mid definition that there must be at least one layer here.) + let layer_rev = log_h - 1; + dit_layer_oop( + &src_submat, + &mut dst_submat_maybe, + 0, + twiddles[layer_rev].iter().copied(), + ); + + // submat is now initialized. + let mut dst_submat = unsafe { + transmute::>, RowMajorMatrixViewMut>( + dst_submat_maybe, + ) + }; + + // Subsequent layers. + let mut backwards = true; + for layer in 1..mid { + let layer_rev = log_h - 1 - layer; + dit_layer( + &mut dst_submat, + layer, + twiddles[layer_rev].iter().copied(), + backwards, + ); + backwards = !backwards; + } + }); +} + +/// This can be used as the second half of a DIT butterfly network. It works in bit-reversed order. +/// +/// The optional `scale` parameter is used to scale the matrix by a constant factor. Normally that +/// would be a separate step, but it's best to merge it into a butterfly network to avoid a +/// separate pass through main memory. +#[instrument(level = "debug", skip_all)] +#[inline(always)] // To avoid branch on scale +fn second_half( + mat: &mut RowMajorMatrix, + mid: usize, + twiddles_rev: &[F], + scale: Option, +) { + let log_h = log2_strict_usize(mat.height()); + + // max block size: 2^(log_h - mid) + mat.par_row_chunks_exact_mut(1 << (log_h - mid)) + .enumerate() + .for_each(|(thread, mut submat)| { + let mut backwards = false; + if let Some(scale) = scale { + submat.scale(scale); + } + for layer in mid..log_h { + let first_block = thread << (layer - mid); + dit_layer_rev( + &mut submat, + log_h, + layer, + twiddles_rev[first_block..].iter().copied(), + backwards, + ); + backwards = !backwards; + } + }); +} + +/// Like `second_half`, except supporting different twiddle factors per layer, enabling coset shifts +/// to be baked into them. +#[instrument(level = "debug", skip_all)] +fn second_half_general( + mat: &mut RowMajorMatrixViewMut, + mid: usize, + twiddles_rev: &[Vec], +) { + let log_h = log2_strict_usize(mat.height()); + mat.par_row_chunks_exact_mut(1 << (log_h - mid)) + .enumerate() + .for_each(|(thread, mut submat)| { + let mut backwards = false; + for layer in mid..log_h { + let layer_rev = log_h - 1 - layer; + let first_block = thread << (layer - mid); + dit_layer_rev( + &mut submat, + log_h, + layer, + twiddles_rev[layer_rev][first_block..].iter().copied(), + backwards, + ); + backwards = !backwards; + } + }); +} + +/// One layer of a DIT butterfly network. +fn dit_layer( + submat: &mut RowMajorMatrixViewMut<'_, F>, + layer: usize, + twiddles: impl Iterator + Clone, + backwards: bool, +) { + let half_block_size = 1 << layer; + let block_size = half_block_size * 2; + let width = submat.width(); + debug_assert!(submat.height() >= block_size); + + let process_block = |block: &mut [F]| { + let (lows, highs) = block.split_at_mut(half_block_size * width); + + for (lo, hi, twiddle) in izip!( + lows.chunks_mut(width), + highs.chunks_mut(width), + twiddles.clone() + ) { + DitButterfly(twiddle).apply_to_rows(lo, hi); + } + }; + + let blocks = submat.values.chunks_mut(block_size * width); + if backwards { + for block in blocks.rev() { + process_block(block); + } + } else { + for block in blocks { + process_block(block); + } + } +} + +/// One layer of a DIT butterfly network. +fn dit_layer_oop( + src: &RowMajorMatrixView, + dst: &mut RowMajorMatrixViewMut<'_, MaybeUninit>, + layer: usize, + twiddles: impl Iterator + Clone, +) { + debug_assert_eq!(src.dimensions(), dst.dimensions()); + let half_block_size = 1 << layer; + let block_size = half_block_size * 2; + let width = dst.width(); + debug_assert!(dst.height() >= block_size); + + let src_chunks = src.values.chunks(block_size * width); + let dst_chunks = dst.values.chunks_mut(block_size * width); + for (src_block, dst_block) in src_chunks.zip(dst_chunks) { + let (src_lows, src_highs) = src_block.split_at(half_block_size * width); + let (dst_lows, dst_highs) = dst_block.split_at_mut(half_block_size * width); + + for (src_lo, dst_lo, src_hi, dst_hi, twiddle) in izip!( + src_lows.chunks(width), + dst_lows.chunks_mut(width), + src_highs.chunks(width), + dst_highs.chunks_mut(width), + twiddles.clone() + ) { + DitButterfly(twiddle).apply_to_rows_oop(src_lo, dst_lo, src_hi, dst_hi); + } + } +} + +/// Like `dit_layer`, except the matrix and twiddles are encoded in bit-reversed order. +/// This can also be viewed as a layer of the Bowers G^T network. +fn dit_layer_rev( + submat: &mut RowMajorMatrixViewMut<'_, F>, + log_h: usize, + layer: usize, + twiddles_rev: impl DoubleEndedIterator + ExactSizeIterator, + backwards: bool, +) { + let layer_rev = log_h - 1 - layer; + + let half_block_size = 1 << layer_rev; + let block_size = half_block_size * 2; + let width = submat.width(); + debug_assert!(submat.height() >= block_size); + + let blocks_and_twiddles = submat + .values + .chunks_mut(block_size * width) + .zip(twiddles_rev); + if backwards { + for (block, twiddle) in blocks_and_twiddles.rev() { + let (lo, hi) = block.split_at_mut(half_block_size * width); + DitButterfly(twiddle).apply_to_rows(lo, hi) + } + } else { + for (block, twiddle) in blocks_and_twiddles { + let (lo, hi) = block.split_at_mut(half_block_size * width); + DitButterfly(twiddle).apply_to_rows(lo, hi) + } + } +} diff --git a/CoqOfRust/plonky3/dft/src/radix_2_dit_parallel.v b/CoqOfRust/plonky3/dft/src/radix_2_dit_parallel.v new file mode 100644 index 000000000..e2fc95cd1 --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/radix_2_dit_parallel.v @@ -0,0 +1,20943 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module radix_2_dit_parallel. + (* StructRecord + { + name := "Radix2DitParallel"; + const_params := []; + ty_params := [ "F" ]; + fields := + [ + ("twiddles", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ]); + ("coset_twiddles", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]); + ("inverse_twiddles", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ]) + ]; + } *) + + Module Impl_core_default_Default_where_core_default_Default_F_for_p3_dft_radix_2_dit_parallel_Radix2DitParallel_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") [] [ F ]. + + (* Default *) + Definition default (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_dft::radix_2_dit_parallel::Radix2DitParallel" + [ + ("twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "default", + [], + [] + |), + [] + |)); + ("coset_twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "default", + [], + [] + |), + [] + |)); + ("inverse_twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("default", InstanceField.Method (default F)) ]. + End Impl_core_default_Default_where_core_default_Default_F_for_p3_dft_radix_2_dit_parallel_Radix2DitParallel_F. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_dft_radix_2_dit_parallel_Radix2DitParallel_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_dft::radix_2_dit_parallel::Radix2DitParallel" + [ + ("twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::Radix2DitParallel", + "twiddles" + |) + |) + |) + |) + ] + |)); + ("coset_twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::Radix2DitParallel", + "coset_twiddles" + |) + |) + |) + |) + ] + |)); + ("inverse_twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::Radix2DitParallel", + "inverse_twiddles" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_dft_radix_2_dit_parallel_Radix2DitParallel_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_dft_radix_2_dit_parallel_Radix2DitParallel_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Radix2DitParallel" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::Radix2DitParallel", + "twiddles" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "coset_twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::Radix2DitParallel", + "coset_twiddles" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inverse_twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::Radix2DitParallel", + "inverse_twiddles" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_dft_radix_2_dit_parallel_Radix2DitParallel_F. + + (* StructRecord + { + name := "VectorPair"; + const_params := []; + ty_params := [ "F" ]; + fields := + [ + ("twiddles", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]); + ("bitrev_twiddles", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]) + ]; + } *) + + Module Impl_core_default_Default_where_core_default_Default_F_for_p3_dft_radix_2_dit_parallel_VectorPair_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]. + + (* Default *) + Definition default (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_dft::radix_2_dit_parallel::VectorPair" + [ + ("twiddles", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::default::Default", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "default", + [], + [] + |), + [] + |)); + ("bitrev_twiddles", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::default::Default", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("default", InstanceField.Method (default F)) ]. + End Impl_core_default_Default_where_core_default_Default_F_for_p3_dft_radix_2_dit_parallel_VectorPair_F. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_dft_radix_2_dit_parallel_VectorPair_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_dft::radix_2_dit_parallel::VectorPair" + [ + ("twiddles", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::VectorPair", + "twiddles" + |) + |) + |) + |) + ] + |)); + ("bitrev_twiddles", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::VectorPair", + "bitrev_twiddles" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_dft_radix_2_dit_parallel_VectorPair_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_dft_radix_2_dit_parallel_VectorPair_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "VectorPair" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::VectorPair", + "twiddles" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "bitrev_twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::VectorPair", + "bitrev_twiddles" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_dft_radix_2_dit_parallel_VectorPair_F. + + (* #[instrument(level = "debug", skip_all)] *) + Definition compute_twiddles (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ log_h ] => + ltac:(M.monadic + (let log_h := M.alloc (| log_h |) in + M.catch_return (Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ half_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |); + Value.Integer IntegerKind.I32 1 + ] + |) + |) in + let~ root : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_h |) ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, root |) ] + |); + M.read (| half_h |) + ] + |) + ] + |) + |) in + let~ bit_reversed_twiddles : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, twiddles |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, bit_reversed_twiddles |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_dft::radix_2_dit_parallel::VectorPair" + [ + ("twiddles", M.read (| twiddles |)); + ("bitrev_twiddles", M.read (| bit_reversed_twiddles |)) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_compute_twiddles : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::compute_twiddles" compute_twiddles. + Admitted. + Global Typeclasses Opaque compute_twiddles. + + (* #[instrument(level = "debug", skip_all)] *) + Definition compute_coset_twiddles (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ log_h; shift ] => + ltac:(M.monadic + (let log_h := M.alloc (| log_h |) in + let shift := M.alloc (| shift |) in + M.catch_return + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_coset_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_coset_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_coset_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_coset_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ mid : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "div_ceil", [], [] |), + [ M.read (| log_h |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ root : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_h |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| log_h |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let layer := M.copy (| γ |) in + M.read (| + let~ shift_power : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, shift |); + M.read (| layer |) + ] + |) + |) in + let~ powers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ] := + M.alloc (| + Value.StructRecord + "p3_field::field::Powers" + [ + ("base", + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, root |); + M.read (| layer |) + ] + |)); + ("current", M.read (| shift_power |)) + ] + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.read (| powers |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.read (| h |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| layer |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ layer_rev : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| log_h |); + Value.Integer IntegerKind.Usize 1 + ] + |); + M.read (| layer |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| layer_rev |); + M.read (| mid |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::reverse_slice_index_bits", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + twiddles + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + twiddles + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_compute_coset_twiddles : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::compute_coset_twiddles" compute_coset_twiddles. + Admitted. + Global Typeclasses Opaque compute_coset_twiddles. + + (* #[instrument(level = "debug", skip_all)] *) + Definition compute_inverse_twiddles (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ log_h ] => + ltac:(M.monadic + (let log_h := M.alloc (| log_h |) in + M.catch_return (Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_inverse_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_inverse_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_inverse_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::compute_inverse_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ half_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |); + Value.Integer IntegerKind.I32 1 + ] + |) + |) in + let~ root_inv : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_h |) ] + |) + |) + |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, root_inv |) ] + |); + M.read (| half_h |) + ] + |) + ] + |) + |) in + let~ bit_reversed_twiddles : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, twiddles |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, bit_reversed_twiddles |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_dft::radix_2_dit_parallel::VectorPair" + [ + ("twiddles", M.read (| twiddles |)); + ("bitrev_twiddles", M.read (| bit_reversed_twiddles |)) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_compute_inverse_twiddles : + M.IsFunction.C + "p3_dft::radix_2_dit_parallel::compute_inverse_twiddles" + compute_inverse_twiddles. + Admitted. + Global Typeclasses Opaque compute_inverse_twiddles. + + Module Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_field_field_TwoAdicField_F_where_core_cmp_Ord_F_F_for_p3_dft_radix_2_dit_parallel_Radix2DitParallel_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") [] [ F ]. + + (* type Evaluations = BitReversedMatrixView>; *) + Definition _Evaluations (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + ]. + + (* + fn dft_batch(&self, mut mat: RowMajorMatrix) -> Self::Evaluations { + let h = mat.height(); + let log_h = log2_strict_usize(h); + + // Compute twiddle factors, or take memoized ones if already available. + let mut twiddles_ref_mut = self.twiddles.borrow_mut(); + let twiddles = twiddles_ref_mut + .entry(log_h) + .or_insert_with(|| compute_twiddles(log_h)); + + let mid = log_h.div_ceil(2); + + // The first half looks like a normal DIT. + reverse_matrix_index_bits(&mut mat); + first_half(&mut mat, mid, &twiddles.twiddles); + + // For the second half, we flip the DIT, working in bit-reversed order. + reverse_matrix_index_bits(&mut mat); + second_half(&mut mat, mid, &twiddles.bitrev_twiddles, None); + + mat.bit_reverse_rows() + } + *) + Definition dft_batch (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.read (| + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ twiddles_ref_mut : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::Radix2DitParallel", + "twiddles" + |) + |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ] ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + "or_insert_with", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + "entry", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, twiddles_ref_mut |) ] + |) + |) + |); + M.read (| log_h |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ], + M.get_function (| + "p3_dft::radix_2_dit_parallel::compute_twiddles", + [], + [ F ] + |), + [ M.read (| log_h |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ mid : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "div_ceil", [], [] |), + [ M.read (| log_h |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::reverse_matrix_index_bits", + [], + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_dit_parallel::first_half", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |); + M.read (| mid |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| twiddles |) |), + "p3_dft::radix_2_dit_parallel::VectorPair", + "twiddles" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::reverse_matrix_index_bits", + [], + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_dit_parallel::second_half", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |); + M.read (| mid |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| twiddles |) |), + "p3_dft::radix_2_dit_parallel::VectorPair", + "bitrev_twiddles" + |) + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "p3_matrix::bitrev::BitReversibleMatrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "bit_reverse_rows", + [], + [] + |), + [ M.read (| mat |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* #[instrument(skip_all, fields(dims = %mat.dimensions(), added_bits = added_bits))] *) + Definition coset_lde_batch + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat; added_bits; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let added_bits := M.alloc (| added_bits |) in + let shift := M.alloc (| shift |) in + M.catch_return + (Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + (Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") [] [ F ]) + "Evaluations") (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + F + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + mat + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + added_bits + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ w : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "width" + |) + |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ mid : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "div_ceil", [], [] |), + [ M.read (| log_h |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ inverse_twiddles_ref_mut : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_dft::radix_2_dit_parallel::Radix2DitParallel", + "inverse_twiddles" + |) + |) + ] + |) + |) in + let~ inverse_twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ] ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path "usize"; + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]; + Ty.path "alloc::alloc::Global" + ], + "or_insert_with", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") [] [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "entry", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, inverse_twiddles_ref_mut |) ] + |) + |) + |); + M.read (| log_h |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::VectorPair") + [] + [ F ], + M.get_function (| + "p3_dft::radix_2_dit_parallel::compute_inverse_twiddles", + [], + [ F ] + |), + [ M.read (| log_h |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::reverse_matrix_index_bits", + [], + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_dit_parallel::first_half", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |); + M.read (| mid |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| inverse_twiddles |) |), + "p3_dft::radix_2_dit_parallel::VectorPair", + "twiddles" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::reverse_matrix_index_bits", + [], + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |) + ] + |) + |) in + let~ h_inv_subfield : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield" + ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + [], + [], + "try_inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + [], + [ Ty.path "usize" ], + "from_int", + [], + [] + |), + [ M.read (| h |) ] + |) + |) + |) + ] + |) + |) in + let~ scale : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::option::Option") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield" + ], + "map", + [], + [ + F; + Ty.function + [ + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield" + ] + F + ] + |), + [ + M.read (| h_inv_subfield |); + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_prime_subfield", + [], + [] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_dit_parallel::second_half", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |); + M.read (| mid |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| inverse_twiddles |) |), + "p3_dft::radix_2_dit_parallel::VectorPair", + "bitrev_twiddles" + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| scale |) + ] + |) + |) in + let~ lde_elems : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| w |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ M.read (| h |); M.read (| added_bits |) ] + |) + ] + |) + |) in + let~ elems_to_add : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| lde_elems |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| w |); M.read (| h |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_lde_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_lde_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_lde_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_lde_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "reserve_exact", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |); + M.read (| elems_to_add |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ g_big : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_h |); M.read (| added_bits |) ] + |) + ] + |) + |) in + let~ mat_ptr : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "*mut") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "as_mut_ptr", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |) + |) in + let~ rest_ptr : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + "add", + [], + [] + |), + [ + M.cast + (Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ]) + (M.read (| mat_ptr |)); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| w |); M.read (| h |) ] + |) + ] + |) + |) in + let~ first_slice : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] := + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_function (| + "core::slice::raw::from_raw_parts_mut", + [], + [ F ] + |), + [ + M.read (| mat_ptr |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| w |); M.read (| h |) ] + |) + ] + |) + |) + |) + |) + |) + |) in + let~ rest_slice : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_function (| + "core::slice::raw::from_raw_parts_mut", + [], + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + |), + [ + M.read (| rest_ptr |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| lde_elems |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| w |); M.read (| h |) ] + |) + ] + |) + ] + |) + |) + |) + |) + |) + |) in + let~ first_coset_mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + "new", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| first_slice |) |) |); + M.read (| w |) + ] + |) + |) in + let~ rest_cosets_mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| rest_slice |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| w |); M.read (| h |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let slice := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| slice |) |) + |); + M.read (| w |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 1); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| added_bits |) ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let coset_idx := M.copy (| γ0_0 |) in + let~ total_shift : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, g_big |); + M.cast + (Ty.path "u64") + (M.read (| coset_idx |)) + ] + |); + M.read (| shift |) + ] + |) + |) in + let~ coset_idx : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::reverse_bits_len", + [], + [] + |), + [ M.read (| coset_idx |); M.read (| added_bits |) ] + |) + |) in + let~ dest : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rest_cosets_mat + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| coset_idx |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::coset_dft_oop", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ], + "as_view", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + first_coset_mat + |) + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| dest |) |) + |); + M.read (| total_shift |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::radix_2_dit_parallel::coset_dft", [], [ F ] |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + "as_view_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, first_coset_mat |) ] + |) + |) + |) + |) + |); + M.read (| shift |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "set_len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |); + M.read (| lde_elems |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_associated_function (| + Ty.path "p3_matrix::bitrev::BitReversalPerm", + "new_view", + [], + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ M.read (| mat |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_dft::traits::TwoAdicSubgroupDft" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) + [ + ("Evaluations", InstanceField.Ty (_Evaluations F)); + ("dft_batch", InstanceField.Method (dft_batch F)); + ("coset_lde_batch", InstanceField.Method (coset_lde_batch F)) + ]. + End Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_field_field_TwoAdicField_F_where_core_cmp_Ord_F_F_for_p3_dft_radix_2_dit_parallel_Radix2DitParallel_F. + + (* #[instrument(level = "debug", skip_all)] *) + Definition coset_dft (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ dft; mat; shift ] => + ltac:(M.monadic + (let dft := M.alloc (| dft |) in + let mat := M.alloc (| mat |) in + let shift := M.alloc (| shift |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_dft::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_dft::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_dft::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_dft::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |) ] + |) + ] + |) + |) in + let~ mid : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "div_ceil", [], [] |), + [ M.read (| log_h |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ twiddles_ref_mut : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| dft |) |), + "p3_dft::radix_2_dit_parallel::Radix2DitParallel", + "coset_twiddles" + |) + |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + "or_insert_with", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + "entry", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, twiddles_ref_mut |) ] + |) + |) + |); + Value.Tuple [ M.read (| log_h |); M.read (| shift |) ] + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_dft::radix_2_dit_parallel::compute_coset_twiddles", + [], + [ F ] + |), + [ M.read (| log_h |); M.read (| shift |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::first_half_general", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.read (| mid |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| twiddles |) |) |) ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::reverse_matrix_index_bits", + [], + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::second_half_general", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.read (| mid |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| twiddles |) |) |) ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_coset_dft : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::coset_dft" coset_dft. + Admitted. + Global Typeclasses Opaque coset_dft. + + (* #[instrument(level = "debug", skip_all)] *) + Definition coset_dft_oop (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ dft; src; dst_maybe; shift ] => + ltac:(M.monadic + (let dft := M.alloc (| dft |) in + let src := M.alloc (| src |) in + let dst_maybe := M.alloc (| dst_maybe |) in + let shift := M.alloc (| shift |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_dft_oop::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_dft_oop::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_dft_oop::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::coset_dft_oop::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + [], + [ F ], + "dimensions", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| src |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + [], + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| dst_maybe |) |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "p3_matrix::Dimensions", + [], + [ Ty.path "p3_matrix::Dimensions" ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "p3_matrix::Dimensions"; + Ty.path "p3_matrix::Dimensions" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + [], + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| dst_maybe |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| log_h |); Value.Integer IntegerKind.Usize 0 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ src_maybe : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + "copy_from", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| dst_maybe |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src_maybe |) |) + |) + ] + |) + |) in + M.return_ (| Value.Tuple [] |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ mid : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "div_ceil", [], [] |), + [ M.read (| log_h |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ twiddles_ref_mut : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| dft |) |), + "p3_dft::radix_2_dit_parallel::Radix2DitParallel", + "coset_twiddles" + |) + |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + "or_insert_with", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + "entry", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ + Ty.apply + (Ty.path "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, twiddles_ref_mut |) ] + |) + |) + |); + Value.Tuple [ M.read (| log_h |); M.read (| shift |) ] + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_dft::radix_2_dit_parallel::compute_coset_twiddles", + [], + [ F ] + |), + [ M.read (| log_h |); M.read (| shift |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::first_half_general_oop", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| src |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| dst_maybe |) |) |); + M.read (| mid |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| twiddles |) |) |) ] + |) + |) + |) + ] + |) + |) in + let~ dst : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| dst_maybe |) |) |) ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::reverse_matrix_index_bits", + [], + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| dst |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::second_half_general", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| dst |) |) |); + M.read (| mid |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| twiddles |) |) |) ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_coset_dft_oop : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::coset_dft_oop" coset_dft_oop. + Admitted. + Global Typeclasses Opaque coset_dft_oop. + + (* #[instrument(level = "debug", skip_all)] *) + Definition first_half (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ mat; mid; twiddles ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let mid := M.alloc (| mid |) in + let twiddles := M.alloc (| twiddles |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "par_row_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| mid |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let submat := M.copy (| γ |) in + M.read (| + let~ backwards : + Ty.apply (Ty.path "*") [] [ Ty.path "bool" ] := + M.alloc (| Value.Bool false |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| mid |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let layer := M.copy (| γ0_0 |) in + let~ layer_rev : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| log_h |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + M.read (| layer |) + ] + |) + |) in + let~ layer_pow : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer + IntegerKind.Usize + 1; + M.read (| layer_rev |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::dit_layer", + [], + [ + F; + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + submat + |) + |) + |); + M.read (| layer |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "step_by", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + [], + [], + "copied", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + twiddles + |) + |) + |) + ] + |) + ] + |); + M.read (| layer_pow |) + ] + |); + M.read (| backwards |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + backwards, + UnOp.not (| + M.read (| backwards |) + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_first_half : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::first_half" first_half. + Admitted. + Global Typeclasses Opaque first_half. + + (* #[instrument(level = "debug", skip_all)] *) + Definition first_half_general (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ mat; mid; twiddles ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let mid := M.alloc (| mid |) in + let twiddles := M.alloc (| twiddles |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half_general::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half_general::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half_general::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half_general::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + "par_row_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| mid |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let submat := M.copy (| γ |) in + M.read (| + let~ backwards : + Ty.apply (Ty.path "*") [] [ Ty.path "bool" ] := + M.alloc (| Value.Bool false |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| mid |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let layer := M.copy (| γ0_0 |) in + let~ layer_rev : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| log_h |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + M.read (| layer |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::dit_layer", + [], + [ + F; + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + submat + |) + |) + |); + M.read (| layer |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + [], + [], + "copied", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + twiddles + |) + |), + M.read (| + layer_rev + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.read (| backwards |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + backwards, + UnOp.not (| + M.read (| backwards |) + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_first_half_general : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::first_half_general" first_half_general. + Admitted. + Global Typeclasses Opaque first_half_general. + + (* #[instrument(level = "debug", skip_all)] *) + Definition first_half_general_oop (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ src; dst_maybe; mid; twiddles ] => + ltac:(M.monadic + (let src := M.alloc (| src |) in + let dst_maybe := M.alloc (| dst_maybe |) in + let mid := M.alloc (| mid |) in + let twiddles := M.alloc (| twiddles |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half_general_oop::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half_general_oop::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half_general_oop::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::first_half_general_oop::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| src |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ Ty.associated_unknown; Ty.associated_unknown ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ Ty.associated_unknown; Ty.associated_unknown ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "zip", + [], + [ Ty.associated_unknown ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + "par_row_chunks_exact", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| src |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| mid |) ] + |) + ] + |); + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + "par_row_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| dst_maybe |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| mid |) ] + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let src_submat := M.copy (| γ0_0 |) in + let dst_submat_maybe := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ], + [], + [ F ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + src_submat + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + dst_submat_maybe + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path + "p3_matrix::Dimensions", + [], + [ + Ty.path + "p3_matrix::Dimensions" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "p3_matrix::Dimensions" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ layer_rev : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| log_h |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::dit_layer_oop", + [], + [ + F; + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, src_submat |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + dst_submat_maybe + |) + |) + |); + Value.Integer IntegerKind.Usize 0; + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ], + [], + [], + "copied", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| twiddles |) + |), + M.read (| layer_rev |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ dst_submat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + |), + [ M.read (| dst_submat_maybe |) ] + |) + |) in + let~ backwards : + Ty.apply (Ty.path "*") [] [ Ty.path "bool" ] := + M.alloc (| Value.Bool true |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 1); + ("end_", M.read (| mid |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let layer := M.copy (| γ0_0 |) in + let~ layer_rev : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| log_h |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + M.read (| layer |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::dit_layer", + [], + [ + F; + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + dst_submat + |) + |) + |); + M.read (| layer |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + [], + [], + "copied", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + twiddles + |) + |), + M.read (| + layer_rev + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.read (| backwards |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + backwards, + UnOp.not (| + M.read (| backwards |) + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_first_half_general_oop : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::first_half_general_oop" first_half_general_oop. + Admitted. + Global Typeclasses Opaque first_half_general_oop. + + (* #[instrument(level = "debug", skip_all)] *) + Definition second_half (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ mat; mid; twiddles_rev; scale ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let mid := M.alloc (| mid |) in + let twiddles_rev := M.alloc (| twiddles_rev |) in + let scale := M.alloc (| scale |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::second_half::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::second_half::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::second_half::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::second_half::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "par_row_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| log_h |); M.read (| mid |) ] + |) + ] + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let thread := M.copy (| γ0_0 |) in + let submat := M.copy (| γ0_1 |) in + M.read (| + let~ backwards : + Ty.apply (Ty.path "*") [] [ Ty.path "bool" ] := + M.alloc (| Value.Bool false |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := scale in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let scale := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ], + "scale", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + submat + |); + M.read (| scale |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| mid |)); + ("end_", M.read (| log_h |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let layer := M.copy (| γ0_0 |) in + let~ first_block : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.read (| thread |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| layer |); + M.read (| mid |) + ] + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::dit_layer_rev", + [], + [ + F; + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + submat + |) + |) + |); + M.read (| log_h |); + M.read (| layer |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + [], + [], + "copied", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "slice") + [] + [ F ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ + Ty.path + "usize" + ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + twiddles_rev + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.read (| + first_block + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |); + M.read (| backwards |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + backwards, + UnOp.not (| + M.read (| backwards |) + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_second_half : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::second_half" second_half. + Admitted. + Global Typeclasses Opaque second_half. + + (* #[instrument(level = "debug", skip_all)] *) + Definition second_half_general (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ mat; mid; twiddles_rev ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let mid := M.alloc (| mid |) in + let twiddles_rev := M.alloc (| twiddles_rev |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::second_half_general::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::second_half_general::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::second_half_general::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::radix_2_dit_parallel::second_half_general::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.associated_unknown ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + "par_row_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| log_h |); M.read (| mid |) ] + |) + ] + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let thread := M.copy (| γ0_0 |) in + let submat := M.copy (| γ0_1 |) in + M.read (| + let~ backwards : + Ty.apply (Ty.path "*") [] [ Ty.path "bool" ] := + M.alloc (| Value.Bool false |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| mid |)); + ("end_", M.read (| log_h |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let layer := M.copy (| γ0_0 |) in + let~ layer_rev : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| log_h |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + M.read (| layer |) + ] + |) + |) in + let~ first_block : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.read (| thread |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| layer |); + M.read (| mid |) + ] + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::radix_2_dit_parallel::dit_layer_rev", + [], + [ + F; + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + submat + |) + |) + |); + M.read (| log_h |); + M.read (| layer |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + [], + [], + "copied", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ + Ty.path + "usize" + ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + twiddles_rev + |) + |), + M.read (| + layer_rev + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.read (| + first_block + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |); + M.read (| backwards |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + backwards, + UnOp.not (| + M.read (| backwards |) + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_second_half_general : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::second_half_general" second_half_general. + Admitted. + Global Typeclasses Opaque second_half_general. + + (* + fn dit_layer( + submat: &mut RowMajorMatrixViewMut<'_, F>, + layer: usize, + twiddles: impl Iterator + Clone, + backwards: bool, + ) { + let half_block_size = 1 << layer; + let block_size = half_block_size * 2; + let width = submat.width(); + debug_assert!(submat.height() >= block_size); + + let process_block = |block: &mut [F]| { + let (lows, highs) = block.split_at_mut(half_block_size * width); + + for (lo, hi, twiddle) in izip!( + lows.chunks_mut(width), + highs.chunks_mut(width), + twiddles.clone() + ) { + DitButterfly(twiddle).apply_to_rows(lo, hi); + } + }; + + let blocks = submat.values.chunks_mut(block_size * width); + if backwards { + for block in blocks.rev() { + process_block(block); + } + } else { + for block in blocks { + process_block(block); + } + } + } + *) + Definition dit_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; impl_Iterator_Item___F___plus__Clone ], [ submat; layer; twiddles; backwards ] => + ltac:(M.monadic + (let submat := M.alloc (| submat |) in + let layer := M.alloc (| layer |) in + let twiddles := M.alloc (| twiddles |) in + let backwards := M.alloc (| backwards |) in + M.read (| + let~ half_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| layer |) ] + |) + |) in + let~ block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| half_block_size |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ], + [], + [ F ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| submat |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| submat |) |) + |) + ] + |); + M.read (| block_size |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: submat.height() >= block_size" |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ process_block : + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + ] + (Ty.tuple []) + ] := + M.alloc (| + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let block := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "split_at_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| block |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| half_block_size |); M.read (| width |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let lows := M.copy (| γ0_0 |) in + let highs := M.copy (| γ0_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ]; + impl_Iterator_Item___F___plus__Clone + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] + ]; + F + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ]; + impl_Iterator_Item___F___plus__Clone + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + F + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ F ], + "chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| lows |) |) + |); + M.read (| width |) + ] + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ] + |), + [ + M.read (| iter |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ F ], + "chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| highs |) |) + |); + M.read (| width |) + ] + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ]; + impl_Iterator_Item___F___plus__Clone + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ]; + impl_Iterator_Item___F___plus__Clone + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ], + [], + [], + "zip", + [], + [ impl_Iterator_Item___F___plus__Clone + ] + |), + [ + M.read (| iter |); + M.call_closure (| + impl_Iterator_Item___F___plus__Clone, + M.get_trait_method (| + "core::clone::Clone", + impl_Iterator_Item___F___plus__Clone, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + twiddles + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ]; + impl_Iterator_Item___F___plus__Clone + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + F + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ]; + impl_Iterator_Item___F___plus__Clone + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + F + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + F + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + F + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := + M.copy (| γ1_0 |) in + let b := + M.copy (| γ1_1 |) in + let b := + M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + F + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ F ] + ]; + impl_Iterator_Item___F___plus__Clone + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + F + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ1_2 := + M.SubPointer.get_tuple_field (| + γ0_0, + 2 + |) in + let lo := M.copy (| γ1_0 |) in + let hi := M.copy (| γ1_1 |) in + let twiddle := + M.copy (| γ1_2 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ], + [], + [ F ], + "apply_to_rows", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "p3_dft::butterflies::DitButterfly" + [ + M.read (| + twiddle + |) + ] + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| lo |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| hi |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + |) in + let~ blocks : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| submat |) |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| block_size |); M.read (| width |) ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use backwards in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ], + [], + [], + "rev", + [], + [] + |), + [ M.read (| blocks |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let block := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + (Ty.tuple []), + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, process_block |); + Value.Tuple + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| block |) |) + |) + ] + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))); + fun γ => + ltac:(M.monadic + (M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| blocks |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ F ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let block := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + (Ty.tuple []), + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, process_block |); + Value.Tuple + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| block |) |) + |) + ] + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dit_layer : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::dit_layer" dit_layer. + Admitted. + Global Typeclasses Opaque dit_layer. + + (* + fn dit_layer_oop( + src: &RowMajorMatrixView, + dst: &mut RowMajorMatrixViewMut<'_, MaybeUninit>, + layer: usize, + twiddles: impl Iterator + Clone, + ) { + debug_assert_eq!(src.dimensions(), dst.dimensions()); + let half_block_size = 1 << layer; + let block_size = half_block_size * 2; + let width = dst.width(); + debug_assert!(dst.height() >= block_size); + + let src_chunks = src.values.chunks(block_size * width); + let dst_chunks = dst.values.chunks_mut(block_size * width); + for (src_block, dst_block) in src_chunks.zip(dst_chunks) { + let (src_lows, src_highs) = src_block.split_at(half_block_size * width); + let (dst_lows, dst_highs) = dst_block.split_at_mut(half_block_size * width); + + for (src_lo, dst_lo, src_hi, dst_hi, twiddle) in izip!( + src_lows.chunks(width), + dst_lows.chunks_mut(width), + src_highs.chunks(width), + dst_highs.chunks_mut(width), + twiddles.clone() + ) { + DitButterfly(twiddle).apply_to_rows_oop(src_lo, dst_lo, src_hi, dst_hi); + } + } + } + *) + Definition dit_layer_oop (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; impl_Iterator_Item___F___plus__Clone ], [ src; dst; layer; twiddles ] => + ltac:(M.monadic + (let src := M.alloc (| src |) in + let dst := M.alloc (| dst |) in + let layer := M.alloc (| layer |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + [], + [ F ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + [], + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| dst |) |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "p3_matrix::Dimensions", + [], + [ Ty.path "p3_matrix::Dimensions" ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "p3_matrix::Dimensions"; + Ty.path "p3_matrix::Dimensions" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ half_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| layer |) ] + |) + |) in + let~ block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| half_block_size |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + ], + [], + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| dst |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + [], + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| dst |) |) + |) + ] + |); + M.read (| block_size |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: dst.height() >= block_size" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ src_chunks : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "chunks", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| src |) |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| block_size |); M.read (| width |) ] + |) + ] + |) + |) in + let~ dst_chunks : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + "chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| dst |) |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| block_size |); M.read (| width |) ] + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ]; + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ]; + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ]; + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + |), + [ M.read (| src_chunks |); M.read (| dst_chunks |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ]; + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let src_block := M.copy (| γ1_0 |) in + let dst_block := M.copy (| γ1_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "split_at", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src_block |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| half_block_size |); M.read (| width |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let src_lows := M.copy (| γ0_0 |) in + let src_highs := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "split_at_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| dst_block |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| half_block_size |); + M.read (| width |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let dst_lows := M.copy (| γ0_0 |) in + let dst_highs := M.copy (| γ0_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + impl_Iterator_Item___F___plus__Clone + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F + ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + F + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + impl_Iterator_Item___F___plus__Clone + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + F + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ F ], + "chunks", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| src_lows |) + |) + |); + M.read (| width |) + ] + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + |), + [ + M.read (| iter |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| dst_lows |) + |) + |); + M.read (| width |) + ] + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ] + |), + [ + M.read (| iter |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ F ], + "chunks", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| src_highs |) + |) + |); + M.read (| width |) + ] + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + |), + [ + M.read (| iter |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| dst_highs |) + |) + |); + M.read (| width |) + ] + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + impl_Iterator_Item___F___plus__Clone + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + impl_Iterator_Item___F___plus__Clone + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + [], + [], + "zip", + [], + [ + impl_Iterator_Item___F___plus__Clone + ] + |), + [ + M.read (| iter |); + M.call_closure (| + impl_Iterator_Item___F___plus__Clone, + M.get_trait_method (| + "core::clone::Clone", + impl_Iterator_Item___F___plus__Clone, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + twiddles + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + impl_Iterator_Item___F___plus__Clone + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F + ] + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F + ] + ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + F + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + impl_Iterator_Item___F___plus__Clone + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + F + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F + ] + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F + ] + ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + F + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ]; + F + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ1_0, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ1_0, + 1 + |) in + let γ3_0 := + M.SubPointer.get_tuple_field (| + γ2_0, + 0 + |) in + let γ3_1 := + M.SubPointer.get_tuple_field (| + γ2_0, + 1 + |) in + let a := + M.copy (| + γ3_0 + |) in + let b := + M.copy (| + γ3_1 + |) in + let b := + M.copy (| + γ2_1 + |) in + let b := + M.copy (| + γ1_1 + |) in + let b := + M.copy (| + γ0_1 + |) in + Value.Tuple + [ + M.read (| + a + |); + M.read (| + b + |); + M.read (| + b + |); + M.read (| + b + |); + M.read (| + b + |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + F + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Chunks") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + impl_Iterator_Item___F___plus__Clone + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + F + ] + ] + ] + ]; + F + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + F + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ1_2 := + M.SubPointer.get_tuple_field (| + γ0_0, + 2 + |) in + let γ1_3 := + M.SubPointer.get_tuple_field (| + γ0_0, + 3 + |) in + let γ1_4 := + M.SubPointer.get_tuple_field (| + γ0_0, + 4 + |) in + let src_lo := + M.copy (| γ1_0 |) in + let dst_lo := + M.copy (| γ1_1 |) in + let src_hi := + M.copy (| γ1_2 |) in + let dst_hi := + M.copy (| γ1_3 |) in + let twiddle := + M.copy (| γ1_4 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ], + [], + [ F ], + "apply_to_rows_oop", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "p3_dft::butterflies::DitButterfly" + [ + M.read (| + twiddle + |) + ] + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + src_lo + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + dst_lo + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + src_hi + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + dst_hi + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dit_layer_oop : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::dit_layer_oop" dit_layer_oop. + Admitted. + Global Typeclasses Opaque dit_layer_oop. + + (* + fn dit_layer_rev( + submat: &mut RowMajorMatrixViewMut<'_, F>, + log_h: usize, + layer: usize, + twiddles_rev: impl DoubleEndedIterator + ExactSizeIterator, + backwards: bool, + ) { + let layer_rev = log_h - 1 - layer; + + let half_block_size = 1 << layer_rev; + let block_size = half_block_size * 2; + let width = submat.width(); + debug_assert!(submat.height() >= block_size); + + let blocks_and_twiddles = submat + .values + .chunks_mut(block_size * width) + .zip(twiddles_rev); + if backwards { + for (block, twiddle) in blocks_and_twiddles.rev() { + let (lo, hi) = block.split_at_mut(half_block_size * width); + DitButterfly(twiddle).apply_to_rows(lo, hi) + } + } else { + for (block, twiddle) in blocks_and_twiddles { + let (lo, hi) = block.split_at_mut(half_block_size * width); + DitButterfly(twiddle).apply_to_rows(lo, hi) + } + } + } + *) + Definition dit_layer_rev (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], + [ F; impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator ], + [ submat; log_h; layer; twiddles_rev; backwards ] => + ltac:(M.monadic + (let submat := M.alloc (| submat |) in + let log_h := M.alloc (| log_h |) in + let layer := M.alloc (| layer |) in + let twiddles_rev := M.alloc (| twiddles_rev |) in + let backwards := M.alloc (| backwards |) in + M.read (| + let~ layer_rev : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| log_h |); Value.Integer IntegerKind.Usize 1 ] + |); + M.read (| layer |) + ] + |) + |) in + let~ half_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| layer_rev |) ] + |) + |) in + let~ block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| half_block_size |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ], + [], + [ F ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| submat |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| submat |) |) + |) + ] + |); + M.read (| block_size |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: submat.height() >= block_size" |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ blocks_and_twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ]; + impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ]; + impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ], + [], + [], + "zip", + [], + [ impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| submat |) |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| block_size |); M.read (| width |) ] + |) + ] + |); + M.read (| twiddles_rev |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use backwards in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ]; + impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ]; + impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ]; + impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ]; + impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator + ], + [], + [], + "rev", + [], + [] + |), + [ M.read (| blocks_and_twiddles |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + F + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ F ]; + impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let block := M.copy (| γ1_0 |) in + let twiddle := M.copy (| γ1_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "split_at_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| block |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| half_block_size |); + M.read (| width |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let lo := M.copy (| γ0_0 |) in + let hi := M.copy (| γ0_1 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ], + [], + [ F ], + "apply_to_rows", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "p3_dft::butterflies::DitButterfly" + [ M.read (| twiddle |) ] + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| lo |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| hi |) |) + |) + ] + |) + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))); + fun γ => + ltac:(M.monadic + (M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ]; + impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ]; + impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| blocks_and_twiddles |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + F + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ F ]; + impl_DoubleEndedIterator_Item___F___plus__ExactSizeIterator + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let block := M.copy (| γ1_0 |) in + let twiddle := M.copy (| γ1_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "split_at_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| block |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| half_block_size |); + M.read (| width |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let lo := M.copy (| γ0_0 |) in + let hi := M.copy (| γ0_1 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_dft::butterflies::Butterfly", + Ty.apply + (Ty.path + "p3_dft::butterflies::DitButterfly") + [] + [ F ], + [], + [ F ], + "apply_to_rows", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "p3_dft::butterflies::DitButterfly" + [ M.read (| twiddle |) ] + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| lo |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| hi |) |) + |) + ] + |) + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dit_layer_rev : + M.IsFunction.C "p3_dft::radix_2_dit_parallel::dit_layer_rev" dit_layer_rev. + Admitted. + Global Typeclasses Opaque dit_layer_rev. +End radix_2_dit_parallel. diff --git a/CoqOfRust/plonky3/dft/src/traits.rs b/CoqOfRust/plonky3/dft/src/traits.rs new file mode 100644 index 000000000..bc1c4ee7f --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/traits.rs @@ -0,0 +1,472 @@ +use alloc::vec::Vec; + +use p3_field::{BasedVectorSpace, TwoAdicField}; +use p3_matrix::Matrix; +use p3_matrix::bitrev::BitReversibleMatrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::util::swap_rows; + +use crate::util::{coset_shift_cols, divide_by_height}; + +/// This trait gives an interface for computing discrete fourier transforms (DFT's) and their inverses over +/// cosets of two-adic subgroups of a field `F`. It also contains combined methods which allow you to take the +/// evaluation vector of a polynomial on a coset `gH` and extend it to a coset `g'K` for some possibly larger +/// subgroup `K` and different shift `g'`. +/// +/// It supports polynomials with evaluations/coefficients valued in either `F` or `A` where `A` +/// is a vector space over `F` with specified basis. This latter case makes use of the fact that the DFT +/// is linear meaning we can decompose an `A` valued polynomial into a collection of `F` valued polynomials, +/// apply the DFT to each of them, and then recombine. When `A` is an extension field, this approach +/// is much faster than using a `TwoAdicSubgroupDft` implementation directly. +/// +/// Most implementations of this trait are optimised for the batch case where the input +/// is a matrix and we is a want to perform the same operation on every column. Note that +/// depending on the width and height of the matrix (as well as whether or not you are using the +/// parallel feature) different implementation may be faster. Hence depending on your use case +/// you may want to be using `Radix2Dit, Radix2DitParallel, RecursiveDft` or `Radix2Bowers`. +pub trait TwoAdicSubgroupDft: Clone + Default { + // Effectively this is either RowMajorMatrix or BitReversedMatrixView. + // Always owned. + type Evaluations: BitReversibleMatrix + 'static; + + /// Compute the discrete Fourier transform (DFT) of `vec`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `vec.len()`. + /// Treating `vec` as coefficients of a polynomial, compute the evaluations + /// of that polynomial on the subgroup `H`. + fn dft(&self, vec: Vec) -> Vec { + self.dft_batch(RowMajorMatrix::new_col(vec)) + .to_row_major_matrix() + .values + } + + /// Compute the discrete Fourier transform (DFT) of each column in `mat`. + /// This is the only method an implementer needs to define, all other + /// methods can be derived from this one. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `mat.height()`. + /// Treating each column of `mat` as the coefficients of a polynomial, compute the + /// evaluations of those polynomials on the subgroup `H`. + fn dft_batch(&self, mat: RowMajorMatrix) -> Self::Evaluations; + + /// Compute the "coset DFT" of `vec`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `vec.len()`. + /// Treating `vec` as coefficients of a polynomial, compute the evaluations + /// of that polynomial on the coset `shift * H`. + fn coset_dft(&self, vec: Vec, shift: F) -> Vec { + self.coset_dft_batch(RowMajorMatrix::new_col(vec), shift) + .to_row_major_matrix() + .values + } + + /// Compute the "coset DFT" of each column in `mat`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `mat.height()`. + /// Treating each column of `mat` as the coefficients of a polynomial, compute the + /// evaluations of those polynomials on the coset `shift * H`. + fn coset_dft_batch(&self, mut mat: RowMajorMatrix, shift: F) -> Self::Evaluations { + // Observe that + // y_i = \sum_j c_j (s g^i)^j + // = \sum_j (c_j s^j) (g^i)^j + // which has the structure of an ordinary DFT, except each coefficient `c_j` is first replaced + // by `c_j s^j`. + coset_shift_cols(&mut mat, shift); + self.dft_batch(mat) + } + + /// Compute the inverse DFT of `vec`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `vec.len()`. + /// Treating `vec` as the evaluations of a polynomial on `H`, compute the + /// coefficients of that polynomial. + fn idft(&self, vec: Vec) -> Vec { + self.idft_batch(RowMajorMatrix::new(vec, 1)).values + } + + /// Compute the inverse DFT of each column in `mat`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `mat.height()`. + /// Treating each column of `mat` as the evaluations of a polynomial on `H`, + /// compute the coefficients of those polynomials. + fn idft_batch(&self, mat: RowMajorMatrix) -> RowMajorMatrix { + let mut dft = self.dft_batch(mat).to_row_major_matrix(); + let h = dft.height(); + + divide_by_height(&mut dft); + + for row in 1..h / 2 { + swap_rows(&mut dft, row, h - row); + } + + dft + } + + /// Compute the "coset iDFT" of `vec`. This is the inverse operation of "coset DFT". + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `vec.len()`. + /// Treating `vec` as the evaluations of a polynomial on `shift * H`, + /// compute the coefficients of this polynomial. + fn coset_idft(&self, vec: Vec, shift: F) -> Vec { + self.coset_idft_batch(RowMajorMatrix::new(vec, 1), shift) + .values + } + + /// Compute the "coset iDFT" of each column in `mat`. This is the inverse operation + /// of "coset DFT". + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `mat.height()`. + /// Treating each column of `mat` as the evaluations of a polynomial on `shift * H`, + /// compute the coefficients of those polynomials. + fn coset_idft_batch(&self, mut mat: RowMajorMatrix, shift: F) -> RowMajorMatrix { + // Let `f(x)` denote the polynomial we want. Then, if we reinterpret the columns + // as being over the subgroup `H`, this is equivalent to switching our polynomial + // to `g(x) = f(sx)`. + // The output of the iDFT is the coefficients of `g` so to get the coefficients of + // `f` we need to scale the `i`'th coefficient by `s^{-i}`. + mat = self.idft_batch(mat); + coset_shift_cols(&mut mat, shift.inverse()); + mat + } + + /// Compute the low-degree extension of `vec` onto a larger subgroup. + /// + /// #### Mathematical Description + /// + /// Let `H, K` denote the unique multiplicative subgroups of order `vec.len()` + /// and `vec.len() << added_bits`, respectively. + /// Treating `vec` as the evaluations of a polynomial on the subgroup `H`, + /// compute the evaluations of that polynomial on the subgroup `K`. + fn lde(&self, vec: Vec, added_bits: usize) -> Vec { + self.lde_batch(RowMajorMatrix::new(vec, 1), added_bits) + .to_row_major_matrix() + .values + } + + /// Compute the low-degree extension of each column in `mat` onto a larger subgroup. + /// + /// #### Mathematical Description + /// + /// Let `H, K` denote the unique multiplicative subgroups of order `mat.height()` + /// and `mat.height() << added_bits`, respectively. + /// Treating each column of `mat` as the evaluations of a polynomial on the subgroup `H`, + /// compute the evaluations of those polynomials on the subgroup `K`. + fn lde_batch(&self, mat: RowMajorMatrix, added_bits: usize) -> Self::Evaluations { + let mut coeffs = self.idft_batch(mat); + coeffs + .values + .resize(coeffs.values.len() << added_bits, F::ZERO); + self.dft_batch(coeffs) + } + + /// Compute the low-degree extension of of `vec` onto a coset of a larger subgroup. + /// + /// #### Mathematical Description + /// + /// Let `H, K` denote the unique multiplicative subgroups of order `vec.len()` + /// and `vec.len() << added_bits`, respectively. + /// Treating `vec` as the evaluations of a polynomial on the subgroup `H`, + /// compute the evaluations of that polynomial on the coset `shift * K`. + /// + /// There is another way to interpret this transformation which gives a larger + /// use case. We can also view it as treating `vec` as the evaluations of a polynomial + /// over a coset `gH` and then computing the evaluations of that polynomial + /// on the coset `g'K` where `g' = g * shift`. + fn coset_lde(&self, vec: Vec, added_bits: usize, shift: F) -> Vec { + self.coset_lde_batch(RowMajorMatrix::new(vec, 1), added_bits, shift) + .to_row_major_matrix() + .values + } + + /// Compute the low-degree extension of each column in `mat` onto a coset of a larger subgroup. + /// + /// #### Mathematical Description + /// + /// Let `H, K` denote the unique multiplicative subgroups of order `mat.height()` + /// and `mat.height() << added_bits`, respectively. + /// Treating each column of `mat` as the evaluations of a polynomial on the subgroup `H`, + /// compute the evaluations of those polynomials on the coset `shift * K`. + /// + /// There is another way to interpret this transformation which gives a larger + /// use case. We can also view it as treating columns of `mat` as evaluations + /// over a coset `gH` and then computing the evaluations of those polynomials + /// on the coset `g'K` where `g' = g * shift`. + fn coset_lde_batch( + &self, + mat: RowMajorMatrix, + added_bits: usize, + shift: F, + ) -> Self::Evaluations { + // To briefly explain the additional interpretation, start with the evaluations of the polynomial + // `f(x)` over `gH`. If we reinterpret the evaluations as being over the subgroup `H`, this is equivalent to + // switching our polynomial to `f1(x) = f(g x)`. The output of the iDFT will be the coefficients of + // `f1`. Next, when we scale by shift, we are effectively switching to the polynomial + // `f2(x) = f1(shift * x) = f(shift * g x)`. Applying the DFT to this, we get the evaluations of `f2` over + // `K` which is the evaluations of `f1` over `shift * K` which is the evaluations of `f` over `g * shift * K`. + let mut coeffs = self.idft_batch(mat); + // PANICS: possible panic if the new resized length overflows + coeffs.values.resize( + coeffs + .values + .len() + .checked_shl(added_bits.try_into().unwrap()) + .unwrap(), + F::ZERO, + ); + self.coset_dft_batch(coeffs, shift) + } + + /// Compute the discrete Fourier transform (DFT) of `vec`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `vec.len()`. + /// Treating `vec` as coefficients of a polynomial, compute the evaluations + /// of that polynomial on the subgroup `H`. + fn dft_algebra + Clone + Send + Sync>(&self, vec: Vec) -> Vec { + self.dft_algebra_batch(RowMajorMatrix::new_col(vec)).values + } + + /// Compute the discrete Fourier transform (DFT) of each column in `mat`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `mat.height()`. + /// Treating each column of `mat` as the coefficients of a polynomial, compute the + /// evaluations of those polynomials on the subgroup `H`. + fn dft_algebra_batch + Clone + Send + Sync>( + &self, + mat: RowMajorMatrix, + ) -> RowMajorMatrix { + let init_width = mat.width(); + let base_mat = + RowMajorMatrix::new(V::flatten_to_base(mat.values), init_width * V::DIMENSION); + let base_dft_output = self.dft_batch(base_mat).to_row_major_matrix(); + RowMajorMatrix::new( + V::reconstitute_from_base(base_dft_output.values), + init_width, + ) + } + + /// Compute the "coset DFT" of `vec`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `vec.len()`. + /// Treating `vec` as coefficients of a polynomial, compute the evaluations + /// of that polynomial on the coset `shift * H`. + fn coset_dft_algebra + Clone + Send + Sync>( + &self, + vec: Vec, + shift: F, + ) -> Vec { + self.coset_dft_algebra_batch(RowMajorMatrix::new_col(vec), shift) + .to_row_major_matrix() + .values + } + + /// Compute the "coset DFT" of each column in `mat`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `mat.height()`. + /// Treating each column of `mat` as the coefficients of a polynomial, compute the + /// evaluations of those polynomials on the coset `shift * H`. + fn coset_dft_algebra_batch + Clone + Send + Sync>( + &self, + mat: RowMajorMatrix, + shift: F, + ) -> RowMajorMatrix { + let init_width = mat.width(); + let base_mat = + RowMajorMatrix::new(V::flatten_to_base(mat.values), init_width * V::DIMENSION); + let base_dft_output = self.coset_dft_batch(base_mat, shift).to_row_major_matrix(); + RowMajorMatrix::new( + V::reconstitute_from_base(base_dft_output.values), + init_width, + ) + } + + /// Compute the inverse DFT of `vec`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `vec.len()`. + /// Treating `vec` as the evaluations of a polynomial on `H`, compute the + /// coefficients of that polynomial. + fn idft_algebra + Clone + Send + Sync>(&self, vec: Vec) -> Vec { + self.idft_algebra_batch(RowMajorMatrix::new(vec, 1)).values + } + + /// Compute the inverse DFT of each column in `mat`. + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `mat.height()`. + /// Treating each column of `mat` as the evaluations of a polynomial on `H`, + /// compute the coefficients of those polynomials. + fn idft_algebra_batch + Clone + Send + Sync>( + &self, + mat: RowMajorMatrix, + ) -> RowMajorMatrix { + let init_width = mat.width(); + let base_mat = + RowMajorMatrix::new(V::flatten_to_base(mat.values), init_width * V::DIMENSION); + let base_dft_output = self.idft_batch(base_mat); + RowMajorMatrix::new( + V::reconstitute_from_base(base_dft_output.values), + init_width, + ) + } + + /// Compute the "coset iDFT" of `vec`. This is the inverse operation of "coset DFT". + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `vec.len()`. + /// Treating `vec` as the evaluations of a polynomial on `shift * H`, + /// compute the coefficients of this polynomial. + fn coset_idft_algebra + Clone + Send + Sync>( + &self, + vec: Vec, + shift: F, + ) -> Vec { + self.coset_idft_algebra_batch(RowMajorMatrix::new(vec, 1), shift) + .values + } + + /// Compute the "coset iDFT" of each column in `mat`. This is the inverse operation + /// of "coset DFT". + /// + /// #### Mathematical Description + /// + /// Let `H` denote the unique multiplicative subgroup of order `mat.height()`. + /// Treating each column of `mat` as the evaluations of a polynomial on `shift * H`, + /// compute the coefficients of those polynomials. + fn coset_idft_algebra_batch + Clone + Send + Sync>( + &self, + mat: RowMajorMatrix, + shift: F, + ) -> RowMajorMatrix { + let init_width = mat.width(); + let base_mat = + RowMajorMatrix::new(V::flatten_to_base(mat.values), init_width * V::DIMENSION); + let base_dft_output = self.coset_idft_batch(base_mat, shift); + RowMajorMatrix::new( + V::reconstitute_from_base(base_dft_output.values), + init_width, + ) + } + + /// Compute the low-degree extension of `vec` onto a larger subgroup. + /// + /// #### Mathematical Description + /// + /// Let `H, K` denote the unique multiplicative subgroups of order `vec.len()` + /// and `vec.len() << added_bits`, respectively. + /// Treating `vec` as the evaluations of a polynomial on the subgroup `H`, + /// compute the evaluations of that polynomial on the subgroup `K`. + fn lde_algebra + Clone + Send + Sync>( + &self, + vec: Vec, + added_bits: usize, + ) -> Vec { + self.lde_algebra_batch(RowMajorMatrix::new(vec, 1), added_bits) + .to_row_major_matrix() + .values + } + + /// Compute the low-degree extension of each column in `mat` onto a larger subgroup. + /// + /// #### Mathematical Description + /// + /// Let `H, K` denote the unique multiplicative subgroups of order `mat.height()` + /// and `mat.height() << added_bits`, respectively. + /// Treating each column of `mat` as the evaluations of a polynomial on the subgroup `H`, + /// compute the evaluations of those polynomials on the subgroup `K`. + fn lde_algebra_batch + Clone + Send + Sync>( + &self, + mat: RowMajorMatrix, + added_bits: usize, + ) -> RowMajorMatrix { + let init_width = mat.width(); + let base_mat = + RowMajorMatrix::new(V::flatten_to_base(mat.values), init_width * V::DIMENSION); + let base_dft_output = self.lde_batch(base_mat, added_bits).to_row_major_matrix(); + RowMajorMatrix::new( + V::reconstitute_from_base(base_dft_output.values), + init_width, + ) + } + + /// Compute the low-degree extension of of `vec` onto a coset of a larger subgroup. + /// + /// #### Mathematical Description + /// + /// Let `H, K` denote the unique multiplicative subgroups of order `vec.len()` + /// and `vec.len() << added_bits`, respectively. + /// Treating `vec` as the evaluations of a polynomial on the subgroup `H`, + /// compute the evaluations of that polynomial on the coset `shift * K`. + /// + /// There is another way to interpret this transformation which gives a larger + /// use case. We can also view it as treating `vec` as the evaluations of a polynomial + /// over a coset `gH` and then computing the evaluations of that polynomial + /// on the coset `g'K` where `g' = g * shift`. + fn coset_lde_algebra + Clone + Send + Sync>( + &self, + vec: Vec, + added_bits: usize, + shift: F, + ) -> Vec { + self.coset_lde_algebra_batch(RowMajorMatrix::new(vec, 1), added_bits, shift) + .to_row_major_matrix() + .values + } + + /// Compute the low-degree extension of each column in `mat` onto a coset of a larger subgroup. + /// + /// #### Mathematical Description + /// + /// Let `H, K` denote the unique multiplicative subgroups of order `mat.height()` + /// and `mat.height() << added_bits`, respectively. + /// Treating each column of `mat` as the evaluations of a polynomial on the subgroup `H`, + /// compute the evaluations of those polynomials on the coset `shift * K`. + /// + /// There is another way to interpret this transformation which gives a larger + /// use case. We can also view it as treating columns of `mat` as evaluations + /// over a coset `gH` and then computing the evaluations of those polynomials + /// on the coset `g'K` where `g' = g * shift`. + fn coset_lde_algebra_batch + Clone + Send + Sync>( + &self, + mat: RowMajorMatrix, + added_bits: usize, + shift: F, + ) -> RowMajorMatrix { + let init_width = mat.width(); + let base_mat = + RowMajorMatrix::new(V::flatten_to_base(mat.values), init_width * V::DIMENSION); + let base_dft_output = self + .coset_lde_batch(base_mat, added_bits, shift) + .to_row_major_matrix(); + RowMajorMatrix::new( + V::reconstitute_from_base(base_dft_output.values), + init_width, + ) + } +} diff --git a/CoqOfRust/plonky3/dft/src/traits.v b/CoqOfRust/plonky3/dft/src/traits.v new file mode 100644 index 000000000..69cdca2b4 --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/traits.v @@ -0,0 +1,3165 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module traits. + (* Trait *) + Module TwoAdicSubgroupDft. + Definition dft (F Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; vec ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new_col", + [], + [] + |), + [ M.read (| vec |) ] + |) + ] + |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_dft : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "dft" (dft F). + Definition coset_dft + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; vec; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + let shift := M.alloc (| shift |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "coset_dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new_col", + [], + [] + |), + [ M.read (| vec |) ] + |); + M.read (| shift |) + ] + |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_dft : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "coset_dft" (coset_dft F). + Definition coset_dft_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; mat; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let shift := M.alloc (| shift |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::util::coset_shift_cols", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |); + M.read (| shift |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "dft_batch", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); M.read (| mat |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_dft_batch : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "coset_dft_batch" (coset_dft_batch F). + Definition idft (F Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; vec ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_idft : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "idft" (idft F). + Definition idft_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.read (| + let~ dft : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| mat |) + ] + |) + ] + |) + |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, dft |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_dft::util::divide_by_height", + [], + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, dft |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 1); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| h |); Value.Integer IntegerKind.Usize 2 ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let row := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::swap_rows", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, dft |) + |) + |); + M.read (| row |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| h |); M.read (| row |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + dft + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_idft_batch : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "idft_batch" (idft_batch F). + Definition coset_idft + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; vec; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + let shift := M.alloc (| shift |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "coset_idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |); Value.Integer IntegerKind.Usize 1 ] + |); + M.read (| shift |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_idft : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "coset_idft" (coset_idft F). + Definition coset_idft_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; mat; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let shift := M.alloc (| shift |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + mat, + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| mat |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_dft::util::coset_shift_cols", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, shift |) ] + |) + ] + |) + |) in + mat + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_idft_batch : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_dft::traits::TwoAdicSubgroupDft" + "coset_idft_batch" + (coset_idft_batch F). + Definition lde (F Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; vec; added_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + let added_bits := M.alloc (| added_bits |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "lde_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |); Value.Integer IntegerKind.Usize 1 ] + |); + M.read (| added_bits |) + ] + |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_lde : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "lde" (lde F). + Definition lde_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; mat; added_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let added_bits := M.alloc (| added_bits |) in + M.read (| + let~ coeffs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| mat |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "resize", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + coeffs, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + coeffs, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.read (| added_bits |) + ] + |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| coeffs |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_lde_batch : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "lde_batch" (lde_batch F). + Definition coset_lde + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; vec; added_bits; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + let added_bits := M.alloc (| added_bits |) in + let shift := M.alloc (| shift |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "coset_lde_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |); Value.Integer IntegerKind.Usize 1 ] + |); + M.read (| added_bits |); + M.read (| shift |) + ] + |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_lde : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "coset_lde" (coset_lde F). + Definition coset_lde_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; mat; added_bits; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let added_bits := M.alloc (| added_bits |) in + let shift := M.alloc (| shift |) in + M.read (| + let~ coeffs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| mat |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "resize", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + coeffs, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_associated_function (| Ty.path "usize", "checked_shl", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + coeffs, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u32"; Ty.path "core::num::error::TryFromIntError" ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u32"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "usize", + [], + [ Ty.path "u32" ], + "try_into", + [], + [] + |), + [ M.read (| added_bits |) ] + |) + ] + |) + ] + |) + ] + |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "coset_dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| coeffs |); + M.read (| shift |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_lde_batch : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "coset_lde_batch" (coset_lde_batch F). + Definition dft_algebra + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; vec ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "dft_algebra_batch", + [], + [ V ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + "new_col", + [], + [] + |), + [ M.read (| vec |) ] + |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_dft_algebra : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "dft_algebra" (dft_algebra F). + Definition dft_algebra_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.read (| + let~ init_width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + [], + [ V ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ base_mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "flatten_to_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| init_width |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + |) in + let~ base_dft_output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| base_mat |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ V; Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "reconstitute_from_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + base_dft_output, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.read (| init_width |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_dft_algebra_batch : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_dft::traits::TwoAdicSubgroupDft" + "dft_algebra_batch" + (dft_algebra_batch F). + Definition coset_dft_algebra + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; vec; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + let shift := M.alloc (| shift |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + [], + [ V ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "coset_dft_algebra_batch", + [], + [ V ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + "new_col", + [], + [] + |), + [ M.read (| vec |) ] + |); + M.read (| shift |) + ] + |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_dft_algebra : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_dft::traits::TwoAdicSubgroupDft" + "coset_dft_algebra" + (coset_dft_algebra F). + Definition coset_dft_algebra_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; mat; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let shift := M.alloc (| shift |) in + M.read (| + let~ init_width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + [], + [ V ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ base_mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "flatten_to_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| init_width |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + |) in + let~ base_dft_output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "coset_dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| base_mat |); + M.read (| shift |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ V; Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "reconstitute_from_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + base_dft_output, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.read (| init_width |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_dft_algebra_batch : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_dft::traits::TwoAdicSubgroupDft" + "coset_dft_algebra_batch" + (coset_dft_algebra_batch F). + Definition idft_algebra + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; vec ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "idft_algebra_batch", + [], + [ V ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_idft_algebra : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "idft_algebra" (idft_algebra F). + Definition idft_algebra_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.read (| + let~ init_width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + [], + [ V ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ base_mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "flatten_to_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| init_width |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + |) in + let~ base_dft_output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| base_mat |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ V; Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "reconstitute_from_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + base_dft_output, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.read (| init_width |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_idft_algebra_batch : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_dft::traits::TwoAdicSubgroupDft" + "idft_algebra_batch" + (idft_algebra_batch F). + Definition coset_idft_algebra + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; vec; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + let shift := M.alloc (| shift |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "coset_idft_algebra_batch", + [], + [ V ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |); Value.Integer IntegerKind.Usize 1 ] + |); + M.read (| shift |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_idft_algebra : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_dft::traits::TwoAdicSubgroupDft" + "coset_idft_algebra" + (coset_idft_algebra F). + Definition coset_idft_algebra_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; mat; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let shift := M.alloc (| shift |) in + M.read (| + let~ init_width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + [], + [ V ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ base_mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "flatten_to_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| init_width |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + |) in + let~ base_dft_output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "coset_idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| base_mat |); + M.read (| shift |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ V; Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "reconstitute_from_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + base_dft_output, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.read (| init_width |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_idft_algebra_batch : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_dft::traits::TwoAdicSubgroupDft" + "coset_idft_algebra_batch" + (coset_idft_algebra_batch F). + Definition lde_algebra + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; vec; added_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + let added_bits := M.alloc (| added_bits |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + [], + [ V ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "lde_algebra_batch", + [], + [ V ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |); Value.Integer IntegerKind.Usize 1 ] + |); + M.read (| added_bits |) + ] + |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_lde_algebra : + forall (F : Ty.t), + M.IsProvidedMethod "p3_dft::traits::TwoAdicSubgroupDft" "lde_algebra" (lde_algebra F). + Definition lde_algebra_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; mat; added_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let added_bits := M.alloc (| added_bits |) in + M.read (| + let~ init_width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + [], + [ V ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ base_mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "flatten_to_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| init_width |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + |) in + let~ base_dft_output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "lde_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| base_mat |); + M.read (| added_bits |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ V; Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "reconstitute_from_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + base_dft_output, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.read (| init_width |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_lde_algebra_batch : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_dft::traits::TwoAdicSubgroupDft" + "lde_algebra_batch" + (lde_algebra_batch F). + Definition coset_lde_algebra + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; vec; added_bits; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let vec := M.alloc (| vec |) in + let added_bits := M.alloc (| added_bits |) in + let shift := M.alloc (| shift |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + [], + [ V ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "coset_lde_algebra_batch", + [], + [ V ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |); Value.Integer IntegerKind.Usize 1 ] + |); + M.read (| added_bits |); + M.read (| shift |) + ] + |) + ] + |) + |), + "p3_matrix::dense::DenseMatrix", + "values" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_lde_algebra : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_dft::traits::TwoAdicSubgroupDft" + "coset_lde_algebra" + (coset_lde_algebra F). + Definition coset_lde_algebra_batch + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ V ], [ self; mat; added_bits; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let added_bits := M.alloc (| added_bits |) in + let shift := M.alloc (| shift |) in + M.read (| + let~ init_width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ V; Ty.path "alloc::alloc::Global" ] + ], + [], + [ V ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ base_mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "flatten_to_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| init_width |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + |) in + let~ base_dft_output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Self + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Self, + [], + [ F ], + "coset_lde_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| base_mat |); + M.read (| added_bits |); + M.read (| shift |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ V; Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + V; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ V; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + V, + [], + [ F ], + "reconstitute_from_base", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + base_dft_output, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |); + M.read (| init_width |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_coset_lde_algebra_batch : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_dft::traits::TwoAdicSubgroupDft" + "coset_lde_algebra_batch" + (coset_lde_algebra_batch F). + End TwoAdicSubgroupDft. +End traits. diff --git a/CoqOfRust/plonky3/dft/src/util.rs b/CoqOfRust/plonky3/dft/src/util.rs new file mode 100644 index 000000000..247c7d3bb --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/util.rs @@ -0,0 +1,154 @@ +use core::borrow::BorrowMut; + +use p3_field::{Field, PrimeCharacteristicRing}; +use p3_matrix::Matrix; +use p3_matrix::dense::{DenseMatrix, DenseStorage, RowMajorMatrix}; +use p3_util::log2_strict_usize; +use tracing::instrument; + +/// Divide each coefficient of the given matrix by its height. +/// +/// # Panics +/// +/// Panics if the height of the matrix is not a power of two. +#[instrument(skip_all, fields(dims = %mat.dimensions()))] +pub fn divide_by_height + BorrowMut<[F]>>( + mat: &mut DenseMatrix, +) { + let h = mat.height(); + let log_h = log2_strict_usize(h); + // It's cheaper to use div_2exp_u64 as this usually avoids an inversion. + // It's also cheaper to work in the PrimeSubfield whenever possible. + let h_inv_subfield = F::PrimeSubfield::ONE.div_2exp_u64(log_h as u64); + let h_inv = F::from_prime_subfield(h_inv_subfield); + mat.scale(h_inv) +} + +/// Multiply each element of row `i` of `mat` by `shift**i`. +pub(crate) fn coset_shift_cols(mat: &mut RowMajorMatrix, shift: F) { + mat.rows_mut() + .zip(shift.powers()) + .for_each(|(row, weight)| { + row.iter_mut().for_each(|coeff| { + *coeff *= weight; + }) + }); +} + +#[cfg(test)] +mod tests { + use alloc::vec; + + use p3_baby_bear::BabyBear; + use p3_matrix::dense::RowMajorMatrix; + + use super::*; + + type F = BabyBear; + + #[test] + fn test_divide_by_height_2x2() { + // Matrix: + // [ 2, 4 ] + // [ 6, 8 ] + // + // height = 2 => divide each element by 2 + let mut mat = RowMajorMatrix::new( + vec![F::from_u8(2), F::from_u8(4), F::from_u8(6), F::from_u8(8)], + 2, + ); + + divide_by_height(&mut mat); + + // Compute: [2, 4, 6, 8] * 1/2 = [1, 2, 3, 4] + let expected = vec![F::from_u8(1), F::from_u8(2), F::from_u8(3), F::from_u8(4)]; + + assert_eq!(mat.values, expected); + } + + #[test] + fn test_divide_by_height_1x4() { + // Matrix: + // [ 10, 20, 30, 40 ] + // height = 1 => no division (1⁻¹ = 1), matrix should remain unchanged + let mut mat = RowMajorMatrix::new_row(vec![ + F::from_u8(10), + F::from_u8(20), + F::from_u8(30), + F::from_u8(40), + ]); + + divide_by_height(&mut mat); + + let expected = vec![ + F::from_u8(10), + F::from_u8(20), + F::from_u8(30), + F::from_u8(40), + ]; + + assert_eq!(mat.values, expected); + } + + #[test] + #[should_panic] + fn test_divide_by_height_non_power_of_two_height_should_panic() { + // Matrix of height = 3 is not a power of two → should panic + let mut mat = RowMajorMatrix::new(vec![F::from_u8(1), F::from_u8(2), F::from_u8(3)], 1); + + divide_by_height(&mut mat); + } + + #[test] + fn test_coset_shift_cols_3x2_shift_2() { + // Input matrix: + // [ 1, 2 ] + // [ 3, 4 ] + // [ 5, 6 ] + // + // shift = 2 + // Row 0: shift^0 = 1 → [1 * 1, 2 * 1] = [1, 2] + // Row 1: shift^1 = 2 → [3 * 2, 4 * 2] = [6, 8] + // Row 2: shift^2 = 4 → [5 * 4, 6 * 4] = [20, 24] + + let mut mat = RowMajorMatrix::new( + vec![ + F::from_u8(1), + F::from_u8(2), + F::from_u8(3), + F::from_u8(4), + F::from_u8(5), + F::from_u8(6), + ], + 2, + ); + + coset_shift_cols(&mut mat, F::from_u8(2)); + + let expected = vec![ + F::from_u8(1), + F::from_u8(2), + F::from_u8(6), + F::from_u8(8), + F::from_u8(20), + F::from_u8(24), + ]; + + assert_eq!(mat.values, expected); + } + + #[test] + fn test_coset_shift_cols_identity_shift() { + // shift = 1 → all weights = 1 → matrix should remain unchanged + let mut mat = RowMajorMatrix::new( + vec![F::from_u8(7), F::from_u8(8), F::from_u8(9), F::from_u8(10)], + 2, + ); + + coset_shift_cols(&mut mat, F::from_u8(1)); + + let expected = vec![F::from_u8(7), F::from_u8(8), F::from_u8(9), F::from_u8(10)]; + + assert_eq!(mat.values, expected); + } +} diff --git a/CoqOfRust/plonky3/dft/src/util.v b/CoqOfRust/plonky3/dft/src/util.v new file mode 100644 index 000000000..90d4938de --- /dev/null +++ b/CoqOfRust/plonky3/dft/src/util.v @@ -0,0 +1,1178 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module util. + (* #[instrument(skip_all, fields(dims = %mat.dimensions()))] *) + Definition divide_by_height (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; _ as S ], [ mat ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::util::divide_by_height::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::util::divide_by_height::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::util::divide_by_height::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + S + ], + [], + [ + F + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_dft::util::divide_by_height::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply (Ty.path "p3_matrix::dense::DenseMatrix") [] [ F; S ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ h_inv_subfield : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + M.get_trait_method (| + "p3_field::field::Field", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield" + |) + |); + M.cast (Ty.path "u64") (M.read (| log_h |)) + ] + |) + |) in + let~ h_inv : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ M.read (| h_inv_subfield |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_matrix::dense::DenseMatrix") [] [ F; S ], + "scale", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.read (| h_inv |) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_divide_by_height : + M.IsFunction.C "p3_dft::util::divide_by_height" divide_by_height. + Admitted. + Global Typeclasses Opaque divide_by_height. + + (* + pub(crate) fn coset_shift_cols(mat: &mut RowMajorMatrix, shift: F) { + mat.rows_mut() + .zip(shift.powers()) + .for_each(|(row, weight)| { + row.iter_mut().for_each(|coeff| { + *coeff *= weight; + }) + }); + } + *) + Definition coset_shift_cols (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ mat; shift ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let shift := M.alloc (| shift |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ Ty.associated_unknown; Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + F + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ Ty.associated_unknown; Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "rows_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, shift |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + F + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let row := M.copy (| γ0_0 |) in + let weight := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| row |) |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&mut") [] [ F ] ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let coeff := M.copy (| γ |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + F, + [], + [ F ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| coeff |) + |) + |); + M.read (| weight |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_coset_shift_cols : + M.IsFunction.C "p3_dft::util::coset_shift_cols" coset_shift_cols. + Admitted. + Global Typeclasses Opaque coset_shift_cols. +End util. diff --git a/CoqOfRust/plonky3/examples/src/airs.rs b/CoqOfRust/plonky3/examples/src/airs.rs new file mode 100644 index 000000000..8e214b203 --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/airs.rs @@ -0,0 +1,300 @@ +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_blake3_air::Blake3Air; +use p3_challenger::FieldChallenger; +use p3_commit::PolynomialSpace; +use p3_field::{ExtensionField, Field, PrimeField64}; +use p3_keccak_air::KeccakAir; +use p3_matrix::dense::RowMajorMatrix; +use p3_poseidon2::GenericPoseidon2LinearLayers; +use p3_poseidon2_air::{Poseidon2Air, VectorizedPoseidon2Air}; +use p3_uni_stark::{ + DebugConstraintBuilder, ProverConstraintFolder, StarkGenericConfig, SymbolicAirBuilder, + SymbolicExpression, VerifierConstraintFolder, +}; +use rand::distr::StandardUniform; +use rand::prelude::Distribution; + +/// An enum containing the three different AIR's. +/// +/// This implements `AIR` by passing to whatever the contained struct is. +pub enum ProofObjective< + F: Field, + LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> { + Blake3(Blake3Air), + Keccak(KeccakAir), + Poseidon2( + VectorizedPoseidon2Air< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + >, + ), +} + +/// An AIR for a hash function used for example proofs and benchmarking. +/// +/// A key feature is the ability to randomly generate a trace which proves +/// the output of some number of hashes using a given hash function. +pub trait ExampleHashAir: + BaseAir + + for<'a> Air> + + Air> + + for<'a> Air> + + for<'a> Air> +{ + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution; +} + +impl< + F: Field, + LinearLayers: Sync, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> BaseAir + for ProofObjective< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > +{ + #[inline] + fn width(&self) -> usize { + match self { + Self::Blake3(b3_air) => >::width(b3_air), + Self::Poseidon2(p2_air) => p2_air.width(), + Self::Keccak(k_air) => >::width(k_air), + } + } +} + +impl< + AB: AirBuilder, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> Air + for ProofObjective< + AB::F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > +{ + #[inline] + fn eval(&self, builder: &mut AB) { + match self { + Self::Blake3(b3_air) => b3_air.eval(builder), + Self::Poseidon2(p2_air) => p2_air.eval(builder), + Self::Keccak(k_air) => k_air.eval(builder), + } + } +} + +impl< + F: PrimeField64, + Domain: PolynomialSpace, + EF: ExtensionField, + Challenger: FieldChallenger, + Pcs: p3_commit::Pcs, + SC: StarkGenericConfig, + LinearLayers: GenericPoseidon2LinearLayers + + GenericPoseidon2LinearLayers, WIDTH> + + GenericPoseidon2LinearLayers<::Packing, WIDTH> + + GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> ExampleHashAir + for ProofObjective< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > +{ + #[inline] + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution, + { + match self { + Self::Blake3(b3_air) => b3_air.generate_trace_rows(num_hashes, extra_capacity_bits), + Self::Poseidon2(p2_air) => { + p2_air.generate_vectorized_trace_rows(num_hashes, extra_capacity_bits) + } + Self::Keccak(k_air) => k_air.generate_trace_rows(num_hashes, extra_capacity_bits), + } + } +} + +impl< + F: PrimeField64, + Domain: PolynomialSpace, + EF: ExtensionField, + Challenger: FieldChallenger, + Pcs: p3_commit::Pcs, + SC: StarkGenericConfig, +> ExampleHashAir for Blake3Air +{ + #[inline] + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution, + { + self.generate_trace_rows(num_hashes, extra_capacity_bits) + } +} + +impl< + F: PrimeField64, + Domain: PolynomialSpace, + EF: ExtensionField, + Challenger: FieldChallenger, + Pcs: p3_commit::Pcs, + SC: StarkGenericConfig, +> ExampleHashAir for KeccakAir +{ + #[inline] + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution, + { + self.generate_trace_rows(num_hashes, extra_capacity_bits) + } +} + +impl< + F: PrimeField64, + Domain: PolynomialSpace, + EF: ExtensionField, + Challenger: FieldChallenger, + Pcs: p3_commit::Pcs, + SC: StarkGenericConfig, + LinearLayers: GenericPoseidon2LinearLayers + + GenericPoseidon2LinearLayers, WIDTH> + + GenericPoseidon2LinearLayers<::Packing, WIDTH> + + GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> ExampleHashAir + for VectorizedPoseidon2Air< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > +{ + #[inline] + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution, + { + self.generate_vectorized_trace_rows(num_hashes, extra_capacity_bits) + } +} + +impl< + F: PrimeField64, + Domain: PolynomialSpace, + EF: ExtensionField, + Challenger: FieldChallenger, + Pcs: p3_commit::Pcs, + SC: StarkGenericConfig, + LinearLayers: GenericPoseidon2LinearLayers + + GenericPoseidon2LinearLayers, WIDTH> + + GenericPoseidon2LinearLayers<::Packing, WIDTH> + + GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +> ExampleHashAir + for Poseidon2Air< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + > +{ + #[inline] + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution, + { + self.generate_trace_rows(num_hashes, extra_capacity_bits) + } +} diff --git a/CoqOfRust/plonky3/examples/src/airs.v b/CoqOfRust/plonky3/examples/src/airs.v new file mode 100644 index 000000000..cb895ba3b --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/airs.v @@ -0,0 +1,989 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module airs. + (* + Enum ProofObjective + { + const_params := + [ "WIDTH"; "SBOX_DEGREE"; "SBOX_REGISTERS"; "HALF_FULL_ROUNDS"; "PARTIAL_ROUNDS"; "VECTOR_LEN" + ]; + ty_params := [ "F"; "LinearLayers" ]; + variants := + [ + { + name := "Blake3"; + item := StructTuple [ Ty.path "p3_blake3_air::air::Blake3Air" ]; + }; + { + name := "Keccak"; + item := StructTuple [ Ty.path "p3_keccak_air::air::KeccakAir" ]; + }; + { + name := "Poseidon2"; + item := + StructTuple + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN + ] + [ F; LinearLayers ] + ]; + } + ]; + } + *) + + Axiom IsDiscriminant_ProofObjective_Blake3 : + M.IsDiscriminant "p3_examples::airs::ProofObjective::Blake3" 0. + Axiom IsDiscriminant_ProofObjective_Keccak : + M.IsDiscriminant "p3_examples::airs::ProofObjective::Keccak" 1. + Axiom IsDiscriminant_ProofObjective_Poseidon2 : + M.IsDiscriminant "p3_examples::airs::ProofObjective::Poseidon2" 2. + + (* Trait *) + (* Empty module 'ExampleHashAir' *) + + Module Impl_p3_air_air_BaseAir_where_p3_field_field_Field_F_where_core_marker_Sync_LinearLayers_F_for_p3_examples_airs_ProofObjective_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_examples::airs::ProofObjective") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ] + [ F; LinearLayers ]. + + (* + fn width(&self) -> usize { + match self { + Self::Blake3(b3_air) => >::width(b3_air), + Self::Poseidon2(p2_air) => p2_air.width(), + Self::Keccak(k_air) => >::width(k_air), + } + } + *) + Definition width + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::airs::ProofObjective::Blake3", + 0 + |) in + let b3_air := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_air::air::BaseAir", + Ty.path "p3_blake3_air::air::Blake3Air", + [], + [ F ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| b3_air |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::airs::ProofObjective::Poseidon2", + 0 + |) in + let p2_air := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_air::air::BaseAir", + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ F; LinearLayers ], + [], + [ F ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| p2_air |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::airs::ProofObjective::Keccak", + 0 + |) in + let k_air := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_air::air::BaseAir", + Ty.path "p3_keccak_air::air::KeccakAir", + [], + [ F ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| k_air |) |) |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t), + M.IsTraitInstance + "p3_air::air::BaseAir" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers) + (* Instance *) + [ + ("width", + InstanceField.Method + (width + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers)) + ]. + End Impl_p3_air_air_BaseAir_where_p3_field_field_Field_F_where_core_marker_Sync_LinearLayers_F_for_p3_examples_airs_ProofObjective_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_F_LinearLayers. + + Module Impl_p3_air_air_Air_where_p3_air_air_AirBuilder_AB_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_air_air_AirBuilder___AB_Expr_AB_for_p3_examples_airs_ProofObjective_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_associated_in_trait_p3_air_air_AirBuilder___AB_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (AB LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_examples::airs::ProofObjective") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F"; LinearLayers ]. + + (* + fn eval(&self, builder: &mut AB) { + match self { + Self::Blake3(b3_air) => b3_air.eval(builder), + Self::Poseidon2(p2_air) => p2_air.eval(builder), + Self::Keccak(k_air) => k_air.eval(builder), + } + } + *) + Definition eval + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (AB LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + AB + LinearLayers in + match ε, τ, α with + | [], [], [ self; builder ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let builder := M.alloc (| builder |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::airs::ProofObjective::Blake3", + 0 + |) in + let b3_air := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::Air", + Ty.path "p3_blake3_air::air::Blake3Air", + [], + [ AB ], + "eval", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| b3_air |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::airs::ProofObjective::Poseidon2", + 0 + |) in + let p2_air := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::Air", + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F"; + LinearLayers + ], + [], + [ AB ], + "eval", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| p2_air |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::airs::ProofObjective::Keccak", + 0 + |) in + let k_air := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::Air", + Ty.path "p3_keccak_air::air::KeccakAir", + [], + [ AB ], + "eval", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| k_air |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (AB LinearLayers : Ty.t), + M.IsTraitInstance + "p3_air::air::Air" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ AB ] + (Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + AB + LinearLayers) + (* Instance *) + [ + ("eval", + InstanceField.Method + (eval + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + AB + LinearLayers)) + ]. + End Impl_p3_air_air_Air_where_p3_air_air_AirBuilder_AB_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_air_air_AirBuilder___AB_Expr_AB_for_p3_examples_airs_ProofObjective_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_associated_in_trait_p3_air_air_AirBuilder___AB_F_LinearLayers. + + Module Impl_p3_examples_airs_ExampleHashAir_where_p3_field_field_PrimeField64_F_where_p3_commit_domain_PolynomialSpace_Domain_where_p3_field_field_ExtensionField_EF_F_where_p3_challenger_FieldChallenger_Challenger_F_where_p3_commit_pcs_Pcs_Pcs_EF_Challenger_where_p3_uni_stark_config_StarkGenericConfig_SC_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_p3_uni_stark_symbolic_expression_SymbolicExpression_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_field_field_Field___F_Packing_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_EF_F_SC_for_p3_examples_airs_ProofObjective_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F Domain EF Challenger Pcs SC LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_examples::airs::ProofObjective") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ] + [ F; LinearLayers ]. + + (* + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution, + { + match self { + Self::Blake3(b3_air) => b3_air.generate_trace_rows(num_hashes, extra_capacity_bits), + Self::Poseidon2(p2_air) => { + p2_air.generate_vectorized_trace_rows(num_hashes, extra_capacity_bits) + } + Self::Keccak(k_air) => k_air.generate_trace_rows(num_hashes, extra_capacity_bits), + } + } + *) + Definition generate_trace_rows + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F Domain EF Challenger Pcs SC LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + Domain + EF + Challenger + Pcs + SC + LinearLayers in + match ε, τ, α with + | [], [], [ self; num_hashes; extra_capacity_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_hashes := M.alloc (| num_hashes |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::airs::ProofObjective::Blake3", + 0 + |) in + let b3_air := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "generate_trace_rows", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| b3_air |) |) |); + M.read (| num_hashes |); + M.read (| extra_capacity_bits |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::airs::ProofObjective::Poseidon2", + 0 + |) in + let p2_air := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ F; LinearLayers ], + "generate_vectorized_trace_rows", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| p2_air |) |) |); + M.read (| num_hashes |); + M.read (| extra_capacity_bits |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::airs::ProofObjective::Keccak", + 0 + |) in + let k_air := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.path "p3_keccak_air::air::KeccakAir", + "generate_trace_rows", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| k_air |) |) |); + M.read (| num_hashes |); + M.read (| extra_capacity_bits |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F Domain EF Challenger Pcs SC LinearLayers : Ty.t), + M.IsTraitInstance + "p3_examples::airs::ExampleHashAir" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F; SC ] + (Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + Domain + EF + Challenger + Pcs + SC + LinearLayers) + (* Instance *) + [ + ("generate_trace_rows", + InstanceField.Method + (generate_trace_rows + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + Domain + EF + Challenger + Pcs + SC + LinearLayers)) + ]. + End Impl_p3_examples_airs_ExampleHashAir_where_p3_field_field_PrimeField64_F_where_p3_commit_domain_PolynomialSpace_Domain_where_p3_field_field_ExtensionField_EF_F_where_p3_challenger_FieldChallenger_Challenger_F_where_p3_commit_pcs_Pcs_Pcs_EF_Challenger_where_p3_uni_stark_config_StarkGenericConfig_SC_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_p3_uni_stark_symbolic_expression_SymbolicExpression_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_field_field_Field___F_Packing_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_EF_F_SC_for_p3_examples_airs_ProofObjective_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_F_LinearLayers. + + Module Impl_p3_examples_airs_ExampleHashAir_where_p3_field_field_PrimeField64_F_where_p3_commit_domain_PolynomialSpace_Domain_where_p3_field_field_ExtensionField_EF_F_where_p3_challenger_FieldChallenger_Challenger_F_where_p3_commit_pcs_Pcs_Pcs_EF_Challenger_where_p3_uni_stark_config_StarkGenericConfig_SC_F_SC_for_p3_blake3_air_air_Blake3Air. + Definition Self (F Domain EF Challenger Pcs SC : Ty.t) : Ty.t := + Ty.path "p3_blake3_air::air::Blake3Air". + + (* + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution, + { + self.generate_trace_rows(num_hashes, extra_capacity_bits) + } + *) + Definition generate_trace_rows + (F Domain EF Challenger Pcs SC : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F Domain EF Challenger Pcs SC in + match ε, τ, α with + | [], [], [ self; num_hashes; extra_capacity_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_hashes := M.alloc (| num_hashes |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ], + M.get_associated_function (| + Ty.path "p3_blake3_air::air::Blake3Air", + "generate_trace_rows", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| num_hashes |); + M.read (| extra_capacity_bits |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Domain EF Challenger Pcs SC : Ty.t), + M.IsTraitInstance + "p3_examples::airs::ExampleHashAir" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F; SC ] + (Self F Domain EF Challenger Pcs SC) + (* Instance *) + [ + ("generate_trace_rows", + InstanceField.Method (generate_trace_rows F Domain EF Challenger Pcs SC)) + ]. + End Impl_p3_examples_airs_ExampleHashAir_where_p3_field_field_PrimeField64_F_where_p3_commit_domain_PolynomialSpace_Domain_where_p3_field_field_ExtensionField_EF_F_where_p3_challenger_FieldChallenger_Challenger_F_where_p3_commit_pcs_Pcs_Pcs_EF_Challenger_where_p3_uni_stark_config_StarkGenericConfig_SC_F_SC_for_p3_blake3_air_air_Blake3Air. + + Module Impl_p3_examples_airs_ExampleHashAir_where_p3_field_field_PrimeField64_F_where_p3_commit_domain_PolynomialSpace_Domain_where_p3_field_field_ExtensionField_EF_F_where_p3_challenger_FieldChallenger_Challenger_F_where_p3_commit_pcs_Pcs_Pcs_EF_Challenger_where_p3_uni_stark_config_StarkGenericConfig_SC_F_SC_for_p3_keccak_air_air_KeccakAir. + Definition Self (F Domain EF Challenger Pcs SC : Ty.t) : Ty.t := + Ty.path "p3_keccak_air::air::KeccakAir". + + (* + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution, + { + self.generate_trace_rows(num_hashes, extra_capacity_bits) + } + *) + Definition generate_trace_rows + (F Domain EF Challenger Pcs SC : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F Domain EF Challenger Pcs SC in + match ε, τ, α with + | [], [], [ self; num_hashes; extra_capacity_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_hashes := M.alloc (| num_hashes |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ], + M.get_associated_function (| + Ty.path "p3_keccak_air::air::KeccakAir", + "generate_trace_rows", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| num_hashes |); + M.read (| extra_capacity_bits |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Domain EF Challenger Pcs SC : Ty.t), + M.IsTraitInstance + "p3_examples::airs::ExampleHashAir" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F; SC ] + (Self F Domain EF Challenger Pcs SC) + (* Instance *) + [ + ("generate_trace_rows", + InstanceField.Method (generate_trace_rows F Domain EF Challenger Pcs SC)) + ]. + End Impl_p3_examples_airs_ExampleHashAir_where_p3_field_field_PrimeField64_F_where_p3_commit_domain_PolynomialSpace_Domain_where_p3_field_field_ExtensionField_EF_F_where_p3_challenger_FieldChallenger_Challenger_F_where_p3_commit_pcs_Pcs_Pcs_EF_Challenger_where_p3_uni_stark_config_StarkGenericConfig_SC_F_SC_for_p3_keccak_air_air_KeccakAir. + + Module Impl_p3_examples_airs_ExampleHashAir_where_p3_field_field_PrimeField64_F_where_p3_commit_domain_PolynomialSpace_Domain_where_p3_field_field_ExtensionField_EF_F_where_p3_challenger_FieldChallenger_Challenger_F_where_p3_commit_pcs_Pcs_Pcs_EF_Challenger_where_p3_uni_stark_config_StarkGenericConfig_SC_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_p3_uni_stark_symbolic_expression_SymbolicExpression_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_field_field_Field___F_Packing_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_EF_F_SC_for_p3_poseidon2_air_vectorized_VectorizedPoseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F Domain EF Challenger Pcs SC LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ] + [ F; LinearLayers ]. + + (* + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution, + { + self.generate_vectorized_trace_rows(num_hashes, extra_capacity_bits) + } + *) + Definition generate_trace_rows + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F Domain EF Challenger Pcs SC LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + Domain + EF + Challenger + Pcs + SC + LinearLayers in + match ε, τ, α with + | [], [], [ self; num_hashes; extra_capacity_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_hashes := M.alloc (| num_hashes |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ] + [ F; LinearLayers ], + "generate_vectorized_trace_rows", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| num_hashes |); + M.read (| extra_capacity_bits |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F Domain EF Challenger Pcs SC LinearLayers : Ty.t), + M.IsTraitInstance + "p3_examples::airs::ExampleHashAir" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F; SC ] + (Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + Domain + EF + Challenger + Pcs + SC + LinearLayers) + (* Instance *) + [ + ("generate_trace_rows", + InstanceField.Method + (generate_trace_rows + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + Domain + EF + Challenger + Pcs + SC + LinearLayers)) + ]. + End Impl_p3_examples_airs_ExampleHashAir_where_p3_field_field_PrimeField64_F_where_p3_commit_domain_PolynomialSpace_Domain_where_p3_field_field_ExtensionField_EF_F_where_p3_challenger_FieldChallenger_Challenger_F_where_p3_commit_pcs_Pcs_Pcs_EF_Challenger_where_p3_uni_stark_config_StarkGenericConfig_SC_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_p3_uni_stark_symbolic_expression_SymbolicExpression_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_field_field_Field___F_Packing_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_EF_F_SC_for_p3_poseidon2_air_vectorized_VectorizedPoseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_F_LinearLayers. + + Module Impl_p3_examples_airs_ExampleHashAir_where_p3_field_field_PrimeField64_F_where_p3_commit_domain_PolynomialSpace_Domain_where_p3_field_field_ExtensionField_EF_F_where_p3_challenger_FieldChallenger_Challenger_F_where_p3_commit_pcs_Pcs_Pcs_EF_Challenger_where_p3_uni_stark_config_StarkGenericConfig_SC_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_p3_uni_stark_symbolic_expression_SymbolicExpression_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_field_field_Field___F_Packing_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_EF_F_SC_for_p3_poseidon2_air_air_Poseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F Domain EF Challenger Pcs SC LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::air::Poseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F; LinearLayers ]. + + (* + fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + StandardUniform: Distribution, + { + self.generate_trace_rows(num_hashes, extra_capacity_bits) + } + *) + Definition generate_trace_rows + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F Domain EF Challenger Pcs SC LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + F + Domain + EF + Challenger + Pcs + SC + LinearLayers in + match ε, τ, α with + | [], [], [ self; num_hashes; extra_capacity_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_hashes := M.alloc (| num_hashes |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2_air::air::Poseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F; LinearLayers ], + "generate_trace_rows", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| num_hashes |); + M.read (| extra_capacity_bits |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F Domain EF Challenger Pcs SC LinearLayers : Ty.t), + M.IsTraitInstance + "p3_examples::airs::ExampleHashAir" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F; SC ] + (Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + F + Domain + EF + Challenger + Pcs + SC + LinearLayers) + (* Instance *) + [ + ("generate_trace_rows", + InstanceField.Method + (generate_trace_rows + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + F + Domain + EF + Challenger + Pcs + SC + LinearLayers)) + ]. + End Impl_p3_examples_airs_ExampleHashAir_where_p3_field_field_PrimeField64_F_where_p3_commit_domain_PolynomialSpace_Domain_where_p3_field_field_ExtensionField_EF_F_where_p3_challenger_FieldChallenger_Challenger_F_where_p3_commit_pcs_Pcs_Pcs_EF_Challenger_where_p3_uni_stark_config_StarkGenericConfig_SC_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_p3_uni_stark_symbolic_expression_SymbolicExpression_F_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_field_field_Field___F_Packing_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_EF_F_SC_for_p3_poseidon2_air_air_Poseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F_LinearLayers. +End airs. diff --git a/CoqOfRust/plonky3/examples/src/dfts.rs b/CoqOfRust/plonky3/examples/src/dfts.rs new file mode 100644 index 000000000..75e8eb3b8 --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/dfts.rs @@ -0,0 +1,60 @@ +use p3_dft::{Radix2DitParallel, TwoAdicSubgroupDft}; +use p3_field::TwoAdicField; +use p3_matrix::bitrev::BitReversedMatrixView; +use p3_matrix::dense::RowMajorMatrix; +use p3_monty_31::dft::RecursiveDft; + +/// An enum containing several different options for discrete Fourier Transform. +/// +/// This implements `TwoAdicSubgroupDft` by passing to whatever the contained struct is. +#[derive(Clone, Debug)] +pub enum DftChoice { + Recursive(RecursiveDft), + Parallel(Radix2DitParallel), +} + +impl Default for DftChoice { + // We have to fix a default for the `TwoAdicSubgroupDft` trait. We choose `Radix2DitParallel` as one of the features + // of `RecursiveDft` is that it works better when initialized with knowledge of the expected size. + fn default() -> Self { + Self::Parallel(Radix2DitParallel::::default()) + } +} + +impl TwoAdicSubgroupDft for DftChoice +where + RecursiveDft: TwoAdicSubgroupDft>>, + Radix2DitParallel: + TwoAdicSubgroupDft>>, +{ + type Evaluations = BitReversedMatrixView>; + + #[inline] + fn dft_batch(&self, mat: RowMajorMatrix) -> Self::Evaluations { + match self { + Self::Recursive(inner_dft) => inner_dft.dft_batch(mat), + Self::Parallel(inner_dft) => inner_dft.dft_batch(mat), + } + } + + #[inline] + fn coset_dft_batch(&self, mat: RowMajorMatrix, shift: F) -> Self::Evaluations { + match self { + Self::Recursive(inner_dft) => inner_dft.coset_dft_batch(mat, shift), + Self::Parallel(inner_dft) => inner_dft.coset_dft_batch(mat, shift), + } + } + + #[inline] + fn coset_lde_batch( + &self, + mat: RowMajorMatrix, + added_bits: usize, + shift: F, + ) -> Self::Evaluations { + match self { + Self::Recursive(inner_dft) => inner_dft.coset_lde_batch(mat, added_bits, shift), + Self::Parallel(inner_dft) => inner_dft.coset_lde_batch(mat, added_bits, shift), + } + } +} diff --git a/CoqOfRust/plonky3/examples/src/dfts.v b/CoqOfRust/plonky3/examples/src/dfts.v new file mode 100644 index 000000000..1533692ce --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/dfts.v @@ -0,0 +1,740 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module dfts. + (* + Enum DftChoice + { + const_params := []; + ty_params := [ "F" ]; + variants := + [ + { + name := "Recursive"; + item := StructTuple [ Ty.apply (Ty.path "p3_monty_31::dft::RecursiveDft") [] [ F ] ]; + }; + { + name := "Parallel"; + item := + StructTuple + [ Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") [] [ F ] ]; + } + ]; + } + *) + + Axiom IsDiscriminant_DftChoice_Recursive : + M.IsDiscriminant "p3_examples::dfts::DftChoice::Recursive" 0. + Axiom IsDiscriminant_DftChoice_Parallel : + M.IsDiscriminant "p3_examples::dfts::DftChoice::Parallel" 1. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_examples_dfts_DftChoice_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_examples::dfts::DftChoice") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_examples::dfts::DftChoice") [] [ F ] ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::dfts::DftChoice::Recursive", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "p3_examples::dfts::DftChoice::Recursive" + [ + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::dft::RecursiveDft") [] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "p3_monty_31::dft::RecursiveDft") [] [ F ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::dfts::DftChoice::Parallel", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "p3_examples::dfts::DftChoice::Parallel" + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") + [] + [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") + [] + [ F ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |) ] + |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_examples_dfts_DftChoice_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_examples_dfts_DftChoice_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_examples::dfts::DftChoice") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::dfts::DftChoice::Recursive", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Recursive" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::dfts::DftChoice::Parallel", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Parallel" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_examples_dfts_DftChoice_F. + + Module Impl_core_default_Default_where_core_default_Default_F_for_p3_examples_dfts_DftChoice_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_examples::dfts::DftChoice") [] [ F ]. + + (* + fn default() -> Self { + Self::Parallel(Radix2DitParallel::::default()) + } + *) + Definition default (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "p3_examples::dfts::DftChoice::Parallel" + [ + M.call_closure (| + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") [] [ F ], + M.get_trait_method (| + "core::default::Default", + Ty.apply (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") [] [ F ], + [], + [], + "default", + [], + [] + |), + [] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("default", InstanceField.Method (default F)) ]. + End Impl_core_default_Default_where_core_default_Default_F_for_p3_examples_dfts_DftChoice_F. + + Module Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_field_field_TwoAdicField_F_where_p3_dft_traits_TwoAdicSubgroupDft_p3_monty_31_dft_RecursiveDft_F_F_where_p3_dft_traits_TwoAdicSubgroupDft_p3_dft_radix_2_dit_parallel_Radix2DitParallel_F_F_F_for_p3_examples_dfts_DftChoice_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_examples::dfts::DftChoice") [] [ F ]. + + (* type Evaluations = BitReversedMatrixView>; *) + Definition _Evaluations (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + ]. + + (* + fn dft_batch(&self, mat: RowMajorMatrix) -> Self::Evaluations { + match self { + Self::Recursive(inner_dft) => inner_dft.dft_batch(mat), + Self::Parallel(inner_dft) => inner_dft.dft_batch(mat), + } + } + *) + Definition dft_batch (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::dfts::DftChoice::Recursive", + 0 + |) in + let inner_dft := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.apply (Ty.path "p3_monty_31::dft::RecursiveDft") [] [ F ], + [], + [ F ], + "dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| inner_dft |) |) |); + M.read (| mat |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::dfts::DftChoice::Parallel", + 0 + |) in + let inner_dft := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") + [] + [ F ], + [], + [ F ], + "dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| inner_dft |) |) |); + M.read (| mat |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn coset_dft_batch(&self, mat: RowMajorMatrix, shift: F) -> Self::Evaluations { + match self { + Self::Recursive(inner_dft) => inner_dft.coset_dft_batch(mat, shift), + Self::Parallel(inner_dft) => inner_dft.coset_dft_batch(mat, shift), + } + } + *) + Definition coset_dft_batch + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let shift := M.alloc (| shift |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::dfts::DftChoice::Recursive", + 0 + |) in + let inner_dft := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.apply (Ty.path "p3_monty_31::dft::RecursiveDft") [] [ F ], + [], + [ F ], + "coset_dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| inner_dft |) |) |); + M.read (| mat |); + M.read (| shift |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::dfts::DftChoice::Parallel", + 0 + |) in + let inner_dft := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") + [] + [ F ], + [], + [ F ], + "coset_dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| inner_dft |) |) |); + M.read (| mat |); + M.read (| shift |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn coset_lde_batch( + &self, + mat: RowMajorMatrix, + added_bits: usize, + shift: F, + ) -> Self::Evaluations { + match self { + Self::Recursive(inner_dft) => inner_dft.coset_lde_batch(mat, added_bits, shift), + Self::Parallel(inner_dft) => inner_dft.coset_lde_batch(mat, added_bits, shift), + } + } + *) + Definition coset_lde_batch + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; mat; added_bits; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let added_bits := M.alloc (| added_bits |) in + let shift := M.alloc (| shift |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::dfts::DftChoice::Recursive", + 0 + |) in + let inner_dft := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.apply (Ty.path "p3_monty_31::dft::RecursiveDft") [] [ F ], + [], + [ F ], + "coset_lde_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| inner_dft |) |) |); + M.read (| mat |); + M.read (| added_bits |); + M.read (| shift |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_examples::dfts::DftChoice::Parallel", + 0 + |) in + let inner_dft := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.apply + (Ty.path "p3_dft::radix_2_dit_parallel::Radix2DitParallel") + [] + [ F ], + [], + [ F ], + "coset_lde_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| inner_dft |) |) |); + M.read (| mat |); + M.read (| added_bits |); + M.read (| shift |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_dft::traits::TwoAdicSubgroupDft" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) + [ + ("Evaluations", InstanceField.Ty (_Evaluations F)); + ("dft_batch", InstanceField.Method (dft_batch F)); + ("coset_dft_batch", InstanceField.Method (coset_dft_batch F)); + ("coset_lde_batch", InstanceField.Method (coset_lde_batch F)) + ]. + End Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_field_field_TwoAdicField_F_where_p3_dft_traits_TwoAdicSubgroupDft_p3_monty_31_dft_RecursiveDft_F_F_where_p3_dft_traits_TwoAdicSubgroupDft_p3_dft_radix_2_dit_parallel_Radix2DitParallel_F_F_F_for_p3_examples_dfts_DftChoice_F. +End dfts. diff --git a/CoqOfRust/plonky3/examples/src/lib.rs b/CoqOfRust/plonky3/examples/src/lib.rs new file mode 100644 index 000000000..03425ebef --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/lib.rs @@ -0,0 +1,8 @@ +pub mod airs; +pub mod dfts; +pub mod parsers; +pub mod proofs; +pub mod types; + +#[cfg(test)] +mod tests; diff --git a/CoqOfRust/plonky3/examples/src/parsers.rs b/CoqOfRust/plonky3/examples/src/parsers.rs new file mode 100644 index 000000000..9c50c2428 --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/parsers.rs @@ -0,0 +1,146 @@ +//! This file contains a collection of Enums which allow a nice command line interface. +//! +//! For each enum, we allow the user to specify the enum either using the whole string or any substring +//! which fully determines the choice. We additionally add a few extra aliases if other natural ones exist. +//! +//! For most of the enums, this allows the user to + +use clap::ValueEnum; +use clap::builder::PossibleValue; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum FieldOptions { + BabyBear, + KoalaBear, + Mersenne31, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum ProofOptions { + Blake3Permutations, + KeccakFPermutations, + Poseidon2Permutations, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum DftOptions { + None, + Radix2DitParallel, + RecursiveDft, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum MerkleHashOptions { + KeccakF, + Poseidon2, +} + +/// Produce a collection of PossibleValue's for an Enum variant. +/// +/// We allow any prefix of the full name which uniquely determines the variant. +/// We additionally allow the user to specify a collection of aliases which are +/// not prefixes. For each alias, we also allow any unique prefix of that alias. +/// +/// For example, for the `KoalaBear` variant of `FieldOptions`, running +/// `get_aliases("koala-bear", 1, vec![("koalabear", 6), ("kb", 2)])` produces the following set of +/// allowed strings: +/// +/// `koala-bear, k, ko, koa, koal, koala, koala-, koala-b, koala-be, koala-bea, koalab, koalabe, koalabea, koalabear, kb` +fn get_aliases( + base: &'static str, + min_unique_base_prefix: usize, + alias: Option>, +) -> PossibleValue { + match alias { + None => PossibleValue::new(base) + .aliases((min_unique_base_prefix..base.len()).map(|i| &base[..i])), + Some(vec) => PossibleValue::new(base).aliases( + (min_unique_base_prefix..base.len()) + .map(|i| &base[..i]) + .chain(vec.into_iter().flat_map(|(alias, min_unique)| { + (min_unique..alias.len() + 1).map(|i| &alias[..i]) + })), + ), + } +} + +impl ValueEnum for FieldOptions { + fn value_variants<'a>() -> &'a [Self] { + &[Self::BabyBear, Self::KoalaBear, Self::Mersenne31] + } + + fn to_possible_value(&self) -> Option { + Some(match self { + Self::BabyBear => get_aliases("baby-bear", 1, Some(vec![("babybear", 5), ("bb", 2)])), + Self::KoalaBear => { + get_aliases("koala-bear", 1, Some(vec![("koalabear", 6), ("kb", 2)])) + } + Self::Mersenne31 => { + get_aliases("mersenne-31", 1, Some(vec![("mersenne31", 9), ("m31", 2)])) + } + }) + } +} + +impl ValueEnum for ProofOptions { + fn value_variants<'a>() -> &'a [Self] { + &[ + Self::Blake3Permutations, + Self::Poseidon2Permutations, + Self::KeccakFPermutations, + ] + } + + fn to_possible_value(&self) -> Option { + Some(match self { + Self::Blake3Permutations => get_aliases( + "blake-3-permutations", + 1, + Some(vec![("blake3-permutations", 6), ("b3", 2)]), + ), + Self::KeccakFPermutations => get_aliases( + "keccak-f-permutations", + 1, + Some(vec![("keccakf-permutations", 7), ("kf", 2)]), + ), + Self::Poseidon2Permutations => get_aliases( + "poseidon-2-permutations", + 1, + Some(vec![("poseidon2-permutations", 9), ("p2", 2)]), + ), + }) + } +} + +impl ValueEnum for DftOptions { + fn value_variants<'a>() -> &'a [Self] { + &[Self::Radix2DitParallel, Self::RecursiveDft, Self::None] + } + + fn to_possible_value(&self) -> Option { + Some(match self { + Self::RecursiveDft => get_aliases("recursive-dft", 2, Some(vec![("recursivedft", 10)])), + Self::Radix2DitParallel => get_aliases( + "radix-2-dit-parallel", + 2, + Some(vec![("radix2ditparallel", 6), ("parallel", 1)]), + ), + Self::None => PossibleValue::new(""), + }) + } +} + +impl ValueEnum for MerkleHashOptions { + fn value_variants<'a>() -> &'a [Self] { + &[Self::Poseidon2, Self::KeccakF] + } + + fn to_possible_value(&self) -> Option { + Some(match self { + Self::KeccakF => get_aliases("keccak-f", 1, Some(vec![("keccakf", 7), ("kf", 2)])), + Self::Poseidon2 => { + get_aliases("poseidon-2", 1, Some(vec![("poseidon2", 9), ("p2", 2)])) + } + }) + } +} diff --git a/CoqOfRust/plonky3/examples/src/parsers.v b/CoqOfRust/plonky3/examples/src/parsers.v new file mode 100644 index 000000000..c3cdbd8d8 --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/parsers.v @@ -0,0 +1,3358 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module parsers. + (* + Enum FieldOptions + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "BabyBear"; + item := StructTuple []; + }; + { + name := "KoalaBear"; + item := StructTuple []; + }; + { + name := "Mersenne31"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_FieldOptions_BabyBear : + M.IsDiscriminant "p3_examples::parsers::FieldOptions::BabyBear" 0. + Axiom IsDiscriminant_FieldOptions_KoalaBear : + M.IsDiscriminant "p3_examples::parsers::FieldOptions::KoalaBear" 1. + Axiom IsDiscriminant_FieldOptions_Mersenne31 : + M.IsDiscriminant "p3_examples::parsers::FieldOptions::Mersenne31" 2. + + Module Impl_core_fmt_Debug_for_p3_examples_parsers_FieldOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::FieldOptions". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::FieldOptions::BabyBear" + |) in + M.alloc (| + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "BabyBear" |) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::FieldOptions::KoalaBear" + |) in + M.alloc (| + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "KoalaBear" |) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::FieldOptions::Mersenne31" + |) in + M.alloc (| + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Mersenne31" |) |) |) + |))) + ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_examples_parsers_FieldOptions. + + Module Impl_core_marker_Copy_for_p3_examples_parsers_FieldOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::FieldOptions". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_examples_parsers_FieldOptions. + + Module Impl_core_clone_Clone_for_p3_examples_parsers_FieldOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::FieldOptions". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_examples_parsers_FieldOptions. + + Module Impl_core_marker_StructuralPartialEq_for_p3_examples_parsers_FieldOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::FieldOptions". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_examples_parsers_FieldOptions. + + Module Impl_core_cmp_PartialEq_p3_examples_parsers_FieldOptions_for_p3_examples_parsers_FieldOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::FieldOptions". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_examples::parsers::FieldOptions" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_examples::parsers::FieldOptions" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| __self_discr |); M.read (| __arg1_discr |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_examples::parsers::FieldOptions" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_p3_examples_parsers_FieldOptions_for_p3_examples_parsers_FieldOptions. + + Module Impl_core_cmp_Eq_for_p3_examples_parsers_FieldOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::FieldOptions". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_p3_examples_parsers_FieldOptions. + + (* + Enum ProofOptions + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "Blake3Permutations"; + item := StructTuple []; + }; + { + name := "KeccakFPermutations"; + item := StructTuple []; + }; + { + name := "Poseidon2Permutations"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_ProofOptions_Blake3Permutations : + M.IsDiscriminant "p3_examples::parsers::ProofOptions::Blake3Permutations" 0. + Axiom IsDiscriminant_ProofOptions_KeccakFPermutations : + M.IsDiscriminant "p3_examples::parsers::ProofOptions::KeccakFPermutations" 1. + Axiom IsDiscriminant_ProofOptions_Poseidon2Permutations : + M.IsDiscriminant "p3_examples::parsers::ProofOptions::Poseidon2Permutations" 2. + + Module Impl_core_fmt_Debug_for_p3_examples_parsers_ProofOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::ProofOptions". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::ProofOptions::Blake3Permutations" + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Blake3Permutations" |) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::ProofOptions::KeccakFPermutations" + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "KeccakFPermutations" |) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::ProofOptions::Poseidon2Permutations" + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Poseidon2Permutations" |) |) + |) + |))) + ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_examples_parsers_ProofOptions. + + Module Impl_core_marker_Copy_for_p3_examples_parsers_ProofOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::ProofOptions". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_examples_parsers_ProofOptions. + + Module Impl_core_clone_Clone_for_p3_examples_parsers_ProofOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::ProofOptions". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_examples_parsers_ProofOptions. + + Module Impl_core_marker_StructuralPartialEq_for_p3_examples_parsers_ProofOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::ProofOptions". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_examples_parsers_ProofOptions. + + Module Impl_core_cmp_PartialEq_p3_examples_parsers_ProofOptions_for_p3_examples_parsers_ProofOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::ProofOptions". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_examples::parsers::ProofOptions" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_examples::parsers::ProofOptions" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| __self_discr |); M.read (| __arg1_discr |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_examples::parsers::ProofOptions" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_p3_examples_parsers_ProofOptions_for_p3_examples_parsers_ProofOptions. + + Module Impl_core_cmp_Eq_for_p3_examples_parsers_ProofOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::ProofOptions". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_p3_examples_parsers_ProofOptions. + + (* + Enum DftOptions + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "None"; + item := StructTuple []; + }; + { + name := "Radix2DitParallel"; + item := StructTuple []; + }; + { + name := "RecursiveDft"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_DftOptions_None : + M.IsDiscriminant "p3_examples::parsers::DftOptions::None" 0. + Axiom IsDiscriminant_DftOptions_Radix2DitParallel : + M.IsDiscriminant "p3_examples::parsers::DftOptions::Radix2DitParallel" 1. + Axiom IsDiscriminant_DftOptions_RecursiveDft : + M.IsDiscriminant "p3_examples::parsers::DftOptions::RecursiveDft" 2. + + Module Impl_core_fmt_Debug_for_p3_examples_parsers_DftOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::DftOptions". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| γ, "p3_examples::parsers::DftOptions::None" |) in + M.alloc (| + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "None" |) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::DftOptions::Radix2DitParallel" + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Radix2DitParallel" |) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::DftOptions::RecursiveDft" + |) in + M.alloc (| + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "RecursiveDft" |) |) |) + |))) + ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_examples_parsers_DftOptions. + + Module Impl_core_marker_Copy_for_p3_examples_parsers_DftOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::DftOptions". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_examples_parsers_DftOptions. + + Module Impl_core_clone_Clone_for_p3_examples_parsers_DftOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::DftOptions". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_examples_parsers_DftOptions. + + Module Impl_core_marker_StructuralPartialEq_for_p3_examples_parsers_DftOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::DftOptions". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_examples_parsers_DftOptions. + + Module Impl_core_cmp_PartialEq_p3_examples_parsers_DftOptions_for_p3_examples_parsers_DftOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::DftOptions". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_examples::parsers::DftOptions" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_examples::parsers::DftOptions" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| __self_discr |); M.read (| __arg1_discr |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_examples::parsers::DftOptions" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_p3_examples_parsers_DftOptions_for_p3_examples_parsers_DftOptions. + + Module Impl_core_cmp_Eq_for_p3_examples_parsers_DftOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::DftOptions". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_p3_examples_parsers_DftOptions. + + (* + Enum MerkleHashOptions + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "KeccakF"; + item := StructTuple []; + }; + { + name := "Poseidon2"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_MerkleHashOptions_KeccakF : + M.IsDiscriminant "p3_examples::parsers::MerkleHashOptions::KeccakF" 0. + Axiom IsDiscriminant_MerkleHashOptions_Poseidon2 : + M.IsDiscriminant "p3_examples::parsers::MerkleHashOptions::Poseidon2" 1. + + Module Impl_core_fmt_Debug_for_p3_examples_parsers_MerkleHashOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::MerkleHashOptions". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::MerkleHashOptions::KeccakF" + |) in + M.alloc (| + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "KeccakF" |) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::MerkleHashOptions::Poseidon2" + |) in + M.alloc (| + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Poseidon2" |) |) |) + |))) + ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_examples_parsers_MerkleHashOptions. + + Module Impl_core_marker_Copy_for_p3_examples_parsers_MerkleHashOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::MerkleHashOptions". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_examples_parsers_MerkleHashOptions. + + Module Impl_core_clone_Clone_for_p3_examples_parsers_MerkleHashOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::MerkleHashOptions". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_examples_parsers_MerkleHashOptions. + + Module Impl_core_marker_StructuralPartialEq_for_p3_examples_parsers_MerkleHashOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::MerkleHashOptions". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_examples_parsers_MerkleHashOptions. + + Module Impl_core_cmp_PartialEq_p3_examples_parsers_MerkleHashOptions_for_p3_examples_parsers_MerkleHashOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::MerkleHashOptions". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_examples::parsers::MerkleHashOptions" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_examples::parsers::MerkleHashOptions" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| __self_discr |); M.read (| __arg1_discr |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_examples::parsers::MerkleHashOptions" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_p3_examples_parsers_MerkleHashOptions_for_p3_examples_parsers_MerkleHashOptions. + + Module Impl_core_cmp_Eq_for_p3_examples_parsers_MerkleHashOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::MerkleHashOptions". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_p3_examples_parsers_MerkleHashOptions. + + (* + fn get_aliases( + base: &'static str, + min_unique_base_prefix: usize, + alias: Option>, + ) -> PossibleValue { + match alias { + None => PossibleValue::new(base) + .aliases((min_unique_base_prefix..base.len()).map(|i| &base[..i])), + Some(vec) => PossibleValue::new(base).aliases( + (min_unique_base_prefix..base.len()) + .map(|i| &base[..i]) + .chain(vec.into_iter().flat_map(|(alias, min_unique)| { + (min_unique..alias.len() + 1).map(|i| &alias[..i]) + })), + ), + } + } + *) + Definition get_aliases (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ base; min_unique_base_prefix; alias ] => + ltac:(M.monadic + (let base := M.alloc (| base |) in + let min_unique_base_prefix := M.alloc (| min_unique_base_prefix |) in + let alias := M.alloc (| alias |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.path "clap_builder::builder::possible_value::PossibleValue" ], + alias, + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_associated_function (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + "aliases", + [], + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ] + ] + |), + [ + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_associated_function (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + "new", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + |), + [ M.read (| base |) ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| min_unique_base_prefix |)); + ("end_", + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "str", "len", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| base |) |) + |) + ] + |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| base |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", M.read (| i |)) ] + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| γ, "core::option::Option::Some", 0 |) in + let vec := M.copy (| γ0_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_associated_function (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + "aliases", + [], + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]; + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]) + ] + ] + ] + |), + [ + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_associated_function (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + "new", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + |), + [ M.read (| base |) ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]; + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]) + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]) + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| min_unique_base_prefix |)); + ("end_", + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "str", + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| base |) |) + |) + ] + |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| base |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", M.read (| i |)) ] + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]) + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| vec |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]) + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let alias := M.copy (| γ0_0 |) in + let min_unique := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| min_unique |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "str", + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| alias |) + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.path "usize" ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeTo") + [] + [ + Ty.path + "usize" + ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + alias + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.read (| + i + |)) + ] + ] + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_get_aliases : + M.IsFunction.C "p3_examples::parsers::get_aliases" get_aliases. + Admitted. + Global Typeclasses Opaque get_aliases. + + Module Impl_clap_builder_derive_ValueEnum_for_p3_examples_parsers_FieldOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::FieldOptions". + + (* + fn value_variants<'a>() -> &'a [Self] { + &[Self::BabyBear, Self::KoalaBear, Self::Mersenne31] + } + *) + Definition value_variants (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (* Unsize *) + (M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.StructTuple "p3_examples::parsers::FieldOptions::BabyBear" []; + Value.StructTuple "p3_examples::parsers::FieldOptions::KoalaBear" []; + Value.StructTuple "p3_examples::parsers::FieldOptions::Mersenne31" [] + ] + |) + |) + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn to_possible_value(&self) -> Option { + Some(match self { + Self::BabyBear => get_aliases("baby-bear", 1, Some(vec![("babybear", 5), ("bb", 2)])), + Self::KoalaBear => { + get_aliases("koala-bear", 1, Some(vec![("koalabear", 6), ("kb", 2)])) + } + Self::Mersenne31 => { + get_aliases("mersenne-31", 1, Some(vec![("mersenne31", 9), ("m31", 2)])) + } + }) + } + *) + Definition to_possible_value (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.path "clap_builder::builder::possible_value::PossibleValue" ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::FieldOptions::BabyBear" + |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_function (| "p3_examples::parsers::get_aliases", [], [] |), + [ + mk_str (| "baby-bear" |); + Value.Integer IntegerKind.Usize 1; + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "babybear" |) |) + |); + Value.Integer IntegerKind.Usize 5 + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "bb" |) |) + |); + Value.Integer IntegerKind.Usize 2 + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::FieldOptions::KoalaBear" + |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_function (| "p3_examples::parsers::get_aliases", [], [] |), + [ + mk_str (| "koala-bear" |); + Value.Integer IntegerKind.Usize 1; + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "koalabear" |) |) + |); + Value.Integer IntegerKind.Usize 6 + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "kb" |) |) + |); + Value.Integer IntegerKind.Usize 2 + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::FieldOptions::Mersenne31" + |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_function (| "p3_examples::parsers::get_aliases", [], [] |), + [ + mk_str (| "mersenne-31" |); + Value.Integer IntegerKind.Usize 1; + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "mersenne31" |) |) + |); + Value.Integer IntegerKind.Usize 9 + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "m31" |) |) + |); + Value.Integer IntegerKind.Usize 2 + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + |))) + ] + |) + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "clap_builder::derive::ValueEnum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_variants", InstanceField.Method value_variants); + ("to_possible_value", InstanceField.Method to_possible_value) + ]. + End Impl_clap_builder_derive_ValueEnum_for_p3_examples_parsers_FieldOptions. + + Module Impl_clap_builder_derive_ValueEnum_for_p3_examples_parsers_ProofOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::ProofOptions". + + (* + fn value_variants<'a>() -> &'a [Self] { + &[ + Self::Blake3Permutations, + Self::Poseidon2Permutations, + Self::KeccakFPermutations, + ] + } + *) + Definition value_variants (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (* Unsize *) + (M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.StructTuple + "p3_examples::parsers::ProofOptions::Blake3Permutations" + []; + Value.StructTuple + "p3_examples::parsers::ProofOptions::Poseidon2Permutations" + []; + Value.StructTuple + "p3_examples::parsers::ProofOptions::KeccakFPermutations" + [] + ] + |) + |) + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn to_possible_value(&self) -> Option { + Some(match self { + Self::Blake3Permutations => get_aliases( + "blake-3-permutations", + 1, + Some(vec![("blake3-permutations", 6), ("b3", 2)]), + ), + Self::KeccakFPermutations => get_aliases( + "keccak-f-permutations", + 1, + Some(vec![("keccakf-permutations", 7), ("kf", 2)]), + ), + Self::Poseidon2Permutations => get_aliases( + "poseidon-2-permutations", + 1, + Some(vec![("poseidon2-permutations", 9), ("p2", 2)]), + ), + }) + } + *) + Definition to_possible_value (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.path "clap_builder::builder::possible_value::PossibleValue" ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::ProofOptions::Blake3Permutations" + |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_function (| "p3_examples::parsers::get_aliases", [], [] |), + [ + mk_str (| "blake-3-permutations" |); + Value.Integer IntegerKind.Usize 1; + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| "blake3-permutations" |) + |) + |); + Value.Integer IntegerKind.Usize 6 + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "b3" |) |) + |); + Value.Integer IntegerKind.Usize 2 + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::ProofOptions::KeccakFPermutations" + |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_function (| "p3_examples::parsers::get_aliases", [], [] |), + [ + mk_str (| "keccak-f-permutations" |); + Value.Integer IntegerKind.Usize 1; + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| "keccakf-permutations" |) + |) + |); + Value.Integer IntegerKind.Usize 7 + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "kf" |) |) + |); + Value.Integer IntegerKind.Usize 2 + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::ProofOptions::Poseidon2Permutations" + |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_function (| "p3_examples::parsers::get_aliases", [], [] |), + [ + mk_str (| "poseidon-2-permutations" |); + Value.Integer IntegerKind.Usize 1; + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| "poseidon2-permutations" |) + |) + |); + Value.Integer IntegerKind.Usize 9 + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "p2" |) |) + |); + Value.Integer IntegerKind.Usize 2 + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + |))) + ] + |) + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "clap_builder::derive::ValueEnum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_variants", InstanceField.Method value_variants); + ("to_possible_value", InstanceField.Method to_possible_value) + ]. + End Impl_clap_builder_derive_ValueEnum_for_p3_examples_parsers_ProofOptions. + + Module Impl_clap_builder_derive_ValueEnum_for_p3_examples_parsers_DftOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::DftOptions". + + (* + fn value_variants<'a>() -> &'a [Self] { + &[Self::Radix2DitParallel, Self::RecursiveDft, Self::None] + } + *) + Definition value_variants (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (* Unsize *) + (M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.StructTuple "p3_examples::parsers::DftOptions::Radix2DitParallel" []; + Value.StructTuple "p3_examples::parsers::DftOptions::RecursiveDft" []; + Value.StructTuple "p3_examples::parsers::DftOptions::None" [] + ] + |) + |) + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn to_possible_value(&self) -> Option { + Some(match self { + Self::RecursiveDft => get_aliases("recursive-dft", 2, Some(vec![("recursivedft", 10)])), + Self::Radix2DitParallel => get_aliases( + "radix-2-dit-parallel", + 2, + Some(vec![("radix2ditparallel", 6), ("parallel", 1)]), + ), + Self::None => PossibleValue::new(""), + }) + } + *) + Definition to_possible_value (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.path "clap_builder::builder::possible_value::PossibleValue" ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::DftOptions::RecursiveDft" + |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_function (| "p3_examples::parsers::get_aliases", [], [] |), + [ + mk_str (| "recursive-dft" |); + Value.Integer IntegerKind.Usize 2; + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "recursivedft" |) |) + |); + Value.Integer IntegerKind.Usize 10 + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::DftOptions::Radix2DitParallel" + |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_function (| "p3_examples::parsers::get_aliases", [], [] |), + [ + mk_str (| "radix-2-dit-parallel" |); + Value.Integer IntegerKind.Usize 2; + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| "radix2ditparallel" |) + |) + |); + Value.Integer IntegerKind.Usize 6 + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "parallel" |) |) + |); + Value.Integer IntegerKind.Usize 1 + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| γ, "p3_examples::parsers::DftOptions::None" |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_associated_function (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + "new", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + |), + [ mk_str (| "" |) ] + |) + |))) + ] + |) + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "clap_builder::derive::ValueEnum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_variants", InstanceField.Method value_variants); + ("to_possible_value", InstanceField.Method to_possible_value) + ]. + End Impl_clap_builder_derive_ValueEnum_for_p3_examples_parsers_DftOptions. + + Module Impl_clap_builder_derive_ValueEnum_for_p3_examples_parsers_MerkleHashOptions. + Definition Self : Ty.t := Ty.path "p3_examples::parsers::MerkleHashOptions". + + (* + fn value_variants<'a>() -> &'a [Self] { + &[Self::Poseidon2, Self::KeccakF] + } + *) + Definition value_variants (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (* Unsize *) + (M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.StructTuple "p3_examples::parsers::MerkleHashOptions::Poseidon2" []; + Value.StructTuple "p3_examples::parsers::MerkleHashOptions::KeccakF" [] + ] + |) + |) + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn to_possible_value(&self) -> Option { + Some(match self { + Self::KeccakF => get_aliases("keccak-f", 1, Some(vec![("keccakf", 7), ("kf", 2)])), + Self::Poseidon2 => { + get_aliases("poseidon-2", 1, Some(vec![("poseidon2", 9), ("p2", 2)])) + } + }) + } + *) + Definition to_possible_value (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.path "clap_builder::builder::possible_value::PossibleValue" ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::MerkleHashOptions::KeccakF" + |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_function (| "p3_examples::parsers::get_aliases", [], [] |), + [ + mk_str (| "keccak-f" |); + Value.Integer IntegerKind.Usize 1; + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "keccakf" |) |) + |); + Value.Integer IntegerKind.Usize 7 + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "kf" |) |) + |); + Value.Integer IntegerKind.Usize 2 + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_examples::parsers::MerkleHashOptions::Poseidon2" + |) in + M.alloc (| + M.call_closure (| + Ty.path "clap_builder::builder::possible_value::PossibleValue", + M.get_function (| "p3_examples::parsers::get_aliases", [], [] |), + [ + mk_str (| "poseidon-2" |); + Value.Integer IntegerKind.Usize 1; + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ]; + Ty.path "usize" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "poseidon2" |) |) + |); + Value.Integer IntegerKind.Usize 9 + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "p2" |) |) + |); + Value.Integer IntegerKind.Usize 2 + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + |))) + ] + |) + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "clap_builder::derive::ValueEnum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_variants", InstanceField.Method value_variants); + ("to_possible_value", InstanceField.Method to_possible_value) + ]. + End Impl_clap_builder_derive_ValueEnum_for_p3_examples_parsers_MerkleHashOptions. +End parsers. diff --git a/CoqOfRust/plonky3/examples/src/proofs.rs b/CoqOfRust/plonky3/examples/src/proofs.rs new file mode 100644 index 000000000..157c3a4d3 --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/proofs.rs @@ -0,0 +1,238 @@ +use core::fmt::Debug; + +use p3_challenger::{DuplexChallenger, SerializingChallenger32}; +use p3_circle::CirclePcs; +use p3_commit::ExtensionMmcs; +use p3_dft::TwoAdicSubgroupDft; +use p3_field::extension::{BinomialExtensionField, ComplexExtendable}; +use p3_field::{ExtensionField, Field, PrimeField32, PrimeField64, TwoAdicField}; +use p3_fri::{TwoAdicFriPcs, create_benchmark_fri_config}; +use p3_keccak::{Keccak256Hash, KeccakF}; +use p3_mersenne_31::Mersenne31; +use p3_symmetric::{CryptographicPermutation, PaddingFreeSponge, SerializingHasher32To64}; +use p3_uni_stark::{Proof, StarkGenericConfig, prove, verify}; +use rand::distr::StandardUniform; +use rand::prelude::Distribution; + +use crate::airs::ExampleHashAir; +use crate::types::{ + KeccakCircleStarkConfig, KeccakCompressionFunction, KeccakMerkleMmcs, KeccakStarkConfig, + Poseidon2CircleStarkConfig, Poseidon2Compression, Poseidon2MerkleMmcs, Poseidon2Sponge, + Poseidon2StarkConfig, +}; + +/// Produce a MerkleTreeMmcs which uses the KeccakF permutation. +const fn get_keccak_mmcs() -> KeccakMerkleMmcs { + let u64_hash = PaddingFreeSponge::::new(KeccakF {}); + + let field_hash = SerializingHasher32To64::new(u64_hash); + + let compress = KeccakCompressionFunction::new(u64_hash); + + KeccakMerkleMmcs::new(field_hash, compress) +} + +/// Produce a MerkleTreeMmcs from a pair of cryptographic field permutations. +/// +/// The first permutation will be used for compression and the second for more sponge hashing. +/// Currently this is only intended to be used with a pair of Poseidon2 hashes of with 16 and 24 +/// but this can easily be generalised in future if we desire. +const fn get_poseidon2_mmcs< + F: Field, + Perm16: CryptographicPermutation<[F; 16]> + CryptographicPermutation<[F::Packing; 16]>, + Perm24: CryptographicPermutation<[F; 24]> + CryptographicPermutation<[F::Packing; 24]>, +>( + perm16: Perm16, + perm24: Perm24, +) -> Poseidon2MerkleMmcs { + let hash = Poseidon2Sponge::new(perm24); + + let compress = Poseidon2Compression::new(perm16); + + Poseidon2MerkleMmcs::::new(hash, compress) +} + +/// Prove the given ProofGoal using the Keccak hash function to build the merkle tree. +/// +/// This allows the user to choose: +/// - The Field +/// - The Proof Goal (Choice of both hash function and desired number of hashes to prove) +/// - The DFT +#[inline] +pub fn prove_monty31_keccak< + F: PrimeField32 + TwoAdicField, + EF: ExtensionField + TwoAdicField, + DFT: TwoAdicSubgroupDft, + PG: ExampleHashAir>, +>( + proof_goal: PG, + dft: DFT, + num_hashes: usize, +) -> Result<(), impl Debug> +where + StandardUniform: Distribution, +{ + let val_mmcs = get_keccak_mmcs(); + + let challenge_mmcs = ExtensionMmcs::::new(val_mmcs.clone()); + let fri_config = create_benchmark_fri_config(challenge_mmcs); + + let trace = proof_goal.generate_trace_rows(num_hashes, fri_config.log_blowup); + + let pcs = TwoAdicFriPcs::new(dft, val_mmcs, fri_config); + let challenger = SerializingChallenger32::from_hasher(vec![], Keccak256Hash {}); + + let config = KeccakStarkConfig::new(pcs, challenger); + + let proof = prove(&config, &proof_goal, trace, &vec![]); + report_proof_size(&proof); + + verify(&config, &proof_goal, &proof, &vec![]) +} + +/// Prove the given ProofGoal using the Poseidon2 hash function to build the merkle tree. +/// +/// This allows the user to choose: +/// - The Field +/// - The Proof Goal (Choice of Hash function and number of hashes to prove) +/// - The DFT +#[inline] +pub fn prove_monty31_poseidon2< + F: PrimeField32 + TwoAdicField, + EF: ExtensionField + TwoAdicField, + DFT: TwoAdicSubgroupDft, + Perm16: CryptographicPermutation<[F; 16]> + CryptographicPermutation<[F::Packing; 16]>, + Perm24: CryptographicPermutation<[F; 24]> + CryptographicPermutation<[F::Packing; 24]>, + PG: ExampleHashAir>, +>( + proof_goal: PG, + dft: DFT, + num_hashes: usize, + perm16: Perm16, + perm24: Perm24, +) -> Result<(), impl Debug> +where + StandardUniform: Distribution, +{ + let val_mmcs = get_poseidon2_mmcs::(perm16, perm24.clone()); + + let challenge_mmcs = ExtensionMmcs::::new(val_mmcs.clone()); + let fri_config = create_benchmark_fri_config(challenge_mmcs); + + let trace = proof_goal.generate_trace_rows(num_hashes, fri_config.log_blowup); + + let pcs = TwoAdicFriPcs::new(dft, val_mmcs, fri_config); + let challenger = DuplexChallenger::new(perm24); + + let config = Poseidon2StarkConfig::new(pcs, challenger); + + let proof = prove(&config, &proof_goal, trace, &vec![]); + report_proof_size(&proof); + + verify(&config, &proof_goal, &proof, &vec![]) +} + +/// Prove the given ProofGoal using the Keccak hash function to build the merkle tree. +/// +/// This fixes the field and Mersenne31 and makes use of the circle stark. +/// +/// It currently allows the user to choose: +/// - The Proof Goal (Choice of Hash function and number of hashes to prove) +#[inline] +pub fn prove_m31_keccak< + PG: ExampleHashAir< + Mersenne31, + KeccakCircleStarkConfig>, + >, +>( + proof_goal: PG, + num_hashes: usize, +) -> Result<(), impl Debug> { + type F = Mersenne31; + type EF = BinomialExtensionField; + + let val_mmcs = get_keccak_mmcs(); + let challenge_mmcs = ExtensionMmcs::::new(val_mmcs.clone()); + let fri_config = create_benchmark_fri_config(challenge_mmcs); + + let trace = proof_goal.generate_trace_rows(num_hashes, fri_config.log_blowup); + + let pcs = CirclePcs::new(val_mmcs, fri_config); + let challenger = SerializingChallenger32::from_hasher(vec![], Keccak256Hash {}); + + let config = KeccakCircleStarkConfig::new(pcs, challenger); + + let proof = prove(&config, &proof_goal, trace, &vec![]); + report_proof_size(&proof); + + verify(&config, &proof_goal, &proof, &vec![]) +} + +/// Prove the given ProofGoal using the Keccak hash function to build the merkle tree. +/// +/// This fixes the field and Mersenne31 and makes use of the circle stark. +/// +/// It currently allows the user to choose: +/// - The Proof Goal (Choice of Hash function and number of hashes to prove) +#[inline] +pub fn prove_m31_poseidon2< + F: PrimeField64 + ComplexExtendable, + EF: ExtensionField, + Perm16: CryptographicPermutation<[F; 16]> + CryptographicPermutation<[F::Packing; 16]>, + Perm24: CryptographicPermutation<[F; 24]> + CryptographicPermutation<[F::Packing; 24]>, + PG: ExampleHashAir>, +>( + proof_goal: PG, + num_hashes: usize, + perm16: Perm16, + perm24: Perm24, +) -> Result<(), impl Debug> +where + StandardUniform: Distribution, +{ + let val_mmcs = get_poseidon2_mmcs::(perm16, perm24.clone()); + + let challenge_mmcs = ExtensionMmcs::::new(val_mmcs.clone()); + let fri_config = create_benchmark_fri_config(challenge_mmcs); + + let trace = proof_goal.generate_trace_rows(num_hashes, fri_config.log_blowup); + + let pcs = CirclePcs::new(val_mmcs, fri_config); + let challenger = DuplexChallenger::new(perm24); + + let config = Poseidon2CircleStarkConfig::new(pcs, challenger); + + let proof = prove(&config, &proof_goal, trace, &vec![]); + report_proof_size(&proof); + + verify(&config, &proof_goal, &proof, &vec![]) +} + +/// Report the result of the proof. +/// +/// Either print that the proof was successful or panic and return the error. +#[inline] +pub fn report_result(result: Result<(), impl Debug>) { + if let Err(e) = result { + panic!("{:?}", e); + } else { + println!("Proof Verified Successfully") + } +} + +/// Report the size of the serialized proof. +/// +/// Serializes the given proof instance using bincode and prints the size in bytes. +/// Panics if serialization fails. +#[inline] +pub fn report_proof_size(proof: &Proof) +where + SC: StarkGenericConfig, +{ + let config = bincode::config::standard() + .with_little_endian() + .with_fixed_int_encoding(); + let proof_bytes = + bincode::serde::encode_to_vec(proof, config).expect("Failed to serialize proof"); + println!("Proof size: {} bytes", proof_bytes.len()); +} diff --git a/CoqOfRust/plonky3/examples/src/proofs.v b/CoqOfRust/plonky3/examples/src/proofs.v new file mode 100644 index 000000000..a4227de25 --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/proofs.v @@ -0,0 +1,8400 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module proofs. + (* + const fn get_keccak_mmcs() -> KeccakMerkleMmcs { + let u64_hash = PaddingFreeSponge::::new(KeccakF {}); + + let field_hash = SerializingHasher32To64::new(u64_hash); + + let compress = KeccakCompressionFunction::new(u64_hash); + + KeccakMerkleMmcs::new(field_hash, compress) + } + *) + Definition get_keccak_mmcs (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [] => + ltac:(M.monadic + (M.read (| + let~ u64_hash : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ], + "new", + [], + [] + |), + [ Value.StructTuple "p3_keccak::KeccakF" [] ] + |) + |) in + let~ field_hash : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ], + "new", + [], + [] + |), + [ M.read (| u64_hash |) ] + |) + |) in + let~ compress : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ], + "new", + [], + [] + |), + [ M.read (| u64_hash |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ], + "new", + [], + [] + |), + [ M.read (| field_hash |); M.read (| compress |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_get_keccak_mmcs : + M.IsFunction.C "p3_examples::proofs::get_keccak_mmcs" get_keccak_mmcs. + Admitted. + Global Typeclasses Opaque get_keccak_mmcs. + + (* + const fn get_poseidon2_mmcs< + F: Field, + Perm16: CryptographicPermutation<[F; 16]> + CryptographicPermutation<[F::Packing; 16]>, + Perm24: CryptographicPermutation<[F; 24]> + CryptographicPermutation<[F::Packing; 24]>, + >( + perm16: Perm16, + perm24: Perm24, + ) -> Poseidon2MerkleMmcs { + let hash = Poseidon2Sponge::new(perm24); + + let compress = Poseidon2Compression::new(perm16); + + Poseidon2MerkleMmcs::::new(hash, compress) + } + *) + Definition get_poseidon2_mmcs (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; Perm16; Perm24 ], [ perm16; perm24 ] => + ltac:(M.monadic + (let perm16 := M.alloc (| perm16 |) in + let perm24 := M.alloc (| perm24 |) in + M.read (| + let~ hash : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ], + "new", + [], + [] + |), + [ M.read (| perm24 |) ] + |) + |) in + let~ compress : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ], + "new", + [], + [] + |), + [ M.read (| perm16 |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ], + "new", + [], + [] + |), + [ M.read (| hash |); M.read (| compress |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_get_poseidon2_mmcs : + M.IsFunction.C "p3_examples::proofs::get_poseidon2_mmcs" get_poseidon2_mmcs. + Admitted. + Global Typeclasses Opaque get_poseidon2_mmcs. + + (* + pub fn prove_monty31_keccak< + F: PrimeField32 + TwoAdicField, + EF: ExtensionField + TwoAdicField, + DFT: TwoAdicSubgroupDft, + PG: ExampleHashAir>, + >( + proof_goal: PG, + dft: DFT, + num_hashes: usize, + ) -> Result<(), impl Debug> + where + StandardUniform: Distribution, + { + let val_mmcs = get_keccak_mmcs(); + + let challenge_mmcs = ExtensionMmcs::::new(val_mmcs.clone()); + let fri_config = create_benchmark_fri_config(challenge_mmcs); + + let trace = proof_goal.generate_trace_rows(num_hashes, fri_config.log_blowup); + + let pcs = TwoAdicFriPcs::new(dft, val_mmcs, fri_config); + let challenger = SerializingChallenger32::from_hasher(vec![], Keccak256Hash {}); + + let config = KeccakStarkConfig::new(pcs, challenger); + + let proof = prove(&config, &proof_goal, trace, &vec![]); + report_proof_size(&proof); + + verify(&config, &proof_goal, &proof, &vec![]) + } + *) + Definition prove_monty31_keccak (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF; DFT; PG ], [ proof_goal; dft; num_hashes ] => + ltac:(M.monadic + (let proof_goal := M.alloc (| proof_goal |) in + let dft := M.alloc (| dft |) in + let num_hashes := M.alloc (| num_hashes |) in + M.read (| + let~ val_mmcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ], + M.get_function (| "p3_examples::proofs::get_keccak_mmcs", [], [ F ] |), + [] + |) + |) in + let~ challenge_mmcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, val_mmcs |) ] + |) + ] + |) + |) in + let~ fri_config : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::config::FriConfig") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_fri::config::FriConfig") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ], + M.get_function (| + "p3_fri::config::create_benchmark_fri_config", + [], + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ] + |), + [ M.read (| challenge_mmcs |) ] + |) + |) in + let~ trace : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_examples::airs::ExampleHashAir", + PG, + [], + [ + F; + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] + ], + "generate_trace_rows", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, proof_goal |); + M.read (| num_hashes |); + M.read (| + M.SubPointer.get_struct_record_field (| + fri_config, + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + |) in + let~ pcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ], + "new", + [], + [] + |), + [ M.read (| dft |); M.read (| val_mmcs |); M.read (| fri_config |) ] + |) + |) in + let~ challenger : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ], + "from_hasher", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |); + Value.StructTuple "p3_keccak::Keccak256Hash" [] + ] + |) + |) in + let~ config : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ], + "new", + [], + [] + |), + [ M.read (| pcs |); M.read (| challenger |) ] + |) + |) in + let~ proof : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::proof::Proof") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path + "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::proof::Proof") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] + ], + M.get_function (| + "p3_uni_stark::prover::prove", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ]; + PG + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, config |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof_goal |) |) + |); + M.read (| trace |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_examples::proofs::report_proof_size", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof |) |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError"; + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" + ] + ] + ], + M.get_function (| + "p3_uni_stark::verifier::verify", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ F ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ]; + PG + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, config |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof_goal |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_prove_monty31_keccak : + M.IsFunction.C "p3_examples::proofs::prove_monty31_keccak" prove_monty31_keccak. + Admitted. + Global Typeclasses Opaque prove_monty31_keccak. + + (* + pub fn prove_monty31_poseidon2< + F: PrimeField32 + TwoAdicField, + EF: ExtensionField + TwoAdicField, + DFT: TwoAdicSubgroupDft, + Perm16: CryptographicPermutation<[F; 16]> + CryptographicPermutation<[F::Packing; 16]>, + Perm24: CryptographicPermutation<[F; 24]> + CryptographicPermutation<[F::Packing; 24]>, + PG: ExampleHashAir>, + >( + proof_goal: PG, + dft: DFT, + num_hashes: usize, + perm16: Perm16, + perm24: Perm24, + ) -> Result<(), impl Debug> + where + StandardUniform: Distribution, + { + let val_mmcs = get_poseidon2_mmcs::(perm16, perm24.clone()); + + let challenge_mmcs = ExtensionMmcs::::new(val_mmcs.clone()); + let fri_config = create_benchmark_fri_config(challenge_mmcs); + + let trace = proof_goal.generate_trace_rows(num_hashes, fri_config.log_blowup); + + let pcs = TwoAdicFriPcs::new(dft, val_mmcs, fri_config); + let challenger = DuplexChallenger::new(perm24); + + let config = Poseidon2StarkConfig::new(pcs, challenger); + + let proof = prove(&config, &proof_goal, trace, &vec![]); + report_proof_size(&proof); + + verify(&config, &proof_goal, &proof, &vec![]) + } + *) + Definition prove_monty31_poseidon2 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF; DFT; Perm16; Perm24; PG ], [ proof_goal; dft; num_hashes; perm16; perm24 ] => + ltac:(M.monadic + (let proof_goal := M.alloc (| proof_goal |) in + let dft := M.alloc (| dft |) in + let num_hashes := M.alloc (| num_hashes |) in + let perm16 := M.alloc (| perm16 |) in + let perm24 := M.alloc (| perm24 |) in + M.read (| + let~ val_mmcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ], + M.get_function (| + "p3_examples::proofs::get_poseidon2_mmcs", + [], + [ F; Perm16; Perm24 ] + |), + [ + M.read (| perm16 |); + M.call_closure (| + Perm24, + M.get_trait_method (| "core::clone::Clone", Perm24, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, perm24 |) ] + |) + ] + |) + |) in + let~ challenge_mmcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, val_mmcs |) ] + |) + ] + |) + |) in + let~ fri_config : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::config::FriConfig") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_fri::config::FriConfig") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ], + M.get_function (| + "p3_fri::config::create_benchmark_fri_config", + [], + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ] + |), + [ M.read (| challenge_mmcs |) ] + |) + |) in + let~ trace : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_examples::airs::ExampleHashAir", + PG, + [], + [ + F; + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ] + ], + "generate_trace_rows", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, proof_goal |); + M.read (| num_hashes |); + M.read (| + M.SubPointer.get_struct_record_field (| + fri_config, + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + |) in + let~ pcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ], + "new", + [], + [] + |), + [ M.read (| dft |); M.read (| val_mmcs |); M.read (| fri_config |) ] + |) + |) in + let~ challenger : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ], + "new", + [], + [] + |), + [ M.read (| perm24 |) ] + |) + |) in + let~ config : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ], + "new", + [], + [] + |), + [ M.read (| pcs |); M.read (| challenger |) ] + |) + |) in + let~ proof : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::proof::Proof") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 + ] + [ F; Perm24 ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::proof::Proof") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ] + ], + M.get_function (| + "p3_uni_stark::prover::prove", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ]; + PG + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, config |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof_goal |) |) + |); + M.read (| trace |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_examples::proofs::report_proof_size", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof |) |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError"; + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" + ] + ] + ], + M.get_function (| + "p3_uni_stark::verifier::verify", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ]; + PG + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, config |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof_goal |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_prove_monty31_poseidon2 : + M.IsFunction.C "p3_examples::proofs::prove_monty31_poseidon2" prove_monty31_poseidon2. + Admitted. + Global Typeclasses Opaque prove_monty31_poseidon2. + + (* + pub fn prove_m31_keccak< + PG: ExampleHashAir< + Mersenne31, + KeccakCircleStarkConfig>, + >, + >( + proof_goal: PG, + num_hashes: usize, + ) -> Result<(), impl Debug> { + type F = Mersenne31; + type EF = BinomialExtensionField; + + let val_mmcs = get_keccak_mmcs(); + let challenge_mmcs = ExtensionMmcs::::new(val_mmcs.clone()); + let fri_config = create_benchmark_fri_config(challenge_mmcs); + + let trace = proof_goal.generate_trace_rows(num_hashes, fri_config.log_blowup); + + let pcs = CirclePcs::new(val_mmcs, fri_config); + let challenger = SerializingChallenger32::from_hasher(vec![], Keccak256Hash {}); + + let config = KeccakCircleStarkConfig::new(pcs, challenger); + + let proof = prove(&config, &proof_goal, trace, &vec![]); + report_proof_size(&proof); + + verify(&config, &proof_goal, &proof, &vec![]) + } + *) + Definition prove_m31_keccak (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ PG ], [ proof_goal; num_hashes ] => + ltac:(M.monadic + (let proof_goal := M.alloc (| proof_goal |) in + let num_hashes := M.alloc (| num_hashes |) in + M.read (| + let~ val_mmcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ], + M.get_function (| + "p3_examples::proofs::get_keccak_mmcs", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + |), + [] + |) + |) in + let~ challenge_mmcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, val_mmcs |) ] + |) + ] + |) + |) in + let~ fri_config : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::config::FriConfig") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_fri::config::FriConfig") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ], + M.get_function (| + "p3_fri::config::create_benchmark_fri_config", + [], + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ] + |), + [ M.read (| challenge_mmcs |) ] + |) + |) in + let~ trace : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "p3_examples::airs::ExampleHashAir", + PG, + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] + ], + "generate_trace_rows", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, proof_goal |); + M.read (| num_hashes |); + M.read (| + M.SubPointer.get_struct_record_field (| + fri_config, + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + |) in + let~ pcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ], + "new", + [], + [] + |), + [ M.read (| val_mmcs |); M.read (| fri_config |) ] + |) + |) in + let~ challenger : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ], + "from_hasher", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |); + Value.StructTuple "p3_keccak::Keccak256Hash" [] + ] + |) + |) in + let~ config : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ], + "new", + [], + [] + |), + [ M.read (| pcs |); M.read (| challenger |) ] + |) + |) in + let~ proof : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::proof::Proof") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::proof::Proof") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] + ], + M.get_function (| + "p3_uni_stark::prover::prove", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ]; + PG + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, config |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof_goal |) |) + |); + M.read (| trace |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_examples::proofs::report_proof_size", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof |) |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError"; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError"; + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" + ] + ] + ] + ], + M.get_function (| + "p3_uni_stark::verifier::verify", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path + "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path + "p3_symmetric::compression::CompressionFunctionFromHasher") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ]; + PG + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, config |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof_goal |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_prove_m31_keccak : + M.IsFunction.C "p3_examples::proofs::prove_m31_keccak" prove_m31_keccak. + Admitted. + Global Typeclasses Opaque prove_m31_keccak. + + Module prove_m31_keccak. + Axiom F : + (Ty.path "p3_examples::proofs::prove_m31_keccak::F") = + (Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"). + + Axiom EF : + (Ty.path "p3_examples::proofs::prove_m31_keccak::EF") = + (Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]). + End prove_m31_keccak. + + (* + pub fn prove_m31_poseidon2< + F: PrimeField64 + ComplexExtendable, + EF: ExtensionField, + Perm16: CryptographicPermutation<[F; 16]> + CryptographicPermutation<[F::Packing; 16]>, + Perm24: CryptographicPermutation<[F; 24]> + CryptographicPermutation<[F::Packing; 24]>, + PG: ExampleHashAir>, + >( + proof_goal: PG, + num_hashes: usize, + perm16: Perm16, + perm24: Perm24, + ) -> Result<(), impl Debug> + where + StandardUniform: Distribution, + { + let val_mmcs = get_poseidon2_mmcs::(perm16, perm24.clone()); + + let challenge_mmcs = ExtensionMmcs::::new(val_mmcs.clone()); + let fri_config = create_benchmark_fri_config(challenge_mmcs); + + let trace = proof_goal.generate_trace_rows(num_hashes, fri_config.log_blowup); + + let pcs = CirclePcs::new(val_mmcs, fri_config); + let challenger = DuplexChallenger::new(perm24); + + let config = Poseidon2CircleStarkConfig::new(pcs, challenger); + + let proof = prove(&config, &proof_goal, trace, &vec![]); + report_proof_size(&proof); + + verify(&config, &proof_goal, &proof, &vec![]) + } + *) + Definition prove_m31_poseidon2 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF; Perm16; Perm24; PG ], [ proof_goal; num_hashes; perm16; perm24 ] => + ltac:(M.monadic + (let proof_goal := M.alloc (| proof_goal |) in + let num_hashes := M.alloc (| num_hashes |) in + let perm16 := M.alloc (| perm16 |) in + let perm24 := M.alloc (| perm24 |) in + M.read (| + let~ val_mmcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ], + M.get_function (| + "p3_examples::proofs::get_poseidon2_mmcs", + [], + [ F; Perm16; Perm24 ] + |), + [ + M.read (| perm16 |); + M.call_closure (| + Perm24, + M.get_trait_method (| "core::clone::Clone", Perm24, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, perm24 |) ] + |) + ] + |) + |) in + let~ challenge_mmcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, val_mmcs |) ] + |) + ] + |) + |) in + let~ fri_config : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::config::FriConfig") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_fri::config::FriConfig") + [] + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ], + M.get_function (| + "p3_fri::config::create_benchmark_fri_config", + [], + [ + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ] + |), + [ M.read (| challenge_mmcs |) ] + |) + |) in + let~ trace : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_examples::airs::ExampleHashAir", + PG, + [], + [ + F; + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ] + ], + "generate_trace_rows", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, proof_goal |); + M.read (| num_hashes |); + M.read (| + M.SubPointer.get_struct_record_field (| + fri_config, + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + |) in + let~ pcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ], + "new", + [], + [] + |), + [ M.read (| val_mmcs |); M.read (| fri_config |) ] + |) + |) in + let~ challenger : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ], + "new", + [], + [] + |), + [ M.read (| perm24 |) ] + |) + |) in + let~ config : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ], + "new", + [], + [] + |), + [ M.read (| pcs |); M.read (| challenger |) ] + |) + |) in + let~ proof : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::proof::Proof") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 + ] + [ F; Perm24 ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::proof::Proof") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ] + ], + M.get_function (| + "p3_uni_stark::prover::prove", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ]; + PG + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, config |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof_goal |) |) + |); + M.read (| trace |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_examples::proofs::report_proof_size", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof |) |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError"; + Ty.apply + (Ty.path "p3_circle::pcs::InputError") + [] + [ + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError"; + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" + ] + ] + ] + ], + M.get_function (| + "p3_uni_stark::verifier::verify", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ]; + PG + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, config |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof_goal |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, proof |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_prove_m31_poseidon2 : + M.IsFunction.C "p3_examples::proofs::prove_m31_poseidon2" prove_m31_poseidon2. + Admitted. + Global Typeclasses Opaque prove_m31_poseidon2. + + (* + pub fn report_result(result: Result<(), impl Debug>) { + if let Err(e) = result { + panic!("{:?}", e); + } else { + println!("Proof Verified Successfully") + } + } + *) + Definition report_result (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ impl_Debug ], [ result ] => + ltac:(M.monadic + (let result := M.alloc (| result |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := result in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| γ, "core::result::Result::Err", 0 |) in + let e := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ Value.Integer IntegerKind.Usize 1; Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ mk_str (| "" |) ] |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_debug", + [], + [ impl_Debug ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, e |) |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "std::io::stdio::_print", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ mk_str (| "Proof Verified Successfully +" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_report_result : + M.IsFunction.C "p3_examples::proofs::report_result" report_result. + Admitted. + Global Typeclasses Opaque report_result. + + (* + pub fn report_proof_size(proof: &Proof) + where + SC: StarkGenericConfig, + { + let config = bincode::config::standard() + .with_little_endian() + .with_fixed_int_encoding(); + let proof_bytes = + bincode::serde::encode_to_vec(proof, config).expect("Failed to serialize proof"); + println!("Proof size: {} bytes", proof_bytes.len()); + } + *) + Definition report_proof_size (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ SC ], [ proof ] => + ltac:(M.monadic + (let proof := M.alloc (| proof |) in + M.read (| + let~ config : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "bincode::config::Configuration") + [] + [ + Ty.path "bincode::config::LittleEndian"; + Ty.path "bincode::config::Fixint"; + Ty.path "bincode::config::NoLimit" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "bincode::config::Configuration") + [] + [ + Ty.path "bincode::config::LittleEndian"; + Ty.path "bincode::config::Fixint"; + Ty.path "bincode::config::NoLimit" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "bincode::config::Configuration") + [] + [ + Ty.path "bincode::config::LittleEndian"; + Ty.path "bincode::config::Varint"; + Ty.path "bincode::config::NoLimit" + ], + "with_fixed_int_encoding", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "bincode::config::Configuration") + [] + [ + Ty.path "bincode::config::LittleEndian"; + Ty.path "bincode::config::Varint"; + Ty.path "bincode::config::NoLimit" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "bincode::config::Configuration") + [] + [ + Ty.path "bincode::config::LittleEndian"; + Ty.path "bincode::config::Varint"; + Ty.path "bincode::config::NoLimit" + ], + "with_little_endian", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "bincode::config::Configuration") + [] + [ + Ty.path "bincode::config::LittleEndian"; + Ty.path "bincode::config::Varint"; + Ty.path "bincode::config::NoLimit" + ], + M.get_function (| "bincode::config::standard", [], [] |), + [] + |) + ] + |) + ] + |) + |) in + let~ proof_bytes : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.path "bincode::error::EncodeError" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.path "bincode::error::EncodeError" + ], + M.get_function (| + "bincode::features::serde::ser::encode_to_vec", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_uni_stark::proof::Proof") [] [ SC ] ]; + Ty.apply + (Ty.path "bincode::config::Configuration") + [] + [ + Ty.path "bincode::config::LittleEndian"; + Ty.path "bincode::config::Fixint"; + Ty.path "bincode::config::NoLimit" + ] + ] + |), + [ M.read (| proof |); M.read (| config |) ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Failed to serialize proof" |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "std::io::stdio::_print", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ mk_str (| "Proof size: " |); mk_str (| " bytes +" |) ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, proof_bytes |) ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_report_proof_size : + M.IsFunction.C "p3_examples::proofs::report_proof_size" report_proof_size. + Admitted. + Global Typeclasses Opaque report_proof_size. +End proofs. diff --git a/CoqOfRust/plonky3/examples/src/tests.rs b/CoqOfRust/plonky3/examples/src/tests.rs new file mode 100644 index 000000000..1e399299d --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/tests.rs @@ -0,0 +1,262 @@ +//! Adding tests for all our End-to-End proofs. + +use std::fmt::Debug; + +use p3_baby_bear::{BabyBear, GenericPoseidon2LinearLayersBabyBear, Poseidon2BabyBear}; +use p3_blake3_air::Blake3Air; +use p3_dft::Radix2DitParallel; +use p3_field::extension::BinomialExtensionField; +use p3_keccak::VECTOR_LEN; +use p3_keccak_air::KeccakAir; +use p3_koala_bear::{GenericPoseidon2LinearLayersKoalaBear, KoalaBear, Poseidon2KoalaBear}; +use p3_mersenne_31::{GenericPoseidon2LinearLayersMersenne31, Mersenne31, Poseidon2Mersenne31}; +use p3_monty_31::dft::RecursiveDft; +use p3_poseidon2_air::{Poseidon2Air, RoundConstants, VectorizedPoseidon2Air}; +use rand::SeedableRng; +use rand::rngs::SmallRng; + +use crate::dfts::DftChoice; +use crate::proofs::{ + prove_m31_keccak, prove_m31_poseidon2, prove_monty31_keccak, prove_monty31_poseidon2, +}; + +// 128 rows for the Generic Poseidon2 AIR. +// Wider traces will be make shorter. +const TRACE_SIZE: usize = 1 << 7; + +// General constants for constructing the Poseidon2 AIR. +const P2_WIDTH: usize = 16; +const P2_HALF_FULL_ROUNDS: usize = 4; +const P2_LOG_VECTOR_LEN: u8 = 3; +const P2_VECTOR_LEN: usize = 1 << P2_LOG_VECTOR_LEN; + +#[test] +fn test_end_to_end_koalabear_vectorized_poseidon2_hashes_recursive_dft_poseidon2_merkle_tree() +-> Result<(), impl Debug> { + // WARNING: Use a real cryptographic PRNG in applications!! + let mut rng = SmallRng::seed_from_u64(1); + + type EF = BinomialExtensionField; + + let constants = RoundConstants::from_rng(&mut rng); + const SBOX_DEGREE: u64 = 3; + const SBOX_REGISTERS: usize = 0; + const PARTIAL_ROUNDS: usize = 20; + + let proof_goal: VectorizedPoseidon2Air< + KoalaBear, + GenericPoseidon2LinearLayersKoalaBear, + P2_WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + P2_HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + P2_VECTOR_LEN, + > = VectorizedPoseidon2Air::new(constants); + + let dft = DftChoice::Recursive(RecursiveDft::new(TRACE_SIZE >> VECTOR_LEN)); + + let perm16 = Poseidon2KoalaBear::<16>::new_from_rng_128(&mut rng); + let perm24 = Poseidon2KoalaBear::<24>::new_from_rng_128(&mut rng); + + prove_monty31_poseidon2::<_, EF, _, _, _, _>(proof_goal, dft, TRACE_SIZE, perm16, perm24) +} + +#[test] +fn test_end_to_end_koalabear_poseidon2_hashes_recursive_dft_keccak_merkle_tree() +-> Result<(), impl Debug> { + let num_hashes = TRACE_SIZE; + + // WARNING: Use a real cryptographic PRNG in applications!! + let mut rng = SmallRng::seed_from_u64(1); + + type EF = BinomialExtensionField; + + let constants = RoundConstants::from_rng(&mut rng); + const SBOX_DEGREE: u64 = 3; + const SBOX_REGISTERS: usize = 0; + const PARTIAL_ROUNDS: usize = 20; + + let proof_goal: Poseidon2Air< + KoalaBear, + GenericPoseidon2LinearLayersKoalaBear, + P2_WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + P2_HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + > = Poseidon2Air::new(constants); + + let dft = DftChoice::Recursive(RecursiveDft::new(TRACE_SIZE << 1)); + + prove_monty31_keccak::<_, EF, _, _>(proof_goal, dft, num_hashes) +} + +#[test] +fn test_end_to_end_koalabear_keccak_hashes_parallel_dft_keccak_merkle_tree() +-> Result<(), impl Debug> { + let num_hashes = TRACE_SIZE / 24; + + type EF = BinomialExtensionField; + + let proof_goal = KeccakAir {}; + + let dft = DftChoice::Parallel(Radix2DitParallel::default()); + + prove_monty31_keccak::<_, EF, _, _>(proof_goal, dft, num_hashes) +} + +#[test] +fn test_end_to_end_babybear_vectorized_poseidon2_hashes_recursive_dft_poseidon2_merkle_tree() +-> Result<(), impl Debug> { + // WARNING: Use a real cryptographic PRNG in applications!! + let mut rng = SmallRng::seed_from_u64(1); + + type EF = BinomialExtensionField; + + let constants = RoundConstants::from_rng(&mut rng); + const SBOX_DEGREE: u64 = 3; + const SBOX_REGISTERS: usize = 0; + const PARTIAL_ROUNDS: usize = 20; + + let proof_goal: Poseidon2Air< + BabyBear, + GenericPoseidon2LinearLayersBabyBear, + P2_WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + P2_HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + > = Poseidon2Air::new(constants); + + let dft = DftChoice::Recursive(RecursiveDft::new(TRACE_SIZE << 1)); + + let perm16 = Poseidon2BabyBear::<16>::new_from_rng_128(&mut rng); + let perm24 = Poseidon2BabyBear::<24>::new_from_rng_128(&mut rng); + + prove_monty31_poseidon2::<_, EF, _, _, _, _>(proof_goal, dft, TRACE_SIZE, perm16, perm24) +} + +#[test] +fn test_end_to_end_babybear_poseidon2_hashes_parallel_dft_poseidon2_merkle_tree() +-> Result<(), impl Debug> { + // WARNING: Use a real cryptographic PRNG in applications!! + let mut rng = SmallRng::seed_from_u64(1); + + type EF = BinomialExtensionField; + + let constants = RoundConstants::from_rng(&mut rng); + const SBOX_DEGREE: u64 = 3; + const SBOX_REGISTERS: usize = 0; + const PARTIAL_ROUNDS: usize = 20; + + let proof_goal: Poseidon2Air< + BabyBear, + GenericPoseidon2LinearLayersBabyBear, + P2_WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + P2_HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + > = Poseidon2Air::new(constants); + + let dft = DftChoice::Parallel(Radix2DitParallel::default()); + + let perm16 = Poseidon2BabyBear::<16>::new_from_rng_128(&mut rng); + let perm24 = Poseidon2BabyBear::<24>::new_from_rng_128(&mut rng); + + prove_monty31_poseidon2::<_, EF, _, _, _, _>(proof_goal, dft, TRACE_SIZE, perm16, perm24) +} + +#[test] +fn test_end_to_end_babybear_blake3_hashes_parallel_dft_poseidon2_merkle_tree() +-> Result<(), impl Debug> { + let num_hashes = TRACE_SIZE >> 4; + + // WARNING: Use a real cryptographic PRNG in applications!! + let mut rng = SmallRng::seed_from_u64(1); + + type EF = BinomialExtensionField; + + let proof_goal = Blake3Air {}; + + let dft = DftChoice::Parallel(Radix2DitParallel::default()); + + let perm16 = Poseidon2BabyBear::<16>::new_from_rng_128(&mut rng); + let perm24 = Poseidon2BabyBear::<24>::new_from_rng_128(&mut rng); + + prove_monty31_poseidon2::<_, EF, _, _, _, _>(proof_goal, dft, num_hashes, perm16, perm24) +} + +#[test] +fn test_end_to_end_mersenne_31_keccak_hashes_keccak_merkle_tree() -> Result<(), impl Debug> { + let num_hashes = TRACE_SIZE / 24; + let proof_goal = KeccakAir {}; + + prove_m31_keccak(proof_goal, num_hashes) +} + +#[test] +fn test_end_to_end_mersenne31_blake3_hashes_keccak_merkle_tree() -> Result<(), impl Debug> { + let num_hashes = TRACE_SIZE >> 4; + let proof_goal = Blake3Air {}; + + prove_m31_keccak(proof_goal, num_hashes) +} + +#[test] +fn test_end_to_end_mersenne31_vectorized_poseidon2_hashes_poseidon2_merkle_tree() +-> Result<(), impl Debug> { + type EF = BinomialExtensionField; + + // WARNING: Use a real cryptographic PRNG in applications!! + let mut rng = SmallRng::seed_from_u64(1); + + let constants = RoundConstants::from_rng(&mut rng); + + // Field specific constants for constructing the Poseidon2 AIR. + const SBOX_DEGREE: u64 = 5; + const SBOX_REGISTERS: usize = 1; + const PARTIAL_ROUNDS: usize = 14; + + let proof_goal: VectorizedPoseidon2Air< + Mersenne31, + GenericPoseidon2LinearLayersMersenne31, + P2_WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + P2_HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + P2_VECTOR_LEN, + > = VectorizedPoseidon2Air::new(constants); + + let perm16 = Poseidon2Mersenne31::<16>::new_from_rng_128(&mut rng); + let perm24 = Poseidon2Mersenne31::<24>::new_from_rng_128(&mut rng); + + prove_m31_poseidon2::<_, EF, _, _, _>(proof_goal, TRACE_SIZE, perm16, perm24) +} + +#[test] +fn test_end_to_end_mersenne31_poseidon2_hashes_keccak_merkle_tree() -> Result<(), impl Debug> { + // WARNING: Use a real cryptographic PRNG in applications!! + let mut rng = SmallRng::seed_from_u64(1); + + let constants = RoundConstants::from_rng(&mut rng); + + // Field specific constants for constructing the Poseidon2 AIR. + const SBOX_DEGREE: u64 = 5; + const SBOX_REGISTERS: usize = 1; + const PARTIAL_ROUNDS: usize = 14; + + let proof_goal: Poseidon2Air< + Mersenne31, + GenericPoseidon2LinearLayersMersenne31, + P2_WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + P2_HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + > = Poseidon2Air::new(constants); + + prove_m31_keccak(proof_goal, TRACE_SIZE) +} diff --git a/CoqOfRust/plonky3/examples/src/types.rs b/CoqOfRust/plonky3/examples/src/types.rs new file mode 100644 index 000000000..2050a24b8 --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/types.rs @@ -0,0 +1,70 @@ +//! This contains a large number of type definitions which help simplify the code in other files and keep clippy happy. +//! +//! In particular this builds up to defining the types `KeccakStarkConfig`, +//! `KeccakCircleStarkConfig`, `Poseidon2StarkConfig`, `Poseidon2CircleStarkConfig`. +//! These are needed to define our proof functions. + +use p3_challenger::{DuplexChallenger, HashChallenger, SerializingChallenger32}; +use p3_circle::CirclePcs; +use p3_commit::ExtensionMmcs; +use p3_field::Field; +use p3_fri::TwoAdicFriPcs; +use p3_keccak::{Keccak256Hash, KeccakF}; +use p3_merkle_tree::MerkleTreeMmcs; +use p3_symmetric::{ + CompressionFunctionFromHasher, PaddingFreeSponge, SerializingHasher32To64, TruncatedPermutation, +}; +use p3_uni_stark::StarkConfig; + +// Types related to using Keccak in the Merkle tree. +const KECCAK_VECTOR_LEN: usize = p3_keccak::VECTOR_LEN; +pub(crate) type KeccakCompressionFunction = + CompressionFunctionFromHasher, 2, 4>; +pub(crate) type KeccakMerkleMmcs = MerkleTreeMmcs< + [F; KECCAK_VECTOR_LEN], + [u64; KECCAK_VECTOR_LEN], + SerializingHasher32To64>, + KeccakCompressionFunction, + 4, +>; + +pub(crate) type KeccakStarkConfig = StarkConfig< + TwoAdicFriPcs, ExtensionMmcs>>, + EF, + SerializingChallenger32>, +>; +pub(crate) type KeccakCircleStarkConfig = StarkConfig< + CirclePcs, ExtensionMmcs>>, + EF, + SerializingChallenger32>, +>; + +// Types related to using Poseidon2 in the Merkle tree. +pub(crate) type Poseidon2Sponge = PaddingFreeSponge; +pub(crate) type Poseidon2Compression = TruncatedPermutation; +pub(crate) type Poseidon2MerkleMmcs = MerkleTreeMmcs< + ::Packing, + ::Packing, + Poseidon2Sponge, + Poseidon2Compression, + 8, +>; +pub(crate) type Poseidon2StarkConfig = StarkConfig< + TwoAdicFriPcs< + F, + DFT, + Poseidon2MerkleMmcs, + ExtensionMmcs>, + >, + EF, + DuplexChallenger, +>; +pub(crate) type Poseidon2CircleStarkConfig = StarkConfig< + CirclePcs< + F, + Poseidon2MerkleMmcs, + ExtensionMmcs>, + >, + EF, + DuplexChallenger, +>; diff --git a/CoqOfRust/plonky3/examples/src/types.v b/CoqOfRust/plonky3/examples/src/types.v new file mode 100644 index 000000000..8efeda84a --- /dev/null +++ b/CoqOfRust/plonky3/examples/src/types.v @@ -0,0 +1,522 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module types. + Definition value_KECCAK_VECTOR_LEN (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (get_constant (| "p3_keccak::sse2::VECTOR_LEN", Ty.path "usize" |))). + + Global Instance Instance_IsConstant_value_KECCAK_VECTOR_LEN : + M.IsFunction.C "p3_examples::types::KECCAK_VECTOR_LEN" value_KECCAK_VECTOR_LEN. + Admitted. + Global Typeclasses Opaque value_KECCAK_VECTOR_LEN. + + Axiom KeccakCompressionFunction : + (Ty.path "p3_examples::types::KeccakCompressionFunction") = + (Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]). + + Axiom KeccakMerkleMmcs : + forall (F : Ty.t), + (Ty.apply (Ty.path "p3_examples::types::KeccakMerkleMmcs") [] [ F ]) = + (Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ M.unevaluated_const (mk_str (| "p3_examples_types_KeccakMerkleMmcs_discriminant" |)) ] + [ F ]; + Ty.apply + (Ty.path "array") + [ M.unevaluated_const (mk_str (| "p3_examples_types_KeccakMerkleMmcs_discriminant" |)) ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]). + + Axiom KeccakStarkConfig : + forall (F EF DFT : Ty.t), + (Ty.apply (Ty.path "p3_examples::types::KeccakStarkConfig") [] [ F; EF; DFT ]) = + (Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_examples_types_KeccakMerkleMmcs_discriminant" |)) + ] + [ F ]; + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_examples_types_KeccakMerkleMmcs_discriminant" |)) + ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_examples_types_KeccakMerkleMmcs_discriminant" |)) + ] + [ F ]; + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_examples_types_KeccakMerkleMmcs_discriminant" |)) + ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ]). + + Axiom KeccakCircleStarkConfig : + forall (F EF : Ty.t), + (Ty.apply (Ty.path "p3_examples::types::KeccakCircleStarkConfig") [] [ F; EF ]) = + (Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_examples_types_KeccakMerkleMmcs_discriminant" |)) + ] + [ F ]; + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_examples_types_KeccakMerkleMmcs_discriminant" |)) + ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_examples_types_KeccakMerkleMmcs_discriminant" |)) + ] + [ F ]; + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_examples_types_KeccakMerkleMmcs_discriminant" |)) + ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ]; + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ Value.Integer IntegerKind.Usize 2; Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 25; + Value.Integer IntegerKind.Usize 17; + Value.Integer IntegerKind.Usize 4 + ] + [ Ty.path "p3_keccak::KeccakF" ] + ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::serializing_challenger::SerializingChallenger32") + [] + [ + F; + Ty.apply + (Ty.path "p3_challenger::hash_challenger::HashChallenger") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8"; Ty.path "p3_keccak::Keccak256Hash" ] + ] + ]). + + Axiom Poseidon2Sponge : + forall (Perm24 : Ty.t), + (Ty.apply (Ty.path "p3_examples::types::Poseidon2Sponge") [] [ Perm24 ]) = + (Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]). + + Axiom Poseidon2Compression : + forall (Perm16 : Ty.t), + (Ty.apply (Ty.path "p3_examples::types::Poseidon2Compression") [] [ Perm16 ]) = + (Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ]). + + Axiom Poseidon2MerkleMmcs : + forall (F Perm16 Perm24 : Ty.t), + (Ty.apply (Ty.path "p3_examples::types::Poseidon2MerkleMmcs") [] [ F; Perm16; Perm24 ]) = + (Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]). + + Axiom Poseidon2StarkConfig : + forall (F EF DFT Perm16 Perm24 : Ty.t), + (Ty.apply + (Ty.path "p3_examples::types::Poseidon2StarkConfig") + [] + [ F; EF; DFT; Perm16; Perm24 ]) = + (Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ + F; + DFT; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ]). + + Axiom Poseidon2CircleStarkConfig : + forall (F EF Perm16 Perm24 : Ty.t), + (Ty.apply + (Ty.path "p3_examples::types::Poseidon2CircleStarkConfig") + [] + [ F; EF; Perm16; Perm24 ]) = + (Ty.apply + (Ty.path "p3_uni_stark::config::StarkConfig") + [] + [ + Ty.apply + (Ty.path "p3_circle::pcs::CirclePcs") + [] + [ + F; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ]; + Ty.apply + (Ty.path "p3_commit::adapters::extension_mmcs::ExtensionMmcs") + [] + [ + F; + EF; + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.apply + (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") + [ + Value.Integer IntegerKind.Usize 24; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 8 + ] + [ Perm24 ]; + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 16 + ] + [ Perm16 ] + ] + ] + ]; + EF; + Ty.apply + (Ty.path "p3_challenger::duplex_challenger::DuplexChallenger") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 16 ] + [ F; Perm24 ] + ]). +End types. diff --git a/CoqOfRust/plonky3/field-testing/src/bench_func.rs b/CoqOfRust/plonky3/field-testing/src/bench_func.rs new file mode 100644 index 000000000..037add1b8 --- /dev/null +++ b/CoqOfRust/plonky3/field-testing/src/bench_func.rs @@ -0,0 +1,317 @@ +use alloc::format; +use alloc::vec::Vec; + +use criterion::{BatchSize, Criterion, black_box}; +use p3_field::{Field, PrimeCharacteristicRing}; +use rand::distr::StandardUniform; +use rand::prelude::Distribution; +use rand::rngs::SmallRng; +use rand::{Rng, SeedableRng}; + +pub fn benchmark_square(c: &mut Criterion, name: &str) +where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + c.bench_function(&format!("{} square", name), |b| { + b.iter(|| black_box(black_box(x).square())) + }); +} + +pub fn benchmark_inv(c: &mut Criterion, name: &str) +where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + c.bench_function(&format!("{} inv", name), |b| { + b.iter(|| black_box(black_box(x)).inverse()) + }); +} + +pub fn benchmark_mul_2exp( + c: &mut Criterion, + name: &str, + val: u64, +) where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let mut input = Vec::new(); + for _ in 0..REPS { + input.push(rng.random::()) + } + c.bench_function(&format!("{} mul_2exp_u64 {}", name, val), |b| { + b.iter(|| input.iter_mut().for_each(|i| *i = i.mul_2exp_u64(val))) + }); +} + +pub fn benchmark_div_2exp(c: &mut Criterion, name: &str, val: u64) +where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let mut input = Vec::new(); + for _ in 0..REPS { + input.push(rng.random::()) + } + c.bench_function(&format!("{} div_2exp_u64 {}", name, val), |b| { + b.iter(|| input.iter_mut().for_each(|i| *i = i.div_2exp_u64(val))) + }); +} + +/// Benchmark the time taken to sum an array [[F; N]; REPS] by summing each array +/// [F; N] using .sum() method and accumulating the sums into an accumulator. +/// +/// Making N larger and REPS smaller (vs the opposite) leans the benchmark more sensitive towards +/// the latency (resp throughput) of the sum method. +pub fn benchmark_iter_sum( + c: &mut Criterion, + name: &str, +) where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let mut input = Vec::new(); + for _ in 0..REPS { + input.push(rng.random::<[R; N]>()) + } + c.bench_function(&format!("{} sum/{}, {}", name, REPS, N), |b| { + b.iter(|| { + let mut acc = R::ZERO; + for row in &mut input { + acc += row.iter().copied().sum() + } + acc + }) + }); +} + +/// Benchmark the time taken to sum an array [[F; N]; REPS] by summing each array +/// [F; N] using sum_array method and accumulating the sums into an accumulator. +/// +/// Making N larger and REPS smaller (vs the opposite) leans the benchmark more sensitive towards +/// the latency (resp throughput) of the sum method. +pub fn benchmark_sum_array( + c: &mut Criterion, + name: &str, +) where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let mut input = Vec::new(); + for _ in 0..REPS { + input.push(rng.random::<[R; N]>()) + } + c.bench_function(&format!("{} tree sum/{}, {}", name, REPS, N), |b| { + b.iter(|| { + let mut acc = R::ZERO; + for row in &mut input { + acc += R::sum_array::(row) + } + acc + }) + }); +} + +pub fn benchmark_add_latency( + c: &mut Criterion, + name: &str, +) where + StandardUniform: Distribution, +{ + c.bench_function(&format!("add-latency/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + let mut vec = Vec::new(); + for _ in 0..N { + vec.push(rng.random::()) + } + vec + }, + |x| x.iter().fold(R::ZERO, |x, y| x + *y), + BatchSize::SmallInput, + ) + }); +} + +pub fn benchmark_add_throughput( + c: &mut Criterion, + name: &str, +) where + StandardUniform: Distribution, +{ + c.bench_function(&format!("add-throughput/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + ( + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + ) + }, + |(mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h, mut i, mut j)| { + for _ in 0..N { + (a, b, c, d, e, f, g, h, i, j) = ( + a + b, + b + c, + c + d, + d + e, + e + f, + f + g, + g + h, + h + i, + i + j, + j + a, + ); + } + (a, b, c, d, e, f, g, h, i, j) + }, + BatchSize::SmallInput, + ) + }); +} + +pub fn benchmark_sub_latency( + c: &mut Criterion, + name: &str, +) where + StandardUniform: Distribution, +{ + c.bench_function(&format!("sub-latency/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + let mut vec = Vec::new(); + for _ in 0..N { + vec.push(rng.random::()) + } + vec + }, + |x| x.iter().fold(R::ZERO, |x, y| x - *y), + BatchSize::SmallInput, + ) + }); +} + +pub fn benchmark_sub_throughput( + c: &mut Criterion, + name: &str, +) where + StandardUniform: Distribution, +{ + c.bench_function(&format!("sub-throughput/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + ( + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + ) + }, + |(mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h, mut i, mut j)| { + for _ in 0..N { + (a, b, c, d, e, f, g, h, i, j) = ( + a - b, + b - c, + c - d, + d - e, + e - f, + f - g, + g - h, + h - i, + i - j, + j - a, + ); + } + (a, b, c, d, e, f, g, h, i, j) + }, + BatchSize::SmallInput, + ) + }); +} + +pub fn benchmark_mul_latency( + c: &mut Criterion, + name: &str, +) where + StandardUniform: Distribution, +{ + c.bench_function(&format!("mul-latency/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + let mut vec = Vec::new(); + for _ in 0..N { + vec.push(rng.random::()) + } + vec + }, + |x| x.iter().fold(R::ZERO, |x, y| x * *y), + BatchSize::SmallInput, + ) + }); +} + +pub fn benchmark_mul_throughput( + c: &mut Criterion, + name: &str, +) where + StandardUniform: Distribution, +{ + c.bench_function(&format!("mul-throughput/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + ( + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + ) + }, + |(mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h, mut i, mut j)| { + for _ in 0..N { + (a, b, c, d, e, f, g, h, i, j) = ( + a * b, + b * c, + c * d, + d * e, + e * f, + f * g, + g * h, + h * i, + i * j, + j * a, + ); + } + (a, b, c, d, e, f, g, h, i, j) + }, + BatchSize::SmallInput, + ) + }); +} diff --git a/CoqOfRust/plonky3/field-testing/src/bench_func.v b/CoqOfRust/plonky3/field-testing/src/bench_func.v new file mode 100644 index 000000000..931e3619c --- /dev/null +++ b/CoqOfRust/plonky3/field-testing/src/bench_func.v @@ -0,0 +1,9946 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module bench_func. + (* + pub fn benchmark_square(c: &mut Criterion, name: &str) + where + StandardUniform: Distribution, + { + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + c.bench_function(&format!("{} square", name), |b| { + b.iter(|| black_box(black_box(x).square())) + }); + } + *) + Definition benchmark_square (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ c; name ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ x : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ F ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "" |); + mk_str (| " square" |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter", + [], + [ F; Ty.function [ Ty.tuple [] ] F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + F, + M.get_function (| + "criterion::black_box", + [], + [ F ] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_function (| + "criterion::black_box", + [], + [ F ] + |), + [ M.read (| x |) ] + |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_square : + M.IsFunction.C "p3_field_testing::bench_func::benchmark_square" benchmark_square. + Admitted. + Global Typeclasses Opaque benchmark_square. + + (* + pub fn benchmark_inv(c: &mut Criterion, name: &str) + where + StandardUniform: Distribution, + { + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + c.bench_function(&format!("{} inv", name), |b| { + b.iter(|| black_box(black_box(x)).inverse()) + }); + } + *) + Definition benchmark_inv (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ c; name ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ x : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ F ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "" |); mk_str (| " inv" |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter", + [], + [ F; Ty.function [ Ty.tuple [] ] F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_function (| + "criterion::black_box", + [], + [ F ] + |), + [ + M.call_closure (| + F, + M.get_function (| + "criterion::black_box", + [], + [ F ] + |), + [ M.read (| x |) ] + |) + ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_inv : + M.IsFunction.C "p3_field_testing::bench_func::benchmark_inv" benchmark_inv. + Admitted. + Global Typeclasses Opaque benchmark_inv. + + (* + pub fn benchmark_mul_2exp( + c: &mut Criterion, + name: &str, + val: u64, + ) where + StandardUniform: Distribution, + { + let mut rng = SmallRng::seed_from_u64(1); + let mut input = Vec::new(); + for _ in 0..REPS { + input.push(rng.random::()) + } + c.bench_function(&format!("{} mul_2exp_u64 {}", name, val), |b| { + b.iter(|| input.iter_mut().for_each(|i| *i = i.mul_2exp_u64(val))) + }); + } + *) + Definition benchmark_mul_2exp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ REPS ], [ R ], [ c; name; val ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + let val := M.alloc (| val |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ input : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ R; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ R; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ R; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", REPS) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, input |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "" |); + mk_str (| " mul_2exp_u64 " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "u64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + val + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter", + [], + [ Ty.tuple []; Ty.function [ Ty.tuple [] ] (Ty.tuple []) ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ R ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ R ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ R ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ R ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ R ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + input + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ R ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := + M.copy (| γ |) in + M.write (| + M.deref (| + M.read (| i |) + |), + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "mul_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + i + |) + |) + |); + M.read (| + val + |) + ] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_mul_2exp : + M.IsFunction.C "p3_field_testing::bench_func::benchmark_mul_2exp" benchmark_mul_2exp. + Admitted. + Global Typeclasses Opaque benchmark_mul_2exp. + + (* + pub fn benchmark_div_2exp(c: &mut Criterion, name: &str, val: u64) + where + StandardUniform: Distribution, + { + let mut rng = SmallRng::seed_from_u64(1); + let mut input = Vec::new(); + for _ in 0..REPS { + input.push(rng.random::()) + } + c.bench_function(&format!("{} div_2exp_u64 {}", name, val), |b| { + b.iter(|| input.iter_mut().for_each(|i| *i = i.div_2exp_u64(val))) + }); + } + *) + Definition benchmark_div_2exp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ REPS ], [ F ], [ c; name; val ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + let val := M.alloc (| val |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ input : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", REPS) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, input |); + M.call_closure (| + F, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ F ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "" |); + mk_str (| " div_2exp_u64 " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "u64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + val + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter", + [], + [ Ty.tuple []; Ty.function [ Ty.tuple [] ] (Ty.tuple []) ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ F ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ F ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + input + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ F ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := + M.copy (| γ |) in + M.write (| + M.deref (| + M.read (| i |) + |), + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + i + |) + |) + |); + M.read (| + val + |) + ] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_div_2exp : + M.IsFunction.C "p3_field_testing::bench_func::benchmark_div_2exp" benchmark_div_2exp. + Admitted. + Global Typeclasses Opaque benchmark_div_2exp. + + (* + pub fn benchmark_iter_sum( + c: &mut Criterion, + name: &str, + ) where + StandardUniform: Distribution, + { + let mut rng = SmallRng::seed_from_u64(1); + let mut input = Vec::new(); + for _ in 0..REPS { + input.push(rng.random::<[R; N]>()) + } + c.bench_function(&format!("{} sum/{}, {}", name, REPS, N), |b| { + b.iter(|| { + let mut acc = R::ZERO; + for row in &mut input { + acc += row.iter().copied().sum() + } + acc + }) + }); + } + *) + Definition benchmark_iter_sum (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N; REPS ], [ R ], [ c; name ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ input : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ N ] [ R ]; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ N ] [ R ]; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ N ] [ R ]; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", REPS) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ R ]; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, input |); + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ R ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ Ty.apply (Ty.path "array") [ N ] [ R ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 3 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "" |); + mk_str (| " sum/" |); + mk_str (| ", " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| REPS |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| N |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter", + [], + [ R; Ty.function [ Ty.tuple [] ] R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] R ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ acc : + Ty.apply (Ty.path "*") [] [ R ] := + M.copy (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ R ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ R ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + input + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "array") + [ N ] + [ R ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "array") + [ N ] + [ R ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let row := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + acc + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + R + ] + ], + [], + [], + "sum", + [], + [ R + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + R + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + R + ], + [], + [], + "copied", + [], + [ + R + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + R + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + R + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + row + |) + |) + |)) + ] + |) + ] + |) + ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)) in + acc + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_iter_sum : + M.IsFunction.C "p3_field_testing::bench_func::benchmark_iter_sum" benchmark_iter_sum. + Admitted. + Global Typeclasses Opaque benchmark_iter_sum. + + (* + pub fn benchmark_sum_array( + c: &mut Criterion, + name: &str, + ) where + StandardUniform: Distribution, + { + let mut rng = SmallRng::seed_from_u64(1); + let mut input = Vec::new(); + for _ in 0..REPS { + input.push(rng.random::<[R; N]>()) + } + c.bench_function(&format!("{} tree sum/{}, {}", name, REPS, N), |b| { + b.iter(|| { + let mut acc = R::ZERO; + for row in &mut input { + acc += R::sum_array::(row) + } + acc + }) + }); + } + *) + Definition benchmark_sum_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N; REPS ], [ R ], [ c; name ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ input : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ N ] [ R ]; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ N ] [ R ]; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ N ] [ R ]; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", REPS) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ R ]; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, input |); + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ R ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ Ty.apply (Ty.path "array") [ N ] [ R ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 3 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "" |); + mk_str (| " tree sum/" |); + mk_str (| ", " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| REPS |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| N |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter", + [], + [ R; Ty.function [ Ty.tuple [] ] R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] R ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ acc : + Ty.apply (Ty.path "*") [] [ R ] := + M.copy (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ R ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ R ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + input + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "array") + [ N ] + [ R ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "array") + [ N ] + [ R ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let row := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + acc + |); + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ N + ], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + row + |) + |) + |)) + ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)) in + acc + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_sum_array : + M.IsFunction.C "p3_field_testing::bench_func::benchmark_sum_array" benchmark_sum_array. + Admitted. + Global Typeclasses Opaque benchmark_sum_array. + + (* + pub fn benchmark_add_latency( + c: &mut Criterion, + name: &str, + ) where + StandardUniform: Distribution, + { + c.bench_function(&format!("add-latency/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + let mut vec = Vec::new(); + for _ in 0..N { + vec.push(rng.random::()) + } + vec + }, + |x| x.iter().fold(R::ZERO, |x, y| x + *y), + BatchSize::SmallInput, + ) + }); + } + *) + Definition benchmark_add_latency (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ R ], [ c; name ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "add-latency/" |); + mk_str (| " " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| N |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter_batched", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ]; + R; + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ]); + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ] + ] + ] + R + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ rng : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "rand::rngs::small::SmallRng" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 + ] + |) + |) in + let~ vec : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", N) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + vec + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)) in + vec + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path "alloc::alloc::Global" + ] + ] + ] + R + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ R ], + [], + [], + "fold", + [], + [ + R; + Ty.function + [ + Ty.tuple + [ + R; + Ty.apply + (Ty.path "&") + [] + [ R ] + ] + ] + R + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ R ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ R ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + x + |) + ] + |) + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + R; + Ty.apply + (Ty.path + "&") + [] + [ R ] + ] + ] + R + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := + M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + R; + Ty.apply + (Ty.path + "&") + [] + [ R + ] + ] + ] + R + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := + M.copy (| + γ + |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.read (| + x + |); + M.read (| + M.deref (| + M.read (| + y + |) + |) + |) + ] + |))) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + Value.StructTuple "criterion::BatchSize::SmallInput" [] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_add_latency : + M.IsFunction.C "p3_field_testing::bench_func::benchmark_add_latency" benchmark_add_latency. + Admitted. + Global Typeclasses Opaque benchmark_add_latency. + + (* + pub fn benchmark_add_throughput( + c: &mut Criterion, + name: &str, + ) where + StandardUniform: Distribution, + { + c.bench_function(&format!("add-throughput/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + ( + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + ) + }, + |(mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h, mut i, mut j)| { + for _ in 0..N { + (a, b, c, d, e, f, g, h, i, j) = ( + a + b, + b + c, + c + d, + d + e, + e + f, + f + g, + g + h, + h + i, + i + j, + j + a, + ); + } + (a, b, c, d, e, f, g, h, i, j) + }, + BatchSize::SmallInput, + ) + }); + } + *) + Definition benchmark_add_throughput (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ R ], [ c; name ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "add-throughput/" |); + mk_str (| " " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| N |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter_batched", + [], + [ + Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]; + Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]; + Ty.function + [ Ty.tuple [] ] + (Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]); + Ty.function + [ Ty.tuple [ Ty.tuple [ R; R; R; R; R; R; R; R; R; R ] ] + ] + (Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]) + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ R; R; R; R; R; R; R; R; R; R ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ rng : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "rand::rngs::small::SmallRng" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 + ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ R; R; R; R; R; R; R; R; R; R ] + ] + ] + (Ty.tuple + [ R; R; R; R; R; R; R; R; R; R ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let γ0_3 := + M.SubPointer.get_tuple_field (| + γ, + 3 + |) in + let γ0_4 := + M.SubPointer.get_tuple_field (| + γ, + 4 + |) in + let γ0_5 := + M.SubPointer.get_tuple_field (| + γ, + 5 + |) in + let γ0_6 := + M.SubPointer.get_tuple_field (| + γ, + 6 + |) in + let γ0_7 := + M.SubPointer.get_tuple_field (| + γ, + 7 + |) in + let γ0_8 := + M.SubPointer.get_tuple_field (| + γ, + 8 + |) in + let γ0_9 := + M.SubPointer.get_tuple_field (| + γ, + 9 + |) in + let a := M.copy (| γ0_0 |) in + let b := M.copy (| γ0_1 |) in + let c := M.copy (| γ0_2 |) in + let d := M.copy (| γ0_3 |) in + let e := M.copy (| γ0_4 |) in + let f := M.copy (| γ0_5 |) in + let g := M.copy (| γ0_6 |) in + let h := M.copy (| γ0_7 |) in + let i := M.copy (| γ0_8 |) in + let j := M.copy (| γ0_9 |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", N) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + Value.Tuple + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ + R + ], + "add", + [], + [] + |), + [ + M.read (| + a + |); + M.read (| + b + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ + R + ], + "add", + [], + [] + |), + [ + M.read (| + b + |); + M.read (| + c + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ + R + ], + "add", + [], + [] + |), + [ + M.read (| + c + |); + M.read (| + d + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ + R + ], + "add", + [], + [] + |), + [ + M.read (| + d + |); + M.read (| + e + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ + R + ], + "add", + [], + [] + |), + [ + M.read (| + e + |); + M.read (| + f + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ + R + ], + "add", + [], + [] + |), + [ + M.read (| + f + |); + M.read (| + g + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ + R + ], + "add", + [], + [] + |), + [ + M.read (| + g + |); + M.read (| + h + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ + R + ], + "add", + [], + [] + |), + [ + M.read (| + h + |); + M.read (| + i + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ + R + ], + "add", + [], + [] + |), + [ + M.read (| + i + |); + M.read (| + j + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ + R + ], + "add", + [], + [] + |), + [ + M.read (| + j + |); + M.read (| + a + |) + ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let + γ0_3 := + M.SubPointer.get_tuple_field (| + γ, + 3 + |) in + let + γ0_4 := + M.SubPointer.get_tuple_field (| + γ, + 4 + |) in + let + γ0_5 := + M.SubPointer.get_tuple_field (| + γ, + 5 + |) in + let + γ0_6 := + M.SubPointer.get_tuple_field (| + γ, + 6 + |) in + let + γ0_7 := + M.SubPointer.get_tuple_field (| + γ, + 7 + |) in + let + γ0_8 := + M.SubPointer.get_tuple_field (| + γ, + 8 + |) in + let + γ0_9 := + M.SubPointer.get_tuple_field (| + γ, + 9 + |) in + let + lhs := + M.copy (| + γ0_0 + |) in + let + lhs := + M.copy (| + γ0_1 + |) in + let + lhs := + M.copy (| + γ0_2 + |) in + let + lhs := + M.copy (| + γ0_3 + |) in + let + lhs := + M.copy (| + γ0_4 + |) in + let + lhs := + M.copy (| + γ0_5 + |) in + let + lhs := + M.copy (| + γ0_6 + |) in + let + lhs := + M.copy (| + γ0_7 + |) in + let + lhs := + M.copy (| + γ0_8 + |) in + let + lhs := + M.copy (| + γ0_9 + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + a, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + b, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + c, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + d, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + e, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + f, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + g, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + h, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + i, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + j, + M.read (| + lhs + |) + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)) in + M.alloc (| + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| c |); + M.read (| d |); + M.read (| e |); + M.read (| f |); + M.read (| g |); + M.read (| h |); + M.read (| i |); + M.read (| j |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + Value.StructTuple "criterion::BatchSize::SmallInput" [] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_add_throughput : + M.IsFunction.C + "p3_field_testing::bench_func::benchmark_add_throughput" + benchmark_add_throughput. + Admitted. + Global Typeclasses Opaque benchmark_add_throughput. + + (* + pub fn benchmark_sub_latency( + c: &mut Criterion, + name: &str, + ) where + StandardUniform: Distribution, + { + c.bench_function(&format!("sub-latency/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + let mut vec = Vec::new(); + for _ in 0..N { + vec.push(rng.random::()) + } + vec + }, + |x| x.iter().fold(R::ZERO, |x, y| x - *y), + BatchSize::SmallInput, + ) + }); + } + *) + Definition benchmark_sub_latency (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ R ], [ c; name ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "sub-latency/" |); + mk_str (| " " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| N |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter_batched", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ]; + R; + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ]); + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ] + ] + ] + R + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ rng : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "rand::rngs::small::SmallRng" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 + ] + |) + |) in + let~ vec : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", N) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + vec + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)) in + vec + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path "alloc::alloc::Global" + ] + ] + ] + R + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ R ], + [], + [], + "fold", + [], + [ + R; + Ty.function + [ + Ty.tuple + [ + R; + Ty.apply + (Ty.path "&") + [] + [ R ] + ] + ] + R + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ R ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ R ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + x + |) + ] + |) + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + R; + Ty.apply + (Ty.path + "&") + [] + [ R ] + ] + ] + R + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := + M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + R; + Ty.apply + (Ty.path + "&") + [] + [ R + ] + ] + ] + R + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := + M.copy (| + γ + |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.read (| + x + |); + M.read (| + M.deref (| + M.read (| + y + |) + |) + |) + ] + |))) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + Value.StructTuple "criterion::BatchSize::SmallInput" [] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_sub_latency : + M.IsFunction.C "p3_field_testing::bench_func::benchmark_sub_latency" benchmark_sub_latency. + Admitted. + Global Typeclasses Opaque benchmark_sub_latency. + + (* + pub fn benchmark_sub_throughput( + c: &mut Criterion, + name: &str, + ) where + StandardUniform: Distribution, + { + c.bench_function(&format!("sub-throughput/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + ( + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + ) + }, + |(mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h, mut i, mut j)| { + for _ in 0..N { + (a, b, c, d, e, f, g, h, i, j) = ( + a - b, + b - c, + c - d, + d - e, + e - f, + f - g, + g - h, + h - i, + i - j, + j - a, + ); + } + (a, b, c, d, e, f, g, h, i, j) + }, + BatchSize::SmallInput, + ) + }); + } + *) + Definition benchmark_sub_throughput (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ R ], [ c; name ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "sub-throughput/" |); + mk_str (| " " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| N |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter_batched", + [], + [ + Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]; + Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]; + Ty.function + [ Ty.tuple [] ] + (Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]); + Ty.function + [ Ty.tuple [ Ty.tuple [ R; R; R; R; R; R; R; R; R; R ] ] + ] + (Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]) + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ R; R; R; R; R; R; R; R; R; R ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ rng : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "rand::rngs::small::SmallRng" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 + ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ R; R; R; R; R; R; R; R; R; R ] + ] + ] + (Ty.tuple + [ R; R; R; R; R; R; R; R; R; R ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let γ0_3 := + M.SubPointer.get_tuple_field (| + γ, + 3 + |) in + let γ0_4 := + M.SubPointer.get_tuple_field (| + γ, + 4 + |) in + let γ0_5 := + M.SubPointer.get_tuple_field (| + γ, + 5 + |) in + let γ0_6 := + M.SubPointer.get_tuple_field (| + γ, + 6 + |) in + let γ0_7 := + M.SubPointer.get_tuple_field (| + γ, + 7 + |) in + let γ0_8 := + M.SubPointer.get_tuple_field (| + γ, + 8 + |) in + let γ0_9 := + M.SubPointer.get_tuple_field (| + γ, + 9 + |) in + let a := M.copy (| γ0_0 |) in + let b := M.copy (| γ0_1 |) in + let c := M.copy (| γ0_2 |) in + let d := M.copy (| γ0_3 |) in + let e := M.copy (| γ0_4 |) in + let f := M.copy (| γ0_5 |) in + let g := M.copy (| γ0_6 |) in + let h := M.copy (| γ0_7 |) in + let i := M.copy (| γ0_8 |) in + let j := M.copy (| γ0_9 |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", N) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + Value.Tuple + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ + R + ], + "sub", + [], + [] + |), + [ + M.read (| + a + |); + M.read (| + b + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ + R + ], + "sub", + [], + [] + |), + [ + M.read (| + b + |); + M.read (| + c + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ + R + ], + "sub", + [], + [] + |), + [ + M.read (| + c + |); + M.read (| + d + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ + R + ], + "sub", + [], + [] + |), + [ + M.read (| + d + |); + M.read (| + e + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ + R + ], + "sub", + [], + [] + |), + [ + M.read (| + e + |); + M.read (| + f + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ + R + ], + "sub", + [], + [] + |), + [ + M.read (| + f + |); + M.read (| + g + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ + R + ], + "sub", + [], + [] + |), + [ + M.read (| + g + |); + M.read (| + h + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ + R + ], + "sub", + [], + [] + |), + [ + M.read (| + h + |); + M.read (| + i + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ + R + ], + "sub", + [], + [] + |), + [ + M.read (| + i + |); + M.read (| + j + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ + R + ], + "sub", + [], + [] + |), + [ + M.read (| + j + |); + M.read (| + a + |) + ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let + γ0_3 := + M.SubPointer.get_tuple_field (| + γ, + 3 + |) in + let + γ0_4 := + M.SubPointer.get_tuple_field (| + γ, + 4 + |) in + let + γ0_5 := + M.SubPointer.get_tuple_field (| + γ, + 5 + |) in + let + γ0_6 := + M.SubPointer.get_tuple_field (| + γ, + 6 + |) in + let + γ0_7 := + M.SubPointer.get_tuple_field (| + γ, + 7 + |) in + let + γ0_8 := + M.SubPointer.get_tuple_field (| + γ, + 8 + |) in + let + γ0_9 := + M.SubPointer.get_tuple_field (| + γ, + 9 + |) in + let + lhs := + M.copy (| + γ0_0 + |) in + let + lhs := + M.copy (| + γ0_1 + |) in + let + lhs := + M.copy (| + γ0_2 + |) in + let + lhs := + M.copy (| + γ0_3 + |) in + let + lhs := + M.copy (| + γ0_4 + |) in + let + lhs := + M.copy (| + γ0_5 + |) in + let + lhs := + M.copy (| + γ0_6 + |) in + let + lhs := + M.copy (| + γ0_7 + |) in + let + lhs := + M.copy (| + γ0_8 + |) in + let + lhs := + M.copy (| + γ0_9 + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + a, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + b, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + c, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + d, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + e, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + f, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + g, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + h, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + i, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + j, + M.read (| + lhs + |) + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)) in + M.alloc (| + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| c |); + M.read (| d |); + M.read (| e |); + M.read (| f |); + M.read (| g |); + M.read (| h |); + M.read (| i |); + M.read (| j |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + Value.StructTuple "criterion::BatchSize::SmallInput" [] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_sub_throughput : + M.IsFunction.C + "p3_field_testing::bench_func::benchmark_sub_throughput" + benchmark_sub_throughput. + Admitted. + Global Typeclasses Opaque benchmark_sub_throughput. + + (* + pub fn benchmark_mul_latency( + c: &mut Criterion, + name: &str, + ) where + StandardUniform: Distribution, + { + c.bench_function(&format!("mul-latency/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + let mut vec = Vec::new(); + for _ in 0..N { + vec.push(rng.random::()) + } + vec + }, + |x| x.iter().fold(R::ZERO, |x, y| x * *y), + BatchSize::SmallInput, + ) + }); + } + *) + Definition benchmark_mul_latency (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ R ], [ c; name ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "mul-latency/" |); + mk_str (| " " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| N |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter_batched", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ]; + R; + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ]); + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ] + ] + ] + R + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ R; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ rng : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "rand::rngs::small::SmallRng" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 + ] + |) + |) in + let~ vec : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", N) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + vec + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)) in + vec + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + R; + Ty.path "alloc::alloc::Global" + ] + ] + ] + R + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ R ], + [], + [], + "fold", + [], + [ + R; + Ty.function + [ + Ty.tuple + [ + R; + Ty.apply + (Ty.path "&") + [] + [ R ] + ] + ] + R + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ R ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ R ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + R; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + x + |) + ] + |) + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + R; + Ty.apply + (Ty.path + "&") + [] + [ R ] + ] + ] + R + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := + M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + R; + Ty.apply + (Ty.path + "&") + [] + [ R + ] + ] + ] + R + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := + M.copy (| + γ + |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.read (| + x + |); + M.read (| + M.deref (| + M.read (| + y + |) + |) + |) + ] + |))) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + Value.StructTuple "criterion::BatchSize::SmallInput" [] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_mul_latency : + M.IsFunction.C "p3_field_testing::bench_func::benchmark_mul_latency" benchmark_mul_latency. + Admitted. + Global Typeclasses Opaque benchmark_mul_latency. + + (* + pub fn benchmark_mul_throughput( + c: &mut Criterion, + name: &str, + ) where + StandardUniform: Distribution, + { + c.bench_function(&format!("mul-throughput/{} {}", N, name), |b| { + b.iter_batched( + || { + let mut rng = SmallRng::seed_from_u64(1); + ( + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + rng.random::(), + ) + }, + |(mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h, mut i, mut j)| { + for _ in 0..N { + (a, b, c, d, e, f, g, h, i, j) = ( + a * b, + b * c, + c * d, + d * e, + e * f, + f * g, + g * h, + h * i, + i * j, + j * a, + ); + } + (a, b, c, d, e, f, g, h, i, j) + }, + BatchSize::SmallInput, + ) + }); + } + *) + Definition benchmark_mul_throughput (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ R ], [ c; name ] => + ltac:(M.monadic + (let c := M.alloc (| c |) in + let name := M.alloc (| name |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::Criterion") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "bench_function", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| c |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "mul-throughput/" |); + mk_str (| " " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| N |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + name + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let b := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "criterion::bencher::Bencher") + [] + [ Ty.path "criterion::measurement::WallTime" ], + "iter_batched", + [], + [ + Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]; + Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]; + Ty.function + [ Ty.tuple [] ] + (Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]); + Ty.function + [ Ty.tuple [ Ty.tuple [ R; R; R; R; R; R; R; R; R; R ] ] + ] + (Ty.tuple [ R; R; R; R; R; R; R; R; R; R ]) + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| b |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ R; R; R; R; R; R; R; R; R; R ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ rng : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "rand::rngs::small::SmallRng" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 + ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path + "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ R; R; R; R; R; R; R; R; R; R ] + ] + ] + (Ty.tuple + [ R; R; R; R; R; R; R; R; R; R ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let γ0_3 := + M.SubPointer.get_tuple_field (| + γ, + 3 + |) in + let γ0_4 := + M.SubPointer.get_tuple_field (| + γ, + 4 + |) in + let γ0_5 := + M.SubPointer.get_tuple_field (| + γ, + 5 + |) in + let γ0_6 := + M.SubPointer.get_tuple_field (| + γ, + 6 + |) in + let γ0_7 := + M.SubPointer.get_tuple_field (| + γ, + 7 + |) in + let γ0_8 := + M.SubPointer.get_tuple_field (| + γ, + 8 + |) in + let γ0_9 := + M.SubPointer.get_tuple_field (| + γ, + 9 + |) in + let a := M.copy (| γ0_0 |) in + let b := M.copy (| γ0_1 |) in + let c := M.copy (| γ0_2 |) in + let d := M.copy (| γ0_3 |) in + let e := M.copy (| γ0_4 |) in + let f := M.copy (| γ0_5 |) in + let g := M.copy (| γ0_6 |) in + let h := M.copy (| γ0_7 |) in + let i := M.copy (| γ0_8 |) in + let j := M.copy (| γ0_9 |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", N) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + Value.Tuple + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ + R + ], + "mul", + [], + [] + |), + [ + M.read (| + a + |); + M.read (| + b + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ + R + ], + "mul", + [], + [] + |), + [ + M.read (| + b + |); + M.read (| + c + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ + R + ], + "mul", + [], + [] + |), + [ + M.read (| + c + |); + M.read (| + d + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ + R + ], + "mul", + [], + [] + |), + [ + M.read (| + d + |); + M.read (| + e + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ + R + ], + "mul", + [], + [] + |), + [ + M.read (| + e + |); + M.read (| + f + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ + R + ], + "mul", + [], + [] + |), + [ + M.read (| + f + |); + M.read (| + g + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ + R + ], + "mul", + [], + [] + |), + [ + M.read (| + g + |); + M.read (| + h + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ + R + ], + "mul", + [], + [] + |), + [ + M.read (| + h + |); + M.read (| + i + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ + R + ], + "mul", + [], + [] + |), + [ + M.read (| + i + |); + M.read (| + j + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ + R + ], + "mul", + [], + [] + |), + [ + M.read (| + j + |); + M.read (| + a + |) + ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let + γ0_3 := + M.SubPointer.get_tuple_field (| + γ, + 3 + |) in + let + γ0_4 := + M.SubPointer.get_tuple_field (| + γ, + 4 + |) in + let + γ0_5 := + M.SubPointer.get_tuple_field (| + γ, + 5 + |) in + let + γ0_6 := + M.SubPointer.get_tuple_field (| + γ, + 6 + |) in + let + γ0_7 := + M.SubPointer.get_tuple_field (| + γ, + 7 + |) in + let + γ0_8 := + M.SubPointer.get_tuple_field (| + γ, + 8 + |) in + let + γ0_9 := + M.SubPointer.get_tuple_field (| + γ, + 9 + |) in + let + lhs := + M.copy (| + γ0_0 + |) in + let + lhs := + M.copy (| + γ0_1 + |) in + let + lhs := + M.copy (| + γ0_2 + |) in + let + lhs := + M.copy (| + γ0_3 + |) in + let + lhs := + M.copy (| + γ0_4 + |) in + let + lhs := + M.copy (| + γ0_5 + |) in + let + lhs := + M.copy (| + γ0_6 + |) in + let + lhs := + M.copy (| + γ0_7 + |) in + let + lhs := + M.copy (| + γ0_8 + |) in + let + lhs := + M.copy (| + γ0_9 + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + a, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + b, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + c, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + d, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + e, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + f, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + g, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + h, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + i, + M.read (| + lhs + |) + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + j, + M.read (| + lhs + |) + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)) in + M.alloc (| + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| c |); + M.read (| d |); + M.read (| e |); + M.read (| f |); + M.read (| g |); + M.read (| h |); + M.read (| i |); + M.read (| j |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)); + Value.StructTuple "criterion::BatchSize::SmallInput" [] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_benchmark_mul_throughput : + M.IsFunction.C + "p3_field_testing::bench_func::benchmark_mul_throughput" + benchmark_mul_throughput. + Admitted. + Global Typeclasses Opaque benchmark_mul_throughput. +End bench_func. diff --git a/CoqOfRust/plonky3/field-testing/src/dft_testing.rs b/CoqOfRust/plonky3/field-testing/src/dft_testing.rs new file mode 100644 index 000000000..3d09ac317 --- /dev/null +++ b/CoqOfRust/plonky3/field-testing/src/dft_testing.rs @@ -0,0 +1,335 @@ +use p3_dft::{NaiveDft, TwoAdicSubgroupDft}; +use p3_field::{ExtensionField, TwoAdicField}; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use rand::SeedableRng; +use rand::distr::{Distribution, StandardUniform}; +use rand::rngs::SmallRng; + +pub fn test_dft_matches_naive() +where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let dft_naive = NaiveDft.dft_batch(mat.clone()); + let dft_result = dft.dft_batch(mat); + assert_eq!(dft_naive, dft_result.to_row_major_matrix()); + } +} + +pub fn test_coset_dft_matches_naive() +where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let coset_dft_naive = NaiveDft.coset_dft_batch(mat.clone(), shift); + let coset_dft_result = dft.coset_dft_batch(mat, shift); + assert_eq!(coset_dft_naive, coset_dft_result.to_row_major_matrix()); + } +} + +pub fn test_idft_matches_naive() +where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let idft_naive = NaiveDft.idft_batch(mat.clone()); + let idft_result = dft.idft_batch(mat.clone()); + assert_eq!(idft_naive, idft_result.to_row_major_matrix()); + } +} + +pub fn test_coset_idft_matches_naive() +where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let idft_naive = NaiveDft.coset_idft_batch(mat.clone(), shift); + let idft_result = dft.coset_idft_batch(mat, shift); + assert_eq!(idft_naive, idft_result.to_row_major_matrix()); + } +} + +pub fn test_lde_matches_naive() +where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let lde_naive = NaiveDft.lde_batch(mat.clone(), 1); + let lde_result = dft.lde_batch(mat, 1); + assert_eq!(lde_naive, lde_result.to_row_major_matrix()); + } +} + +pub fn test_coset_lde_matches_naive() +where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let coset_lde_naive = NaiveDft.coset_lde_batch(mat.clone(), 1, shift); + let coset_lde_result = dft.coset_lde_batch(mat, 1, shift); + assert_eq!(coset_lde_naive, coset_lde_result.to_row_major_matrix()); + } +} + +pub fn test_dft_idft_consistency() +where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let original = RowMajorMatrix::::rand(&mut rng, h, 3); + let dft_output = dft.dft_batch(original.clone()); + let idft_output = dft.idft_batch(dft_output.to_row_major_matrix()); + assert_eq!(original, idft_output.to_row_major_matrix()); + } +} + +pub fn test_dft_algebra_matches_naive() +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let dft_naive = NaiveDft.dft_batch(mat.clone()); + let dft_result = dft.dft_algebra_batch(mat); + assert_eq!(dft_naive, dft_result.to_row_major_matrix()); + } +} + +pub fn test_coset_dft_algebra_matches_naive() +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let coset_dft_naive = NaiveDft.coset_dft_batch(mat.clone(), EF::from(shift)); + let coset_dft_result = dft.coset_dft_algebra_batch(mat, shift); + assert_eq!(coset_dft_naive, coset_dft_result.to_row_major_matrix()); + } +} + +pub fn test_idft_algebra_matches_naive() +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let idft_naive = NaiveDft.idft_batch(mat.clone()); + let idft_result = dft.idft_algebra_batch(mat.clone()); + assert_eq!(idft_naive, idft_result.to_row_major_matrix()); + } +} + +pub fn test_coset_idft_algebra_matches_naive() +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let idft_naive = NaiveDft.coset_idft_batch(mat.clone(), EF::from(shift)); + let idft_result = dft.coset_idft_algebra_batch(mat, shift); + assert_eq!(idft_naive, idft_result.to_row_major_matrix()); + } +} + +pub fn test_lde_algebra_matches_naive() +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let lde_naive = NaiveDft.lde_batch(mat.clone(), 1); + let lde_result = dft.lde_algebra_batch(mat, 1); + assert_eq!(lde_naive, lde_result.to_row_major_matrix()); + } +} + +pub fn test_coset_lde_algebra_matches_naive() +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let coset_lde_naive = NaiveDft.coset_lde_batch(mat.clone(), 1, EF::from(shift)); + let coset_lde_result = dft.coset_lde_algebra_batch(mat, 1, shift); + assert_eq!(coset_lde_naive, coset_lde_result.to_row_major_matrix()); + } +} + +pub fn test_dft_idft_algebra_consistency() +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, +{ + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let original = RowMajorMatrix::::rand(&mut rng, h, 3); + let dft_output = dft.dft_algebra_batch(original.clone()); + let idft_output = dft.idft_algebra_batch(dft_output.to_row_major_matrix()); + assert_eq!(original, idft_output.to_row_major_matrix()); + } +} + +#[macro_export] +macro_rules! test_field_dft { + ($mod:ident, $field:ty, $extfield:ty, $dft:ty) => { + mod $mod { + #[test] + fn dft_matches_naive() { + $crate::test_dft_matches_naive::<$field, $dft>(); + } + + #[test] + fn coset_dft_matches_naive() { + $crate::test_coset_dft_matches_naive::<$field, $dft>(); + } + + #[test] + fn idft_matches_naive() { + $crate::test_idft_matches_naive::<$field, $dft>(); + } + + #[test] + fn coset_idft_matches_naive() { + $crate::test_coset_idft_matches_naive::<$field, $dft>(); + } + + #[test] + fn lde_matches_naive() { + $crate::test_lde_matches_naive::<$field, $dft>(); + } + + #[test] + fn coset_lde_matches_naive() { + $crate::test_coset_lde_matches_naive::<$field, $dft>(); + } + + #[test] + fn dft_idft_consistency() { + $crate::test_dft_idft_consistency::<$field, $dft>(); + } + + #[test] + fn dft_algebra_matches_naive() { + $crate::test_dft_algebra_matches_naive::<$field, $extfield, $dft>(); + } + + #[test] + fn coset_dft_algebra_matches_naive() { + $crate::test_coset_dft_algebra_matches_naive::<$field, $extfield, $dft>(); + } + + #[test] + fn idft_algebra_matches_naive() { + $crate::test_idft_algebra_matches_naive::<$field, $extfield, $dft>(); + } + + #[test] + fn coset_idft_algebra_matches_naive() { + $crate::test_coset_idft_algebra_matches_naive::<$field, $extfield, $dft>(); + } + + #[test] + fn lde_algebra_matches_naive() { + $crate::test_lde_algebra_matches_naive::<$field, $extfield, $dft>(); + } + + #[test] + fn coset_lde_algebra_matches_naive() { + $crate::test_coset_lde_algebra_matches_naive::<$field, $extfield, $dft>(); + } + + #[test] + fn dft_idft_algebra_consistency() { + $crate::test_dft_idft_algebra_consistency::<$field, $extfield, $dft>(); + } + } + }; +} diff --git a/CoqOfRust/plonky3/field-testing/src/dft_testing.v b/CoqOfRust/plonky3/field-testing/src/dft_testing.v new file mode 100644 index 000000000..d63af5607 --- /dev/null +++ b/CoqOfRust/plonky3/field-testing/src/dft_testing.v @@ -0,0 +1,7679 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module dft_testing. + (* + pub fn test_dft_matches_naive() + where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let dft_naive = NaiveDft.dft_batch(mat.clone()); + let dft_result = dft.dft_batch(mat); + assert_eq!(dft_naive, dft_result.to_row_major_matrix()); + } + } + *) + Definition test_dft_matches_naive (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ dft_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ F ], + "dft_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + ] + |) + |) in + let~ dft_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "dft_batch", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, dft |); M.read (| mat |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dft_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| dft_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_dft_matches_naive : + M.IsFunction.C "p3_field_testing::dft_testing::test_dft_matches_naive" test_dft_matches_naive. + Admitted. + Global Typeclasses Opaque test_dft_matches_naive. + + (* + pub fn test_coset_dft_matches_naive() + where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let coset_dft_naive = NaiveDft.coset_dft_batch(mat.clone(), shift); + let coset_dft_result = dft.coset_dft_batch(mat, shift); + assert_eq!(coset_dft_naive, coset_dft_result.to_row_major_matrix()); + } + } + *) + Definition test_coset_dft_matches_naive + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ shift : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| "p3_field::field::Field::GENERATOR", F |) + |) in + let~ coset_dft_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ F ], + "coset_dft_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |); + M.read (| shift |) + ] + |) + |) in + let~ coset_dft_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "coset_dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.read (| mat |); + M.read (| shift |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, coset_dft_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| coset_dft_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_coset_dft_matches_naive : + M.IsFunction.C + "p3_field_testing::dft_testing::test_coset_dft_matches_naive" + test_coset_dft_matches_naive. + Admitted. + Global Typeclasses Opaque test_coset_dft_matches_naive. + + (* + pub fn test_idft_matches_naive() + where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let idft_naive = NaiveDft.idft_batch(mat.clone()); + let idft_result = dft.idft_batch(mat.clone()); + assert_eq!(idft_naive, idft_result.to_row_major_matrix()); + } + } + *) + Definition test_idft_matches_naive (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ idft_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ F ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + ] + |) + |) in + let~ idft_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, idft_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| idft_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_idft_matches_naive : + M.IsFunction.C "p3_field_testing::dft_testing::test_idft_matches_naive" test_idft_matches_naive. + Admitted. + Global Typeclasses Opaque test_idft_matches_naive. + + (* + pub fn test_coset_idft_matches_naive() + where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let idft_naive = NaiveDft.coset_idft_batch(mat.clone(), shift); + let idft_result = dft.coset_idft_batch(mat, shift); + assert_eq!(idft_naive, idft_result.to_row_major_matrix()); + } + } + *) + Definition test_coset_idft_matches_naive + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ shift : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| "p3_field::field::Field::GENERATOR", F |) + |) in + let~ idft_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ F ], + "coset_idft_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |); + M.read (| shift |) + ] + |) + |) in + let~ idft_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "coset_idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.read (| mat |); + M.read (| shift |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, idft_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| idft_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_coset_idft_matches_naive : + M.IsFunction.C + "p3_field_testing::dft_testing::test_coset_idft_matches_naive" + test_coset_idft_matches_naive. + Admitted. + Global Typeclasses Opaque test_coset_idft_matches_naive. + + (* + pub fn test_lde_matches_naive() + where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let lde_naive = NaiveDft.lde_batch(mat.clone(), 1); + let lde_result = dft.lde_batch(mat, 1); + assert_eq!(lde_naive, lde_result.to_row_major_matrix()); + } + } + *) + Definition test_lde_matches_naive (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ lde_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ F ], + "lde_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ lde_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "lde_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.read (| mat |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, lde_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| lde_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_lde_matches_naive : + M.IsFunction.C "p3_field_testing::dft_testing::test_lde_matches_naive" test_lde_matches_naive. + Admitted. + Global Typeclasses Opaque test_lde_matches_naive. + + (* + pub fn test_coset_lde_matches_naive() + where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let coset_lde_naive = NaiveDft.coset_lde_batch(mat.clone(), 1, shift); + let coset_lde_result = dft.coset_lde_batch(mat, 1, shift); + assert_eq!(coset_lde_naive, coset_lde_result.to_row_major_matrix()); + } + } + *) + Definition test_coset_lde_matches_naive + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ shift : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| "p3_field::field::Field::GENERATOR", F |) + |) in + let~ coset_lde_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ F ], + "coset_lde_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |); + Value.Integer IntegerKind.Usize 1; + M.read (| shift |) + ] + |) + |) in + let~ coset_lde_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "coset_lde_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.read (| mat |); + Value.Integer IntegerKind.Usize 1; + M.read (| shift |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, coset_lde_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| coset_lde_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_coset_lde_matches_naive : + M.IsFunction.C + "p3_field_testing::dft_testing::test_coset_lde_matches_naive" + test_coset_lde_matches_naive. + Admitted. + Global Typeclasses Opaque test_coset_lde_matches_naive. + + (* + pub fn test_dft_idft_consistency() + where + F: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let original = RowMajorMatrix::::rand(&mut rng, h, 3); + let dft_output = dft.dft_batch(original.clone()); + let idft_output = dft.idft_batch(dft_output.to_row_major_matrix()); + assert_eq!(original, idft_output.to_row_major_matrix()); + } + } + *) + Definition test_dft_idft_consistency (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ original : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ dft_output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, original |) ] + |) + ] + |) + |) in + let~ idft_output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ F ] + Dft + "Evaluations", + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| dft_output |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, original |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| idft_output |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_dft_idft_consistency : + M.IsFunction.C + "p3_field_testing::dft_testing::test_dft_idft_consistency" + test_dft_idft_consistency. + Admitted. + Global Typeclasses Opaque test_dft_idft_consistency. + + (* + pub fn test_dft_algebra_matches_naive() + where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let dft_naive = NaiveDft.dft_batch(mat.clone()); + let dft_result = dft.dft_algebra_batch(mat); + assert_eq!(dft_naive, dft_result.to_row_major_matrix()); + } + } + *) + Definition test_dft_algebra_matches_naive + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ dft_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ EF ], + "dft_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + ] + |) + |) in + let~ dft_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "dft_algebra_batch", + [], + [ EF ] + |), + [ M.borrow (| Pointer.Kind.Ref, dft |); M.read (| mat |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dft_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [ EF ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| dft_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_dft_algebra_matches_naive : + M.IsFunction.C + "p3_field_testing::dft_testing::test_dft_algebra_matches_naive" + test_dft_algebra_matches_naive. + Admitted. + Global Typeclasses Opaque test_dft_algebra_matches_naive. + + (* + pub fn test_coset_dft_algebra_matches_naive() + where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let coset_dft_naive = NaiveDft.coset_dft_batch(mat.clone(), EF::from(shift)); + let coset_dft_result = dft.coset_dft_algebra_batch(mat, shift); + assert_eq!(coset_dft_naive, coset_dft_result.to_row_major_matrix()); + } + } + *) + Definition test_coset_dft_algebra_matches_naive + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ shift : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| "p3_field::field::Field::GENERATOR", F |) + |) in + let~ coset_dft_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ EF ], + "coset_dft_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |); + M.call_closure (| + EF, + M.get_trait_method (| + "core::convert::From", + EF, + [], + [ F ], + "from", + [], + [] + |), + [ M.read (| shift |) ] + |) + ] + |) + |) in + let~ coset_dft_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "coset_dft_algebra_batch", + [], + [ EF ] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.read (| mat |); + M.read (| shift |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, coset_dft_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [ EF ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| coset_dft_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_coset_dft_algebra_matches_naive : + M.IsFunction.C + "p3_field_testing::dft_testing::test_coset_dft_algebra_matches_naive" + test_coset_dft_algebra_matches_naive. + Admitted. + Global Typeclasses Opaque test_coset_dft_algebra_matches_naive. + + (* + pub fn test_idft_algebra_matches_naive() + where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let idft_naive = NaiveDft.idft_batch(mat.clone()); + let idft_result = dft.idft_algebra_batch(mat.clone()); + assert_eq!(idft_naive, idft_result.to_row_major_matrix()); + } + } + *) + Definition test_idft_algebra_matches_naive + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ idft_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ EF ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + ] + |) + |) in + let~ idft_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "idft_algebra_batch", + [], + [ EF ] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, idft_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [ EF ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| idft_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_idft_algebra_matches_naive : + M.IsFunction.C + "p3_field_testing::dft_testing::test_idft_algebra_matches_naive" + test_idft_algebra_matches_naive. + Admitted. + Global Typeclasses Opaque test_idft_algebra_matches_naive. + + (* + pub fn test_coset_idft_algebra_matches_naive() + where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let idft_naive = NaiveDft.coset_idft_batch(mat.clone(), EF::from(shift)); + let idft_result = dft.coset_idft_algebra_batch(mat, shift); + assert_eq!(idft_naive, idft_result.to_row_major_matrix()); + } + } + *) + Definition test_coset_idft_algebra_matches_naive + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ shift : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| "p3_field::field::Field::GENERATOR", F |) + |) in + let~ idft_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ EF ], + "coset_idft_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |); + M.call_closure (| + EF, + M.get_trait_method (| + "core::convert::From", + EF, + [], + [ F ], + "from", + [], + [] + |), + [ M.read (| shift |) ] + |) + ] + |) + |) in + let~ idft_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "coset_idft_algebra_batch", + [], + [ EF ] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.read (| mat |); + M.read (| shift |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, idft_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [ EF ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| idft_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_coset_idft_algebra_matches_naive : + M.IsFunction.C + "p3_field_testing::dft_testing::test_coset_idft_algebra_matches_naive" + test_coset_idft_algebra_matches_naive. + Admitted. + Global Typeclasses Opaque test_coset_idft_algebra_matches_naive. + + (* + pub fn test_lde_algebra_matches_naive() + where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let lde_naive = NaiveDft.lde_batch(mat.clone(), 1); + let lde_result = dft.lde_algebra_batch(mat, 1); + assert_eq!(lde_naive, lde_result.to_row_major_matrix()); + } + } + *) + Definition test_lde_algebra_matches_naive + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ lde_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ EF ], + "lde_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ lde_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "lde_algebra_batch", + [], + [ EF ] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.read (| mat |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, lde_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [ EF ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| lde_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_lde_algebra_matches_naive : + M.IsFunction.C + "p3_field_testing::dft_testing::test_lde_algebra_matches_naive" + test_lde_algebra_matches_naive. + Admitted. + Global Typeclasses Opaque test_lde_algebra_matches_naive. + + (* + pub fn test_coset_lde_algebra_matches_naive() + where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let mat = RowMajorMatrix::::rand(&mut rng, h, 3); + let shift = F::GENERATOR; + let coset_lde_naive = NaiveDft.coset_lde_batch(mat.clone(), 1, EF::from(shift)); + let coset_lde_result = dft.coset_lde_algebra_batch(mat, 1, shift); + assert_eq!(coset_lde_naive, coset_lde_result.to_row_major_matrix()); + } + } + *) + Definition test_coset_lde_algebra_matches_naive + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ shift : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| "p3_field::field::Field::GENERATOR", F |) + |) in + let~ coset_lde_naive : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.path "p3_dft::naive::NaiveDft", + [], + [ EF ], + "coset_lde_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple "p3_dft::naive::NaiveDft" [] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |); + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + EF, + M.get_trait_method (| + "core::convert::From", + EF, + [], + [ F ], + "from", + [], + [] + |), + [ M.read (| shift |) ] + |) + ] + |) + |) in + let~ coset_lde_result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "coset_lde_algebra_batch", + [], + [ EF ] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.read (| mat |); + Value.Integer IntegerKind.Usize 1; + M.read (| shift |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, coset_lde_naive |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [ EF ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| coset_lde_result |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_coset_lde_algebra_matches_naive : + M.IsFunction.C + "p3_field_testing::dft_testing::test_coset_lde_algebra_matches_naive" + test_coset_lde_algebra_matches_naive. + Admitted. + Global Typeclasses Opaque test_coset_lde_algebra_matches_naive. + + (* + pub fn test_dft_idft_algebra_consistency() + where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + { + let dft = Dft::default(); + let mut rng = SmallRng::seed_from_u64(1); + for log_h in 0..5 { + let h = 1 << log_h; + let original = RowMajorMatrix::::rand(&mut rng, h, 3); + let dft_output = dft.dft_algebra_batch(original.clone()); + let idft_output = dft.idft_algebra_batch(dft_output.to_row_major_matrix()); + assert_eq!(original, idft_output.to_row_major_matrix()); + } + } + *) + Definition test_dft_idft_algebra_consistency + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF; Dft ], [] => + ltac:(M.monadic + (M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_h := M.copy (| γ0_0 |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_h |) ] + |) + |) in + let~ original : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + "rand", + [], + [ Ty.path "rand::rngs::small::SmallRng" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rng |) |) + |); + M.read (| h |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ dft_output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "dft_algebra_batch", + [], + [ EF ] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, original |) ] + |) + ] + |) + |) in + let~ idft_output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ F ], + "idft_algebra_batch", + [], + [ EF ] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [ EF ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| dft_output |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, original |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [ EF ], + "to_row_major_matrix", + [], + [] + |), + [ M.read (| idft_output |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_dft_idft_algebra_consistency : + M.IsFunction.C + "p3_field_testing::dft_testing::test_dft_idft_algebra_consistency" + test_dft_idft_algebra_consistency. + Admitted. + Global Typeclasses Opaque test_dft_idft_algebra_consistency. +End dft_testing. diff --git a/CoqOfRust/plonky3/field-testing/src/from_integer_tests.rs b/CoqOfRust/plonky3/field-testing/src/from_integer_tests.rs new file mode 100644 index 000000000..ce1c5a752 --- /dev/null +++ b/CoqOfRust/plonky3/field-testing/src/from_integer_tests.rs @@ -0,0 +1,112 @@ +//! Macros for testing the implementations of converting integers into field elements. +#[macro_export] +macro_rules! generate_from_int_tests { + ($field:ty, $val:expr, $field_val:expr) => { + assert_eq!(<$field>::from_int($val), $field_val); + let poss_val = <$field>::from_canonical_checked($val); + assert!(poss_val.is_some()); + assert_eq!(poss_val.unwrap(), $field_val); + assert_eq!( + unsafe { <$field>::from_canonical_unchecked($val) }, + $field_val + ); + }; +} + +#[macro_export] +macro_rules! generate_from_small_int_tests { + ($field:ty, [$($int_type:ty), *]) => { + $( + // We check 0, 1 and a couple of other small values. + $crate::generate_from_int_tests!($field, 0 as $int_type, <$field>::ZERO); + $crate::generate_from_int_tests!($field, 1 as $int_type, <$field>::ONE); + let field_two = <$field>::ONE + <$field>::ONE; + $crate::generate_from_int_tests!($field, 2 as $int_type, field_two); + let field_three = field_two + <$field>::ONE; + $crate::generate_from_int_tests!($field, 3 as $int_type, field_three); + let field_six = field_two * field_three; + $crate::generate_from_int_tests!($field, 6 as $int_type, field_six); + let field_36 = field_six * field_six; + $crate::generate_from_int_tests!($field, 36 as $int_type, field_36); + let field_108 = field_36 * field_three; + $crate::generate_from_int_tests!($field, 108 as $int_type, field_108); + )* + }; +} + +#[macro_export] +macro_rules! generate_from_small_neg_int_tests { + ($field:ty, [$($int_type:ty), *]) => { + $( + // We check -1 and a couple of other small negative values. + let field_neg_one = -<$field>::ONE; + $crate::generate_from_int_tests!($field, -1 as $int_type, field_neg_one); + let field_neg_two = field_neg_one + field_neg_one; + $crate::generate_from_int_tests!($field, -2 as $int_type, field_neg_two); + let field_neg_four = field_neg_two + field_neg_two; + $crate::generate_from_int_tests!($field, -4 as $int_type, field_neg_four); + let field_neg_six = field_neg_two + field_neg_four; + $crate::generate_from_int_tests!($field, -6 as $int_type, field_neg_six); + let field_neg_24 = -field_neg_six * field_neg_four; + $crate::generate_from_int_tests!($field, -24 as $int_type, field_neg_24); + )* + }; +} + +#[macro_export] +macro_rules! generate_from_large_u_int_tests { + ($field:ty, $field_order:expr, [$($int_type:ty), *]) => { + $( + // Check some wraparound cases: + // Note that for unsigned integers, from_canonical_checked returns + // None when the input is bigger or equal to the field order. + // Similarly, from_canonical_unchecked may also return invalid results in these cases. + let field_order = $field_order as $int_type; + + // On the other hand, everything should work fine for field_order - 1 and (field_order + 1)/2. + $crate::generate_from_int_tests!($field, field_order - 1, -<$field>::ONE); + + let half = (field_order + 1) >> 1; + let field_half = <$field>::ONE.halve(); + $crate::generate_from_int_tests!($field, half, field_half); + + // We check that from_canonical_checked returns None for large enough values + // but from_int is still correct. + assert_eq!(<$field>::from_int(field_order), <$field>::ZERO); + assert_eq!(<$field>::from_canonical_checked(field_order), None); + assert_eq!(<$field>::from_int(field_order + 1), <$field>::ONE); + assert_eq!(<$field>::from_canonical_checked(field_order + 1), None); + assert_eq!(<$field>::from_canonical_checked(<$int_type>::MAX), None); + )* + }; +} + +#[macro_export] +macro_rules! generate_from_large_i_int_tests { + ($field:ty, $field_order:expr, [$($int_type:ty), *]) => { + $( + // Check some wraparound cases: + // Note that for unsigned integers, from_canonical_checked returns + // None when |input| is bigger than (field order - 1)/2 and from_canonical_unchecked + // may also return invalid results in these cases. + let neg_half = ($field_order >> 1) as $int_type; + let half_as_neg_rep = -neg_half; + + let field_half = <$field>::ONE.halve(); + let field_neg_half = field_half - <$field>::ONE; + + $crate::generate_from_int_tests!($field, half_as_neg_rep, field_half); + $crate::generate_from_int_tests!($field, neg_half, field_neg_half); + + // We check that from_canonical_checked returns None for large enough values but + // from_int is still correct. + let half = neg_half + 1; + assert_eq!(<$field>::from_int(half), field_half); + assert_eq!(<$field>::from_canonical_checked(half), None); + assert_eq!(<$field>::from_int(-half), field_neg_half); + assert_eq!(<$field>::from_canonical_checked(-half), None); + assert_eq!(<$field>::from_canonical_checked(<$int_type>::MAX), None); + assert_eq!(<$field>::from_canonical_checked(<$int_type>::MIN), None); + )* + }; +} diff --git a/CoqOfRust/plonky3/field-testing/src/lib.rs b/CoqOfRust/plonky3/field-testing/src/lib.rs new file mode 100644 index 000000000..67922eaa0 --- /dev/null +++ b/CoqOfRust/plonky3/field-testing/src/lib.rs @@ -0,0 +1,833 @@ +//! Utilities for testing field implementations. + +#![no_std] + +extern crate alloc; + +pub mod bench_func; +pub mod dft_testing; +pub mod from_integer_tests; +pub mod packedfield_testing; + +use alloc::vec::Vec; + +pub use bench_func::*; +pub use dft_testing::*; +use num_bigint::BigUint; +use p3_field::{ + ExtensionField, Field, PrimeCharacteristicRing, TwoAdicField, + cyclic_subgroup_coset_known_order, cyclic_subgroup_known_order, + two_adic_coset_vanishing_polynomial, two_adic_subgroup_vanishing_polynomial, +}; +pub use packedfield_testing::*; +use rand::distr::{Distribution, StandardUniform}; +use rand::rngs::SmallRng; +use rand::{Rng, SeedableRng}; + +#[allow(clippy::eq_op)] +pub fn test_ring_with_eq(zeros: &[R], ones: &[R]) +where + StandardUniform: Distribution + Distribution<[R; 16]>, +{ + // zeros should be a vector containing differenent representatives of `R::ZERO`. + // ones should be a vector containing differenent representatives of `R::ONE`. + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + let y = rng.random::(); + let z = rng.random::(); + assert_eq!(R::ONE + R::NEG_ONE, R::ZERO, "Error 1 + (-1) =/= 0"); + assert_eq!(R::NEG_ONE + R::TWO, R::ONE, "Error -1 + 2 =/= 1"); + assert_eq!(x + (-x), R::ZERO, "Error x + (-x) =/= 0"); + assert_eq!(R::ONE + R::ONE, R::TWO, "Error 1 + 1 =/= 2"); + assert_eq!(-(-x), x, "Error when testing double negation"); + assert_eq!(x + x, x * R::TWO, "Error when comparing x * 2 to x + x"); + assert_eq!( + x * R::TWO, + x.double(), + "Error when comparing x.double() to x * 2" + ); + + // Check different representatives of Zero. + for zero in zeros.iter().copied() { + assert_eq!(zero, R::ZERO); + assert_eq!(x + zero, x, "Error when testing additive identity right."); + assert_eq!(zero + x, x, "Error when testing additive identity left."); + assert_eq!(x - zero, x, "Error when testing subtracting zero."); + assert_eq!(zero - x, -x, "Error when testing subtracting from zero."); + assert_eq!( + x * zero, + zero, + "Error when testing right multiplication by 0." + ); + assert_eq!( + zero * x, + zero, + "Error when testing left multiplication by 0." + ); + } + + // Check different representatives of One. + for one in ones.iter().copied() { + assert_eq!(one, R::ONE); + assert_eq!(one * one, one); + assert_eq!( + x * one, + x, + "Error when testing multiplicative identity right." + ); + assert_eq!( + one * x, + x, + "Error when testing multiplicative identity left." + ); + } + + assert_eq!( + x * R::NEG_ONE, + -x, + "Error when testing right multiplication by -1." + ); + assert_eq!( + R::NEG_ONE * x, + -x, + "Error when testing left multiplication by -1." + ); + assert_eq!(x * x, x.square(), "Error when testing x * x = x.square()"); + assert_eq!( + x * x * x, + x.cube(), + "Error when testing x * x * x = x.cube()" + ); + assert_eq!(x + y, y + x, "Error when testing commutativity of addition"); + assert_eq!( + (x - y), + -(y - x), + "Error when testing anticommutativity of sub." + ); + assert_eq!( + x * y, + y * x, + "Error when testing commutativity of multiplication." + ); + assert_eq!( + x + (y + z), + (x + y) + z, + "Error when testing associativity of addition" + ); + assert_eq!( + x * (y * z), + (x * y) * z, + "Error when testing associativity of multiplication." + ); + assert_eq!( + x - (y - z), + (x - y) + z, + "Error when testing subtraction and addition" + ); + assert_eq!( + x - (y + z), + (x - y) - z, + "Error when testing subtraction and addition" + ); + assert_eq!( + (x + y) - z, + x + (y - z), + "Error when testing subtraction and addition" + ); + assert_eq!( + x * (-y), + -(x * y), + "Error when testing distributivity of mul and right neg." + ); + assert_eq!( + (-x) * y, + -(x * y), + "Error when testing distributivity of mul and left neg." + ); + + assert_eq!( + x * (y + z), + x * y + x * z, + "Error when testing distributivity of add and left mul." + ); + assert_eq!( + (x + y) * z, + x * z + y * z, + "Error when testing distributivity of add and right mul." + ); + assert_eq!( + x * (y - z), + x * y - x * z, + "Error when testing distributivity of sub and left mul." + ); + assert_eq!( + (x - y) * z, + x * z - y * z, + "Error when testing distributivity of sub and right mul." + ); + + let vec1: [R; 64] = rng.random(); + let vec2: [R; 64] = rng.random(); + test_sums(&vec1[..16].try_into().unwrap()); + test_dot_product(&vec1, &vec2); + + assert_eq!( + x.exp_const_u64::<0>(), + R::ONE, + "Error when comparing x.exp_const_u64::<0> to R::ONE." + ); + assert_eq!( + x.exp_const_u64::<1>(), + x, + "Error when comparing x.exp_const_u64::<3> to x." + ); + assert_eq!( + x.exp_const_u64::<2>(), + x * x, + "Error when comparing x.exp_const_u64::<3> to x*x." + ); + assert_eq!( + x.exp_const_u64::<3>(), + x * x * x, + "Error when comparing x.exp_const_u64::<3> to x*x*x." + ); + assert_eq!( + x.exp_const_u64::<4>(), + x * x * x * x, + "Error when comparing x.exp_const_u64::<3> to x*x*x*x." + ); + assert_eq!( + x.exp_const_u64::<5>(), + x * x * x * x * x, + "Error when comparing x.exp_const_u64::<5> to x*x*x*x*x." + ); + assert_eq!( + x.exp_const_u64::<6>(), + x * x * x * x * x * x, + "Error when comparing x.exp_const_u64::<7> to x*x*x*x*x*x." + ); + assert_eq!( + x.exp_const_u64::<7>(), + x * x * x * x * x * x * x, + "Error when comparing x.exp_const_u64::<7> to x*x*x*x*x*x*x." + ); + + test_binary_ops(zeros, ones, x, y, z); +} + +pub fn test_inv_div() +where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + let y = rng.random::(); + let z = rng.random::(); + assert_eq!(x, x.halve() * F::TWO); + assert_eq!(x * x.inverse(), F::ONE); + assert_eq!(x.inverse() * x, F::ONE); + assert_eq!(x.square().inverse(), x.inverse().square()); + assert_eq!((x / y) * y, x); + assert_eq!(x / (y * z), (x / y) / z); + assert_eq!((x * y) / z, x * (y / z)); +} + +pub fn test_mul_2exp_u64() +where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + assert_eq!(x.mul_2exp_u64(0), x); + assert_eq!(x.mul_2exp_u64(1), x.double()); + for i in 0..128 { + assert_eq!( + x.clone().mul_2exp_u64(i), + x.clone() * R::from_u128(1_u128 << i) + ); + } +} + +pub fn test_div_2exp_u64() +where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + assert_eq!(x.div_2exp_u64(0), x); + assert_eq!(x.div_2exp_u64(1), x.halve()); + for i in 0..128 { + assert_eq!(x.mul_2exp_u64(i).div_2exp_u64(i), x); + assert_eq!( + x.div_2exp_u64(i), + // Best to invert in the prime subfield in case F is an extension field. + x * F::from_prime_subfield(F::PrimeSubfield::from_u128(1_u128 << i).inverse()) + ); + } +} + +pub fn test_inverse() +where + StandardUniform: Distribution, +{ + assert_eq!(None, F::ZERO.try_inverse()); + assert_eq!(Some(F::ONE), F::ONE.try_inverse()); + let mut rng = SmallRng::seed_from_u64(1); + for _ in 0..1000 { + let x = rng.random::(); + if !x.is_zero() && !x.is_one() { + let z = x.inverse(); + assert_ne!(x, z); + assert_eq!(x * z, F::ONE); + } + } +} + +pub fn test_dot_product(u: &[R; 64], v: &[R; 64]) { + let mut dot = R::ZERO; + assert_eq!( + dot, + R::dot_product::<0>(u[..0].try_into().unwrap(), v[..0].try_into().unwrap()) + ); + dot += u[0] * v[0]; + assert_eq!( + dot, + R::dot_product::<1>(u[..1].try_into().unwrap(), v[..1].try_into().unwrap()) + ); + dot += u[1] * v[1]; + assert_eq!( + dot, + R::dot_product::<2>(u[..2].try_into().unwrap(), v[..2].try_into().unwrap()) + ); + dot += u[2] * v[2]; + assert_eq!( + dot, + R::dot_product::<3>(u[..3].try_into().unwrap(), v[..3].try_into().unwrap()) + ); + dot += u[3] * v[3]; + assert_eq!( + dot, + R::dot_product::<4>(u[..4].try_into().unwrap(), v[..4].try_into().unwrap()) + ); + dot += u[4] * v[4]; + assert_eq!( + dot, + R::dot_product::<5>(u[..5].try_into().unwrap(), v[..5].try_into().unwrap()) + ); + dot += u[5] * v[5]; + assert_eq!( + dot, + R::dot_product::<6>(u[..6].try_into().unwrap(), v[..6].try_into().unwrap()) + ); + dot += u[6] * v[6]; + assert_eq!( + dot, + R::dot_product::<7>(u[..7].try_into().unwrap(), v[..7].try_into().unwrap()) + ); + dot += u[7] * v[7]; + assert_eq!( + dot, + R::dot_product::<8>(u[..8].try_into().unwrap(), v[..8].try_into().unwrap()) + ); + dot += u[8] * v[8]; + assert_eq!( + dot, + R::dot_product::<9>(u[..9].try_into().unwrap(), v[..9].try_into().unwrap()) + ); + dot += u[9] * v[9]; + assert_eq!( + dot, + R::dot_product::<10>(u[..10].try_into().unwrap(), v[..10].try_into().unwrap()) + ); + dot += u[10] * v[10]; + assert_eq!( + dot, + R::dot_product::<11>(u[..11].try_into().unwrap(), v[..11].try_into().unwrap()) + ); + dot += u[11] * v[11]; + assert_eq!( + dot, + R::dot_product::<12>(u[..12].try_into().unwrap(), v[..12].try_into().unwrap()) + ); + dot += u[12] * v[12]; + assert_eq!( + dot, + R::dot_product::<13>(u[..13].try_into().unwrap(), v[..13].try_into().unwrap()) + ); + dot += u[13] * v[13]; + assert_eq!( + dot, + R::dot_product::<14>(u[..14].try_into().unwrap(), v[..14].try_into().unwrap()) + ); + dot += u[14] * v[14]; + assert_eq!( + dot, + R::dot_product::<15>(u[..15].try_into().unwrap(), v[..15].try_into().unwrap()) + ); + dot += u[15] * v[15]; + assert_eq!( + dot, + R::dot_product::<16>(u[..16].try_into().unwrap(), v[..16].try_into().unwrap()) + ); + + let dot_64: R = u + .iter() + .zip(v.iter()) + .fold(R::ZERO, |acc, (&lhs, &rhs)| acc + (lhs * rhs)); + assert_eq!(dot_64, R::dot_product::<64>(u, v)); +} + +pub fn test_sums(u: &[R; 16]) { + let mut sum = R::ZERO; + assert_eq!(sum, R::sum_array::<0>(u[..0].try_into().unwrap())); + assert_eq!(sum, u[..0].iter().copied().sum()); + sum += u[0]; + assert_eq!(sum, R::sum_array::<1>(u[..1].try_into().unwrap())); + assert_eq!(sum, u[..1].iter().copied().sum()); + sum += u[1]; + assert_eq!(sum, R::sum_array::<2>(u[..2].try_into().unwrap())); + assert_eq!(sum, u[..2].iter().copied().sum()); + sum += u[2]; + assert_eq!(sum, R::sum_array::<3>(u[..3].try_into().unwrap())); + assert_eq!(sum, u[..3].iter().copied().sum()); + sum += u[3]; + assert_eq!(sum, R::sum_array::<4>(u[..4].try_into().unwrap())); + assert_eq!(sum, u[..4].iter().copied().sum()); + sum += u[4]; + assert_eq!(sum, R::sum_array::<5>(u[..5].try_into().unwrap())); + assert_eq!(sum, u[..5].iter().copied().sum()); + sum += u[5]; + assert_eq!(sum, R::sum_array::<6>(u[..6].try_into().unwrap())); + assert_eq!(sum, u[..6].iter().copied().sum()); + sum += u[6]; + assert_eq!(sum, R::sum_array::<7>(u[..7].try_into().unwrap())); + assert_eq!(sum, u[..7].iter().copied().sum()); + sum += u[7]; + assert_eq!(sum, R::sum_array::<8>(u[..8].try_into().unwrap())); + assert_eq!(sum, u[..8].iter().copied().sum()); + sum += u[8]; + assert_eq!(sum, R::sum_array::<9>(u[..9].try_into().unwrap())); + assert_eq!(sum, u[..9].iter().copied().sum()); + sum += u[9]; + assert_eq!(sum, R::sum_array::<10>(u[..10].try_into().unwrap())); + assert_eq!(sum, u[..10].iter().copied().sum()); + sum += u[10]; + assert_eq!(sum, R::sum_array::<11>(u[..11].try_into().unwrap())); + assert_eq!(sum, u[..11].iter().copied().sum()); + sum += u[11]; + assert_eq!(sum, R::sum_array::<12>(u[..12].try_into().unwrap())); + assert_eq!(sum, u[..12].iter().copied().sum()); + sum += u[12]; + assert_eq!(sum, R::sum_array::<13>(u[..13].try_into().unwrap())); + assert_eq!(sum, u[..13].iter().copied().sum()); + sum += u[13]; + assert_eq!(sum, R::sum_array::<14>(u[..14].try_into().unwrap())); + assert_eq!(sum, u[..14].iter().copied().sum()); + sum += u[14]; + assert_eq!(sum, R::sum_array::<15>(u[..15].try_into().unwrap())); + assert_eq!(sum, u[..15].iter().copied().sum()); + sum += u[15]; + assert_eq!(sum, R::sum_array::<16>(u)); + assert_eq!(sum, u.iter().copied().sum()); +} + +pub fn test_binary_ops( + zeros: &[R], + ones: &[R], + x: R, + y: R, + z: R, +) { + for zero in zeros { + for one in ones { + assert_eq!(one.xor(one), R::ZERO, "Error when testing xor(1, 1) = 0."); + assert_eq!(zero.xor(one), R::ONE, "Error when testing xor(0, 1) = 1."); + assert_eq!(one.xor(zero), R::ONE, "Error when testing xor(1, 0) = 1."); + assert_eq!(zero.xor(zero), R::ZERO, "Error when testing xor(0, 0) = 0."); + assert_eq!(one.andn(one), R::ZERO, "Error when testing andn(1, 1) = 0."); + assert_eq!(zero.andn(one), R::ONE, "Error when testing andn(0, 1) = 1."); + assert_eq!( + one.andn(zero), + R::ZERO, + "Error when testing andn(1, 0) = 0." + ); + assert_eq!( + zero.andn(zero), + R::ZERO, + "Error when testing andn(0, 0) = 0." + ); + assert_eq!( + zero.bool_check(), + R::ZERO, + "Error when testing bool_check(0) = 0." + ); + assert_eq!( + one.bool_check(), + R::ZERO, + "Error when testing bool_check(1) = 0." + ); + } + } + + assert_eq!( + R::ONE.xor(&R::NEG_ONE), + R::TWO, + "Error when testing xor(1, -1) = 2." + ); + assert_eq!( + R::NEG_ONE.xor(&R::ONE), + R::TWO, + "Error when testing xor(-1, 1) = 2." + ); + assert_eq!( + R::NEG_ONE.xor(&R::NEG_ONE), + R::from_i8(-4), + "Error when testing xor(-1, -1) = -4." + ); + assert_eq!( + R::ONE.andn(&R::NEG_ONE), + R::ZERO, + "Error when testing andn(1, -1) = 0." + ); + assert_eq!( + R::NEG_ONE.andn(&R::ONE), + R::TWO, + "Error when testing andn(-1, 1) = 2." + ); + assert_eq!( + R::NEG_ONE.andn(&R::NEG_ONE), + -R::TWO, + "Error when testing andn(-1, -1) = -2." + ); + + assert_eq!(x.xor(&y), x + y - x * y.double(), "Error when testing xor."); + + assert_eq!(x.andn(&y), (R::ONE - x) * y, "Error when testing andn."); + + assert_eq!( + x.xor3(&y, &z), + x + y + z - (x * y + x * z + y * z).double() + x * y * z.double().double(), + "Error when testing xor3." + ); +} + +/// Given a list of the factors of the multiplicative group of a field, check +/// that the defined generator is actually a generator of that group. +pub fn test_generator(multiplicative_group_factors: &[(BigUint, u32)]) { + // First we check that the given factors multiply to the order of the + // multiplicative group (|F| - 1). Ideally this would also check that + // the given factors are prime but as factors can be large that check + // can end up being quite expensive so ignore that for now. As the factors + // are hardcoded and public, these prime checks can be easily done using + // sage or wolfram alpha. + let product: BigUint = multiplicative_group_factors + .iter() + .map(|(factor, exponent)| factor.pow(*exponent)) + .product(); + assert_eq!(product + BigUint::from(1u32), F::order()); + + // Given a prime factorization r = p1^e1 * p2^e2 * ... * pk^ek, an element g has order + // r if and only if g^r = 1 and g^(r/pi) != 1 for all pi in the prime factorization of r. + let mut partial_products: Vec = (0..=multiplicative_group_factors.len()) + .map(|i| { + let mut generator_power = F::GENERATOR; + multiplicative_group_factors + .iter() + .enumerate() + .for_each(|(j, (factor, exponent))| { + let modified_exponent = if i == j { exponent - 1 } else { *exponent }; + let digits = factor.to_u64_digits(); + let size = digits.len(); + for _ in 0..modified_exponent { + // The main complication here is extending our `exp_u64` code to handle `BigUints`. + // This solution is slow (particularly when dealing with extension fields + // which should really be making use of the frobenius map) but should be + // fast enough for testing purposes. + let bases = (0..size).map(|i| generator_power.exp_power_of_2(64 * i)); + let mut power = F::ONE; + digits + .iter() + .zip(bases) + .for_each(|(digit, base)| power *= base.exp_u64(*digit)); + generator_power = power; + } + }); + generator_power + }) + .collect(); + + assert_eq!(partial_products.pop().unwrap(), F::ONE); + + for elem in partial_products.into_iter() { + assert_ne!(elem, F::ONE); + } +} + +pub fn test_two_adic_subgroup_vanishing_polynomial() { + for log_n in 0..5 { + let g = F::two_adic_generator(log_n); + for x in cyclic_subgroup_known_order(g, 1 << log_n) { + let vanishing_polynomial_eval = two_adic_subgroup_vanishing_polynomial(log_n, x); + assert_eq!(vanishing_polynomial_eval, F::ZERO); + } + } +} + +pub fn test_two_adic_coset_vanishing_polynomial() { + for log_n in 0..5 { + let g = F::two_adic_generator(log_n); + let shift = F::GENERATOR; + for x in cyclic_subgroup_coset_known_order(g, shift, 1 << log_n) { + let vanishing_polynomial_eval = two_adic_coset_vanishing_polynomial(log_n, shift, x); + assert_eq!(vanishing_polynomial_eval, F::ZERO); + } + } +} + +pub fn test_two_adic_generator_consistency() { + let log_n = F::TWO_ADICITY; + let g = F::two_adic_generator(log_n); + for bits in 0..=log_n { + assert_eq!(g.exp_power_of_2(bits), F::two_adic_generator(log_n - bits)); + } +} + +pub fn test_ef_two_adic_generator_consistency< + F: TwoAdicField, + EF: TwoAdicField + ExtensionField, +>() { + assert_eq!( + Into::::into(F::two_adic_generator(F::TWO_ADICITY)), + EF::two_adic_generator(F::TWO_ADICITY) + ); +} + +#[macro_export] +macro_rules! test_field { + ($field:ty, $zeros: expr, $ones: expr, $factors: expr) => { + mod field_tests { + #[test] + fn test_ring_with_eq() { + $crate::test_ring_with_eq::<$field>($zeros, $ones); + } + #[test] + fn test_inv_div() { + $crate::test_inv_div::<$field>(); + } + #[test] + fn test_inverse() { + $crate::test_inverse::<$field>(); + } + #[test] + fn test_generator() { + $crate::test_generator::<$field>($factors); + } + #[test] + fn test_mul_2exp_u64() { + $crate::test_mul_2exp_u64::<$field>(); + } + #[test] + fn test_div_2exp_u64() { + $crate::test_div_2exp_u64::<$field>(); + } + } + }; +} + +#[macro_export] +macro_rules! test_prime_field { + ($field:ty) => { + mod from_integer_small_tests { + use p3_field::integers::QuotientMap; + use p3_field::{Field, PrimeCharacteristicRing}; + + #[test] + fn test_small_integer_conversions() { + $crate::generate_from_small_int_tests!( + $field, + [ + u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize + ] + ); + } + + #[test] + fn test_small_signed_integer_conversions() { + $crate::generate_from_small_neg_int_tests!( + $field, + [i8, i16, i32, i64, i128, isize] + ); + } + } + }; +} + +#[macro_export] +macro_rules! test_prime_field_64 { + ($field:ty) => { + mod from_integer_tests_prime_field_64 { + use p3_field::integers::QuotientMap; + use p3_field::{Field, PrimeCharacteristicRing, PrimeField64}; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + #[test] + fn test_as_canonical_u64() { + let mut rng = SmallRng::seed_from_u64(1); + let x: u64 = rng.random(); + let x_mod_order = x % <$field>::ORDER_U64; + + assert_eq!(<$field>::ZERO.as_canonical_u64(), 0); + assert_eq!(<$field>::ONE.as_canonical_u64(), 1); + assert_eq!(<$field>::TWO.as_canonical_u64(), 2 % <$field>::ORDER_U64); + assert_eq!( + <$field>::NEG_ONE.as_canonical_u64(), + <$field>::ORDER_U64 - 1 + ); + + assert_eq!( + <$field>::from_int(<$field>::ORDER_U64).as_canonical_u64(), + 0 + ); + assert_eq!(<$field>::from_int(x).as_canonical_u64(), x_mod_order); + assert_eq!( + unsafe { <$field>::from_canonical_unchecked(x_mod_order).as_canonical_u64() }, + x_mod_order + ); + } + + #[test] + fn test_as_unique_u64() { + assert_ne!( + <$field>::ZERO.to_unique_u64(), + <$field>::ONE.to_unique_u64() + ); + assert_ne!( + <$field>::ZERO.to_unique_u64(), + <$field>::NEG_ONE.to_unique_u64() + ); + assert_eq!( + <$field>::from_int(<$field>::ORDER_U64).to_unique_u64(), + <$field>::ZERO.to_unique_u64() + ); + } + + #[test] + fn test_large_unsigned_integer_conversions() { + $crate::generate_from_large_u_int_tests!($field, <$field>::ORDER_U64, [u64, u128]); + } + + #[test] + fn test_large_signed_integer_conversions() { + $crate::generate_from_large_i_int_tests!($field, <$field>::ORDER_U64, [i64, i128]); + } + } + }; +} + +#[macro_export] +macro_rules! test_prime_field_32 { + ($field:ty) => { + mod from_integer_tests_prime_field_32 { + use p3_field::integers::QuotientMap; + use p3_field::{Field, PrimeCharacteristicRing, PrimeField32}; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + #[test] + fn test_as_canonical_u32() { + let mut rng = SmallRng::seed_from_u64(1); + let x: u32 = rng.random(); + let x_mod_order = x % <$field>::ORDER_U32; + + assert_eq!(<$field>::ZERO.as_canonical_u32(), 0); + assert_eq!(<$field>::ONE.as_canonical_u32(), 1); + assert_eq!(<$field>::TWO.as_canonical_u32(), 2 % <$field>::ORDER_U32); + assert_eq!( + <$field>::NEG_ONE.as_canonical_u32(), + <$field>::ORDER_U32 - 1 + ); + assert_eq!( + <$field>::from_int(<$field>::ORDER_U32).as_canonical_u32(), + 0 + ); + assert_eq!(<$field>::from_int(x).as_canonical_u32(), x_mod_order); + assert_eq!( + unsafe { <$field>::from_canonical_unchecked(x_mod_order).as_canonical_u32() }, + x_mod_order + ); + } + + #[test] + fn test_as_unique_u32() { + assert_ne!( + <$field>::ZERO.to_unique_u32(), + <$field>::ONE.to_unique_u32() + ); + assert_ne!( + <$field>::ZERO.to_unique_u32(), + <$field>::NEG_ONE.to_unique_u32() + ); + assert_eq!( + <$field>::from_int(<$field>::ORDER_U32).to_unique_u32(), + <$field>::ZERO.to_unique_u32() + ); + } + + #[test] + fn test_large_unsigned_integer_conversions() { + $crate::generate_from_large_u_int_tests!( + $field, + <$field>::ORDER_U32, + [u32, u64, u128] + ); + } + + #[test] + fn test_large_signed_integer_conversions() { + $crate::generate_from_large_i_int_tests!( + $field, + <$field>::ORDER_U32, + [i32, i64, i128] + ); + } + } + }; +} + +#[macro_export] +macro_rules! test_two_adic_field { + ($field:ty) => { + mod two_adic_field_tests { + #[test] + fn test_two_adic_field_subgroup_vanishing_polynomial() { + $crate::test_two_adic_subgroup_vanishing_polynomial::<$field>(); + } + #[test] + fn test_two_adic_coset_vanishing_polynomial() { + $crate::test_two_adic_coset_vanishing_polynomial::<$field>(); + } + #[test] + fn test_two_adic_consistency() { + $crate::test_two_adic_generator_consistency::<$field>(); + } + } + }; +} + +#[macro_export] +macro_rules! test_two_adic_extension_field { + ($field:ty, $ef:ty) => { + use $crate::test_two_adic_field; + + test_two_adic_field!($ef); + + mod two_adic_extension_field_tests { + + #[test] + fn test_ef_two_adic_generator_consistency() { + $crate::test_ef_two_adic_generator_consistency::<$field, $ef>(); + } + } + }; +} diff --git a/CoqOfRust/plonky3/field-testing/src/lib.v b/CoqOfRust/plonky3/field-testing/src/lib.v new file mode 100644 index 000000000..40d2b4a74 --- /dev/null +++ b/CoqOfRust/plonky3/field-testing/src/lib.v @@ -0,0 +1,33243 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +(* +pub fn test_ring_with_eq(zeros: &[R], ones: &[R]) +where + StandardUniform: Distribution + Distribution<[R; 16]>, +{ + // zeros should be a vector containing differenent representatives of `R::ZERO`. + // ones should be a vector containing differenent representatives of `R::ONE`. + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + let y = rng.random::(); + let z = rng.random::(); + assert_eq!(R::ONE + R::NEG_ONE, R::ZERO, "Error 1 + (-1) =/= 0"); + assert_eq!(R::NEG_ONE + R::TWO, R::ONE, "Error -1 + 2 =/= 1"); + assert_eq!(x + (-x), R::ZERO, "Error x + (-x) =/= 0"); + assert_eq!(R::ONE + R::ONE, R::TWO, "Error 1 + 1 =/= 2"); + assert_eq!(-(-x), x, "Error when testing double negation"); + assert_eq!(x + x, x * R::TWO, "Error when comparing x * 2 to x + x"); + assert_eq!( + x * R::TWO, + x.double(), + "Error when comparing x.double() to x * 2" + ); + + // Check different representatives of Zero. + for zero in zeros.iter().copied() { + assert_eq!(zero, R::ZERO); + assert_eq!(x + zero, x, "Error when testing additive identity right."); + assert_eq!(zero + x, x, "Error when testing additive identity left."); + assert_eq!(x - zero, x, "Error when testing subtracting zero."); + assert_eq!(zero - x, -x, "Error when testing subtracting from zero."); + assert_eq!( + x * zero, + zero, + "Error when testing right multiplication by 0." + ); + assert_eq!( + zero * x, + zero, + "Error when testing left multiplication by 0." + ); + } + + // Check different representatives of One. + for one in ones.iter().copied() { + assert_eq!(one, R::ONE); + assert_eq!(one * one, one); + assert_eq!( + x * one, + x, + "Error when testing multiplicative identity right." + ); + assert_eq!( + one * x, + x, + "Error when testing multiplicative identity left." + ); + } + + assert_eq!( + x * R::NEG_ONE, + -x, + "Error when testing right multiplication by -1." + ); + assert_eq!( + R::NEG_ONE * x, + -x, + "Error when testing left multiplication by -1." + ); + assert_eq!(x * x, x.square(), "Error when testing x * x = x.square()"); + assert_eq!( + x * x * x, + x.cube(), + "Error when testing x * x * x = x.cube()" + ); + assert_eq!(x + y, y + x, "Error when testing commutativity of addition"); + assert_eq!( + (x - y), + -(y - x), + "Error when testing anticommutativity of sub." + ); + assert_eq!( + x * y, + y * x, + "Error when testing commutativity of multiplication." + ); + assert_eq!( + x + (y + z), + (x + y) + z, + "Error when testing associativity of addition" + ); + assert_eq!( + x * (y * z), + (x * y) * z, + "Error when testing associativity of multiplication." + ); + assert_eq!( + x - (y - z), + (x - y) + z, + "Error when testing subtraction and addition" + ); + assert_eq!( + x - (y + z), + (x - y) - z, + "Error when testing subtraction and addition" + ); + assert_eq!( + (x + y) - z, + x + (y - z), + "Error when testing subtraction and addition" + ); + assert_eq!( + x * (-y), + -(x * y), + "Error when testing distributivity of mul and right neg." + ); + assert_eq!( + (-x) * y, + -(x * y), + "Error when testing distributivity of mul and left neg." + ); + + assert_eq!( + x * (y + z), + x * y + x * z, + "Error when testing distributivity of add and left mul." + ); + assert_eq!( + (x + y) * z, + x * z + y * z, + "Error when testing distributivity of add and right mul." + ); + assert_eq!( + x * (y - z), + x * y - x * z, + "Error when testing distributivity of sub and left mul." + ); + assert_eq!( + (x - y) * z, + x * z - y * z, + "Error when testing distributivity of sub and right mul." + ); + + let vec1: [R; 64] = rng.random(); + let vec2: [R; 64] = rng.random(); + test_sums(&vec1[..16].try_into().unwrap()); + test_dot_product(&vec1, &vec2); + + assert_eq!( + x.exp_const_u64::<0>(), + R::ONE, + "Error when comparing x.exp_const_u64::<0> to R::ONE." + ); + assert_eq!( + x.exp_const_u64::<1>(), + x, + "Error when comparing x.exp_const_u64::<3> to x." + ); + assert_eq!( + x.exp_const_u64::<2>(), + x * x, + "Error when comparing x.exp_const_u64::<3> to x*x." + ); + assert_eq!( + x.exp_const_u64::<3>(), + x * x * x, + "Error when comparing x.exp_const_u64::<3> to x*x*x." + ); + assert_eq!( + x.exp_const_u64::<4>(), + x * x * x * x, + "Error when comparing x.exp_const_u64::<3> to x*x*x*x." + ); + assert_eq!( + x.exp_const_u64::<5>(), + x * x * x * x * x, + "Error when comparing x.exp_const_u64::<5> to x*x*x*x*x." + ); + assert_eq!( + x.exp_const_u64::<6>(), + x * x * x * x * x * x, + "Error when comparing x.exp_const_u64::<7> to x*x*x*x*x*x." + ); + assert_eq!( + x.exp_const_u64::<7>(), + x * x * x * x * x * x * x, + "Error when comparing x.exp_const_u64::<7> to x*x*x*x*x*x*x." + ); + + test_binary_ops(zeros, ones, x, y, z); +} +*) +Definition test_ring_with_eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ zeros; ones ] => + ltac:(M.monadic + (let zeros := M.alloc (| zeros |) in + let ones := M.alloc (| ones |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ x : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ y : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ z : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", R |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", R |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Error 1 + (-1) =/= 0" |) ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", R |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", R |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Error -1 + 2 =/= 1" |) ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Neg", + R, + [], + [], + "neg", + [], + [] + |), + [ M.read (| x |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", R |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Error x + (-x) =/= 0" |) ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", R |) + |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", R |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", R |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Error 1 + 1 =/= 2" |) ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Neg", R, [], [], "neg", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Neg", + R, + [], + [], + "neg", + [], + [] + |), + [ M.read (| x |) ] + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing double negation" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", R |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when comparing x * 2 to x + x" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", R |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when comparing x.double() to x * 2" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| zeros |) |) |) ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ R ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let zero := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, zero |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| zero |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing additive identity right." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| zero |); M.read (| x |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing additive identity left." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ M.read (| x |); M.read (| zero |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing subtracting zero." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ M.read (| zero |); M.read (| x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Neg", + R, + [], + [], + "neg", + [], + [] + |), + [ M.read (| x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing subtracting from zero." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| zero |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, zero |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing right multiplication by 0." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| zero |); M.read (| x |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, zero |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing left multiplication by 0." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| ones |) |) |) ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ R ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let one := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, one |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| one |); M.read (| one |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, one |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| one |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing multiplicative identity right." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| one |); M.read (| x |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing multiplicative identity left." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Neg", R, [], [], "neg", [], [] |), + [ M.read (| x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing right multiplication by -1." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |); + M.read (| x |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Neg", R, [], [], "neg", [], [] |), + [ M.read (| x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing left multiplication by -1." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing x * x = x.square()" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| x |) ] + |); + M.read (| x |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "cube", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing x * x * x = x.cube()" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| y |); M.read (| x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing commutativity of addition" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Neg", R, [], [], "neg", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ M.read (| y |); M.read (| x |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing anticommutativity of sub." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| y |); M.read (| x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing commutativity of multiplication." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| z |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing associativity of addition" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| z |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing associativity of multiplication." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| z |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing subtraction and addition" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| z |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing subtraction and addition" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| z |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing subtraction and addition" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Neg", + R, + [], + [], + "neg", + [], + [] + |), + [ M.read (| y |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Neg", R, [], [], "neg", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing distributivity of mul and right neg." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Neg", + R, + [], + [], + "neg", + [], + [] + |), + [ M.read (| x |) ] + |); + M.read (| y |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Neg", R, [], [], "neg", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing distributivity of mul and left neg." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| z |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing distributivity of add and left mul." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| z |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| z |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing distributivity of add and right mul." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| z |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing distributivity of sub and left mul." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| z |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| z |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing distributivity of sub and right mul." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ vec1 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ R ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ R ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ R ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ vec2 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ R ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ R ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ R ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_field_testing::test_sums", [], [ R ] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ R ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, vec1 |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 16) ] + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_field_testing::test_dot_product", [], [ R ] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, vec1 |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.borrow (| Pointer.Kind.Ref, vec2 |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 0 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", R |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when comparing x.exp_const_u64::<0> to R::ONE." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 1 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when comparing x.exp_const_u64::<3> to x." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 2 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when comparing x.exp_const_u64::<3> to x*x." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 3 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| x |) ] + |); + M.read (| x |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when comparing x.exp_const_u64::<3> to x*x*x." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 4 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| x |) ] + |); + M.read (| x |) + ] + |); + M.read (| x |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when comparing x.exp_const_u64::<3> to x*x*x*x." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 5 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| x |) ] + |); + M.read (| x |) + ] + |); + M.read (| x |) + ] + |); + M.read (| x |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when comparing x.exp_const_u64::<5> to x*x*x*x*x." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 6 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| x |) ] + |); + M.read (| x |) + ] + |); + M.read (| x |) + ] + |); + M.read (| x |) + ] + |); + M.read (| x |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when comparing x.exp_const_u64::<7> to x*x*x*x*x*x." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 7 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| x |) ] + |); + M.read (| x |) + ] + |); + M.read (| x |) + ] + |); + M.read (| x |) + ] + |); + M.read (| x |) + ] + |); + M.read (| x |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when comparing x.exp_const_u64::<7> to x*x*x*x*x*x*x." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_field_testing::test_binary_ops", [], [ R ] |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| zeros |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| ones |) |) |); + M.read (| x |); + M.read (| y |); + M.read (| z |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_ring_with_eq : + M.IsFunction.C "p3_field_testing::test_ring_with_eq" test_ring_with_eq. +Admitted. +Global Typeclasses Opaque test_ring_with_eq. + +(* +pub fn test_inv_div() +where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + let y = rng.random::(); + let z = rng.random::(); + assert_eq!(x, x.halve() * F::TWO); + assert_eq!(x * x.inverse(), F::ONE); + assert_eq!(x.inverse() * x, F::ONE); + assert_eq!(x.square().inverse(), x.inverse().square()); + assert_eq!((x / y) * y, x); + assert_eq!(x / (y * z), (x / y) / z); + assert_eq!((x * y) / z, x * (y / z)); +} +*) +Definition test_inv_div (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [] => + ltac:(M.monadic + (M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ x : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ F ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ y : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ F ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ z : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ F ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "halve", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", F |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |); + M.read (| x |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Div", + F, + [], + [ F ], + "div", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| y |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Div", + F, + [], + [ F ], + "div", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Div", + F, + [], + [ F ], + "div", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Div", + F, + [], + [ F ], + "div", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| z |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Div", + F, + [], + [ F ], + "div", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| z |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Div", + F, + [], + [ F ], + "div", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_inv_div : + M.IsFunction.C "p3_field_testing::test_inv_div" test_inv_div. +Admitted. +Global Typeclasses Opaque test_inv_div. + +(* +pub fn test_mul_2exp_u64() +where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + assert_eq!(x.mul_2exp_u64(0), x); + assert_eq!(x.mul_2exp_u64(1), x.double()); + for i in 0..128 { + assert_eq!( + x.clone().mul_2exp_u64(i), + x.clone() * R::from_u128(1_u128 << i) + ); + } +} +*) +Definition test_mul_2exp_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [] => + ltac:(M.monadic + (M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ x : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ R ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "mul_2exp_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); Value.Integer IntegerKind.U64 0 ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "mul_2exp_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); Value.Integer IntegerKind.U64 1 ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.U64 0); + ("end_", Value.Integer IntegerKind.U64 128) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u64" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "mul_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |); + M.read (| i |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "from_u128", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u128", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.U128 1; + M.read (| i |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_mul_2exp_u64 : + M.IsFunction.C "p3_field_testing::test_mul_2exp_u64" test_mul_2exp_u64. +Admitted. +Global Typeclasses Opaque test_mul_2exp_u64. + +(* +pub fn test_div_2exp_u64() +where + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let x = rng.random::(); + assert_eq!(x.div_2exp_u64(0), x); + assert_eq!(x.div_2exp_u64(1), x.halve()); + for i in 0..128 { + assert_eq!(x.mul_2exp_u64(i).div_2exp_u64(i), x); + assert_eq!( + x.div_2exp_u64(i), + // Best to invert in the prime subfield in case F is an extension field. + x * F::from_prime_subfield(F::PrimeSubfield::from_u128(1_u128 << i).inverse()) + ); + } +} +*) +Definition test_div_2exp_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [] => + ltac:(M.monadic + (M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ x : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ F ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "div_2exp_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); Value.Integer IntegerKind.U64 0 ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "div_2exp_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); Value.Integer IntegerKind.U64 1 ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "halve", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.U64 0); + ("end_", Value.Integer IntegerKind.U64 128) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u64" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "u64" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "mul_2exp_u64", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.read (| i |) + ] + |) + |) + |); + M.read (| i |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, x |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "div_2exp_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); M.read (| i |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + M.get_trait_method (| + "p3_field::field::Field", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + F + "PrimeSubfield", + [], + [], + "from_u128", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u128", + BinOp.Wrap.shl, + [ + Value.Integer + IntegerKind.U128 + 1; + M.read (| i |) + ] + |) + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_div_2exp_u64 : + M.IsFunction.C "p3_field_testing::test_div_2exp_u64" test_div_2exp_u64. +Admitted. +Global Typeclasses Opaque test_div_2exp_u64. + +(* +pub fn test_inverse() +where + StandardUniform: Distribution, +{ + assert_eq!(None, F::ZERO.try_inverse()); + assert_eq!(Some(F::ONE), F::ONE.try_inverse()); + let mut rng = SmallRng::seed_from_u64(1); + for _ in 0..1000 { + let x = rng.random::(); + if !x.is_zero() && !x.is_one() { + let z = x.inverse(); + assert_ne!(x, z); + assert_eq!(x * z, F::ONE); + } + } +} +*) +Definition test_inverse (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [] => + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "core::option::Option::None" [] |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "try_inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "core::option::Option") [] [ F ], + [], + [ Ty.apply (Ty.path "core::option::Option") [] [ F ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply (Ty.path "core::option::Option") [] [ F ]; + Ty.apply (Ty.path "core::option::Option") [] [ F ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) + |) + ] + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "try_inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "core::option::Option") [] [ F ], + [], + [ Ty.apply (Ty.path "core::option::Option") [] [ F ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply (Ty.path "core::option::Option") [] [ F ]; + Ty.apply (Ty.path "core::option::Option") [] [ F ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 1000) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ x : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ F ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |), + ltac:(M.monadic + (UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "is_one", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ z : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.borrow (| Pointer.Kind.Ref, z |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Ne" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| z |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_inverse : + M.IsFunction.C "p3_field_testing::test_inverse" test_inverse. +Admitted. +Global Typeclasses Opaque test_inverse. + +(* +pub fn test_dot_product(u: &[R; 64], v: &[R; 64]) { + let mut dot = R::ZERO; + assert_eq!( + dot, + R::dot_product::<0>(u[..0].try_into().unwrap(), v[..0].try_into().unwrap()) + ); + dot += u[0] * v[0]; + assert_eq!( + dot, + R::dot_product::<1>(u[..1].try_into().unwrap(), v[..1].try_into().unwrap()) + ); + dot += u[1] * v[1]; + assert_eq!( + dot, + R::dot_product::<2>(u[..2].try_into().unwrap(), v[..2].try_into().unwrap()) + ); + dot += u[2] * v[2]; + assert_eq!( + dot, + R::dot_product::<3>(u[..3].try_into().unwrap(), v[..3].try_into().unwrap()) + ); + dot += u[3] * v[3]; + assert_eq!( + dot, + R::dot_product::<4>(u[..4].try_into().unwrap(), v[..4].try_into().unwrap()) + ); + dot += u[4] * v[4]; + assert_eq!( + dot, + R::dot_product::<5>(u[..5].try_into().unwrap(), v[..5].try_into().unwrap()) + ); + dot += u[5] * v[5]; + assert_eq!( + dot, + R::dot_product::<6>(u[..6].try_into().unwrap(), v[..6].try_into().unwrap()) + ); + dot += u[6] * v[6]; + assert_eq!( + dot, + R::dot_product::<7>(u[..7].try_into().unwrap(), v[..7].try_into().unwrap()) + ); + dot += u[7] * v[7]; + assert_eq!( + dot, + R::dot_product::<8>(u[..8].try_into().unwrap(), v[..8].try_into().unwrap()) + ); + dot += u[8] * v[8]; + assert_eq!( + dot, + R::dot_product::<9>(u[..9].try_into().unwrap(), v[..9].try_into().unwrap()) + ); + dot += u[9] * v[9]; + assert_eq!( + dot, + R::dot_product::<10>(u[..10].try_into().unwrap(), v[..10].try_into().unwrap()) + ); + dot += u[10] * v[10]; + assert_eq!( + dot, + R::dot_product::<11>(u[..11].try_into().unwrap(), v[..11].try_into().unwrap()) + ); + dot += u[11] * v[11]; + assert_eq!( + dot, + R::dot_product::<12>(u[..12].try_into().unwrap(), v[..12].try_into().unwrap()) + ); + dot += u[12] * v[12]; + assert_eq!( + dot, + R::dot_product::<13>(u[..13].try_into().unwrap(), v[..13].try_into().unwrap()) + ); + dot += u[13] * v[13]; + assert_eq!( + dot, + R::dot_product::<14>(u[..14].try_into().unwrap(), v[..14].try_into().unwrap()) + ); + dot += u[14] * v[14]; + assert_eq!( + dot, + R::dot_product::<15>(u[..15].try_into().unwrap(), v[..15].try_into().unwrap()) + ); + dot += u[15] * v[15]; + assert_eq!( + dot, + R::dot_product::<16>(u[..16].try_into().unwrap(), v[..16].try_into().unwrap()) + ); + + let dot_64: R = u + .iter() + .zip(v.iter()) + .fold(R::ZERO, |acc, (&lhs, &rhs)| acc + (lhs * rhs)); + assert_eq!(dot_64, R::dot_product::<64>(u, v)); +} +*) +Definition test_dot_product (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ u; v ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + let v := M.alloc (| v |) in + M.read (| + let~ dot : Ty.apply (Ty.path "*") [] [ R ] := + M.copy (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", R |) |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 0 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 0) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 0) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 2) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 2) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 3) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 3) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 5 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 5) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 5) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 5 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 5 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 6 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 6 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 6 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 6 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 6 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 6) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 6 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 6 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 6 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 6 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 6) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 6 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 6 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 7 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 7 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 7 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 7 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 7 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 7) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 7 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 7 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 7 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 7 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 7) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 7 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 7 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 8) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 8) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 8 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 8 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 9 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 9 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 9 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 9 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 9 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 9) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 9 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 9 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 9 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 9 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 9) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 9 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 9 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 10 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 10 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 10 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 10 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 10 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 10) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 10 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 10 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 10 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 10 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 10) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 10 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 10 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 11 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 11 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 11 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 11 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 11 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 11) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 11 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 11 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 11 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 11 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 11) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 11 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 11 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 12 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 12) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 12) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 12 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 12 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 13 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 13) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 13) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 13 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 13 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 14 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 14 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 14 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 14 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 14 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 14) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 14 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 14 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 14 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 14 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 14) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 14 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 14 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 15 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 15) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 15) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 15 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + Value.Integer IntegerKind.Usize 15 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 16) ] + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| v |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 16) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ dot_64 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] + ], + [], + [], + "fold", + [], + [ + R; + Ty.function + [ + Ty.tuple + [ + R; + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ R ]; Ty.apply (Ty.path "&") [] [ R ] ] + ] + ] + R + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| u |) |) |)) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| v |) |) |)) + ] + |) + ] + |); + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", R |) |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + R; + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ R ]; + Ty.apply (Ty.path "&") [] [ R ] + ] + ] + ] + R + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + R; + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ R ]; + Ty.apply (Ty.path "&") [] [ R ] + ] + ] + ] + R + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let lhs := M.copy (| γ0_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let rhs := M.copy (| γ0_1 |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.read (| acc |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| lhs |); M.read (| rhs |) ] + |) + ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot_64 |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ Value.Integer IntegerKind.Usize 64 ], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| u |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| v |) |) |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_dot_product : + M.IsFunction.C "p3_field_testing::test_dot_product" test_dot_product. +Admitted. +Global Typeclasses Opaque test_dot_product. + +(* +pub fn test_sums(u: &[R; 16]) { + let mut sum = R::ZERO; + assert_eq!(sum, R::sum_array::<0>(u[..0].try_into().unwrap())); + assert_eq!(sum, u[..0].iter().copied().sum()); + sum += u[0]; + assert_eq!(sum, R::sum_array::<1>(u[..1].try_into().unwrap())); + assert_eq!(sum, u[..1].iter().copied().sum()); + sum += u[1]; + assert_eq!(sum, R::sum_array::<2>(u[..2].try_into().unwrap())); + assert_eq!(sum, u[..2].iter().copied().sum()); + sum += u[2]; + assert_eq!(sum, R::sum_array::<3>(u[..3].try_into().unwrap())); + assert_eq!(sum, u[..3].iter().copied().sum()); + sum += u[3]; + assert_eq!(sum, R::sum_array::<4>(u[..4].try_into().unwrap())); + assert_eq!(sum, u[..4].iter().copied().sum()); + sum += u[4]; + assert_eq!(sum, R::sum_array::<5>(u[..5].try_into().unwrap())); + assert_eq!(sum, u[..5].iter().copied().sum()); + sum += u[5]; + assert_eq!(sum, R::sum_array::<6>(u[..6].try_into().unwrap())); + assert_eq!(sum, u[..6].iter().copied().sum()); + sum += u[6]; + assert_eq!(sum, R::sum_array::<7>(u[..7].try_into().unwrap())); + assert_eq!(sum, u[..7].iter().copied().sum()); + sum += u[7]; + assert_eq!(sum, R::sum_array::<8>(u[..8].try_into().unwrap())); + assert_eq!(sum, u[..8].iter().copied().sum()); + sum += u[8]; + assert_eq!(sum, R::sum_array::<9>(u[..9].try_into().unwrap())); + assert_eq!(sum, u[..9].iter().copied().sum()); + sum += u[9]; + assert_eq!(sum, R::sum_array::<10>(u[..10].try_into().unwrap())); + assert_eq!(sum, u[..10].iter().copied().sum()); + sum += u[10]; + assert_eq!(sum, R::sum_array::<11>(u[..11].try_into().unwrap())); + assert_eq!(sum, u[..11].iter().copied().sum()); + sum += u[11]; + assert_eq!(sum, R::sum_array::<12>(u[..12].try_into().unwrap())); + assert_eq!(sum, u[..12].iter().copied().sum()); + sum += u[12]; + assert_eq!(sum, R::sum_array::<13>(u[..13].try_into().unwrap())); + assert_eq!(sum, u[..13].iter().copied().sum()); + sum += u[13]; + assert_eq!(sum, R::sum_array::<14>(u[..14].try_into().unwrap())); + assert_eq!(sum, u[..14].iter().copied().sum()); + sum += u[14]; + assert_eq!(sum, R::sum_array::<15>(u[..15].try_into().unwrap())); + assert_eq!(sum, u[..15].iter().copied().sum()); + sum += u[15]; + assert_eq!(sum, R::sum_array::<16>(u)); + assert_eq!(sum, u.iter().copied().sum()); +} +*) +Definition test_sums (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ u ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + M.read (| + let~ sum : Ty.apply (Ty.path "*") [] [ R ] := + M.copy (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", R |) |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 0 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 0) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 0) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 2) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 2) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 3) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 3) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 5 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 5) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 5) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 5 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 6 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 6) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 6) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 6 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 7 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 7) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 7) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 7 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 8) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 8) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 8 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 9 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 9) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 9) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 9 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 10 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 10) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 10) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 10 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 11 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 11) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 11) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 11 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 12 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 12) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 12) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 12 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 13 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 13) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 13) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 13 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 14 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 14) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 14) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 14 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 15 ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ]; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 15) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ R ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| u |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 15) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| u |) |), + Value.Integer IntegerKind.Usize 15 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| u |) |) |)) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, sum |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "copied", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| u |) |) |)) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_sums : + M.IsFunction.C "p3_field_testing::test_sums" test_sums. +Admitted. +Global Typeclasses Opaque test_sums. + +(* +pub fn test_binary_ops( + zeros: &[R], + ones: &[R], + x: R, + y: R, + z: R, +) { + for zero in zeros { + for one in ones { + assert_eq!(one.xor(one), R::ZERO, "Error when testing xor(1, 1) = 0."); + assert_eq!(zero.xor(one), R::ONE, "Error when testing xor(0, 1) = 1."); + assert_eq!(one.xor(zero), R::ONE, "Error when testing xor(1, 0) = 1."); + assert_eq!(zero.xor(zero), R::ZERO, "Error when testing xor(0, 0) = 0."); + assert_eq!(one.andn(one), R::ZERO, "Error when testing andn(1, 1) = 0."); + assert_eq!(zero.andn(one), R::ONE, "Error when testing andn(0, 1) = 1."); + assert_eq!( + one.andn(zero), + R::ZERO, + "Error when testing andn(1, 0) = 0." + ); + assert_eq!( + zero.andn(zero), + R::ZERO, + "Error when testing andn(0, 0) = 0." + ); + assert_eq!( + zero.bool_check(), + R::ZERO, + "Error when testing bool_check(0) = 0." + ); + assert_eq!( + one.bool_check(), + R::ZERO, + "Error when testing bool_check(1) = 0." + ); + } + } + + assert_eq!( + R::ONE.xor(&R::NEG_ONE), + R::TWO, + "Error when testing xor(1, -1) = 2." + ); + assert_eq!( + R::NEG_ONE.xor(&R::ONE), + R::TWO, + "Error when testing xor(-1, 1) = 2." + ); + assert_eq!( + R::NEG_ONE.xor(&R::NEG_ONE), + R::from_i8(-4), + "Error when testing xor(-1, -1) = -4." + ); + assert_eq!( + R::ONE.andn(&R::NEG_ONE), + R::ZERO, + "Error when testing andn(1, -1) = 0." + ); + assert_eq!( + R::NEG_ONE.andn(&R::ONE), + R::TWO, + "Error when testing andn(-1, 1) = 2." + ); + assert_eq!( + R::NEG_ONE.andn(&R::NEG_ONE), + -R::TWO, + "Error when testing andn(-1, -1) = -2." + ); + + assert_eq!(x.xor(&y), x + y - x * y.double(), "Error when testing xor."); + + assert_eq!(x.andn(&y), (R::ONE - x) * y, "Error when testing andn."); + + assert_eq!( + x.xor3(&y, &z), + x + y + z - (x * y + x * z + y * z).double() + x * y * z.double().double(), + "Error when testing xor3." + ); +} +*) +Definition test_binary_ops (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ zeros; ones; x; y; z ] => + ltac:(M.monadic + (let zeros := M.alloc (| zeros |) in + let ones := M.alloc (| ones |) in + let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + let z := M.alloc (| z |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| zeros |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let zero := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ R ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| ones |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ R ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let one := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| one |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| one |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing xor(1, 1) = 0." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| zero |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| one |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing xor(0, 1) = 1." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| one |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| zero |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing xor(1, 0) = 1." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| zero |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| zero |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing xor(0, 0) = 0." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "andn", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| one |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| one |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing andn(1, 1) = 0." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "andn", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| zero |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| one |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing andn(0, 1) = 1." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "andn", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| one |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| zero |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing andn(1, 0) = 0." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "andn", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| zero |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| zero |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing andn(0, 0) = 0." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "bool_check", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| zero |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing bool_check(0) = 0." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "bool_check", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| one |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing bool_check(1) = 0." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", R |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", R |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing xor(1, -1) = 2." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + R + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", R |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing xor(-1, 1) = 2." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "from_i8", + [], + [] + |), + [ Value.Integer IntegerKind.I8 (-4) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing xor(-1, -1) = -4." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "andn", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", R |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", R |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing andn(1, -1) = 0." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "andn", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + R + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", R |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing andn(-1, 1) = 2." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "andn", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + R + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Neg", R, [], [], "neg", [], [] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", R |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing andn(-1, -1) = -2." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, y |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, y |) ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Error when testing xor." |) ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "andn", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, y |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + R + |) + |); + M.read (| x |) + ] + |); + M.read (| y |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Error when testing andn." |) ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "xor3", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, y |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, z |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.read (| z |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| z |) ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| y |); M.read (| z |) ] + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, z |) ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + R, + [], + [ R ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ R; R ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Error when testing xor3." |) ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_binary_ops : + M.IsFunction.C "p3_field_testing::test_binary_ops" test_binary_ops. +Admitted. +Global Typeclasses Opaque test_binary_ops. + +(* +pub fn test_generator(multiplicative_group_factors: &[(BigUint, u32)]) { + // First we check that the given factors multiply to the order of the + // multiplicative group (|F| - 1). Ideally this would also check that + // the given factors are prime but as factors can be large that check + // can end up being quite expensive so ignore that for now. As the factors + // are hardcoded and public, these prime checks can be easily done using + // sage or wolfram alpha. + let product: BigUint = multiplicative_group_factors + .iter() + .map(|(factor, exponent)| factor.pow( *exponent)) + .product(); + assert_eq!(product + BigUint::from(1u32), F::order()); + + // Given a prime factorization r = p1^e1 * p2^e2 * ... * pk^ek, an element g has order + // r if and only if g^r = 1 and g^(r/pi) != 1 for all pi in the prime factorization of r. + let mut partial_products: Vec = (0..=multiplicative_group_factors.len()) + .map(|i| { + let mut generator_power = F::GENERATOR; + multiplicative_group_factors + .iter() + .enumerate() + .for_each(|(j, (factor, exponent))| { + let modified_exponent = if i == j { exponent - 1 } else { *exponent }; + let digits = factor.to_u64_digits(); + let size = digits.len(); + for _ in 0..modified_exponent { + // The main complication here is extending our `exp_u64` code to handle `BigUints`. + // This solution is slow (particularly when dealing with extension fields + // which should really be making use of the frobenius map) but should be + // fast enough for testing purposes. + let bases = (0..size).map(|i| generator_power.exp_power_of_2(64 * i)); + let mut power = F::ONE; + digits + .iter() + .zip(bases) + .for_each(|(digit, base)| power *= base.exp_u64( *digit)); + generator_power = power; + } + }); + generator_power + }) + .collect(); + + assert_eq!(partial_products.pop().unwrap(), F::ONE); + + for elem in partial_products.into_iter() { + assert_ne!(elem, F::ONE); + } +} +*) +Definition test_generator (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ multiplicative_group_factors ] => + ltac:(M.monadic + (let multiplicative_group_factors := M.alloc (| multiplicative_group_factors |) in + M.read (| + let~ product : Ty.apply (Ty.path "*") [] [ Ty.path "num_bigint::biguint::BigUint" ] := + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.tuple [ Ty.path "num_bigint::biguint::BigUint"; Ty.path "u32" ] ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.tuple [ Ty.path "num_bigint::biguint::BigUint"; Ty.path "u32" ] ] + ] + ] + (Ty.path "num_bigint::biguint::BigUint") + ], + [], + [], + "product", + [], + [ Ty.path "num_bigint::biguint::BigUint" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.tuple [ Ty.path "num_bigint::biguint::BigUint"; Ty.path "u32" ] ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.tuple [ Ty.path "num_bigint::biguint::BigUint"; Ty.path "u32" ] + ] + ] + ] + (Ty.path "num_bigint::biguint::BigUint") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.tuple [ Ty.path "num_bigint::biguint::BigUint"; Ty.path "u32" ] ], + [], + [], + "map", + [], + [ + Ty.path "num_bigint::biguint::BigUint"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.tuple [ Ty.path "num_bigint::biguint::BigUint"; Ty.path "u32" ] + ] + ] + ] + (Ty.path "num_bigint::biguint::BigUint") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.tuple [ Ty.path "num_bigint::biguint::BigUint"; Ty.path "u32" ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.tuple [ Ty.path "num_bigint::biguint::BigUint"; Ty.path "u32" ] ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| multiplicative_group_factors |) |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "num_bigint::biguint::BigUint"; + Ty.path "u32" + ] + ] + ] + ] + (Ty.path "num_bigint::biguint::BigUint") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let factor := M.alloc (| γ1_0 |) in + let exponent := M.alloc (| γ1_1 |) in + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_associated_function (| + Ty.path "num_bigint::biguint::BigUint", + "pow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| factor |) |) + |); + M.read (| M.deref (| M.read (| exponent |) |) |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "num_bigint::biguint::BigUint", + [], + [ Ty.path "num_bigint::biguint::BigUint" ], + "add", + [], + [] + |), + [ + M.read (| product |); + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "core::convert::From", + Ty.path "num_bigint::biguint::BigUint", + [], + [ Ty.path "u32" ], + "from", + [], + [] + |), + [ Value.Integer IntegerKind.U32 1 ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "order", + [], + [] + |), + [] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "num_bigint::biguint::BigUint", + [], + [ Ty.path "num_bigint::biguint::BigUint" ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "num_bigint::biguint::BigUint"; + Ty.path "num_bigint::biguint::BigUint" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ partial_products : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "usize" ]; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "usize" ]; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ F; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::ops::range::RangeInclusive") + [] + [ Ty.path "usize" ], + "new", + [], + [] + |), + [ + Value.Integer IntegerKind.Usize 0; + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.tuple [ Ty.path "num_bigint::biguint::BigUint"; Ty.path "u32" ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| multiplicative_group_factors |) |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + let~ generator_power : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| + "p3_field::field::Field::GENERATOR", + F + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path "num_bigint::biguint::BigUint"; + Ty.path "u32" + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "num_bigint::biguint::BigUint"; + Ty.path "u32" + ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path + "num_bigint::biguint::BigUint"; + Ty.path "u32" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path "num_bigint::biguint::BigUint"; + Ty.path "u32" + ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path + "num_bigint::biguint::BigUint"; + Ty.path "u32" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.path + "num_bigint::biguint::BigUint"; + Ty.path "u32" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + multiplicative_group_factors + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "num_bigint::biguint::BigUint"; + Ty.path "u32" + ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let j := M.copy (| γ0_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_1, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_1, + 1 + |) in + let factor := + M.alloc (| γ2_0 |) in + let exponent := + M.alloc (| γ2_1 |) in + M.read (| + let~ modified_exponent : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "u32" ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.path "u32" ], + M.alloc (| + Value.Tuple [] + |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path + "bool", + BinOp.eq, + [ + M.read (| + i + |); + M.read (| + j + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "u32" + ], + [], + [ + Ty.path + "u32" + ], + "sub", + [], + [] + |), + [ + M.read (| + exponent + |); + Value.Integer + IntegerKind.U32 + 1 + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.deref (| + M.read (| + exponent + |) + |))) + ] + |) + |) in + let~ digits : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path "u64"; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path "u64"; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.path + "num_bigint::biguint::BigUint", + "to_u64_digits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| factor |) + |) + |) + ] + |) + |) in + let~ size : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path "u64"; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + digits + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "u32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "u32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.U32 + 0); + ("end_", + M.read (| + modified_exponent + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "u32" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "u32" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ + bases : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + F + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + F + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", + M.read (| + size + |)) + ]; + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + F + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + i := + M.copy (| + γ + |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + generator_power + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + Value.Integer + IntegerKind.Usize + 64; + M.read (| + i + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + let~ + power : + Ty.apply + (Ty.path + "*") + [] + [ + F + ] := + M.copy (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "u64" + ]; + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + F + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "u64" + ]; + F + ] + ] + ] + (Ty.tuple + []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "u64" + ]; + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + F + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "u64" + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + F + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "u64" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "u64" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "u64" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "u64"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + digits + |) + ] + |) + |) + |) + ] + |); + M.read (| + bases + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "u64" + ]; + F + ] + ] + ] + (Ty.tuple + []) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + digit := + M.copy (| + γ0_0 + |) in + let + base := + M.copy (| + γ0_1 + |) in + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + F, + [], + [ + F + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + power + |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + base + |); + M.read (| + M.deref (| + M.read (| + digit + |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + generator_power, + M.read (| + power + |) + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + generator_power + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "pop", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, partial_products |) ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| partial_products |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let elem := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, elem |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Ne" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_generator : + M.IsFunction.C "p3_field_testing::test_generator" test_generator. +Admitted. +Global Typeclasses Opaque test_generator. + +(* +pub fn test_two_adic_subgroup_vanishing_polynomial() { + for log_n in 0..5 { + let g = F::two_adic_generator(log_n); + for x in cyclic_subgroup_known_order(g, 1 << log_n) { + let vanishing_polynomial_eval = two_adic_subgroup_vanishing_polynomial(log_n, x); + assert_eq!(vanishing_polynomial_eval, F::ZERO); + } + } +} +*) +Definition test_two_adic_subgroup_vanishing_polynomial + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [] => + ltac:(M.monadic + (M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_n := M.copy (| γ0_0 |) in + let~ g : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_n |) ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.associated_unknown, + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_function (| + "p3_field::helpers::cyclic_subgroup_known_order", + [], + [ F ] + |), + [ + M.read (| g |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| log_n |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ vanishing_polynomial_eval : + Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_function (| + "p3_field::helpers::two_adic_subgroup_vanishing_polynomial", + [], + [ F ] + |), + [ M.read (| log_n |); M.read (| x |) ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + vanishing_polynomial_eval + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + F + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_two_adic_subgroup_vanishing_polynomial : + M.IsFunction.C + "p3_field_testing::test_two_adic_subgroup_vanishing_polynomial" + test_two_adic_subgroup_vanishing_polynomial. +Admitted. +Global Typeclasses Opaque test_two_adic_subgroup_vanishing_polynomial. + +(* +pub fn test_two_adic_coset_vanishing_polynomial() { + for log_n in 0..5 { + let g = F::two_adic_generator(log_n); + let shift = F::GENERATOR; + for x in cyclic_subgroup_coset_known_order(g, shift, 1 << log_n) { + let vanishing_polynomial_eval = two_adic_coset_vanishing_polynomial(log_n, shift, x); + assert_eq!(vanishing_polynomial_eval, F::ZERO); + } + } +} +*) +Definition test_two_adic_coset_vanishing_polynomial + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [] => + ltac:(M.monadic + (M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_n := M.copy (| γ0_0 |) in + let~ g : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_n |) ] + |) + |) in + let~ shift : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| "p3_field::field::Field::GENERATOR", F |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.associated_unknown, + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_function (| + "p3_field::helpers::cyclic_subgroup_coset_known_order", + [], + [ F ] + |), + [ + M.read (| g |); + M.read (| shift |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| log_n |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ vanishing_polynomial_eval : + Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_function (| + "p3_field::helpers::two_adic_coset_vanishing_polynomial", + [], + [ F ] + |), + [ + M.read (| log_n |); + M.read (| shift |); + M.read (| x |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + vanishing_polynomial_eval + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + F + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := + M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_two_adic_coset_vanishing_polynomial : + M.IsFunction.C + "p3_field_testing::test_two_adic_coset_vanishing_polynomial" + test_two_adic_coset_vanishing_polynomial. +Admitted. +Global Typeclasses Opaque test_two_adic_coset_vanishing_polynomial. + +(* +pub fn test_two_adic_generator_consistency() { + let log_n = F::TWO_ADICITY; + let g = F::two_adic_generator(log_n); + for bits in 0..=log_n { + assert_eq!(g.exp_power_of_2(bits), F::two_adic_generator(log_n - bits)); + } +} +*) +Definition test_two_adic_generator_consistency + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [] => + ltac:(M.monadic + (M.read (| + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + get_constant (| "p3_field::field::TwoAdicField::TWO_ADICITY", Ty.path "usize" |) + |) in + let~ g : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_n |) ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "usize" ], + M.get_associated_function (| + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "usize" ], + "new", + [], + [] + |), + [ Value.Integer IntegerKind.Usize 0; M.read (| log_n |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::RangeInclusive") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let bits := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, g |); + M.read (| bits |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| log_n |); M.read (| bits |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_two_adic_generator_consistency : + M.IsFunction.C + "p3_field_testing::test_two_adic_generator_consistency" + test_two_adic_generator_consistency. +Admitted. +Global Typeclasses Opaque test_two_adic_generator_consistency. + +(* +pub fn test_ef_two_adic_generator_consistency< + F: TwoAdicField, + EF: TwoAdicField + ExtensionField, +>() { + assert_eq!( + Into::::into(F::two_adic_generator(F::TWO_ADICITY)), + EF::two_adic_generator(F::TWO_ADICITY) + ); +} +*) +Definition test_ef_two_adic_generator_consistency + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF ], [] => + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "core::convert::Into", + F, + [], + [ EF ], + "into", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::TwoAdicField::TWO_ADICITY", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + EF, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + EF, + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::TwoAdicField::TWO_ADICITY", + Ty.path "usize" + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + EF, + [], + [ EF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ EF; EF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_test_ef_two_adic_generator_consistency : + M.IsFunction.C + "p3_field_testing::test_ef_two_adic_generator_consistency" + test_ef_two_adic_generator_consistency. +Admitted. +Global Typeclasses Opaque test_ef_two_adic_generator_consistency. diff --git a/CoqOfRust/plonky3/field-testing/src/packedfield_testing.rs b/CoqOfRust/plonky3/field-testing/src/packedfield_testing.rs new file mode 100644 index 000000000..259ea9c7d --- /dev/null +++ b/CoqOfRust/plonky3/field-testing/src/packedfield_testing.rs @@ -0,0 +1,356 @@ +use alloc::vec; +use alloc::vec::Vec; + +use p3_field::{Field, PackedField, PackedFieldPow2, PackedValue, PrimeCharacteristicRing}; +use rand::distr::{Distribution, StandardUniform}; +use rand::rngs::SmallRng; +use rand::{Rng, SeedableRng}; + +fn packed_from_random(seed: u64) -> PV +where + PV: PackedValue, + StandardUniform: Distribution, +{ + let mut rng = SmallRng::seed_from_u64(seed); + PV::from_fn(|_| rng.random()) +} + +/// Interleave arr1 and arr2 using chunks of size i. +fn interleave(arr1: &[T], arr2: &[T], i: usize) -> (Vec, Vec) { + let width = arr1.len(); + assert_eq!(width, arr2.len()); + assert_eq!(width % i, 0); + + if i == width { + return (arr1.to_vec(), arr2.to_vec()); + } + + let mut outleft = vec![T::default(); width]; + let mut outright = vec![T::default(); width]; + + let mut flag = false; + + for j in 0..width { + if j % i == 0 { + flag = !flag; + } + if flag { + outleft[j] = arr1[j]; + outleft[j + i] = arr2[j]; + } else { + outright[j - i] = arr1[j]; + outright[j] = arr2[j]; + } + } + + (outleft, outright) +} + +fn test_interleave(i: usize) +where + PF: PackedFieldPow2 + Eq, + StandardUniform: Distribution, +{ + assert!(PF::WIDTH % i == 0); + + let vec1 = packed_from_random::(0x4ff5dec04791e481); + let vec2 = packed_from_random::(0x5806c495e9451f8e); + + let arr1 = vec1.as_slice(); + let arr2 = vec2.as_slice(); + + let (res1, res2) = vec1.interleave(vec2, i); + let (out1, out2) = interleave(arr1, arr2, i); + + assert_eq!( + res1.as_slice(), + &out1, + "Error in left output when testing interleave {}. Data is: \n {:?} \n {:?} \n {:?} \n {:?} \n {:?} \n {:?}.", + i, + arr1, + arr2, + res1, + res2, + out1, + out2, + ); + assert_eq!( + res2.as_slice(), + &out2, + "Error in right output when testing interleave {}.", + i + ); +} + +pub fn test_interleaves() +where + PF: PackedFieldPow2 + Eq, + StandardUniform: Distribution, +{ + let mut i = 1; + while i <= PF::WIDTH { + test_interleave::(i); + i *= 2; + } +} + +pub fn test_packed_linear_combination() +where + StandardUniform: Distribution + Distribution, +{ + let mut rng = SmallRng::seed_from_u64(1); + let u: [PF::Scalar; 64] = rng.random(); + let v: [PF; 64] = rng.random(); + + let mut dot = PF::ZERO; + assert_eq!(dot, PF::packed_linear_combination::<0>(&u[..0], &v[..0])); + dot += v[0] * u[0]; + assert_eq!(dot, PF::packed_linear_combination::<1>(&u[..1], &v[..1])); + dot += v[1] * u[1]; + assert_eq!(dot, PF::packed_linear_combination::<2>(&u[..2], &v[..2])); + dot += v[2] * u[2]; + assert_eq!(dot, PF::packed_linear_combination::<3>(&u[..3], &v[..3])); + dot += v[3] * u[3]; + assert_eq!(dot, PF::packed_linear_combination::<4>(&u[..4], &v[..4])); + dot += v[4] * u[4]; + assert_eq!(dot, PF::packed_linear_combination::<5>(&u[..5], &v[..5])); + dot += v[5] * u[5]; + assert_eq!(dot, PF::packed_linear_combination::<6>(&u[..6], &v[..6])); + dot += v[6] * u[6]; + assert_eq!(dot, PF::packed_linear_combination::<7>(&u[..7], &v[..7])); + dot += v[7] * u[7]; + assert_eq!(dot, PF::packed_linear_combination::<8>(&u[..8], &v[..8])); + dot += v[8] * u[8]; + assert_eq!(dot, PF::packed_linear_combination::<9>(&u[..9], &v[..9])); + dot += v[9] * u[9]; + assert_eq!(dot, PF::packed_linear_combination::<10>(&u[..10], &v[..10])); + dot += v[10] * u[10]; + assert_eq!(dot, PF::packed_linear_combination::<11>(&u[..11], &v[..11])); + dot += v[11] * u[11]; + assert_eq!(dot, PF::packed_linear_combination::<12>(&u[..12], &v[..12])); + dot += v[12] * u[12]; + assert_eq!(dot, PF::packed_linear_combination::<13>(&u[..13], &v[..13])); + dot += v[13] * u[13]; + assert_eq!(dot, PF::packed_linear_combination::<14>(&u[..14], &v[..14])); + dot += v[14] * u[14]; + assert_eq!(dot, PF::packed_linear_combination::<15>(&u[..15], &v[..15])); + dot += v[15] * u[15]; + assert_eq!(dot, PF::packed_linear_combination::<16>(&u[..16], &v[..16])); + + let dot_64: PF = u + .iter() + .zip(v.iter()) + .fold(PF::ZERO, |acc, (&lhs, &rhs)| acc + (rhs * lhs)); + assert_eq!(dot_64, PF::packed_linear_combination::<64>(&u, &v)); +} + +pub fn test_vs_scalar(special_vals: PF) +where + PF: PackedField + Eq, + StandardUniform: Distribution, +{ + let vec0: PF = packed_from_random(0x278d9e202925a1d1); + let vec1: PF = packed_from_random(0xf04cbac0cbad419f); + let vec_special = special_vals; + + let arr0 = vec0.as_slice(); + let arr1 = vec1.as_slice(); + + let vec_sum = vec0 + vec1; + let arr_sum = vec_sum.as_slice(); + let vec_special_sum_left = vec_special + vec0; + let arr_special_sum_left = vec_special_sum_left.as_slice(); + let vec_special_sum_right = vec1 + vec_special; + let arr_special_sum_right = vec_special_sum_right.as_slice(); + + let vec_sub = vec0 - vec1; + let arr_sub = vec_sub.as_slice(); + let vec_special_sub_left = vec_special - vec0; + let arr_special_sub_left = vec_special_sub_left.as_slice(); + let vec_special_sub_right = vec1 - vec_special; + let arr_special_sub_right = vec_special_sub_right.as_slice(); + + let vec_mul = vec0 * vec1; + let arr_mul = vec_mul.as_slice(); + let vec_special_mul_left = vec_special * vec0; + let arr_special_mul_left = vec_special_mul_left.as_slice(); + let vec_special_mul_right = vec1 * vec_special; + let arr_special_mul_right = vec_special_mul_right.as_slice(); + + let vec_neg = -vec0; + let arr_neg = vec_neg.as_slice(); + let vec_special_neg = -vec_special; + let arr_special_neg = vec_special_neg.as_slice(); + + let vec_exp_3 = vec0.exp_const_u64::<3>(); + let arr_exp_3 = vec_exp_3.as_slice(); + let vec_special_exp_3 = vec_special.exp_const_u64::<3>(); + let arr_special_exp_3 = vec_special_exp_3.as_slice(); + + let vec_exp_5 = vec0.exp_const_u64::<5>(); + let arr_exp_5 = vec_exp_5.as_slice(); + let vec_special_exp_5 = vec_special.exp_const_u64::<5>(); + let arr_special_exp_5 = vec_special_exp_5.as_slice(); + + let vec_exp_7 = vec0.exp_const_u64::<7>(); + let arr_exp_7 = vec_exp_7.as_slice(); + let vec_special_exp_7 = vec_special.exp_const_u64::<7>(); + let arr_special_exp_7 = vec_special_exp_7.as_slice(); + + let special_vals = special_vals.as_slice(); + for i in 0..PF::WIDTH { + assert_eq!( + arr_sum[i], + arr0[i] + arr1[i], + "Error when testing add consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_sum_left[i], + special_vals[i] + arr0[i], + "Error when testing consistency of left add for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_sum_right[i], + arr1[i] + special_vals[i], + "Error when testing consistency of right add for special values for packed and scalar at location {}.", + i + ); + + assert_eq!( + arr_sub[i], + arr0[i] - arr1[i], + "Error when testing sub consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_sub_left[i], + special_vals[i] - arr0[i], + "Error when testing consistency of left sub for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_sub_right[i], + arr1[i] - special_vals[i], + "Error when testing consistency of right sub for special values for packed and scalar at location {}.", + i + ); + + assert_eq!( + arr_mul[i], + arr0[i] * arr1[i], + "Error when testing mul consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_mul_left[i], + special_vals[i] * arr0[i], + "Error when testing consistency of left mul for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_mul_right[i], + arr1[i] * special_vals[i], + "Error when testing consistency of right mul for special values for packed and scalar at location {}.", + i + ); + + assert_eq!( + arr_neg[i], -arr0[i], + "Error when testing neg consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_neg[i], -special_vals[i], + "Error when testing consistency of neg for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_exp_3[i], + arr0[i].exp_const_u64::<3>(), + "Error when testing exp_const_u64::<3> consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_exp_3[i], + special_vals[i].exp_const_u64::<3>(), + "Error when testing consistency of exp_const_u64::<3> for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_exp_5[i], + arr0[i].exp_const_u64::<5>(), + "Error when testing exp_const_u64::<5> consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_exp_5[i], + special_vals[i].exp_const_u64::<5>(), + "Error when testing consistency of exp_const_u64::<5> for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_exp_7[i], + arr0[i].exp_const_u64::<7>(), + "Error when testing exp_const_u64::<7> consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_exp_7[i], + special_vals[i].exp_const_u64::<7>(), + "Error when testing consistency of exp_const_u64::<7> for special values for packed and scalar at location {}.", + i + ); + } +} + +pub fn test_multiplicative_inverse() +where + PF: PackedField + Eq, + StandardUniform: Distribution, +{ + let vec: PF = packed_from_random(0xb0c7a5153103c5a8); + let arr = vec.as_slice(); + let vec_inv = PF::from_fn(|i| arr[i].inverse()); + let res = vec * vec_inv; + assert_eq!( + res, + PF::ONE, + "Error when testing multiplication by inverse." + ); +} + +#[macro_export] +macro_rules! test_packed_field { + ($packedfield:ty, $zeros:expr, $ones:expr, $specials:expr) => { + mod packed_field_tests { + use p3_field::PrimeCharacteristicRing; + + #[test] + fn test_interleaves() { + $crate::test_interleaves::<$packedfield>(); + } + #[test] + fn test_ring_with_eq() { + $crate::test_ring_with_eq::<$packedfield>($zeros, $ones); + } + #[test] + fn test_packed_linear_combination() { + $crate::test_packed_linear_combination::<$packedfield>(); + } + #[test] + fn test_vs_scalar() { + $crate::test_vs_scalar::<$packedfield>($specials); + } + #[test] + fn test_multiplicative_inverse() { + $crate::test_multiplicative_inverse::<$packedfield>(); + } + #[test] + fn test_mul_2exp_u64() { + $crate::test_mul_2exp_u64::<$packedfield>(); + } + } + }; +} diff --git a/CoqOfRust/plonky3/field-testing/src/packedfield_testing.v b/CoqOfRust/plonky3/field-testing/src/packedfield_testing.v new file mode 100644 index 000000000..1dc4946c7 --- /dev/null +++ b/CoqOfRust/plonky3/field-testing/src/packedfield_testing.v @@ -0,0 +1,12968 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module packedfield_testing. + (* + fn packed_from_random(seed: u64) -> PV + where + PV: PackedValue, + StandardUniform: Distribution, + { + let mut rng = SmallRng::seed_from_u64(seed); + PV::from_fn(|_| rng.random()) + } + *) + Definition packed_from_random (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ PV ], [ seed ] => + ltac:(M.monadic + (let seed := M.alloc (| seed |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ M.read (| seed |) ] + |) + |) in + M.alloc (| + M.call_closure (| + PV, + M.get_trait_method (| + "p3_field::packed::PackedValue", + PV, + [], + [], + "from_fn", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PV "Value") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PV + "Value") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PV + "Value", + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PV + "Value" + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_packed_from_random : + M.IsFunction.C "p3_field_testing::packedfield_testing::packed_from_random" packed_from_random. + Admitted. + Global Typeclasses Opaque packed_from_random. + + (* + fn interleave(arr1: &[T], arr2: &[T], i: usize) -> (Vec, Vec) { + let width = arr1.len(); + assert_eq!(width, arr2.len()); + assert_eq!(width % i, 0); + + if i == width { + return (arr1.to_vec(), arr2.to_vec()); + } + + let mut outleft = vec![T::default(); width]; + let mut outright = vec![T::default(); width]; + + let mut flag = false; + + for j in 0..width { + if j % i == 0 { + flag = !flag; + } + if flag { + outleft[j] = arr1[j]; + outleft[j + i] = arr2[j]; + } else { + outright[j - i] = arr1[j]; + outright[j] = arr2[j]; + } + } + + (outleft, outright) + } + *) + Definition interleave (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ arr1; arr2; i ] => + ltac:(M.monadic + (let arr1 := M.alloc (| arr1 |) in + let arr2 := M.alloc (| arr2 |) in + let i := M.alloc (| i |) in + M.catch_return + (Ty.tuple + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ]; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| arr1 |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, width |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| arr2 |) |) |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| width |); M.read (| i |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 0 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| i |); M.read (| width |) ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.Tuple + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| arr1 |) |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| arr2 |) |) + |) + ] + |) + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ outleft : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloc::vec::from_elem", [], [ T ] |), + [ + M.call_closure (| + T, + M.get_trait_method (| + "core::default::Default", + T, + [], + [], + "default", + [], + [] + |), + [] + |); + M.read (| width |) + ] + |) + |) in + let~ outright : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloc::vec::from_elem", [], [ T ] |), + [ + M.call_closure (| + T, + M.get_trait_method (| + "core::default::Default", + T, + [], + [], + "default", + [], + [] + |), + [] + |); + M.read (| width |) + ] + |) + |) in + let~ flag : Ty.apply (Ty.path "*") [] [ Ty.path "bool" ] := + M.alloc (| Value.Bool false |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| width |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let j := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| j |); M.read (| i |) ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + flag, + UnOp.not (| M.read (| flag |) |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use flag in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ T ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + outleft + |); + M.read (| j |) + ] + |) + |), + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr1 |) |), + M.read (| j |) + |) + |) + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ T ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + outleft + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| j |); M.read (| i |) ] + |) + ] + |) + |), + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr2 |) |), + M.read (| j |) + |) + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ T ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + outright + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| j |); M.read (| i |) ] + |) + ] + |) + |), + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr1 |) |), + M.read (| j |) + |) + |) + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ T ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + outright + |); + M.read (| j |) + ] + |) + |), + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr2 |) |), + M.read (| j |) + |) + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| Value.Tuple [ M.read (| outleft |); M.read (| outright |) ] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_interleave : + M.IsFunction.C "p3_field_testing::packedfield_testing::interleave" interleave. + Admitted. + Global Typeclasses Opaque interleave. + + (* + fn test_interleave(i: usize) + where + PF: PackedFieldPow2 + Eq, + StandardUniform: Distribution, + { + assert!(PF::WIDTH % i == 0); + + let vec1 = packed_from_random::(0x4ff5dec04791e481); + let vec2 = packed_from_random::(0x5806c495e9451f8e); + + let arr1 = vec1.as_slice(); + let arr2 = vec2.as_slice(); + + let (res1, res2) = vec1.interleave(vec2, i); + let (out1, out2) = interleave(arr1, arr2, i); + + assert_eq!( + res1.as_slice(), + &out1, + "Error in left output when testing interleave {}. Data is: \n {:?} \n {:?} \n {:?} \n {:?} \n {:?} \n {:?}.", + i, + arr1, + arr2, + res1, + res2, + out1, + out2, + ); + assert_eq!( + res2.as_slice(), + &out2, + "Error in right output when testing interleave {}.", + i + ); + } + *) + Definition test_interleave (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ PF ], [ i ] => + ltac:(M.monadic + (let i := M.alloc (| i |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |); + M.read (| i |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: PF::WIDTH % i == 0" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ vec1 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_function (| + "p3_field_testing::packedfield_testing::packed_from_random", + [], + [ PF ] + |), + [ Value.Integer IntegerKind.U64 5761756215706248321 ] + |) + |) in + let~ vec2 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_function (| + "p3_field_testing::packedfield_testing::packed_from_random", + [], + [ PF ] + |), + [ Value.Integer IntegerKind.U64 6342973273340714894 ] + |) + |) in + let~ arr1 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec1 |) ] + |) + |) in + let~ arr2 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec2 |) ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ PF; PF ], + M.get_trait_method (| + "p3_field::packed::PackedFieldPow2", + PF, + [], + [], + "interleave", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec1 |); M.read (| vec2 |); M.read (| i |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let res1 := M.copy (| γ0_0 |) in + let res2 := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_function (| + "p3_field_testing::packedfield_testing::interleave", + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| arr1 |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| arr2 |) |) |); + M.read (| i |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let out1 := M.copy (| γ0_0 |) in + let out2 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, res1 |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| M.borrow (| Pointer.Kind.Ref, out1 |) |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 7 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error in left output when testing interleave " + |); + mk_str (| + ". Data is: + " + |); + mk_str (| " + " |); + mk_str (| " + " |); + mk_str (| " + " |); + mk_str (| " + " |); + mk_str (| " + " |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_debug", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + arr1 + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_debug", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + arr2 + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_debug", + [], + [ PF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + res1 + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_debug", + [], + [ PF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + res2 + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_debug", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + out1 + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_debug", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + out2 + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, res2 |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| M.borrow (| Pointer.Kind.Ref, out2 |) |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error in right output when testing interleave " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_interleave : + M.IsFunction.C "p3_field_testing::packedfield_testing::test_interleave" test_interleave. + Admitted. + Global Typeclasses Opaque test_interleave. + + (* + pub fn test_interleaves() + where + PF: PackedFieldPow2 + Eq, + StandardUniform: Distribution, + { + let mut i = 1; + while i <= PF::WIDTH { + test_interleave::(i); + i *= 2; + } + } + *) + Definition test_interleaves (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ PF ], [] => + ltac:(M.monadic + (M.read (| + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 1 |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| i |); + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field_testing::packedfield_testing::test_interleave", + [], + [ PF ] + |), + [ M.read (| i |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| β |); Value.Integer IntegerKind.Usize 2 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_interleaves : + M.IsFunction.C "p3_field_testing::packedfield_testing::test_interleaves" test_interleaves. + Admitted. + Global Typeclasses Opaque test_interleaves. + + (* + pub fn test_packed_linear_combination() + where + StandardUniform: Distribution + Distribution, + { + let mut rng = SmallRng::seed_from_u64(1); + let u: [PF::Scalar; 64] = rng.random(); + let v: [PF; 64] = rng.random(); + + let mut dot = PF::ZERO; + assert_eq!(dot, PF::packed_linear_combination::<0>(&u[..0], &v[..0])); + dot += v[0] * u[0]; + assert_eq!(dot, PF::packed_linear_combination::<1>(&u[..1], &v[..1])); + dot += v[1] * u[1]; + assert_eq!(dot, PF::packed_linear_combination::<2>(&u[..2], &v[..2])); + dot += v[2] * u[2]; + assert_eq!(dot, PF::packed_linear_combination::<3>(&u[..3], &v[..3])); + dot += v[3] * u[3]; + assert_eq!(dot, PF::packed_linear_combination::<4>(&u[..4], &v[..4])); + dot += v[4] * u[4]; + assert_eq!(dot, PF::packed_linear_combination::<5>(&u[..5], &v[..5])); + dot += v[5] * u[5]; + assert_eq!(dot, PF::packed_linear_combination::<6>(&u[..6], &v[..6])); + dot += v[6] * u[6]; + assert_eq!(dot, PF::packed_linear_combination::<7>(&u[..7], &v[..7])); + dot += v[7] * u[7]; + assert_eq!(dot, PF::packed_linear_combination::<8>(&u[..8], &v[..8])); + dot += v[8] * u[8]; + assert_eq!(dot, PF::packed_linear_combination::<9>(&u[..9], &v[..9])); + dot += v[9] * u[9]; + assert_eq!(dot, PF::packed_linear_combination::<10>(&u[..10], &v[..10])); + dot += v[10] * u[10]; + assert_eq!(dot, PF::packed_linear_combination::<11>(&u[..11], &v[..11])); + dot += v[11] * u[11]; + assert_eq!(dot, PF::packed_linear_combination::<12>(&u[..12], &v[..12])); + dot += v[12] * u[12]; + assert_eq!(dot, PF::packed_linear_combination::<13>(&u[..13], &v[..13])); + dot += v[13] * u[13]; + assert_eq!(dot, PF::packed_linear_combination::<14>(&u[..14], &v[..14])); + dot += v[14] * u[14]; + assert_eq!(dot, PF::packed_linear_combination::<15>(&u[..15], &v[..15])); + dot += v[15] * u[15]; + assert_eq!(dot, PF::packed_linear_combination::<16>(&u[..16], &v[..16])); + + let dot_64: PF = u + .iter() + .zip(v.iter()) + .fold(PF::ZERO, |acc, (&lhs, &rhs)| acc + (rhs * lhs)); + assert_eq!(dot_64, PF::packed_linear_combination::<64>(&u, &v)); + } + *) + Definition test_packed_linear_combination + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ PF ], [] => + ltac:(M.monadic + (M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ u : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ v : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ PF ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ PF ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ PF ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |) + |) in + let~ dot : Ty.apply (Ty.path "*") [] [ PF ] := + M.copy (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", PF |) |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 0 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 0) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 0) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 0 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 0 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 1 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 1 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 2) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 2) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 2 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 2 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 3) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 3) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 3 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 3 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 4 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 4 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 5 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 5) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 5) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 5 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 5 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 6 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 6) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 6) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 6 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 6 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 7 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 7) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 7) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 7 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 7 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 8) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 8) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 8 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 8 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 9 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 9) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 9) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 9 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 9 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 10 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 10) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 10) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 10 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 10 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 11 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 11) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 11) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 11 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 11 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 12 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 12) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 12) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 12 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 12 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 13 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 13) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 13) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 13 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 13 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 14 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 14) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 14) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 14 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 14 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 15 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 15) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 15) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dot |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 15 |) + |); + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 15 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, u |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 16) ] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, v |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 16) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ dot_64 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ PF ] + ], + [], + [], + "fold", + [], + [ + PF; + Ty.function + [ + Ty.tuple + [ + PF; + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ]; + Ty.apply (Ty.path "&") [] [ PF ] + ] + ] + ] + PF + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ PF ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" + ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ PF ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "iter", + [], + [] + |), + [ (* Unsize *) M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, u |)) ] + |); + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ PF ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ PF ], + "iter", + [], + [] + |), + [ (* Unsize *) M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, v |)) ] + |) + ] + |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", PF |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + PF; + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ]; + Ty.apply (Ty.path "&") [] [ PF ] + ] + ] + ] + PF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + PF; + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ]; + Ty.apply (Ty.path "&") [] [ PF ] + ] + ] + ] + PF + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let lhs := M.copy (| γ0_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let rhs := M.copy (| γ0_1 |) in + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Add", + PF, + [], + [ PF ], + "add", + [], + [] + |), + [ + M.read (| acc |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "mul", + [], + [] + |), + [ M.read (| rhs |); M.read (| lhs |) ] + |) + ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, dot_64 |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedField", + PF, + [], + [], + "packed_linear_combination", + [ Value.Integer IntegerKind.Usize 64 ], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, u |) |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, v |) |) + |)) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_packed_linear_combination : + M.IsFunction.C + "p3_field_testing::packedfield_testing::test_packed_linear_combination" + test_packed_linear_combination. + Admitted. + Global Typeclasses Opaque test_packed_linear_combination. + + (* + pub fn test_vs_scalar(special_vals: PF) + where + PF: PackedField + Eq, + StandardUniform: Distribution, + { + let vec0: PF = packed_from_random(0x278d9e202925a1d1); + let vec1: PF = packed_from_random(0xf04cbac0cbad419f); + let vec_special = special_vals; + + let arr0 = vec0.as_slice(); + let arr1 = vec1.as_slice(); + + let vec_sum = vec0 + vec1; + let arr_sum = vec_sum.as_slice(); + let vec_special_sum_left = vec_special + vec0; + let arr_special_sum_left = vec_special_sum_left.as_slice(); + let vec_special_sum_right = vec1 + vec_special; + let arr_special_sum_right = vec_special_sum_right.as_slice(); + + let vec_sub = vec0 - vec1; + let arr_sub = vec_sub.as_slice(); + let vec_special_sub_left = vec_special - vec0; + let arr_special_sub_left = vec_special_sub_left.as_slice(); + let vec_special_sub_right = vec1 - vec_special; + let arr_special_sub_right = vec_special_sub_right.as_slice(); + + let vec_mul = vec0 * vec1; + let arr_mul = vec_mul.as_slice(); + let vec_special_mul_left = vec_special * vec0; + let arr_special_mul_left = vec_special_mul_left.as_slice(); + let vec_special_mul_right = vec1 * vec_special; + let arr_special_mul_right = vec_special_mul_right.as_slice(); + + let vec_neg = -vec0; + let arr_neg = vec_neg.as_slice(); + let vec_special_neg = -vec_special; + let arr_special_neg = vec_special_neg.as_slice(); + + let vec_exp_3 = vec0.exp_const_u64::<3>(); + let arr_exp_3 = vec_exp_3.as_slice(); + let vec_special_exp_3 = vec_special.exp_const_u64::<3>(); + let arr_special_exp_3 = vec_special_exp_3.as_slice(); + + let vec_exp_5 = vec0.exp_const_u64::<5>(); + let arr_exp_5 = vec_exp_5.as_slice(); + let vec_special_exp_5 = vec_special.exp_const_u64::<5>(); + let arr_special_exp_5 = vec_special_exp_5.as_slice(); + + let vec_exp_7 = vec0.exp_const_u64::<7>(); + let arr_exp_7 = vec_exp_7.as_slice(); + let vec_special_exp_7 = vec_special.exp_const_u64::<7>(); + let arr_special_exp_7 = vec_special_exp_7.as_slice(); + + let special_vals = special_vals.as_slice(); + for i in 0..PF::WIDTH { + assert_eq!( + arr_sum[i], + arr0[i] + arr1[i], + "Error when testing add consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_sum_left[i], + special_vals[i] + arr0[i], + "Error when testing consistency of left add for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_sum_right[i], + arr1[i] + special_vals[i], + "Error when testing consistency of right add for special values for packed and scalar at location {}.", + i + ); + + assert_eq!( + arr_sub[i], + arr0[i] - arr1[i], + "Error when testing sub consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_sub_left[i], + special_vals[i] - arr0[i], + "Error when testing consistency of left sub for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_sub_right[i], + arr1[i] - special_vals[i], + "Error when testing consistency of right sub for special values for packed and scalar at location {}.", + i + ); + + assert_eq!( + arr_mul[i], + arr0[i] * arr1[i], + "Error when testing mul consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_mul_left[i], + special_vals[i] * arr0[i], + "Error when testing consistency of left mul for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_mul_right[i], + arr1[i] * special_vals[i], + "Error when testing consistency of right mul for special values for packed and scalar at location {}.", + i + ); + + assert_eq!( + arr_neg[i], -arr0[i], + "Error when testing neg consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_neg[i], -special_vals[i], + "Error when testing consistency of neg for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_exp_3[i], + arr0[i].exp_const_u64::<3>(), + "Error when testing exp_const_u64::<3> consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_exp_3[i], + special_vals[i].exp_const_u64::<3>(), + "Error when testing consistency of exp_const_u64::<3> for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_exp_5[i], + arr0[i].exp_const_u64::<5>(), + "Error when testing exp_const_u64::<5> consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_exp_5[i], + special_vals[i].exp_const_u64::<5>(), + "Error when testing consistency of exp_const_u64::<5> for special values for packed and scalar at location {}.", + i + ); + assert_eq!( + arr_exp_7[i], + arr0[i].exp_const_u64::<7>(), + "Error when testing exp_const_u64::<7> consistency of packed and scalar at location {}.", + i + ); + assert_eq!( + arr_special_exp_7[i], + special_vals[i].exp_const_u64::<7>(), + "Error when testing consistency of exp_const_u64::<7> for special values for packed and scalar at location {}.", + i + ); + } + } + *) + Definition test_vs_scalar (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ PF ], [ special_vals ] => + ltac:(M.monadic + (let special_vals := M.alloc (| special_vals |) in + M.read (| + let~ vec0 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_function (| + "p3_field_testing::packedfield_testing::packed_from_random", + [], + [ PF ] + |), + [ Value.Integer IntegerKind.U64 2850108000161866193 ] + |) + |) in + let~ vec1 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_function (| + "p3_field_testing::packedfield_testing::packed_from_random", + [], + [ PF ] + |), + [ Value.Integer IntegerKind.U64 17315420004546331039 ] + |) + |) in + let~ vec_special : Ty.apply (Ty.path "*") [] [ PF ] := M.copy (| special_vals |) in + let~ arr0 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec0 |) ] + |) + |) in + let~ arr1 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec1 |) ] + |) + |) in + let~ vec_sum : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Add", PF, [], [ PF ], "add", [], [] |), + [ M.read (| vec0 |); M.read (| vec1 |) ] + |) + |) in + let~ arr_sum : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_sum |) ] + |) + |) in + let~ vec_special_sum_left : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Add", PF, [], [ PF ], "add", [], [] |), + [ M.read (| vec_special |); M.read (| vec0 |) ] + |) + |) in + let~ arr_special_sum_left : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special_sum_left |) ] + |) + |) in + let~ vec_special_sum_right : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Add", PF, [], [ PF ], "add", [], [] |), + [ M.read (| vec1 |); M.read (| vec_special |) ] + |) + |) in + let~ arr_special_sum_right : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special_sum_right |) ] + |) + |) in + let~ vec_sub : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Sub", PF, [], [ PF ], "sub", [], [] |), + [ M.read (| vec0 |); M.read (| vec1 |) ] + |) + |) in + let~ arr_sub : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_sub |) ] + |) + |) in + let~ vec_special_sub_left : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Sub", PF, [], [ PF ], "sub", [], [] |), + [ M.read (| vec_special |); M.read (| vec0 |) ] + |) + |) in + let~ arr_special_sub_left : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special_sub_left |) ] + |) + |) in + let~ vec_special_sub_right : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Sub", PF, [], [ PF ], "sub", [], [] |), + [ M.read (| vec1 |); M.read (| vec_special |) ] + |) + |) in + let~ arr_special_sub_right : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special_sub_right |) ] + |) + |) in + let~ vec_mul : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Mul", PF, [], [ PF ], "mul", [], [] |), + [ M.read (| vec0 |); M.read (| vec1 |) ] + |) + |) in + let~ arr_mul : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_mul |) ] + |) + |) in + let~ vec_special_mul_left : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Mul", PF, [], [ PF ], "mul", [], [] |), + [ M.read (| vec_special |); M.read (| vec0 |) ] + |) + |) in + let~ arr_special_mul_left : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special_mul_left |) ] + |) + |) in + let~ vec_special_mul_right : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Mul", PF, [], [ PF ], "mul", [], [] |), + [ M.read (| vec1 |); M.read (| vec_special |) ] + |) + |) in + let~ arr_special_mul_right : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special_mul_right |) ] + |) + |) in + let~ vec_neg : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Neg", PF, [], [], "neg", [], [] |), + [ M.read (| vec0 |) ] + |) + |) in + let~ arr_neg : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_neg |) ] + |) + |) in + let~ vec_special_neg : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Neg", PF, [], [], "neg", [], [] |), + [ M.read (| vec_special |) ] + |) + |) in + let~ arr_special_neg : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special_neg |) ] + |) + |) in + let~ vec_exp_3 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 3 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec0 |) ] + |) + |) in + let~ arr_exp_3 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_exp_3 |) ] + |) + |) in + let~ vec_special_exp_3 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 3 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special |) ] + |) + |) in + let~ arr_special_exp_3 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special_exp_3 |) ] + |) + |) in + let~ vec_exp_5 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 5 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec0 |) ] + |) + |) in + let~ arr_exp_5 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_exp_5 |) ] + |) + |) in + let~ vec_special_exp_5 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 5 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special |) ] + |) + |) in + let~ arr_special_exp_5 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special_exp_5 |) ] + |) + |) in + let~ vec_exp_7 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 7 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec0 |) ] + |) + |) in + let~ arr_exp_7 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_exp_7 |) ] + |) + |) in + let~ vec_special_exp_7 : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 7 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special |) ] + |) + |) in + let~ arr_special_exp_7 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec_special_exp_7 |) ] + |) + |) in + let~ special_vals : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, special_vals |) ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_sum |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr0 |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr1 |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing add consistency of packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_special_sum_left |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| special_vals |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr0 |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing consistency of left add for special values for packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_special_sum_right |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr1 |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| special_vals |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing consistency of right add for special values for packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_sub |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr0 |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr1 |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing sub consistency of packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_special_sub_left |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| special_vals |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr0 |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing consistency of left sub for special values for packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_special_sub_right |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr1 |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| special_vals |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing consistency of right sub for special values for packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_mul |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr0 |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr1 |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing mul consistency of packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_special_mul_left |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| special_vals |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr0 |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing consistency of left mul for special values for packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_special_mul_right |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr1 |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| special_vals |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing consistency of right mul for special values for packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_neg |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Neg", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr0 |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing neg consistency of packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_special_neg |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "core::ops::arith::Neg", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| special_vals |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing consistency of neg for special values for packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_exp_3 |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 3 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr0 |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing exp_const_u64::<3> consistency of packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_special_exp_3 |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 3 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| special_vals |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing consistency of exp_const_u64::<3> for special values for packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_exp_5 |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 5 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr0 |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing exp_const_u64::<5> consistency of packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_special_exp_5 |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 5 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| special_vals |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing consistency of exp_const_u64::<5> for special values for packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_exp_7 |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 7 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr0 |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing exp_const_u64::<7> consistency of packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr_special_exp_7 |) |), + M.read (| i |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 7 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| special_vals |) |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar"; + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing consistency of exp_const_u64::<7> for special values for packed and scalar at location " + |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_vs_scalar : + M.IsFunction.C "p3_field_testing::packedfield_testing::test_vs_scalar" test_vs_scalar. + Admitted. + Global Typeclasses Opaque test_vs_scalar. + + (* + pub fn test_multiplicative_inverse() + where + PF: PackedField + Eq, + StandardUniform: Distribution, + { + let vec: PF = packed_from_random(0xb0c7a5153103c5a8); + let arr = vec.as_slice(); + let vec_inv = PF::from_fn(|i| arr[i].inverse()); + let res = vec * vec_inv; + assert_eq!( + res, + PF::ONE, + "Error when testing multiplication by inverse." + ); + } + *) + Definition test_multiplicative_inverse + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ PF ], [] => + ltac:(M.monadic + (M.read (| + let~ vec : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_function (| + "p3_field_testing::packedfield_testing::packed_from_random", + [], + [ PF ] + |), + [ Value.Integer IntegerKind.U64 12738331581475964328 ] + |) + |) in + let~ arr : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar" ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec |) ] + |) + |) in + let~ vec_inv : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::packed::PackedValue", + PF, + [], + [], + "from_fn", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait "p3_field::packed::PackedField" [] [] PF "Scalar") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + M.get_trait_method (| + "p3_field::field::Field", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + PF + "Scalar", + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| arr |) |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ res : Ty.apply (Ty.path "*") [] [ PF ] := + M.alloc (| + M.call_closure (| + PF, + M.get_trait_method (| "core::ops::arith::Mul", PF, [], [ PF ], "mul", [], [] |), + [ M.read (| vec |); M.read (| vec_inv |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, res |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", PF |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + PF, + [], + [ PF ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ PF; PF ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Error when testing multiplication by inverse." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_test_multiplicative_inverse : + M.IsFunction.C + "p3_field_testing::packedfield_testing::test_multiplicative_inverse" + test_multiplicative_inverse. + Admitted. + Global Typeclasses Opaque test_multiplicative_inverse. +End packedfield_testing. diff --git a/CoqOfRust/plonky3/field/links/field.v b/CoqOfRust/plonky3/field/links/field.v new file mode 100644 index 000000000..5506b11dc --- /dev/null +++ b/CoqOfRust/plonky3/field/links/field.v @@ -0,0 +1,160 @@ +Require Import CoqOfRust.CoqOfRust. +Require Import CoqOfRust.links.M. +Require Import plonky3.field.field. + +(* +pub trait Algebra: + PrimeCharacteristicRing + + From + + Add + + AddAssign + + Sub + + SubAssign + + Mul + + MulAssign +{ +} +*) +Module Algebra. +End Algebra. + +(* +pub trait Field: + Algebra + + Packable + + 'static + + Copy + + Div + + Eq + + Hash + + Send + + Sync + + Display + + Serialize + + DeserializeOwned +{ + type Packing: PackedField; + + const GENERATOR: Self; + + fn is_zero(&self) -> bool { + *self == Self::ZERO + } + + fn is_one(&self) -> bool { + *self == Self::ONE + } + + fn try_inverse(&self) -> Option; + + fn inverse(&self) -> Self { + self.try_inverse().expect("Tried to invert zero") + } + + fn halve(&self) -> Self { + // This should be overwritten by most field implementations. + let half = Self::from_prime_subfield( + Self::PrimeSubfield::TWO + .try_inverse() + .expect("Cannot divide by 2 in fields with characteristic 2"), + ); + *self * half + } + + fn div_2exp_u64(&self, exp: u64) -> Self { + // This should be overwritten by most field implementations. + *self + * Self::from_prime_subfield( + Self::PrimeSubfield::TWO + .try_inverse() + .expect("Cannot divide by 2 in fields with characteristic 2") + .exp_u64(exp), + ) + } + + fn order() -> BigUint; + + fn bits() -> usize { + Self::order().bits() as usize + } +} +*) +Module Field. + Definition trait (Self : Set) `{Link Self} : TraitMethod.Header.t := + ("plonky3::field::field::Field", [], [], Φ Self). + + Class Run (Self : Set) `{Link Self} : Set := { + }. +End Field. + +(* +pub trait PrimeField: + Field + + Ord + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap +*) +Module PrimeField. + Definition trait (Self : Set) `{Link Self} : TraitMethod.Header.t := + ("plonky3::field::field::PrimeField", [], [], Φ Self). + + Class Run (Self : Set) `{Link Self} : Set := { + run_Field_for_PrimeField : Field.Run Self; + }. +End PrimeField. + +(* +pub trait PrimeField64: PrimeField { + const ORDER_U64: u64; + + fn as_canonical_u64(&self) -> u64; + + fn to_unique_u64(&self) -> u64 { + // A simple default which is optimal for some fields. + self.as_canonical_u64() + } +} +*) +Module PrimeField64. + Parameter t : Set. + + Definition trait (Self : Set) `{Link Self} : TraitMethod.Header.t := + ("plonky3::field::field::PrimeField64", [], [], Φ Self). + + (* const ORDER_U64: u64; *) + Definition run_ORDER_U64 (Self : Set) `{Link Self} : Set := + TraitMethod.C (trait Self) "ORDER_U64" (fun method => + forall (self : Ref.t Pointer.Kind.Ref Self), + Run.Trait method [] [] [] U64.t + ). + + (* fn as_canonical_u64(&self) -> u64; *) + Definition Run_as_canonical_u64 (Self : Set) `{Link Self} : Set := + TraitMethod.C (trait Self) "as_canonical_u64" (fun method => + forall (self : Ref.t Pointer.Kind.Ref Self), + Run.Trait method [] [] [ φ self ] U64.t + ). + + (* fn to_unique_u64(&self) -> u64 *) + Definition Run_to_unique_u64 (Self : Set) `{Link Self} : Set := + TraitMethod.C (trait Self) "to_unique_u64" (fun method => + forall (self : Ref.t Pointer.Kind.Ref Self), + Run.Trait method [] [] [ φ self ] U64.t + ). + + Class Run (Self : Set) `{Link Self} : Set := { + run_PrimeField_for_PrimeField64 : PrimeField.Run Self; + as_canonical_u64 : Run_as_canonical_u64 Self; + to_unique_u64 : Run_to_unique_u64 Self; + }. +End PrimeField64. \ No newline at end of file diff --git a/CoqOfRust/plonky3/field/src/array.rs b/CoqOfRust/plonky3/field/src/array.rs new file mode 100644 index 000000000..a8bcd9ba5 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/array.rs @@ -0,0 +1,213 @@ +use core::array; +use core::iter::{Product, Sum}; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; + +use crate::batch_inverse::batch_multiplicative_inverse_general; +use crate::{Algebra, Field, PackedValue, PrimeCharacteristicRing}; + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[repr(transparent)] // Needed to make `transmute`s safe. +pub struct FieldArray(pub [F; N]); + +impl FieldArray { + pub(crate) fn inverse(&self) -> Self { + let mut result = Self::default(); + batch_multiplicative_inverse_general(&self.0, &mut result.0, |x| x.inverse()); + result + } +} + +impl Default for FieldArray { + fn default() -> Self { + Self::ZERO + } +} + +impl From for FieldArray { + fn from(val: F) -> Self { + [val; N].into() + } +} + +impl From<[F; N]> for FieldArray { + fn from(arr: [F; N]) -> Self { + Self(arr) + } +} + +impl PrimeCharacteristicRing for FieldArray { + type PrimeSubfield = F::PrimeSubfield; + + const ZERO: Self = Self([F::ZERO; N]); + const ONE: Self = Self([F::ONE; N]); + const TWO: Self = Self([F::TWO; N]); + const NEG_ONE: Self = Self([F::NEG_ONE; N]); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + F::from_prime_subfield(f).into() + } +} + +impl Algebra for FieldArray {} + +unsafe impl PackedValue for FieldArray { + type Value = F; + + const WIDTH: usize = N; + + fn from_slice(slice: &[Self::Value]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { &*slice.as_ptr().cast() } + } + + fn from_slice_mut(slice: &mut [Self::Value]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { &mut *slice.as_mut_ptr().cast() } + } + + fn from_fn(f: Fn) -> Self + where + Fn: FnMut(usize) -> Self::Value, + { + Self(array::from_fn(f)) + } + + fn as_slice(&self) -> &[Self::Value] { + &self.0 + } + + fn as_slice_mut(&mut self) -> &mut [Self::Value] { + &mut self.0 + } +} + +impl Add for FieldArray { + type Output = Self; + + #[inline] + fn add(self, rhs: Self) -> Self::Output { + array::from_fn(|i| self.0[i] + rhs.0[i]).into() + } +} + +impl Add for FieldArray { + type Output = Self; + + #[inline] + fn add(self, rhs: F) -> Self::Output { + self.0.map(|x| x + rhs).into() + } +} + +impl AddAssign for FieldArray { + #[inline] + fn add_assign(&mut self, rhs: Self) { + self.0.iter_mut().zip(rhs.0).for_each(|(x, y)| *x += y); + } +} + +impl AddAssign for FieldArray { + #[inline] + fn add_assign(&mut self, rhs: F) { + self.0.iter_mut().for_each(|x| *x += rhs); + } +} + +impl Sub for FieldArray { + type Output = Self; + + #[inline] + fn sub(self, rhs: Self) -> Self::Output { + array::from_fn(|i| self.0[i] - rhs.0[i]).into() + } +} + +impl Sub for FieldArray { + type Output = Self; + + #[inline] + fn sub(self, rhs: F) -> Self::Output { + self.0.map(|x| x - rhs).into() + } +} + +impl SubAssign for FieldArray { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + self.0.iter_mut().zip(rhs.0).for_each(|(x, y)| *x -= y); + } +} + +impl SubAssign for FieldArray { + #[inline] + fn sub_assign(&mut self, rhs: F) { + self.0.iter_mut().for_each(|x| *x -= rhs); + } +} + +impl Neg for FieldArray { + type Output = Self; + + #[inline] + fn neg(self) -> Self::Output { + self.0.map(|x| -x).into() + } +} + +impl Mul for FieldArray { + type Output = Self; + + #[inline] + fn mul(self, rhs: Self) -> Self::Output { + array::from_fn(|i| self.0[i] * rhs.0[i]).into() + } +} + +impl Mul for FieldArray { + type Output = Self; + + #[inline] + fn mul(self, rhs: F) -> Self::Output { + self.0.map(|x| x * rhs).into() + } +} + +impl MulAssign for FieldArray { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + self.0.iter_mut().zip(rhs.0).for_each(|(x, y)| *x *= y); + } +} + +impl MulAssign for FieldArray { + #[inline] + fn mul_assign(&mut self, rhs: F) { + self.0.iter_mut().for_each(|x| *x *= rhs); + } +} + +impl Div for FieldArray { + type Output = Self; + + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: F) -> Self::Output { + let rhs_inv = rhs.inverse(); + self * rhs_inv + } +} + +impl Sum for FieldArray { + #[inline] + fn sum>(iter: I) -> Self { + iter.reduce(|lhs, rhs| lhs + rhs).unwrap_or(Self::ZERO) + } +} + +impl Product for FieldArray { + #[inline] + fn product>(iter: I) -> Self { + iter.reduce(|lhs, rhs| lhs * rhs).unwrap_or(Self::ONE) + } +} diff --git a/CoqOfRust/plonky3/field/src/array.v b/CoqOfRust/plonky3/field/src/array.v new file mode 100644 index 000000000..bee484157 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/array.v @@ -0,0 +1,3205 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module array. + (* StructTuple + { + name := "FieldArray"; + const_params := [ "N" ]; + ty_params := [ "F" ]; + fields := [ Ty.apply (Ty.path "array") [ N ] [ F ] ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* Clone *) + Definition clone + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "p3_field::array::FieldArray" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |) + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) [ ("clone", InstanceField.Method (clone N F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_marker_Copy_where_core_marker_Copy_F_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_F_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* Debug *) + Definition fmt + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "FieldArray" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_cmp_Eq_where_core_cmp_Eq_F_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* Eq *) + Definition assert_receiver_is_total_eq + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method (assert_receiver_is_total_eq N F)) ]. + End Impl_core_cmp_Eq_where_core_cmp_Eq_F_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_marker_StructuralPartialEq_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* PartialEq *) + Definition eq + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ F ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "p3_field::array::FieldArray", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + (Self N F) + (* Instance *) [ ("eq", InstanceField.Method (eq N F)) ]. + End Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + pub(crate) fn inverse(&self) -> Self { + let mut result = Self::default(); + batch_multiplicative_inverse_general(&self.0, &mut result.0, |x| x.inverse()); + result + } + *) + Definition inverse + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ result : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::default::Default", + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse_general", + [], + [ F; Ty.function [ Ty.tuple [ F ] ] F ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + result, + "p3_field::array::FieldArray", + 0 + |) + |) + |) + |)); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ F ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + result + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_inverse : + forall (N : Value.t) (F : Ty.t), + M.IsAssociatedFunction.C (Self N F) "inverse" (inverse N F). + Admitted. + Global Typeclasses Opaque inverse. + End Impl_p3_field_array_FieldArray_N_F. + + Module Impl_core_default_Default_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn default() -> Self { + Self::ZERO + } + *) + Definition default + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) [ ("default", InstanceField.Method (default N F)) ]. + End Impl_core_default_Default_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_convert_From_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn from(val: F) -> Self { + [val; N].into() + } + *) + Definition from + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ val ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "into", + [], + [] + |), + [ repeat (| M.read (| val |), N |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self N F) + (* Instance *) [ ("from", InstanceField.Method (from N F)) ]. + End Impl_core_convert_From_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_convert_From_where_p3_field_field_Field_F_array_N_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn from(arr: [F; N]) -> Self { + Self(arr) + } + *) + Definition from + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ arr ] => + ltac:(M.monadic + (let arr := M.alloc (| arr |) in + Value.StructTuple "p3_field::array::FieldArray" [ M.read (| arr |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ F ] ] + (Self N F) + (* Instance *) [ ("from", InstanceField.Method (from N F)) ]. + End Impl_core_convert_From_where_p3_field_field_Field_F_array_N_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_p3_field_field_PrimeCharacteristicRing_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* type PrimeSubfield = F::PrimeSubfield; *) + Definition _PrimeSubfield (N : Value.t) (F : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_field::field::PrimeCharacteristicRing" [] [] F "PrimeSubfield". + + (* const ZERO: Self = Self([F::ZERO; N]); *) + (* Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] *) + Definition value_ZERO + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "p3_field::array::FieldArray" + [ + repeat (| + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) |), + N + |) + ] + |))). + + (* const ONE: Self = Self([F::ONE; N]); *) + (* Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] *) + Definition value_ONE + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "p3_field::array::FieldArray" + [ + repeat (| + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) |), + N + |) + ] + |))). + + (* const TWO: Self = Self([F::TWO; N]); *) + (* Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] *) + Definition value_TWO + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "p3_field::array::FieldArray" + [ + repeat (| + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", F |) |), + N + |) + ] + |))). + + (* const NEG_ONE: Self = Self([F::NEG_ONE; N]); *) + (* Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] *) + Definition value_NEG_ONE + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "p3_field::array::FieldArray" + [ + repeat (| + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::NEG_ONE", F |) + |), + N + |) + ] + |))). + + (* + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + F::from_prime_subfield(f).into() + } + *) + Definition from_prime_subfield + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::convert::Into", + F, + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "into", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ M.read (| f |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::field::PrimeCharacteristicRing" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) + [ + ("PrimeSubfield", InstanceField.Ty (_PrimeSubfield N F)); + ("value_ZERO", InstanceField.Method (value_ZERO N F)); + ("value_ONE", InstanceField.Method (value_ONE N F)); + ("value_TWO", InstanceField.Method (value_TWO N F)); + ("value_NEG_ONE", InstanceField.Method (value_NEG_ONE N F)); + ("from_prime_subfield", InstanceField.Method (from_prime_subfield N F)) + ]. + End Impl_p3_field_field_PrimeCharacteristicRing_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_p3_field_field_Algebra_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::field::Algebra" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self N F) + (* Instance *) []. + End Impl_p3_field_field_Algebra_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_p3_field_packed_PackedValue_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* type Value = F; *) + Definition _Value (N : Value.t) (F : Ty.t) : Ty.t := F. + + (* const WIDTH: usize = N; *) + (* Ty.path "usize" *) + Definition value_WIDTH + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + ltac:(M.monadic (M.alloc (| N |))). + + (* + fn from_slice(slice: &[Self::Value]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { &*slice.as_ptr().cast() } + } + *) + Definition from_slice + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "*const") + [] + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + M.get_associated_function (| + Ty.apply (Ty.path "*const") [] [ F ], + "cast", + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "*const") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "as_ptr", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |) + ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_slice_mut(slice: &mut [Self::Value]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { &mut *slice.as_mut_ptr().cast() } + } + *) + Definition from_slice_mut + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + M.get_associated_function (| + Ty.apply (Ty.path "*mut") [] [ F ], + "cast", + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "as_mut_ptr", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| slice |) |) + |) + ] + |) + ] + |) + |) + |) + |) + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_fn(f: Fn) -> Self + where + Fn: FnMut(usize) -> Self::Value, + { + Self(array::from_fn(f)) + } + *) + Definition from_fn + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [ Fn ], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + Value.StructTuple + "p3_field::array::FieldArray" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_function (| "core::array::from_fn", [ N ], [ F; Fn ] |), + [ M.read (| f |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn as_slice(&self) -> &[Self::Value] { + &self.0 + } + *) + Definition as_slice + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |) + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn as_slice_mut(&mut self) -> &mut [Self::Value] { + &mut self.0 + } + *) + Definition as_slice_mut + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |) + |) + |)) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::packed::PackedValue" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) + [ + ("Value", InstanceField.Ty (_Value N F)); + ("value_WIDTH", InstanceField.Method (value_WIDTH N F)); + ("from_slice", InstanceField.Method (from_slice N F)); + ("from_slice_mut", InstanceField.Method (from_slice_mut N F)); + ("from_fn", InstanceField.Method (from_fn N F)); + ("as_slice", InstanceField.Method (as_slice N F)); + ("as_slice_mut", InstanceField.Method (as_slice_mut N F)) + ]. + End Impl_p3_field_packed_PackedValue_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_Add_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* type Output = Self; *) + Definition _Output (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn add(self, rhs: Self) -> Self::Output { + array::from_fn(|i| self.0[i] + rhs.0[i]).into() + } + *) + Definition add + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_function (| + "core::array::from_fn", + [ N ], + [ F; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + self, + "p3_field::array::FieldArray", + 0 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "p3_field::array::FieldArray", + 0 + |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + (Self N F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N F)); ("add", InstanceField.Method (add N F)) ]. + End Impl_core_ops_arith_Add_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_Add_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* type Output = Self; *) + Definition _Output (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn add(self, rhs: F) -> Self::Output { + self.0.map(|x| x + rhs).into() + } + *) + Definition add + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ N ] [ F ], + "map", + [], + [ Ty.function [ Ty.tuple [ F ] ] F; F ] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| self, "p3_field::array::FieldArray", 0 |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ F ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| rhs |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self N F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N F)); ("add", InstanceField.Method (add N F)) ]. + End Impl_core_ops_arith_Add_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_AddAssign_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn add_assign(&mut self, rhs: Self) { + self.0.iter_mut().zip(rhs.0).for_each(|(x, y)| *x += y); + } + *) + Definition add_assign + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ]; F ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "array") [ N ] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |)) + ] + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "p3_field::array::FieldArray", + 0 + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ]; F ] ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| y |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + (Self N F) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign N F)) ]. + End Impl_core_ops_arith_AddAssign_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_AddAssign_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn add_assign(&mut self, rhs: F) { + self.0.iter_mut().for_each(|x| *x += rhs); + } + *) + Definition add_assign + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "for_each", + [], + [ Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ] ] ] (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ] ] ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| rhs |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self N F) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign N F)) ]. + End Impl_core_ops_arith_AddAssign_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_Sub_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* type Output = Self; *) + Definition _Output (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn sub(self, rhs: Self) -> Self::Output { + array::from_fn(|i| self.0[i] - rhs.0[i]).into() + } + *) + Definition sub + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_function (| + "core::array::from_fn", + [ N ], + [ F; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + self, + "p3_field::array::FieldArray", + 0 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "p3_field::array::FieldArray", + 0 + |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + (Self N F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N F)); ("sub", InstanceField.Method (sub N F)) ]. + End Impl_core_ops_arith_Sub_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_Sub_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* type Output = Self; *) + Definition _Output (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn sub(self, rhs: F) -> Self::Output { + self.0.map(|x| x - rhs).into() + } + *) + Definition sub + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ N ] [ F ], + "map", + [], + [ Ty.function [ Ty.tuple [ F ] ] F; F ] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| self, "p3_field::array::FieldArray", 0 |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ F ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ M.read (| x |); M.read (| rhs |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self N F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N F)); ("sub", InstanceField.Method (sub N F)) ]. + End Impl_core_ops_arith_Sub_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_SubAssign_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn sub_assign(&mut self, rhs: Self) { + self.0.iter_mut().zip(rhs.0).for_each(|(x, y)| *x -= y); + } + *) + Definition sub_assign + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ]; F ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "array") [ N ] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |)) + ] + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "p3_field::array::FieldArray", + 0 + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ]; F ] ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + F, + [], + [ F ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| y |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + (Self N F) + (* Instance *) [ ("sub_assign", InstanceField.Method (sub_assign N F)) ]. + End Impl_core_ops_arith_SubAssign_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_SubAssign_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn sub_assign(&mut self, rhs: F) { + self.0.iter_mut().for_each(|x| *x -= rhs); + } + *) + Definition sub_assign + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "for_each", + [], + [ Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ] ] ] (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ] ] ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + F, + [], + [ F ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| rhs |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self N F) + (* Instance *) [ ("sub_assign", InstanceField.Method (sub_assign N F)) ]. + End Impl_core_ops_arith_SubAssign_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_Neg_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* type Output = Self; *) + Definition _Output (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn neg(self) -> Self::Output { + self.0.map(|x| -x).into() + } + *) + Definition neg + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ N ] [ F ], + "map", + [], + [ Ty.function [ Ty.tuple [ F ] ] F; F ] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| self, "p3_field::array::FieldArray", 0 |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ F ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Neg", + F, + [], + [], + "neg", + [], + [] + |), + [ M.read (| x |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N F)); ("neg", InstanceField.Method (neg N F)) ]. + End Impl_core_ops_arith_Neg_where_p3_field_field_Field_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_Mul_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* type Output = Self; *) + Definition _Output (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn mul(self, rhs: Self) -> Self::Output { + array::from_fn(|i| self.0[i] * rhs.0[i]).into() + } + *) + Definition mul + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_function (| + "core::array::from_fn", + [ N ], + [ F; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + self, + "p3_field::array::FieldArray", + 0 + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "p3_field::array::FieldArray", + 0 + |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + (Self N F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N F)); ("mul", InstanceField.Method (mul N F)) ]. + End Impl_core_ops_arith_Mul_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_Mul_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* type Output = Self; *) + Definition _Output (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn mul(self, rhs: F) -> Self::Output { + self.0.map(|x| x * rhs).into() + } + *) + Definition mul + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ N ] [ F ], + "map", + [], + [ Ty.function [ Ty.tuple [ F ] ] F; F ] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| self, "p3_field::array::FieldArray", 0 |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ F ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| rhs |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self N F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N F)); ("mul", InstanceField.Method (mul N F)) ]. + End Impl_core_ops_arith_Mul_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_MulAssign_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn mul_assign(&mut self, rhs: Self) { + self.0.iter_mut().zip(rhs.0).for_each(|(x, y)| *x *= y); + } + *) + Definition mul_assign + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ]; F ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "array") [ N ] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |)) + ] + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "p3_field::array::FieldArray", + 0 + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ]; F ] ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + F, + [], + [ F ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| y |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + (Self N F) + (* Instance *) [ ("mul_assign", InstanceField.Method (mul_assign N F)) ]. + End Impl_core_ops_arith_MulAssign_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_MulAssign_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn mul_assign(&mut self, rhs: F) { + self.0.iter_mut().for_each(|x| *x *= rhs); + } + *) + Definition mul_assign + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "for_each", + [], + [ Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ] ] ] (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_field::array::FieldArray", + 0 + |) + |)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ] ] ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + F, + [], + [ F ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| rhs |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self N F) + (* Instance *) [ ("mul_assign", InstanceField.Method (mul_assign N F)) ]. + End Impl_core_ops_arith_MulAssign_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_ops_arith_Div_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* type Output = Self; *) + Definition _Output (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn div(self, rhs: F) -> Self::Output { + let rhs_inv = rhs.inverse(); + self * rhs_inv + } + *) + Definition div + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ rhs_inv : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| self |); M.read (| rhs_inv |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Div" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self N F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N F)); ("div", InstanceField.Method (div N F)) ]. + End Impl_core_ops_arith_Div_where_p3_field_field_Field_F_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_iter_traits_accum_Sum_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn sum>(iter: I) -> Self { + iter.reduce(|lhs, rhs| lhs + rhs).unwrap_or(Self::ZERO) + } + *) + Definition sum + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]; + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] + ] + ] + (Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ]; + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ] + ] + ] + (Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let lhs := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ]; + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ] + ] + ] + (Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let rhs := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ], + [], + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ] + ], + "add", + [], + [] + |), + [ M.read (| lhs |); M.read (| rhs |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Sum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + (Self N F) + (* Instance *) [ ("sum", InstanceField.Method (sum N F)) ]. + End Impl_core_iter_traits_accum_Sum_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + + Module Impl_core_iter_traits_accum_Product_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]. + + (* + fn product>(iter: I) -> Self { + iter.reduce(|lhs, rhs| lhs * rhs).unwrap_or(Self::ONE) + } + *) + Definition product + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]; + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] + ] + ] + (Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ]; + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ] + ] + ] + (Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let lhs := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ]; + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ] + ] + ] + (Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let rhs := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ], + [], + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ N ] + [ F ] + ], + "mul", + [], + [] + |), + [ M.read (| lhs |); M.read (| rhs |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Product" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_field::array::FieldArray") [ N ] [ F ] ] + (Self N F) + (* Instance *) [ ("product", InstanceField.Method (product N F)) ]. + End Impl_core_iter_traits_accum_Product_where_p3_field_field_Field_F_p3_field_array_FieldArray_N_F_for_p3_field_array_FieldArray_N_F. +End array. diff --git a/CoqOfRust/plonky3/field/src/batch_inverse.rs b/CoqOfRust/plonky3/field/src/batch_inverse.rs new file mode 100644 index 000000000..3b992460c --- /dev/null +++ b/CoqOfRust/plonky3/field/src/batch_inverse.rs @@ -0,0 +1,82 @@ +use alloc::vec::Vec; + +use p3_maybe_rayon::prelude::*; +use tracing::instrument; + +use crate::field::Field; +use crate::{FieldArray, PackedValue, PrimeCharacteristicRing}; + +/// Batch multiplicative inverses with Montgomery's trick +/// This is Montgomery's trick. At a high level, we invert the product of the given field +/// elements, then derive the individual inverses from that via multiplication. +/// +/// The usual Montgomery trick involves calculating an array of cumulative products, +/// resulting in a long dependency chain. To increase instruction-level parallelism, we +/// compute WIDTH separate cumulative product arrays that only meet at the end. +/// +/// # Panics +/// This will panic if any of the inputs is zero. +#[instrument(level = "debug", skip_all)] +pub fn batch_multiplicative_inverse(x: &[F]) -> Vec { + // How many elements to invert in one thread. + const CHUNK_SIZE: usize = 1024; + + let n = x.len(); + let mut result = F::zero_vec(n); + + x.par_chunks(CHUNK_SIZE) + .zip(result.par_chunks_mut(CHUNK_SIZE)) + .for_each(|(x, result)| { + batch_multiplicative_inverse_helper(x, result); + }); + + result +} + +/// Like `batch_multiplicative_inverse`, but writes the result to the given output buffer. +fn batch_multiplicative_inverse_helper(x: &[F], result: &mut [F]) { + // Higher WIDTH increases instruction-level parallelism, but too high a value will cause us + // to run out of registers. + const WIDTH: usize = 4; + + let n = x.len(); + assert_eq!(result.len(), n); + if n % WIDTH != 0 { + // There isn't a very clean way to do this with FieldArray; for now just do it in serial. + // Another simple (though suboptimal) workaround would be to make two separate calls, one + // for the packed part and one for the remainder. + return batch_multiplicative_inverse_general(x, result, |x| x.inverse()); + } + + let x_packed = FieldArray::::pack_slice(x); + let result_packed = FieldArray::::pack_slice_mut(result); + + batch_multiplicative_inverse_general(x_packed, result_packed, |x_packed| x_packed.inverse()); +} + +/// A simple single-threaded implementation of Montgomery's trick. Since not all `PrimeCharacteristicRing`s +/// support inversion, this takes a custom inversion function. +pub(crate) fn batch_multiplicative_inverse_general(x: &[F], result: &mut [F], inv: Inv) +where + F: PrimeCharacteristicRing + Copy, + Inv: Fn(F) -> F, +{ + let n = x.len(); + assert_eq!(result.len(), n); + if n == 0 { + return; + } + + result[0] = F::ONE; + for i in 1..n { + result[i] = result[i - 1] * x[i - 1]; + } + + let product = result[n - 1] * x[n - 1]; + let mut inv = inv(product); + + for i in (0..n).rev() { + result[i] *= inv; + inv *= x[i]; + } +} diff --git a/CoqOfRust/plonky3/field/src/batch_inverse.v b/CoqOfRust/plonky3/field/src/batch_inverse.v new file mode 100644 index 000000000..633c4c04d --- /dev/null +++ b/CoqOfRust/plonky3/field/src/batch_inverse.v @@ -0,0 +1,1879 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module batch_inverse. + (* #[instrument(level = "debug", skip_all)] *) + Definition batch_multiplicative_inverse + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.catch_return + (Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_field::batch_inverse::batch_multiplicative_inverse::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_field::batch_inverse::batch_multiplicative_inverse::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_field::batch_inverse::batch_multiplicative_inverse::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_field::batch_inverse::batch_multiplicative_inverse::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ result : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "zero_vec", + [], + [] + |), + [ M.read (| n |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSlice", + Ty.apply (Ty.path "slice") [] [ F ], + [], + [ F ], + "par_chunks", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |); + M.read (| + get_constant (| + "p3_field::batch_inverse::batch_multiplicative_inverse::CHUNK_SIZE", + Ty.path "usize" + |) + |) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Ty.apply (Ty.path "slice") [] [ F ], + [], + [ F ], + "par_chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, result |) ] + |) + |) + |); + M.read (| + get_constant (| + "p3_field::batch_inverse::batch_multiplicative_inverse::CHUNK_SIZE", + Ty.path "usize" + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let result := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse_helper", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| result |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + result + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_batch_multiplicative_inverse : + M.IsFunction.C + "p3_field::batch_inverse::batch_multiplicative_inverse" + batch_multiplicative_inverse. + Admitted. + Global Typeclasses Opaque batch_multiplicative_inverse. + + Module batch_multiplicative_inverse. + Definition value_CHUNK_SIZE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 1024 |))). + + Global Instance Instance_IsConstant_value_CHUNK_SIZE : + M.IsFunction.C + "p3_field::batch_inverse::batch_multiplicative_inverse::CHUNK_SIZE" + value_CHUNK_SIZE. + Admitted. + Global Typeclasses Opaque value_CHUNK_SIZE. + End batch_multiplicative_inverse. + + (* + fn batch_multiplicative_inverse_helper(x: &[F], result: &mut [F]) { + // Higher WIDTH increases instruction-level parallelism, but too high a value will cause us + // to run out of registers. + const WIDTH: usize = 4; + + let n = x.len(); + assert_eq!(result.len(), n); + if n % WIDTH != 0 { + // There isn't a very clean way to do this with FieldArray; for now just do it in serial. + // Another simple (though suboptimal) workaround would be to make two separate calls, one + // for the packed part and one for the remainder. + return batch_multiplicative_inverse_general(x, result, |x| x.inverse()); + } + + let x_packed = FieldArray::::pack_slice(x); + let result_packed = FieldArray::::pack_slice_mut(result); + + batch_multiplicative_inverse_general(x_packed, result_packed, |x_packed| x_packed.inverse()); + } + *) + Definition batch_multiplicative_inverse_helper + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ x; result ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let result := M.alloc (| result |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| result |) |) |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, n |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.read (| n |); + M.read (| + get_constant (| + "p3_field::batch_inverse::batch_multiplicative_inverse_helper::WIDTH", + Ty.path "usize" + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse_general", + [], + [ F; Ty.function [ Ty.tuple [ F ] ] F ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| result |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ F ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ x_packed : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ] + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ], + [], + [], + "pack_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ result_packed : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ] + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ], + [], + [], + "pack_slice_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| result |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse_general", + [], + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ] + ] + ] + (Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ]) + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x_packed |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| result_packed |) |) |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ] + ] + ] + (Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x_packed := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::array::FieldArray") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x_packed |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_batch_multiplicative_inverse_helper : + M.IsFunction.C + "p3_field::batch_inverse::batch_multiplicative_inverse_helper" + batch_multiplicative_inverse_helper. + Admitted. + Global Typeclasses Opaque batch_multiplicative_inverse_helper. + + Module batch_multiplicative_inverse_helper. + Definition value_WIDTH (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 4 |))). + + Global Instance Instance_IsConstant_value_WIDTH : + M.IsFunction.C + "p3_field::batch_inverse::batch_multiplicative_inverse_helper::WIDTH" + value_WIDTH. + Admitted. + Global Typeclasses Opaque value_WIDTH. + End batch_multiplicative_inverse_helper. + + (* + pub(crate) fn batch_multiplicative_inverse_general(x: &[F], result: &mut [F], inv: Inv) + where + F: PrimeCharacteristicRing + Copy, + Inv: Fn(F) -> F, + { + let n = x.len(); + assert_eq!(result.len(), n); + if n == 0 { + return; + } + + result[0] = F::ONE; + for i in 1..n { + result[i] = result[i - 1] * x[i - 1]; + } + + let product = result[n - 1] * x[n - 1]; + let mut inv = inv(product); + + for i in (0..n).rev() { + result[i] *= inv; + inv *= x[i]; + } + } + *) + Definition batch_multiplicative_inverse_general + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; Inv ], [ x; result; inv ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let result := M.alloc (| result |) in + let inv := M.alloc (| inv |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| result |) |) |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, n |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| n |); Value.Integer IntegerKind.Usize 0 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| Value.Tuple [] |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| result |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 1); ("end_", M.read (| n |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| result |) |), + M.read (| i |) + |), + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| result |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ product : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| result |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| n |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| n |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) + ] + |) + |) in + let~ inv : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::function::Fn", + Inv, + [], + [ Ty.tuple [ F ] ], + "call", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inv |); Value.Tuple [ M.read (| product |) ] ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| n |)) + ] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + F, + [], + [ F ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| result |) |), + M.read (| i |) + |) + |); + M.read (| inv |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + F, + [], + [ F ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, inv |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + M.read (| i |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_batch_multiplicative_inverse_general : + M.IsFunction.C + "p3_field::batch_inverse::batch_multiplicative_inverse_general" + batch_multiplicative_inverse_general. + Admitted. + Global Typeclasses Opaque batch_multiplicative_inverse_general. +End batch_inverse. diff --git a/CoqOfRust/plonky3/field/src/coset.rs b/CoqOfRust/plonky3/field/src/coset.rs new file mode 100644 index 000000000..f0ee628e3 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/coset.rs @@ -0,0 +1,221 @@ +use core::iter::Take; + +use crate::{Powers, TwoAdicField}; + +/// Coset of a subgroup of the group of units of a finite field of order equal +/// to a power of two. +/// +/// # Examples +/// +/// ``` +/// # use p3_field::{ +/// TwoAdicField, +/// PrimeCharacteristicRing, +/// coset::TwoAdicMultiplicativeCoset +/// }; +/// # use itertools::Itertools; +/// # use p3_baby_bear::BabyBear; +/// # +/// type F = BabyBear; +/// let log_size = 3; +/// let shift = F::from_u64(7); +/// let mut coset = TwoAdicMultiplicativeCoset::new(shift, log_size).unwrap(); +/// let generator = coset.subgroup_generator(); +/// +/// // Coset elements can be queried by index +/// assert_eq!(coset.element(4), shift * generator.exp_u64(4)); +/// +/// // Coset elements can be iterated over in the canonical order +/// assert_eq!( +/// coset.iter().collect_vec(), +/// (0..1 << log_size).map(|i| shift * generator.exp_u64(i)).collect_vec() +/// ); +/// +/// // Cosets can be (element-wise) raised to a power of 2, either maintaining +/// // the shift and raising only the subgroup, or raising both. +/// let coset_shrunk_subgroup = coset.shrink_coset(2).unwrap(); +/// assert_eq!( +/// coset_shrunk_subgroup.subgroup_generator(), +/// coset.subgroup_generator().exp_power_of_2(2), +/// ); +/// assert_eq!( +/// coset_shrunk_subgroup.shift(), +/// coset.shift() +/// ); +/// +/// let coset_power = coset.exp_power_of_2(2).unwrap(); +/// assert_eq!( +/// coset_power.subgroup_generator(), +/// coset.subgroup_generator().exp_power_of_2(2), +/// ); +/// assert_eq!( +/// coset_power.shift(), +/// coset.shift().exp_power_of_2(2), +/// ); +/// ``` +#[derive(Clone, Copy, Debug)] +pub struct TwoAdicMultiplicativeCoset { + // Letting s = shift, and g = generator (of order 2^log_size), the coset in + // question is + // s * = {s, s * g, shift * g^2, ..., s * g^(2^log_size - 1)] + shift: F, + log_size: usize, +} + +impl TwoAdicMultiplicativeCoset { + /// Returns the coset `shift * `, where `generator` is a + /// canonical (i. e. fixed in the implementation of `F: TwoAdicField`) + /// generator of the unique subgroup of the units of `F` of order `2 ^ + /// log_size`. Returns `None` if `log_size > F::TWO_ADICITY`. + /// + /// # Arguments + /// + /// - `shift`: the value by which the subgroup is (multiplicatively) + /// shifted + /// - `log_size`: the size of the subgroup (and hence of the coset) is `2 ^ + /// log_size`. This determines the subgroup uniquely. + pub fn new(shift: F, log_size: usize) -> Option { + if log_size <= F::TWO_ADICITY { + Some(Self { shift, log_size }) + } else { + None + } + } + + /// Returns the generator of the subgroup of order `self.size()`. + #[inline] + pub fn subgroup_generator(&self) -> F { + F::two_adic_generator(self.log_size) + } + + /// Returns the shift of the coset. + #[inline] + pub fn shift(&self) -> F { + self.shift + } + + /// Returns the log2 of the size of the coset. + #[inline] + pub fn log_size(&self) -> usize { + self.log_size + } + + /// Returns the size of the coset. + #[inline] + pub fn size(&self) -> usize { + 1 << self.log_size + } + + /// Returns a new coset with its subgroup reduced by a factor of + /// `2^log_scale_factor` in size (i. e. with generator equal to the + /// `2^log_scale_factor`-th power of that of the original coset), leaving + /// the shift untouched. Note that new coset is contained in the original one. + /// Returns `None` if `log_scale_factor` is greater than `self.log_size()`. + pub fn shrink_coset(&self, log_scale_factor: usize) -> Option { + self.log_size + .checked_sub(log_scale_factor) + .map(|new_log_size| TwoAdicMultiplicativeCoset { + shift: self.shift, + log_size: new_log_size, + }) + } + + /// Returns the coset `self^(2^log_scale_factor)` (i. e. with shift and + /// subgroup generator equal to the `2^log_scale_factor`-th power of the + /// original ones). Returns `None` if `log_scale_factor` is greater than `self.log_size()`. + pub fn exp_power_of_2(&self, log_scale_factor: usize) -> Option { + self.shrink_coset(log_scale_factor).map(|mut coset| { + coset.shift = self.shift.exp_power_of_2(log_scale_factor); + coset + }) + } + + /// Returns a new coset of the same size whose shift is equal to `scale * self.shift`. + pub fn shift_by(&self, scale: F) -> TwoAdicMultiplicativeCoset { + TwoAdicMultiplicativeCoset { + shift: self.shift * scale, + log_size: self.log_size, + } + } + + /// Returns a new coset where the shift has been set to `shift` + pub fn set_shift(&self, shift: F) -> TwoAdicMultiplicativeCoset { + TwoAdicMultiplicativeCoset { + shift, + log_size: self.log_size, + } + } + + /// Checks if the given field element is in the coset + pub fn contains(&self, element: F) -> bool { + // Note that, in a finite field F (this is not true of a general finite + // commutative ring), there is exactly one subgroup of |F^*| of order n + // for each divisor n of |F| - 1, and its elements e are uniquely + // caracterised by the condition e^n = 1. + + // We check (shift^{-1} * element)^(2^log_size) = 1, which is equivalent + // to checking shift^(2^log_size) = element^(2^log_size) - this avoids + // inversion at the cost of a few squarings. The loop terminates early + // if possible. + let (mut shift, mut element) = (self.shift, element); + + for _ in 0..self.log_size { + if element == shift { + return true; + } + element = element.square(); + shift = shift.square(); + } + + element == shift + } + + /// Returns the element `shift * generator^index`, which is the `index % + /// self.size()`-th element of `self` (and, in particular, the `index`-th + /// element of `self` whenever `index` < self.size()). + #[inline] + pub fn element(&mut self, index: usize) -> F { + self.shift * self.generator_exp(index) + } + + // Internal function which computes `generator^exp`. It uses the + // square-and-multiply algorithm with the caveat that squares of the + // generator are queried from the field (which typically should have them + // stored), i. e. rather "fetch-and-multiply". + fn generator_exp(&self, exp: usize) -> F { + let mut gen_power = F::ONE; + // As `generator` satisfies `generator^{self.size()} == 1` we can replace `exp` by `exp mod self.size()`. + // As `self.size()` is a power of `2` this can be done with an `&` instead of a `%`. + let mut exp = exp & (self.size() - 1); + let mut i = self.log_size(); + + while exp > 0 { + if exp & 1 != 0 { + gen_power *= F::two_adic_generator(i); + } + exp >>= 1; + + i -= 1; + } + + gen_power + } + + /// Returns an iterator over the elements of the coset in the canonical order + /// `shift * generator^0, shift * generator^1, ..., + /// shift * generator^(2^log_size - 1)`. + pub fn iter(&self) -> Take> { + self.subgroup_generator() + .shifted_powers(self.shift) + .take(1 << self.log_size) + } +} + +impl IntoIterator for TwoAdicMultiplicativeCoset { + type Item = F; + type IntoIter = Take>; + + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} diff --git a/CoqOfRust/plonky3/field/src/coset.v b/CoqOfRust/plonky3/field/src/coset.v new file mode 100644 index 000000000..974223528 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/coset.v @@ -0,0 +1,1406 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module coset. + (* StructRecord + { + name := "TwoAdicMultiplicativeCoset"; + const_params := []; + ty_params := [ "F" ]; + fields := [ ("shift", F); ("log_size", Ty.path "usize") ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_TwoAdicField_F_for_p3_field_coset_TwoAdicMultiplicativeCoset_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_field::coset::TwoAdicMultiplicativeCoset" + [ + ("shift", + M.call_closure (| + F, + M.get_trait_method (| "core::clone::Clone", F, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "shift" + |) + |) + |) + |) + ] + |)); + ("log_size", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "log_size" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_TwoAdicField_F_for_p3_field_coset_TwoAdicMultiplicativeCoset_F. + + Module Impl_core_marker_Copy_where_core_marker_Copy_F_where_p3_field_field_TwoAdicField_F_for_p3_field_coset_TwoAdicMultiplicativeCoset_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ]. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_F_where_p3_field_field_TwoAdicField_F_for_p3_field_coset_TwoAdicMultiplicativeCoset_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_TwoAdicField_F_for_p3_field_coset_TwoAdicMultiplicativeCoset_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "TwoAdicMultiplicativeCoset" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "shift" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "shift" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "log_size" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "log_size" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_TwoAdicField_F_for_p3_field_coset_TwoAdicMultiplicativeCoset_F. + + Module Impl_p3_field_coset_TwoAdicMultiplicativeCoset_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ]. + + (* + pub fn new(shift: F, log_size: usize) -> Option { + if log_size <= F::TWO_ADICITY { + Some(Self { shift, log_size }) + } else { + None + } + } + *) + Definition new (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ shift; log_size ] => + ltac:(M.monadic + (let shift := M.alloc (| shift |) in + let log_size := M.alloc (| log_size |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ] ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| log_size |); + M.read (| + get_constant (| + "p3_field::field::TwoAdicField::TWO_ADICITY", + Ty.path "usize" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + Value.StructRecord + "p3_field::coset::TwoAdicMultiplicativeCoset" + [ ("shift", M.read (| shift |)); ("log_size", M.read (| log_size |)) ] + ] + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "new" (new F). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn subgroup_generator(&self) -> F { + F::two_adic_generator(self.log_size) + } + *) + Definition subgroup_generator + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "log_size" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_subgroup_generator : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "subgroup_generator" (subgroup_generator F). + Admitted. + Global Typeclasses Opaque subgroup_generator. + + (* + pub fn shift(&self) -> F { + self.shift + } + *) + Definition shift (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "shift" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_shift : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "shift" (shift F). + Admitted. + Global Typeclasses Opaque shift. + + (* + pub fn log_size(&self) -> usize { + self.log_size + } + *) + Definition log_size (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "log_size" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_log_size : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "log_size" (log_size F). + Admitted. + Global Typeclasses Opaque log_size. + + (* + pub fn size(&self) -> usize { + 1 << self.log_size + } + *) + Definition size (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "log_size" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_size : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "size" (size F). + Admitted. + Global Typeclasses Opaque size. + + (* + pub fn shrink_coset(&self, log_scale_factor: usize) -> Option { + self.log_size + .checked_sub(log_scale_factor) + .map(|new_log_size| TwoAdicMultiplicativeCoset { + shift: self.shift, + log_size: new_log_size, + }) + } + *) + Definition shrink_coset (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; log_scale_factor ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let log_scale_factor := M.alloc (| log_scale_factor |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ] ], + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + "map", + [], + [ + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_associated_function (| Ty.path "usize", "checked_sub", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "log_size" + |) + |); + M.read (| log_scale_factor |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let new_log_size := M.copy (| γ |) in + Value.StructRecord + "p3_field::coset::TwoAdicMultiplicativeCoset" + [ + ("shift", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "shift" + |) + |)); + ("log_size", M.read (| new_log_size |)) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_shrink_coset : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "shrink_coset" (shrink_coset F). + Admitted. + Global Typeclasses Opaque shrink_coset. + + (* + pub fn exp_power_of_2(&self, log_scale_factor: usize) -> Option { + self.shrink_coset(log_scale_factor).map(|mut coset| { + coset.shift = self.shift.exp_power_of_2(log_scale_factor); + coset + }) + } + *) + Definition exp_power_of_2 + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; log_scale_factor ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let log_scale_factor := M.alloc (| log_scale_factor |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ] ], + "map", + [], + [ + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ] ] + ] + (Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ] ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ], + "shrink_coset", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| log_scale_factor |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let coset := M.copy (| γ |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + coset, + "p3_field::coset::TwoAdicMultiplicativeCoset", + "shift" + |), + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "shift" + |) + |); + M.read (| log_scale_factor |) + ] + |) + |) + |) in + coset + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_exp_power_of_2 : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "exp_power_of_2" (exp_power_of_2 F). + Admitted. + Global Typeclasses Opaque exp_power_of_2. + + (* + pub fn shift_by(&self, scale: F) -> TwoAdicMultiplicativeCoset { + TwoAdicMultiplicativeCoset { + shift: self.shift * scale, + log_size: self.log_size, + } + } + *) + Definition shift_by (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; scale ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let scale := M.alloc (| scale |) in + Value.StructRecord + "p3_field::coset::TwoAdicMultiplicativeCoset" + [ + ("shift", + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "shift" + |) + |); + M.read (| scale |) + ] + |)); + ("log_size", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "log_size" + |) + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_shift_by : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "shift_by" (shift_by F). + Admitted. + Global Typeclasses Opaque shift_by. + + (* + pub fn set_shift(&self, shift: F) -> TwoAdicMultiplicativeCoset { + TwoAdicMultiplicativeCoset { + shift, + log_size: self.log_size, + } + } + *) + Definition set_shift (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let shift := M.alloc (| shift |) in + Value.StructRecord + "p3_field::coset::TwoAdicMultiplicativeCoset" + [ + ("shift", M.read (| shift |)); + ("log_size", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "log_size" + |) + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_set_shift : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "set_shift" (set_shift F). + Admitted. + Global Typeclasses Opaque set_shift. + + (* + pub fn contains(&self, element: F) -> bool { + // Note that, in a finite field F (this is not true of a general finite + // commutative ring), there is exactly one subgroup of |F^*| of order n + // for each divisor n of |F| - 1, and its elements e are uniquely + // caracterised by the condition e^n = 1. + + // We check (shift^{-1} * element)^(2^log_size) = 1, which is equivalent + // to checking shift^(2^log_size) = element^(2^log_size) - this avoids + // inversion at the cost of a few squarings. The loop terminates early + // if possible. + let (mut shift, mut element) = (self.shift, element); + + for _ in 0..self.log_size { + if element == shift { + return true; + } + element = element.square(); + shift = shift.square(); + } + + element == shift + } + *) + Definition contains (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; element ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let element := M.alloc (| element |) in + M.catch_return (Ty.path "bool") (| + ltac:(M.monadic + (M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "bool" ], + M.alloc (| + Value.Tuple + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "shift" + |) + |); + M.read (| element |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let shift := M.copy (| γ0_0 |) in + let element := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "log_size" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + element + |); + M.borrow (| + Pointer.Kind.Ref, + shift + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| Value.Bool true |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + element, + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, element |) + ] + |) + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + shift, + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, shift |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, element |); + M.borrow (| Pointer.Kind.Ref, shift |) + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_contains : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "contains" (contains F). + Admitted. + Global Typeclasses Opaque contains. + + (* + pub fn element(&mut self, index: usize) -> F { + self.shift * self.generator_exp(index) + } + *) + Definition element (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; index ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let index := M.alloc (| index |) in + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "shift" + |) + |); + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ], + "generator_exp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| index |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_element : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "element" (element F). + Admitted. + Global Typeclasses Opaque element. + + (* + fn generator_exp(&self, exp: usize) -> F { + let mut gen_power = F::ONE; + // As `generator` satisfies `generator^{self.size()} == 1` we can replace `exp` by `exp mod self.size()`. + // As `self.size()` is a power of `2` this can be done with an `&` instead of a `%`. + let mut exp = exp & (self.size() - 1); + let mut i = self.log_size(); + + while exp > 0 { + if exp & 1 != 0 { + gen_power *= F::two_adic_generator(i); + } + exp >>= 1; + + i -= 1; + } + + gen_power + } + *) + Definition generator_exp (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.read (| + let~ gen_power : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) |) in + let~ exp : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ + M.read (| exp |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ F ], + "size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) in + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ], + "log_size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ M.read (| exp |); Value.Integer IntegerKind.Usize 0 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ + M.read (| exp |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + F, + [], + [ F ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, gen_power |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| i |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := exp in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| β |); Value.Integer IntegerKind.I32 1 ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + gen_power + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_generator_exp : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "generator_exp" (generator_exp F). + Admitted. + Global Typeclasses Opaque generator_exp. + + (* + pub fn iter(&self) -> Take> { + self.subgroup_generator() + .shifted_powers(self.shift) + .take(1 << self.log_size) + } + *) + Definition iter (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "shifted_powers", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ], + "subgroup_generator", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "shift" + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::coset::TwoAdicMultiplicativeCoset", + "log_size" + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_iter : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "iter" (iter F). + Admitted. + Global Typeclasses Opaque iter. + End Impl_p3_field_coset_TwoAdicMultiplicativeCoset_F. + + Module Impl_core_iter_traits_collect_IntoIterator_where_p3_field_field_TwoAdicField_F_for_p3_field_coset_TwoAdicMultiplicativeCoset_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ]. + + (* type Item = F; *) + Definition _Item (F : Ty.t) : Ty.t := F. + + (* type IntoIter = Take>; *) + Definition _IntoIter (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ]. + + (* + fn into_iter(self) -> Self::IntoIter { + self.iter() + } + *) + Definition into_iter (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ F ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ + ("Item", InstanceField.Ty (_Item F)); + ("IntoIter", InstanceField.Ty (_IntoIter F)); + ("into_iter", InstanceField.Method (into_iter F)) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_p3_field_field_TwoAdicField_F_for_p3_field_coset_TwoAdicMultiplicativeCoset_F. +End coset. diff --git a/CoqOfRust/plonky3/field/src/exponentiation.rs b/CoqOfRust/plonky3/field/src/exponentiation.rs new file mode 100644 index 000000000..b07e50c80 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/exponentiation.rs @@ -0,0 +1,118 @@ +use crate::PrimeCharacteristicRing; + +pub(crate) const fn bits_u64(n: u64) -> usize { + (64 - n.leading_zeros()) as usize +} + +/// Compute the exponential `x -> x^1717986917` using a custom addition chain. +/// +/// This map computes the fifth root of `x` if `x` is a member of the field `Mersenne31`. +/// This follows from the computation: `5 * 1717986917 = 4*(2^31 - 2) + 1 = 1 mod p - 1`. +pub fn exp_1717986917(val: R) -> R { + // Note the binary expansion: 1717986917 = 1100110011001100110011001100101_2 + // This uses 30 Squares + 7 Multiplications => 37 Operations total. + // Suspect it's possible to improve this with enough effort. For example 1717986918 takes only 4 Multiplications. + let p1 = val; + let p10 = p1.square(); + let p11 = p10.clone() * p1; + let p101 = p10 * p11.clone(); + let p110000 = p11.exp_power_of_2(4); + let p110011 = p110000 * p11.clone(); + let p11001100000000 = p110011.exp_power_of_2(8); + let p11001100110011 = p11001100000000.clone() * p110011; + let p1100110000000000000000 = p11001100000000.exp_power_of_2(8); + let p1100110011001100110011 = p1100110000000000000000 * p11001100110011; + let p11001100110011001100110000 = p1100110011001100110011.exp_power_of_2(4); + let p11001100110011001100110011 = p11001100110011001100110000 * p11; + let p1100110011001100110011001100000 = p11001100110011001100110011.exp_power_of_2(5); + p1100110011001100110011001100000 * p101 +} + +/// Compute the exponential `x -> x^1420470955` using a custom addition chain. +/// +/// This map computes the third root of `x` if `x` is a member of the field `KoalaBear`. +/// This follows from the computation: `3 * 1420470955 = 2*(2^31 - 2^24) + 1 = 1 mod (p - 1)`. +pub fn exp_1420470955(val: R) -> R { + // Note the binary expansion: 1420470955 = 1010100101010101010101010101011_2 + // This uses 29 Squares + 7 Multiplications => 36 Operations total. + // Suspect it's possible to improve this with enough effort. + let p1 = val; + let p100 = p1.exp_power_of_2(2); + let p101 = p100.clone() * p1.clone(); + let p10000 = p100.exp_power_of_2(2); + let p10101 = p10000 * p101; + let p10101000000 = p10101.exp_power_of_2(6); + let p10101010101 = p10101000000.clone() * p10101.clone(); + let p101010010101 = p10101000000 * p10101010101.clone(); + let p101010010101000000000000 = p101010010101.exp_power_of_2(12); + let p101010010101010101010101 = p101010010101000000000000 * p10101010101; + let p101010010101010101010101000000 = p101010010101010101010101.exp_power_of_2(6); + let p101010010101010101010101010101 = p101010010101010101010101000000 * p10101; + let p1010100101010101010101010101010 = p101010010101010101010101010101.square(); + p1010100101010101010101010101010 * p1 +} + +/// Compute the exponential `x -> x^1725656503` using a custom addition chain. +/// +/// This map computes the seventh root of `x` if `x` is a member of the field `BabyBear`. +/// This follows from the computation: `7 * 1725656503 = 6*(2^31 - 2^27) + 1 = 1 mod (p - 1)`. +pub fn exp_1725656503(val: R) -> R { + // Note the binary expansion: 1725656503 = 1100110110110110110110110110111_2 + // This uses 29 Squares + 8 Multiplications => 37 Operations total. + // Suspect it's possible to improve this with enough effort. + let p1 = val; + let p10 = p1.square(); + let p11 = p10 * p1.clone(); + let p110 = p11.square(); + let p111 = p110.clone() * p1; + let p11000 = p110.exp_power_of_2(2); + let p11011 = p11000.clone() * p11; + let p11000000 = p11000.exp_power_of_2(3); + let p11011011 = p11000000.clone() * p11011; + let p110011011 = p11011011.clone() * p11000000; + let p110011011000000000 = p110011011.exp_power_of_2(9); + let p110011011011011011 = p110011011000000000 * p11011011.clone(); + let p110011011011011011000000000 = p110011011011011011.exp_power_of_2(9); + let p110011011011011011011011011 = p110011011011011011000000000 * p11011011; + let p1100110110110110110110110110000 = p110011011011011011011011011.exp_power_of_2(4); + p1100110110110110110110110110000 * p111 +} + +/// Compute the exponential `x -> x^10540996611094048183` using a custom addition chain. +/// +/// This map computes the seventh root of `x` if `x` is a member of the field `Goldilocks`. +/// This follows from the computation: `7 * 10540996611094048183 = 4*(2^64 - 2**32) + 1 = 1 mod (p - 1)`. +pub fn exp_10540996611094048183(val: R) -> R { + // Note the binary expansion: 10540996611094048183 = 1001001001001001001001001001000110110110110110110110110110110111_2. + // This uses 63 Squares + 8 Multiplications => 71 Operations total. + // Suspect it's possible to improve this a little with enough effort. + let p1 = val; + let p10 = p1.square(); + let p11 = p10.clone() * p1; + let p100 = p10.square(); + let p111 = p100.clone() * p11.clone(); + let p100000000000000000000000000000000 = p100.exp_power_of_2(30); + let p100000000000000000000000000000011 = p100000000000000000000000000000000 * p11; + let p100000000000000000000000000000011000 = + p100000000000000000000000000000011.exp_power_of_2(3); + let p100100000000000000000000000000011011 = + p100000000000000000000000000000011000 * p100000000000000000000000000000011; + let p100100000000000000000000000000011011000000 = + p100100000000000000000000000000011011.exp_power_of_2(6); + let p100100100100000000000000000000011011011011 = + p100100000000000000000000000000011011000000 * p100100000000000000000000000000011011.clone(); + let p100100100100000000000000000000011011011011000000000000 = + p100100100100000000000000000000011011011011.exp_power_of_2(12); + let p100100100100100100100100000000011011011011011011011011 = + p100100100100000000000000000000011011011011000000000000 + * p100100100100000000000000000000011011011011; + let p100100100100100100100100000000011011011011011011011011000000 = + p100100100100100100100100000000011011011011011011011011.exp_power_of_2(6); + let p100100100100100100100100100100011011011011011011011011011011 = + p100100100100100100100100000000011011011011011011011011000000 + * p100100000000000000000000000000011011; + let p1001001001001001001001001001000110110110110110110110110110110000 = + p100100100100100100100100100100011011011011011011011011011011.exp_power_of_2(4); + + p1001001001001001001001001001000110110110110110110110110110110000 * p111 +} diff --git a/CoqOfRust/plonky3/field/src/exponentiation.v b/CoqOfRust/plonky3/field/src/exponentiation.v new file mode 100644 index 000000000..d7de44aca --- /dev/null +++ b/CoqOfRust/plonky3/field/src/exponentiation.v @@ -0,0 +1,1050 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module exponentiation. + (* + pub(crate) const fn bits_u64(n: u64) -> usize { + (64 - n.leading_zeros()) as usize + } + *) + Definition bits_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ n ] => + ltac:(M.monadic + (let n := M.alloc (| n |) in + M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + Value.Integer IntegerKind.U32 64; + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u64", "leading_zeros", [], [] |), + [ M.read (| n |) ] + |) + ] + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_bits_u64 : + M.IsFunction.C "p3_field::exponentiation::bits_u64" bits_u64. + Admitted. + Global Typeclasses Opaque bits_u64. + + (* + pub fn exp_1717986917(val: R) -> R { + // Note the binary expansion: 1717986917 = 1100110011001100110011001100101_2 + // This uses 30 Squares + 7 Multiplications => 37 Operations total. + // Suspect it's possible to improve this with enough effort. For example 1717986918 takes only 4 Multiplications. + let p1 = val; + let p10 = p1.square(); + let p11 = p10.clone() * p1; + let p101 = p10 * p11.clone(); + let p110000 = p11.exp_power_of_2(4); + let p110011 = p110000 * p11.clone(); + let p11001100000000 = p110011.exp_power_of_2(8); + let p11001100110011 = p11001100000000.clone() * p110011; + let p1100110000000000000000 = p11001100000000.exp_power_of_2(8); + let p1100110011001100110011 = p1100110000000000000000 * p11001100110011; + let p11001100110011001100110000 = p1100110011001100110011.exp_power_of_2(4); + let p11001100110011001100110011 = p11001100110011001100110000 * p11; + let p1100110011001100110011001100000 = p11001100110011001100110011.exp_power_of_2(5); + p1100110011001100110011001100000 * p101 + } + *) + Definition exp_1717986917 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ val ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + M.read (| + let~ p1 : Ty.apply (Ty.path "*") [] [ R ] := M.copy (| val |) in + let~ p10 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1 |) ] + |) + |) in + let~ p11 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p10 |) ] + |); + M.read (| p1 |) + ] + |) + |) in + let~ p101 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| p10 |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p11 |) ] + |) + ] + |) + |) in + let~ p110000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p11 |); Value.Integer IntegerKind.Usize 4 ] + |) + |) in + let~ p110011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| p110000 |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p11 |) ] + |) + ] + |) + |) in + let~ p11001100000000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p110011 |); Value.Integer IntegerKind.Usize 8 ] + |) + |) in + let~ p11001100110011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p11001100000000 |) ] + |); + M.read (| p110011 |) + ] + |) + |) in + let~ p1100110000000000000000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p11001100000000 |); + Value.Integer IntegerKind.Usize 8 + ] + |) + |) in + let~ p1100110011001100110011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ M.read (| p1100110000000000000000 |); M.read (| p11001100110011 |) ] + |) + |) in + let~ p11001100110011001100110000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p1100110011001100110011 |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) in + let~ p11001100110011001100110011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ M.read (| p11001100110011001100110000 |); M.read (| p11 |) ] + |) + |) in + let~ p1100110011001100110011001100000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p11001100110011001100110011 |); + Value.Integer IntegerKind.Usize 5 + ] + |) + |) in + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ M.read (| p1100110011001100110011001100000 |); M.read (| p101 |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_exp_1717986917 : + M.IsFunction.C "p3_field::exponentiation::exp_1717986917" exp_1717986917. + Admitted. + Global Typeclasses Opaque exp_1717986917. + + (* + pub fn exp_1420470955(val: R) -> R { + // Note the binary expansion: 1420470955 = 1010100101010101010101010101011_2 + // This uses 29 Squares + 7 Multiplications => 36 Operations total. + // Suspect it's possible to improve this with enough effort. + let p1 = val; + let p100 = p1.exp_power_of_2(2); + let p101 = p100.clone() * p1.clone(); + let p10000 = p100.exp_power_of_2(2); + let p10101 = p10000 * p101; + let p10101000000 = p10101.exp_power_of_2(6); + let p10101010101 = p10101000000.clone() * p10101.clone(); + let p101010010101 = p10101000000 * p10101010101.clone(); + let p101010010101000000000000 = p101010010101.exp_power_of_2(12); + let p101010010101010101010101 = p101010010101000000000000 * p10101010101; + let p101010010101010101010101000000 = p101010010101010101010101.exp_power_of_2(6); + let p101010010101010101010101010101 = p101010010101010101010101000000 * p10101; + let p1010100101010101010101010101010 = p101010010101010101010101010101.square(); + p1010100101010101010101010101010 * p1 + } + *) + Definition exp_1420470955 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ val ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + M.read (| + let~ p1 : Ty.apply (Ty.path "*") [] [ R ] := M.copy (| val |) in + let~ p100 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1 |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ p101 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p100 |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p1 |) ] + |) + ] + |) + |) in + let~ p10000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p100 |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ p10101 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ M.read (| p10000 |); M.read (| p101 |) ] + |) + |) in + let~ p10101000000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p10101 |); Value.Integer IntegerKind.Usize 6 ] + |) + |) in + let~ p10101010101 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p10101000000 |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p10101 |) ] + |) + ] + |) + |) in + let~ p101010010101 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| p10101000000 |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p10101010101 |) ] + |) + ] + |) + |) in + let~ p101010010101000000000000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p101010010101 |); Value.Integer IntegerKind.Usize 12 + ] + |) + |) in + let~ p101010010101010101010101 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ M.read (| p101010010101000000000000 |); M.read (| p10101010101 |) ] + |) + |) in + let~ p101010010101010101010101000000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p101010010101010101010101 |); + Value.Integer IntegerKind.Usize 6 + ] + |) + |) in + let~ p101010010101010101010101010101 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ M.read (| p101010010101010101010101000000 |); M.read (| p10101 |) ] + |) + |) in + let~ p1010100101010101010101010101010 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p101010010101010101010101010101 |) ] + |) + |) in + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ M.read (| p1010100101010101010101010101010 |); M.read (| p1 |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_exp_1420470955 : + M.IsFunction.C "p3_field::exponentiation::exp_1420470955" exp_1420470955. + Admitted. + Global Typeclasses Opaque exp_1420470955. + + (* + pub fn exp_1725656503(val: R) -> R { + // Note the binary expansion: 1725656503 = 1100110110110110110110110110111_2 + // This uses 29 Squares + 8 Multiplications => 37 Operations total. + // Suspect it's possible to improve this with enough effort. + let p1 = val; + let p10 = p1.square(); + let p11 = p10 * p1.clone(); + let p110 = p11.square(); + let p111 = p110.clone() * p1; + let p11000 = p110.exp_power_of_2(2); + let p11011 = p11000.clone() * p11; + let p11000000 = p11000.exp_power_of_2(3); + let p11011011 = p11000000.clone() * p11011; + let p110011011 = p11011011.clone() * p11000000; + let p110011011000000000 = p110011011.exp_power_of_2(9); + let p110011011011011011 = p110011011000000000 * p11011011.clone(); + let p110011011011011011000000000 = p110011011011011011.exp_power_of_2(9); + let p110011011011011011011011011 = p110011011011011011000000000 * p11011011; + let p1100110110110110110110110110000 = p110011011011011011011011011.exp_power_of_2(4); + p1100110110110110110110110110000 * p111 + } + *) + Definition exp_1725656503 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ val ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + M.read (| + let~ p1 : Ty.apply (Ty.path "*") [] [ R ] := M.copy (| val |) in + let~ p10 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1 |) ] + |) + |) in + let~ p11 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| p10 |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p1 |) ] + |) + ] + |) + |) in + let~ p110 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p11 |) ] + |) + |) in + let~ p111 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p110 |) ] + |); + M.read (| p1 |) + ] + |) + |) in + let~ p11000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p110 |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ p11011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p11000 |) ] + |); + M.read (| p11 |) + ] + |) + |) in + let~ p11000000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p11000 |); Value.Integer IntegerKind.Usize 3 ] + |) + |) in + let~ p11011011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p11000000 |) ] + |); + M.read (| p11011 |) + ] + |) + |) in + let~ p110011011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p11011011 |) ] + |); + M.read (| p11000000 |) + ] + |) + |) in + let~ p110011011000000000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p110011011 |); Value.Integer IntegerKind.Usize 9 ] + |) + |) in + let~ p110011011011011011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| p110011011000000000 |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p11011011 |) ] + |) + ] + |) + |) in + let~ p110011011011011011000000000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p110011011011011011 |); + Value.Integer IntegerKind.Usize 9 + ] + |) + |) in + let~ p110011011011011011011011011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ M.read (| p110011011011011011000000000 |); M.read (| p11011011 |) ] + |) + |) in + let~ p1100110110110110110110110110000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p110011011011011011011011011 |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) in + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ M.read (| p1100110110110110110110110110000 |); M.read (| p111 |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_exp_1725656503 : + M.IsFunction.C "p3_field::exponentiation::exp_1725656503" exp_1725656503. + Admitted. + Global Typeclasses Opaque exp_1725656503. + + (* + pub fn exp_10540996611094048183(val: R) -> R { + // Note the binary expansion: 10540996611094048183 = 1001001001001001001001001001000110110110110110110110110110110111_2. + // This uses 63 Squares + 8 Multiplications => 71 Operations total. + // Suspect it's possible to improve this a little with enough effort. + let p1 = val; + let p10 = p1.square(); + let p11 = p10.clone() * p1; + let p100 = p10.square(); + let p111 = p100.clone() * p11.clone(); + let p100000000000000000000000000000000 = p100.exp_power_of_2(30); + let p100000000000000000000000000000011 = p100000000000000000000000000000000 * p11; + let p100000000000000000000000000000011000 = + p100000000000000000000000000000011.exp_power_of_2(3); + let p100100000000000000000000000000011011 = + p100000000000000000000000000000011000 * p100000000000000000000000000000011; + let p100100000000000000000000000000011011000000 = + p100100000000000000000000000000011011.exp_power_of_2(6); + let p100100100100000000000000000000011011011011 = + p100100000000000000000000000000011011000000 * p100100000000000000000000000000011011.clone(); + let p100100100100000000000000000000011011011011000000000000 = + p100100100100000000000000000000011011011011.exp_power_of_2(12); + let p100100100100100100100100000000011011011011011011011011 = + p100100100100000000000000000000011011011011000000000000 + * p100100100100000000000000000000011011011011; + let p100100100100100100100100000000011011011011011011011011000000 = + p100100100100100100100100000000011011011011011011011011.exp_power_of_2(6); + let p100100100100100100100100100100011011011011011011011011011011 = + p100100100100100100100100000000011011011011011011011011000000 + * p100100000000000000000000000000011011; + let p1001001001001001001001001001000110110110110110110110110110110000 = + p100100100100100100100100100100011011011011011011011011011011.exp_power_of_2(4); + + p1001001001001001001001001001000110110110110110110110110110110000 * p111 + } + *) + Definition exp_10540996611094048183 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ val ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + M.read (| + let~ p1 : Ty.apply (Ty.path "*") [] [ R ] := M.copy (| val |) in + let~ p10 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1 |) ] + |) + |) in + let~ p11 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p10 |) ] + |); + M.read (| p1 |) + ] + |) + |) in + let~ p100 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p10 |) ] + |) + |) in + let~ p111 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p100 |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p11 |) ] + |) + ] + |) + |) in + let~ p100000000000000000000000000000000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p100 |); Value.Integer IntegerKind.Usize 30 ] + |) + |) in + let~ p100000000000000000000000000000011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ M.read (| p100000000000000000000000000000000 |); M.read (| p11 |) ] + |) + |) in + let~ p100000000000000000000000000000011000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p100000000000000000000000000000011 |); + Value.Integer IntegerKind.Usize 3 + ] + |) + |) in + let~ p100100000000000000000000000000011011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| p100000000000000000000000000000011000 |); + M.read (| p100000000000000000000000000000011 |) + ] + |) + |) in + let~ p100100000000000000000000000000011011000000 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p100100000000000000000000000000011011 |); + Value.Integer IntegerKind.Usize 6 + ] + |) + |) in + let~ p100100100100000000000000000000011011011011 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| p100100000000000000000000000000011011000000 |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, p100100000000000000000000000000011011 |) ] + |) + ] + |) + |) in + let~ p100100100100000000000000000000011011011011000000000000 : + Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p100100100100000000000000000000011011011011 |); + Value.Integer IntegerKind.Usize 12 + ] + |) + |) in + let~ p100100100100100100100100000000011011011011011011011011 : + Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| p100100100100000000000000000000011011011011000000000000 |); + M.read (| p100100100100000000000000000000011011011011 |) + ] + |) + |) in + let~ p100100100100100100100100000000011011011011011011011011000000 : + Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + p100100100100100100100100000000011011011011011011011011 + |); + Value.Integer IntegerKind.Usize 6 + ] + |) + |) in + let~ p100100100100100100100100100100011011011011011011011011011011 : + Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| p100100100100100100100100000000011011011011011011011011000000 |); + M.read (| p100100000000000000000000000000011011 |) + ] + |) + |) in + let~ p1001001001001001001001001001000110110110110110110110110110110000 : + Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + p100100100100100100100100100100011011011011011011011011011011 + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) in + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R ], "mul", [], [] |), + [ + M.read (| p1001001001001001001001001001000110110110110110110110110110110000 |); + M.read (| p111 |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_exp_10540996611094048183 : + M.IsFunction.C "p3_field::exponentiation::exp_10540996611094048183" exp_10540996611094048183. + Admitted. + Global Typeclasses Opaque exp_10540996611094048183. +End exponentiation. diff --git a/CoqOfRust/plonky3/field/src/extension/binomial_extension.rs b/CoqOfRust/plonky3/field/src/extension/binomial_extension.rs new file mode 100644 index 000000000..ff3fda71b --- /dev/null +++ b/CoqOfRust/plonky3/field/src/extension/binomial_extension.rs @@ -0,0 +1,662 @@ +use alloc::format; +use alloc::string::ToString; +use alloc::vec::Vec; +use core::array; +use core::fmt::{self, Debug, Display, Formatter}; +use core::iter::{Product, Sum}; +use core::marker::PhantomData; +use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; + +use itertools::Itertools; +use num_bigint::BigUint; +use p3_util::{flatten_to_base, reconstitute_from_base}; +use rand::distr::StandardUniform; +use rand::prelude::Distribution; +use serde::{Deserialize, Serialize}; + +use super::{HasFrobenius, HasTwoAdicBinomialExtension, PackedBinomialExtensionField}; +use crate::extension::BinomiallyExtendable; +use crate::field::Field; +use crate::{ + Algebra, BasedVectorSpace, ExtensionField, Packable, PrimeCharacteristicRing, TwoAdicField, + field_to_array, +}; + +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize, PartialOrd, Ord)] +#[repr(transparent)] // Needed to make various casts safe. +pub struct BinomialExtensionField { + #[serde( + with = "p3_util::array_serialization", + bound(serialize = "A: Serialize", deserialize = "A: Deserialize<'de>") + )] + pub(crate) value: [A; D], + _phantom: PhantomData, +} + +impl BinomialExtensionField { + pub(crate) const fn new(value: [A; D]) -> Self { + Self { + value, + _phantom: PhantomData, + } + } +} + +impl, const D: usize> Default for BinomialExtensionField { + fn default() -> Self { + Self::new(array::from_fn(|_| A::ZERO)) + } +} + +impl, const D: usize> From for BinomialExtensionField { + fn from(x: A) -> Self { + Self::new(field_to_array(x)) + } +} + +impl, const D: usize> Packable for BinomialExtensionField {} + +impl, A: Algebra, const D: usize> BasedVectorSpace + for BinomialExtensionField +{ + const DIMENSION: usize = D; + + #[inline] + fn as_basis_coefficients_slice(&self) -> &[A] { + &self.value + } + + #[inline] + fn from_basis_coefficients_fn A>(f: Fn) -> Self { + Self::new(array::from_fn(f)) + } + + #[inline] + fn from_basis_coefficients_iter>(mut iter: I) -> Option { + (iter.len() == D).then(|| Self::new(array::from_fn(|_| iter.next().unwrap()))) // The unwrap is safe as we just checked the length of iter. + } + + #[inline] + fn flatten_to_base(vec: Vec) -> Vec { + unsafe { + // Safety: + // As `Self` is a `repr(transparent)`, it is stored identically in memory to `[A; D]` + flatten_to_base::(vec) + } + } + + #[inline] + fn reconstitute_from_base(vec: Vec) -> Vec { + unsafe { + // Safety: + // As `Self` is a `repr(transparent)`, it is stored identically in memory to `[A; D]` + reconstitute_from_base::(vec) + } + } +} + +impl, const D: usize> ExtensionField + for BinomialExtensionField +{ + type ExtensionPacking = PackedBinomialExtensionField; + + #[inline] + fn is_in_basefield(&self) -> bool { + self.value[1..].iter().all(F::is_zero) + } + + #[inline] + fn as_base(&self) -> Option { + >::is_in_basefield(self).then(|| self.value[0]) + } +} + +impl, const D: usize> HasFrobenius for BinomialExtensionField { + /// FrobeniusField automorphisms: x -> x^n, where n is the order of BaseField. + #[inline] + fn frobenius(&self) -> Self { + self.repeated_frobenius(1) + } + + /// Repeated Frobenius automorphisms: x -> x^(n^count). + /// + /// Follows precomputation suggestion in Section 11.3.3 of the + /// Handbook of Elliptic and Hyperelliptic Curve Cryptography. + #[inline] + fn repeated_frobenius(&self, count: usize) -> Self { + if count == 0 { + return *self; + } else if count >= D { + // x |-> x^(n^D) is the identity, so x^(n^count) == + // x^(n^(count % D)) + return self.repeated_frobenius(count % D); + } + + // z0 = DTH_ROOT^count = W^(k * count) where k = floor((n-1)/D) + let z0 = F::DTH_ROOT.exp_u64(count as u64); + + let mut res = Self::ZERO; + for (i, z) in z0.powers().take(D).enumerate() { + res.value[i] = self.value[i] * z; + } + + res + } + + /// Algorithm 11.3.4 in Handbook of Elliptic and Hyperelliptic Curve Cryptography. + #[inline] + fn frobenius_inv(&self) -> Self { + // Writing 'a' for self, we need to compute a^(r-1): + // r = n^D-1/n-1 = n^(D-1)+n^(D-2)+...+n + let mut f = Self::ONE; + for _ in 1..D { + f = (f * *self).frobenius(); + } + + // g = a^r is in the base field, so only compute that + // coefficient rather than the full product. + let a = self.value; + let b = f.value; + let mut g = F::ZERO; + for i in 1..D { + g += a[i] * b[D - i]; + } + g *= F::W; + g += a[0] * b[0]; + debug_assert_eq!(Self::from(g), *self * f); + + f * g.inverse() + } +} + +impl PrimeCharacteristicRing for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + type PrimeSubfield = ::PrimeSubfield; + + const ZERO: Self = Self::new([A::ZERO; D]); + + const ONE: Self = Self::new(field_to_array(A::ONE)); + + const TWO: Self = Self::new(field_to_array(A::TWO)); + + const NEG_ONE: Self = Self::new(field_to_array(A::NEG_ONE)); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + ::from_prime_subfield(f).into() + } + + #[inline(always)] + fn square(&self) -> Self { + match D { + 2 => { + let a = self.value.clone(); + let mut res = Self::default(); + res.value[0] = a[0].square() + a[1].square() * F::W; + res.value[1] = a[0].clone() * a[1].double(); + res + } + 3 => { + let mut res = Self::default(); + cubic_square(&self.value, &mut res.value); + res + } + _ => >::mul(self.clone(), self.clone()), + } + } + + #[inline] + fn mul_2exp_u64(&self, exp: u64) -> Self { + Self::new(self.value.clone().map(|x| x.mul_2exp_u64(exp))) + } + + #[inline] + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(F::zero_vec(len * D)) } + } +} + +impl, const D: usize> Algebra for BinomialExtensionField {} + +impl, const D: usize> Field for BinomialExtensionField { + type Packing = Self; + + const GENERATOR: Self = Self::new(F::EXT_GENERATOR); + + fn try_inverse(&self) -> Option { + if self.is_zero() { + return None; + } + + let mut res = Self::default(); + + match D { + 2 => quadratic_inv(&self.value, &mut res.value, F::W), + 3 => cubic_inv(&self.value, &mut res.value, F::W), + _ => res = self.frobenius_inv(), + } + + Some(res) + } + + #[inline] + fn halve(&self) -> Self { + Self::new(self.value.map(|x| x.halve())) + } + + #[inline] + fn div_2exp_u64(&self, exp: u64) -> Self { + Self::new(self.value.map(|x| x.div_2exp_u64(exp))) + } + + #[inline] + fn order() -> BigUint { + F::order().pow(D as u32) + } +} + +impl Display for BinomialExtensionField +where + F: BinomiallyExtendable, +{ + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + if self.is_zero() { + write!(f, "0") + } else { + let str = self + .value + .iter() + .enumerate() + .filter(|(_, x)| !x.is_zero()) + .map(|(i, x)| match (i, x.is_one()) { + (0, _) => format!("{x}"), + (1, true) => "X".to_string(), + (1, false) => format!("{x} X"), + (_, true) => format!("X^{i}"), + (_, false) => format!("{x} X^{i}"), + }) + .join(" + "); + write!(f, "{}", str) + } + } +} + +impl Neg for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + type Output = Self; + + #[inline] + fn neg(self) -> Self { + Self::new(self.value.map(A::neg)) + } +} + +impl Add for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + type Output = Self; + + #[inline] + fn add(self, rhs: Self) -> Self { + let value = vector_add(&self.value, &rhs.value); + Self::new(value) + } +} + +impl Add for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + type Output = Self; + + #[inline] + fn add(mut self, rhs: A) -> Self { + self.value[0] += rhs; + self + } +} + +impl AddAssign for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + #[inline] + fn add_assign(&mut self, rhs: Self) { + for i in 0..D { + self.value[i] += rhs.value[i].clone(); + } + } +} + +impl AddAssign for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + #[inline] + fn add_assign(&mut self, rhs: A) { + self.value[0] += rhs; + } +} + +impl Sum for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + #[inline] + fn sum>(iter: I) -> Self { + iter.reduce(|acc, x| acc + x).unwrap_or(Self::ZERO) + } +} + +impl Sub for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + type Output = Self; + + #[inline] + fn sub(self, rhs: Self) -> Self { + let value = vector_sub(&self.value, &rhs.value); + Self::new(value) + } +} + +impl Sub for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + type Output = Self; + + #[inline] + fn sub(self, rhs: A) -> Self { + let mut res = self.value; + res[0] -= rhs; + Self::new(res) + } +} + +impl SubAssign for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + #[inline] + fn sub_assign(&mut self, rhs: Self) { + for i in 0..D { + self.value[i] -= rhs.value[i].clone(); + } + } +} + +impl SubAssign for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + #[inline] + fn sub_assign(&mut self, rhs: A) { + self.value[0] -= rhs; + } +} + +impl Mul for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + type Output = Self; + + #[inline] + fn mul(self, rhs: Self) -> Self { + let a = self.value; + let b = rhs.value; + let mut res = Self::default(); + let w = F::W; + + binomial_mul(&a, &b, &mut res.value, w); + + res + } +} + +impl Mul for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + type Output = Self; + + #[inline] + fn mul(self, rhs: A) -> Self { + Self::new(self.value.map(|x| x * rhs.clone())) + } +} + +impl MulAssign for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = self.clone() * rhs; + } +} + +impl MulAssign for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + #[inline] + fn mul_assign(&mut self, rhs: A) { + *self = self.clone() * rhs; + } +} + +impl Product for BinomialExtensionField +where + F: BinomiallyExtendable, + A: Algebra, +{ + #[inline] + fn product>(iter: I) -> Self { + iter.reduce(|acc, x| acc * x).unwrap_or(Self::ONE) + } +} + +impl Div for BinomialExtensionField +where + F: BinomiallyExtendable, +{ + type Output = Self; + + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: Self) -> Self::Output { + self * rhs.inverse() + } +} + +impl DivAssign for BinomialExtensionField +where + F: BinomiallyExtendable, +{ + #[inline] + fn div_assign(&mut self, rhs: Self) { + *self = *self / rhs; + } +} + +impl, const D: usize> Distribution> + for StandardUniform +where + Self: Distribution, +{ + #[inline] + fn sample(&self, rng: &mut R) -> BinomialExtensionField { + BinomialExtensionField::new(array::from_fn(|_| self.sample(rng))) + } +} + +impl, const D: usize> TwoAdicField + for BinomialExtensionField +{ + const TWO_ADICITY: usize = F::EXT_TWO_ADICITY; + + #[inline] + fn two_adic_generator(bits: usize) -> Self { + Self::new(F::ext_two_adic_generator(bits)) + } +} + +/// Add two vectors element wise. +#[inline] +pub(crate) fn vector_add< + R: PrimeCharacteristicRing + Add, + R2: Clone, + const D: usize, +>( + a: &[R; D], + b: &[R2; D], +) -> [R; D] { + array::from_fn(|i| a[i].clone() + b[i].clone()) +} + +/// Subtract two vectors element wise. +#[inline] +pub(crate) fn vector_sub< + R: PrimeCharacteristicRing + Sub, + R2: Clone, + const D: usize, +>( + a: &[R; D], + b: &[R2; D], +) -> [R; D] { + array::from_fn(|i| a[i].clone() - b[i].clone()) +} + +/// Multiply two vectors representing elements in a binomial extension. +#[inline] +pub(super) fn binomial_mul< + F: Field, + R: Algebra + Mul, + R2: Add + Clone, + const D: usize, +>( + a: &[R; D], + b: &[R2; D], + res: &mut [R; D], + w: F, +) { + match D { + 2 => { + res[0] = a[0].clone() * b[0].clone() + a[1].clone() * w * b[1].clone(); + res[1] = a[0].clone() * b[1].clone() + a[1].clone() * b[0].clone(); + } + 3 => cubic_mul(a, b, res, w), + _ => + { + #[allow(clippy::needless_range_loop)] + for i in 0..D { + for j in 0..D { + if i + j >= D { + res[i + j - D] += a[i].clone() * w * b[j].clone(); + } else { + res[i + j] += a[i].clone() * b[j].clone(); + } + } + } + } + } +} + +///Section 11.3.6b in Handbook of Elliptic and Hyperelliptic Curve Cryptography. +#[inline] +fn quadratic_inv(a: &[F; D], res: &mut [F; D], w: F) { + assert_eq!(D, 2); + let scalar = (a[0].square() - w * a[1].square()).inverse(); + res[0] = a[0] * scalar; + res[1] = -a[1] * scalar; +} + +/// Section 11.3.6b in Handbook of Elliptic and Hyperelliptic Curve Cryptography. +#[inline] +fn cubic_inv(a: &[F; D], res: &mut [F; D], w: F) { + assert_eq!(D, 3); + let a0_square = a[0].square(); + let a1_square = a[1].square(); + let a2_w = w * a[2]; + let a0_a1 = a[0] * a[1]; + + // scalar = (a0^3+wa1^3+w^2a2^3-3wa0a1a2)^-1 + let scalar = (a0_square * a[0] + w * a[1] * a1_square + a2_w.square() * a[2] + - (F::ONE + F::TWO) * a2_w * a0_a1) + .inverse(); + + //scalar*[a0^2-wa1a2, wa2^2-a0a1, a1^2-a0a2] + res[0] = scalar * (a0_square - a[1] * a2_w); + res[1] = scalar * (a2_w * a[2] - a0_a1); + res[2] = scalar * (a1_square - a[0] * a[2]); +} + +/// karatsuba multiplication for cubic extension field +#[inline] +pub(crate) fn cubic_mul< + F: Field, + R: Algebra + Mul, + R2: Add + Clone, + const D: usize, +>( + a: &[R; D], + b: &[R2; D], + res: &mut [R; D], + w: F, +) { + assert_eq!(D, 3); + + let a0_b0 = a[0].clone() * b[0].clone(); + let a1_b1 = a[1].clone() * b[1].clone(); + let a2_b2 = a[2].clone() * b[2].clone(); + + res[0] = a0_b0.clone() + + ((a[1].clone() + a[2].clone()) * (b[1].clone() + b[2].clone()) + - a1_b1.clone() + - a2_b2.clone()) + * w; + res[1] = (a[0].clone() + a[1].clone()) * (b[0].clone() + b[1].clone()) + - a0_b0.clone() + - a1_b1.clone() + + a2_b2.clone() * w; + res[2] = (a[0].clone() + a[2].clone()) * (b[0].clone() + b[2].clone()) - a0_b0 - a2_b2 + a1_b1; +} + +/// Section 11.3.6a in Handbook of Elliptic and Hyperelliptic Curve Cryptography. +#[inline] +pub(crate) fn cubic_square, A: Algebra, const D: usize>( + a: &[A; D], + res: &mut [A; D], +) { + assert_eq!(D, 3); + + let w_a2 = a[2].clone() * F::W; + + res[0] = a[0].square() + (a[1].clone() * w_a2.clone()).double(); + res[1] = w_a2 * a[2].clone() + (a[0].clone() * a[1].clone()).double(); + res[2] = a[1].square() + (a[0].clone() * a[2].clone()).double(); +} diff --git a/CoqOfRust/plonky3/field/src/extension/binomial_extension.v b/CoqOfRust/plonky3/field/src/extension/binomial_extension.v new file mode 100644 index 000000000..6686d2fa6 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/extension/binomial_extension.v @@ -0,0 +1,11621 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module extension. + Module binomial_extension. + (* StructRecord + { + name := "BinomialExtensionField"; + const_params := [ "D" ]; + ty_params := [ "F"; "A" ]; + fields := + [ + ("value", Ty.apply (Ty.path "array") [ D ] [ A ]); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ]) + ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_F_where_core_marker_Copy_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_F_where_core_marker_Copy_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* Clone *) + Definition clone + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_field::extension::binomial_extension::BinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ D ] [ A ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |)); + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "_phantom" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) [ ("clone", InstanceField.Method (clone D F A)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_cmp_Eq_where_core_cmp_Eq_F_where_core_cmp_Eq_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* Eq *) + Definition assert_receiver_is_total_eq + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) + [ + ("assert_receiver_is_total_eq", + InstanceField.Method (assert_receiver_is_total_eq D F A)) + ]. + End Impl_core_cmp_Eq_where_core_cmp_Eq_F_where_core_cmp_Eq_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_marker_StructuralPartialEq_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_where_core_cmp_PartialEq_A_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* PartialEq *) + Definition eq + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ D ] [ A ], + [], + [ Ty.apply (Ty.path "array") [ D ] [ A ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [ Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "_phantom" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "_phantom" + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + (Self D F A) + (* Instance *) [ ("eq", InstanceField.Method (eq D F A)) ]. + End Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_where_core_cmp_PartialEq_A_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_hash_Hash_where_core_hash_Hash_F_where_core_hash_Hash_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* Hash *) + Definition hash + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply (Ty.path "array") [ D ] [ A ], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "_phantom" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) [ ("hash", InstanceField.Method (hash D F A)) ]. + End Impl_core_hash_Hash_where_core_hash_Hash_F_where_core_hash_Hash_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* Debug *) + Definition fmt + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "BinomialExtensionField" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "value" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) [ ("fmt", InstanceField.Method (fmt D F A)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module underscore. + Module Impl_serde_ser_Serialize_where_serde_ser_Serialize_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* Serialize *) + Definition serialize + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "BinomialExtensionField" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::_::serialize::__SerializeWith") + [ D ] + [ F; A ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "value" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructRecord + "p3_field::extension::binomial_extension::_::serialize::__SerializeWith" + [ + ("values", + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |) + ]); + ("phantom", + Value.StructTuple "core::marker::PhantomData" []) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ] ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "_phantom" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "_phantom" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) [ ("serialize", InstanceField.Method (serialize D F A)) ]. + End Impl_serde_ser_Serialize_where_serde_ser_Serialize_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Module Impl_serde_de_Deserialize_where_serde_de_Deserialize_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* Deserialize *) + Definition deserialize + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::_'1::deserialize::__Visitor") + [ D ] + [ F; A ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "BinomialExtensionField" |); + M.read (| + get_constant (| + "p3_field::extension::binomial_extension::_'1::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_field::extension::binomial_extension::_'1::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize D F A)) ]. + End Impl_serde_de_Deserialize_where_serde_de_Deserialize_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + End underscore. + + + Module Impl_core_cmp_PartialOrd_where_core_cmp_PartialOrd_F_where_core_cmp_PartialOrd_A_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* PartialOrd *) + Definition partial_cmp + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ] + ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "array") [ D ] [ A ], + [], + [ Ty.apply (Ty.path "array") [ D ] [ A ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let _ := M.is_struct_tuple (| γ0_0, "core::cmp::Ordering::Equal" |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [ Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "_phantom" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "_phantom" + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let cmp := M.copy (| γ |) in + cmp)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + (Self D F A) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp D F A)) ]. + End Impl_core_cmp_PartialOrd_where_core_cmp_PartialOrd_F_where_core_cmp_PartialOrd_A_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_cmp_Ord_where_core_cmp_Ord_F_where_core_cmp_Ord_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* Ord *) + Definition cmp + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "core::cmp::Ordering" ], + M.alloc (| + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply (Ty.path "array") [ D ] [ A ], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::cmp::Ordering::Equal" |) in + M.alloc (| + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "_phantom" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "_phantom" + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let cmp := M.copy (| γ |) in + cmp)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) [ ("cmp", InstanceField.Method (cmp D F A)) ]. + End Impl_core_cmp_Ord_where_core_cmp_Ord_F_where_core_cmp_Ord_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + pub(crate) const fn new(value: [A; D]) -> Self { + Self { + value, + _phantom: PhantomData, + } + } + *) + Definition new + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructRecord + "p3_field::extension::binomial_extension::BinomialExtensionField" + [ + ("value", M.read (| value |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (D : Value.t) (F A : Ty.t), + M.IsAssociatedFunction.C (Self D F A) "new" (new D F A). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_default_Default_where_p3_field_field_Field_F_where_p3_field_field_Algebra_A_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn default() -> Self { + Self::new(array::from_fn(|_| A::ZERO)) + } + *) + Definition default + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_function (| + "core::array::from_fn", + [ D ], + [ A; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] A ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] A ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + A + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) [ ("default", InstanceField.Method (default D F A)) ]. + End Impl_core_default_Default_where_p3_field_field_Field_F_where_p3_field_field_Algebra_A_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_convert_From_where_p3_field_field_Field_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn from(x: A) -> Self { + Self::new(field_to_array(x)) + } + *) + Definition from + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_function (| "p3_field::helpers::field_to_array", [ D ], [ A ] |), + [ M.read (| x |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ A ] + (Self D F A) + (* Instance *) [ ("from", InstanceField.Method (from D F A)) ]. + End Impl_core_convert_From_where_p3_field_field_Field_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_p3_field_packed_Packable_where_p3_field_extension_BinomiallyExtendable_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::packed::Packable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F) + (* Instance *) []. + End Impl_p3_field_packed_Packable_where_p3_field_extension_BinomiallyExtendable_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + + Module Impl_p3_field_field_BasedVectorSpace_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* const DIMENSION: usize = D; *) + (* Ty.path "usize" *) + Definition value_DIMENSION + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + ltac:(M.monadic (M.alloc (| D |))). + + (* + fn as_basis_coefficients_slice(&self) -> &[A] { + &self.value + } + *) + Definition as_basis_coefficients_slice + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_basis_coefficients_fn A>(f: Fn) -> Self { + Self::new(array::from_fn(f)) + } + *) + Definition from_basis_coefficients_fn + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [ Fn ], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_function (| "core::array::from_fn", [ D ], [ A; Fn ] |), + [ M.read (| f |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_basis_coefficients_iter>(mut iter: I) -> Option { + (iter.len() == D).then(|| Self::new(array::from_fn(|_| iter.next().unwrap()))) // The unwrap is safe as we just checked the length of iter. + } + *) + Definition from_basis_coefficients_iter + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]; + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]) + ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::iter::traits::exact_size::ExactSizeIterator", + I, + [], + [], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, iter |) ] + |); + D + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_function (| + "core::array::from_fn", + [ D ], + [ A; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] A ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + A + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + A, + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ A ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ A ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn flatten_to_base(vec: Vec) -> Vec { + unsafe { + // Safety: + // As `Self` is a `repr(transparent)`, it is stored identically in memory to `[A; D]` + flatten_to_base::(vec) + } + } + *) + Definition flatten_to_base + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ vec ] => + ltac:(M.monadic + (let vec := M.alloc (| vec |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ A; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_util::flatten_to_base", + [], + [ + A; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + |), + [ M.read (| vec |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn reconstitute_from_base(vec: Vec) -> Vec { + unsafe { + // Safety: + // As `Self` is a `repr(transparent)`, it is stored identically in memory to `[A; D]` + reconstitute_from_base::(vec) + } + } + *) + Definition reconstitute_from_base + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ vec ] => + ltac:(M.monadic + (let vec := M.alloc (| vec |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_util::reconstitute_from_base", + [], + [ + A; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + |), + [ M.read (| vec |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "p3_field::field::BasedVectorSpace" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ A ] + (Self D F A) + (* Instance *) + [ + ("value_DIMENSION", InstanceField.Method (value_DIMENSION D F A)); + ("as_basis_coefficients_slice", + InstanceField.Method (as_basis_coefficients_slice D F A)); + ("from_basis_coefficients_fn", InstanceField.Method (from_basis_coefficients_fn D F A)); + ("from_basis_coefficients_iter", + InstanceField.Method (from_basis_coefficients_iter D F A)); + ("flatten_to_base", InstanceField.Method (flatten_to_base D F A)); + ("reconstitute_from_base", InstanceField.Method (reconstitute_from_base D F A)) + ]. + End Impl_p3_field_field_BasedVectorSpace_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_p3_field_field_ExtensionField_where_p3_field_extension_BinomiallyExtendable_F_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + (* type ExtensionPacking = PackedBinomialExtensionField; *) + Definition _ExtensionPacking (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ]. + + (* + fn is_in_basefield(&self) -> bool { + self.value[1..].iter().all(F::is_zero) + } + *) + Definition is_in_basefield + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "all", + [], + [ Ty.function [ Ty.apply (Ty.path "&") [] [ F ] ] (Ty.path "bool") ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ D ] [ F ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + |) + |); + M.get_trait_method (| "p3_field::field::Field", F, [], [], "is_zero", [], [] |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn as_base(&self) -> Option { + >::is_in_basefield(self).then(|| self.value[0]) + } + *) + Definition as_base + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ F; Ty.function [ Ty.tuple [] ] F ] + |), + [ + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::ExtensionField", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ F ], + "is_in_basefield", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 0 + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::field::ExtensionField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self D F) + (* Instance *) + [ + ("ExtensionPacking", InstanceField.Ty (_ExtensionPacking D F)); + ("is_in_basefield", InstanceField.Method (is_in_basefield D F)); + ("as_base", InstanceField.Method (as_base D F)) + ]. + End Impl_p3_field_field_ExtensionField_where_p3_field_extension_BinomiallyExtendable_F_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + + Module Impl_p3_field_extension_HasFrobenius_where_p3_field_extension_BinomiallyExtendable_F_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + (* + fn frobenius(&self) -> Self { + self.repeated_frobenius(1) + } + *) + Definition frobenius + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "p3_field::extension::HasFrobenius", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ F ], + "repeated_frobenius", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + Value.Integer IntegerKind.Usize 1 + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn repeated_frobenius(&self, count: usize) -> Self { + if count == 0 { + return *self; + } else if count >= D { + // x |-> x^(n^D) is the identity, so x^(n^count) == + // x^(n^(count % D)) + return self.repeated_frobenius(count % D); + } + + // z0 = DTH_ROOT^count = W^(k * count) where k = floor((n-1)/D) + let z0 = F::DTH_ROOT.exp_u64(count as u64); + + let mut res = Self::ZERO; + for (i, z) in z0.powers().take(D).enumerate() { + res.value[i] = self.value[i] * z; + } + + res + } + *) + Definition repeated_frobenius + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self; count ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let count := M.alloc (| count |) in + M.catch_return + (Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| count |); Value.Integer IntegerKind.Usize 0 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| M.read (| M.deref (| M.read (| self |) |) |) |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| count |); D ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "p3_field::extension::HasFrobenius", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ F ], + "repeated_frobenius", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| count |); D ] + |) + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ z0 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::extension::BinomiallyExtendable::DTH_ROOT", + F + |) + |); + M.cast (Ty.path "u64") (M.read (| count |)) + ] + |) + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] := + M.copy (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, z0 |) ] + |); + D + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let i := M.copy (| γ1_0 |) in + let z := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + M.read (| i |) + |), + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + M.read (| i |) + |) + |); + M.read (| z |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + res + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn frobenius_inv(&self) -> Self { + // Writing 'a' for self, we need to compute a^(r-1): + // r = n^D-1/n-1 = n^(D-1)+n^(D-2)+...+n + let mut f = Self::ONE; + for _ in 1..D { + f = (f * *self).frobenius(); + } + + // g = a^r is in the base field, so only compute that + // coefficient rather than the full product. + let a = self.value; + let b = f.value; + let mut g = F::ZERO; + for i in 1..D { + g += a[i] * b[D - i]; + } + g *= F::W; + g += a[0] * b[0]; + debug_assert_eq!(Self::from(g), *self * f); + + f * g.inverse() + } + *) + Definition frobenius_inv + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ f : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] := + M.copy (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 1); ("end_", D) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + f, + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "p3_field::extension::HasFrobenius", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ F ], + "frobenius", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + "mul", + [], + [] + |), + [ + M.read (| f |); + M.read (| + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ a : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ F ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) in + let~ b : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ F ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + f, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) in + let~ g : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 1); ("end_", D) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, g |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + a, + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + b, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ D; M.read (| i |) ] + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + F, + [], + [ F ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, g |); + M.read (| + get_constant (| "p3_field::extension::BinomiallyExtendable::W", F |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, g |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| a, Value.Integer IntegerKind.Usize 0 |) + |); + M.read (| + M.SubPointer.get_array_field (| b, Value.Integer IntegerKind.Usize 0 |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "core::convert::From", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ F ], + "from", + [], + [] + |), + [ M.read (| g |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + "mul", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| self |) |) |); + M.read (| f |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| f |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, g |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::extension::HasFrobenius" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self D F) + (* Instance *) + [ + ("frobenius", InstanceField.Method (frobenius D F)); + ("repeated_frobenius", InstanceField.Method (repeated_frobenius D F)); + ("frobenius_inv", InstanceField.Method (frobenius_inv D F)) + ]. + End Impl_p3_field_extension_HasFrobenius_where_p3_field_extension_BinomiallyExtendable_F_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + + Module Impl_p3_field_field_PrimeCharacteristicRing_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* type PrimeSubfield = ::PrimeSubfield; *) + Definition _PrimeSubfield (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_field::field::PrimeCharacteristicRing" [] [] A "PrimeSubfield". + + (* const ZERO: Self = Self::new([A::ZERO; D]); *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] *) + Definition value_ZERO + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + repeat (| + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", A |) + |), + D + |) + ] + |) + |))). + + (* const ONE: Self = Self::new(field_to_array(A::ONE)); *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] *) + Definition value_ONE + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_function (| "p3_field::helpers::field_to_array", [ D ], [ A ] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", A |) + |) + ] + |) + ] + |) + |))). + + (* const TWO: Self = Self::new(field_to_array(A::TWO)); *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] *) + Definition value_TWO + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_function (| "p3_field::helpers::field_to_array", [ D ], [ A ] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", A |) + |) + ] + |) + ] + |) + |))). + + (* const NEG_ONE: Self = Self::new(field_to_array(A::NEG_ONE)); *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] *) + Definition value_NEG_ONE + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_function (| "p3_field::helpers::field_to_array", [ D ], [ A ] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::NEG_ONE", A |) + |) + ] + |) + ] + |) + |))). + + (* + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + ::from_prime_subfield(f).into() + } + *) + Definition from_prime_subfield + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::convert::Into", + A, + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + "into", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ M.read (| f |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn square(&self) -> Self { + match D { + 2 => { + let a = self.value.clone(); + let mut res = Self::default(); + res.value[0] = a[0].square() + a[1].square() * F::W; + res.value[1] = a[0].clone() * a[1].double(); + res + } + 3 => { + let mut res = Self::default(); + cubic_square(&self.value, &mut res.value); + res + } + _ => >::mul(self.clone(), self.clone()), + } + } + *) + Definition square + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + M.alloc (| D |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + let~ a : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ A ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ D ] [ A ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + ] + |) + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Add", + A, + [], + [ A ], + "add", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + a, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + a, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::extension::BinomiallyExtendable::W", + F + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ A ], + "mul", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + a, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + a, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) + |) in + res)); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 3 + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::extension::binomial_extension::cubic_square", + [ D ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |) + |) in + res)); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn mul_2exp_u64(&self, exp: u64) -> Self { + Self::new(self.value.clone().map(|x| x.mul_2exp_u64(exp))) + } + *) + Definition mul_2exp_u64 + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ D ] [ A ], + "map", + [], + [ Ty.function [ Ty.tuple [ A ] ] A; A ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ D ] [ A ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ A ] ] A ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "mul_2exp_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); M.read (| exp |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(F::zero_vec(len * D)) } + } + *) + Definition zero_vec + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ len ] => + ltac:(M.monadic + (let len := M.alloc (| len |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_util::reconstitute_from_base", + [], + [ + F; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "zero_vec", + [], + [] + |), + [ M.call_closure (| Ty.path "usize", BinOp.Wrap.mul, [ M.read (| len |); D ] |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "p3_field::field::PrimeCharacteristicRing" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) + [ + ("PrimeSubfield", InstanceField.Ty (_PrimeSubfield D F A)); + ("value_ZERO", InstanceField.Method (value_ZERO D F A)); + ("value_ONE", InstanceField.Method (value_ONE D F A)); + ("value_TWO", InstanceField.Method (value_TWO D F A)); + ("value_NEG_ONE", InstanceField.Method (value_NEG_ONE D F A)); + ("from_prime_subfield", InstanceField.Method (from_prime_subfield D F A)); + ("square", InstanceField.Method (square D F A)); + ("mul_2exp_u64", InstanceField.Method (mul_2exp_u64 D F A)); + ("zero_vec", InstanceField.Method (zero_vec D F A)) + ]. + End Impl_p3_field_field_PrimeCharacteristicRing_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_p3_field_field_Algebra_where_p3_field_extension_BinomiallyExtendable_F_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::field::Algebra" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self D F) + (* Instance *) []. + End Impl_p3_field_field_Algebra_where_p3_field_extension_BinomiallyExtendable_F_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + + Module Impl_p3_field_field_Field_where_p3_field_extension_BinomiallyExtendable_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + (* type Packing = Self; *) + Definition _Packing (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + (* const GENERATOR: Self = Self::new(F::EXT_GENERATOR); *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] *) + Definition value_GENERATOR + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + "new", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::extension::BinomiallyExtendable::EXT_GENERATOR", + Ty.apply (Ty.path "array") [ D ] [ F ] + |) + |) + ] + |) + |))). + + (* + fn try_inverse(&self) -> Option { + if self.is_zero() { + return None; + } + + let mut res = Self::default(); + + match D { + 2 => quadratic_inv(&self.value, &mut res.value, F::W), + 3 => cubic_inv(&self.value, &mut res.value, F::W), + _ => res = self.frobenius_inv(), + } + + Some(res) + } + *) + Definition try_inverse + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return + (Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [], + "is_zero", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| Value.StructTuple "core::option::Option::None" [] |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| D |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::extension::binomial_extension::quadratic_inv", + [ D ], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.read (| + get_constant (| + "p3_field::extension::BinomiallyExtendable::W", + F + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 3 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::extension::binomial_extension::cubic_inv", + [ D ], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.read (| + get_constant (| + "p3_field::extension::BinomiallyExtendable::W", + F + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.write (| + res, + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "p3_field::extension::HasFrobenius", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ F ], + "frobenius_inv", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) + ] + |) + |) + |))) + ] + |) in + M.alloc (| Value.StructTuple "core::option::Option::Some" [ M.read (| res |) ] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn halve(&self) -> Self { + Self::new(self.value.map(|x| x.halve())) + } + *) + Definition halve + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ D ] [ F ], + "map", + [], + [ Ty.function [ Ty.tuple [ F ] ] F; F ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ F ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "halve", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn div_2exp_u64(&self, exp: u64) -> Self { + Self::new(self.value.map(|x| x.div_2exp_u64(exp))) + } + *) + Definition div_2exp_u64 + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ D ] [ F ], + "map", + [], + [ Ty.function [ Ty.tuple [ F ] ] F; F ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ F ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "div_2exp_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); M.read (| exp |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn order() -> BigUint { + F::order().pow(D as u32) + } + *) + Definition order + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_associated_function (| Ty.path "num_bigint::biguint::BigUint", "pow", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| "p3_field::field::Field", F, [], [], "order", [], [] |), + [] + |) + |) + |); + M.cast (Ty.path "u32") D + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::field::Field" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F) + (* Instance *) + [ + ("Packing", InstanceField.Ty (_Packing D F)); + ("value_GENERATOR", InstanceField.Method (value_GENERATOR D F)); + ("try_inverse", InstanceField.Method (try_inverse D F)); + ("halve", InstanceField.Method (halve D F)); + ("div_2exp_u64", InstanceField.Method (div_2exp_u64 D F)); + ("order", InstanceField.Method (order D F)) + ]. + End Impl_p3_field_field_Field_where_p3_field_extension_BinomiallyExtendable_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + + Module Impl_core_fmt_Display_where_p3_field_extension_BinomiallyExtendable_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + (* + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + if self.is_zero() { + write!(f, "0") + } else { + let str = self + .value + .iter() + .enumerate() + .filter(|(_, x)| !x.is_zero()) + .map(|(i, x)| match (i, x.is_one()) { + (0, _) => format!("{x}"), + (1, true) => "X".to_string(), + (1, false) => format!("{x} X"), + (_, true) => format!("X^{i}"), + (_, false) => format!("{x} X^{i}"), + }) + .join(" + "); + write!(f, "{}", str) + } + } + *) + Definition fmt + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ mk_str (| "0" |) ] |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ str : Ty.apply (Ty.path "*") [] [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::filter::Filter") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + ] + (Ty.path "bool") + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.path "usize"; Ty.apply (Ty.path "&") [] [ F ] ] + ] + ] + (Ty.path "alloc::string::String") + ], + [], + [], + "join", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::filter::Filter") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + ] + (Ty.path "bool") + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.path "usize"; Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + (Ty.path "alloc::string::String") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::filter::Filter") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + ] + (Ty.path "bool") + ], + [], + [], + "map", + [], + [ + Ty.path "alloc::string::String"; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.path "usize"; Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + (Ty.path "alloc::string::String") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::filter::Filter") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + ] + (Ty.path "bool") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "filter", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |)) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ F ] + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let x := M.alloc (| γ1_1 |) in + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "is_zero", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| M.read (| x |) |) + |) + |) + |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + (Ty.path "alloc::string::String") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let i := M.copy (| γ0_0 |) in + let x := M.copy (| γ0_1 |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.path "alloc::string::String" ], + M.alloc (| + Value.Tuple + [ + M.read (| i |); + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "is_one", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x |) |) + |) + ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer + IntegerKind.Usize + 0 + |) in + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ + Ty.path + "alloc::string::String" + ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "alloc::string::String" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_function (| + "alloc::fmt::format", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 1; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "" + |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + F + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + x + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer + IntegerKind.Usize + 1 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Bool true + |) in + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_trait_method (| + "alloc::string::ToString", + Ty.path "str", + [], + [], + "to_string", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| "X" |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer + IntegerKind.Usize + 1 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Bool false + |) in + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ + Ty.path + "alloc::string::String" + ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "alloc::string::String" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_function (| + "alloc::fmt::format", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "" + |); + mk_str (| + " X" + |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + F + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + x + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Bool true + |) in + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ + Ty.path + "alloc::string::String" + ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "alloc::string::String" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_function (| + "alloc::fmt::format", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 1; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "X^" + |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Bool false + |) in + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ + Ty.path + "alloc::string::String" + ] + |), + [ + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "alloc::string::String" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_function (| + "alloc::fmt::format", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 2; + Value.Integer + IntegerKind.Usize + 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "" + |); + mk_str (| + " X^" + |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + F + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + x + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + i + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| " + " |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 1; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ mk_str (| "" |) ] |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, str |) |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt D F)) ]. + End Impl_core_fmt_Display_where_p3_field_extension_BinomiallyExtendable_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + + Module Impl_core_ops_arith_Neg_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn neg(self) -> Self { + Self::new(self.value.map(A::neg)) + } + *) + Definition neg + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ D ] [ A ], + "map", + [], + [ + Ty.function + [ A ] + (Ty.associated_in_trait "core::ops::arith::Neg" [] [] A "Output"); + A + ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |); + M.get_trait_method (| "core::ops::arith::Neg", A, [], [], "neg", [], [] |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F A) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output D F A)); ("neg", InstanceField.Method (neg D F A)) + ]. + End Impl_core_ops_arith_Neg_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_Add_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn add(self, rhs: Self) -> Self { + let value = vector_add(&self.value, &rhs.value); + Self::new(value) + } + *) + Definition add + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ value : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ A ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_function (| + "p3_field::extension::binomial_extension::vector_add", + [ D ], + [ A; A ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ M.read (| value |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + (Self D F A) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output D F A)); ("add", InstanceField.Method (add D F A)) + ]. + End Impl_core_ops_arith_Add_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_Add_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn add(mut self, rhs: A) -> Self { + self.value[0] += rhs; + self + } + *) + Definition add + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + A, + [], + [ A ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| rhs |) + ] + |) + |) in + self + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ A ] + (Self D F A) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output D F A)); ("add", InstanceField.Method (add D F A)) + ]. + End Impl_core_ops_arith_Add_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_AddAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn add_assign(&mut self, rhs: Self) { + for i in 0..D { + self.value[i] += rhs.value[i].clone(); + } + } + *) + Definition add_assign + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", D) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + A, + [], + [ A ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + M.read (| i |) + |) + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + M.read (| i |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + (Self D F A) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign D F A)) ]. + End Impl_core_ops_arith_AddAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_AddAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn add_assign(&mut self, rhs: A) { + self.value[0] += rhs; + } + *) + Definition add_assign + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + A, + [], + [ A ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| rhs |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ A ] + (Self D F A) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign D F A)) ]. + End Impl_core_ops_arith_AddAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_iter_traits_accum_Sum_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn sum>(iter: I) -> Self { + iter.reduce(|acc, x| acc + x).unwrap_or(Self::ZERO) + } + *) + Definition sum + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + "add", + [], + [] + |), + [ M.read (| acc |); M.read (| x |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Sum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + (Self D F A) + (* Instance *) [ ("sum", InstanceField.Method (sum D F A)) ]. + End Impl_core_iter_traits_accum_Sum_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_Sub_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn sub(self, rhs: Self) -> Self { + let value = vector_sub(&self.value, &rhs.value); + Self::new(value) + } + *) + Definition sub + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ value : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ A ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_function (| + "p3_field::extension::binomial_extension::vector_sub", + [ D ], + [ A; A ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ M.read (| value |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + (Self D F A) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output D F A)); ("sub", InstanceField.Method (sub D F A)) + ]. + End Impl_core_ops_arith_Sub_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_Sub_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn sub(self, rhs: A) -> Self { + let mut res = self.value; + res[0] -= rhs; + Self::new(res) + } + *) + Definition sub + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ res : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ A ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + A, + [], + [ A ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| res, Value.Integer IntegerKind.Usize 0 |) + |); + M.read (| rhs |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ M.read (| res |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ A ] + (Self D F A) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output D F A)); ("sub", InstanceField.Method (sub D F A)) + ]. + End Impl_core_ops_arith_Sub_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_SubAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn sub_assign(&mut self, rhs: Self) { + for i in 0..D { + self.value[i] -= rhs.value[i].clone(); + } + } + *) + Definition sub_assign + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", D) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + A, + [], + [ A ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + M.read (| i |) + |) + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + M.read (| i |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + (Self D F A) + (* Instance *) [ ("sub_assign", InstanceField.Method (sub_assign D F A)) ]. + End Impl_core_ops_arith_SubAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_SubAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn sub_assign(&mut self, rhs: A) { + self.value[0] -= rhs; + } + *) + Definition sub_assign + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + A, + [], + [ A ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| rhs |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ A ] + (Self D F A) + (* Instance *) [ ("sub_assign", InstanceField.Method (sub_assign D F A)) ]. + End Impl_core_ops_arith_SubAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_Mul_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn mul(self, rhs: Self) -> Self { + let a = self.value; + let b = rhs.value; + let mut res = Self::default(); + let w = F::W; + + binomial_mul(&a, &b, &mut res.value, w); + + res + } + *) + Definition mul + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ a : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ A ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) in + let~ b : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ A ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ w : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| get_constant (| "p3_field::extension::BinomiallyExtendable::W", F |) |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::extension::binomial_extension::binomial_mul", + [ D ], + [ F; A; A ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, a |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, b |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |); + M.read (| w |) + ] + |) + |) in + res + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + (Self D F A) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output D F A)); ("mul", InstanceField.Method (mul D F A)) + ]. + End Impl_core_ops_arith_Mul_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_Mul_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn mul(self, rhs: A) -> Self { + Self::new(self.value.map(|x| x * rhs.clone())) + } + *) + Definition mul + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ D ] [ A ], + "map", + [], + [ Ty.function [ Ty.tuple [ A ] ] A; A ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ A ] ] A ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ A ], + "mul", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ A ] + (Self D F A) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output D F A)); ("mul", InstanceField.Method (mul D F A)) + ]. + End Impl_core_ops_arith_Mul_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_MulAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn mul_assign(&mut self, rhs: Self) { + *self = self.clone() * rhs; + } + *) + Definition mul_assign + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.read (| rhs |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + (Self D F A) + (* Instance *) [ ("mul_assign", InstanceField.Method (mul_assign D F A)) ]. + End Impl_core_ops_arith_MulAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_MulAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn mul_assign(&mut self, rhs: A) { + *self = self.clone() * rhs; + } + *) + Definition mul_assign + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [ A ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.read (| rhs |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ A ] + (Self D F A) + (* Instance *) [ ("mul_assign", InstanceField.Method (mul_assign D F A)) ]. + End Impl_core_ops_arith_MulAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_iter_traits_accum_Product_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + Definition Self (D : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]. + + (* + fn product>(iter: I) -> Self { + iter.reduce(|acc, x| acc * x).unwrap_or(Self::ONE) + } + *) + Definition product + (D : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F A in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ], + "mul", + [], + [] + |), + [ M.read (| acc |); M.read (| x |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F A : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Product" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; A ] + ] + (Self D F A) + (* Instance *) [ ("product", InstanceField.Method (product D F A)) ]. + End Impl_core_iter_traits_accum_Product_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_field_Algebra_A_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_A. + + Module Impl_core_ops_arith_Div_where_p3_field_extension_BinomiallyExtendable_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + (* + fn div(self, rhs: Self) -> Self::Output { + self * rhs.inverse() + } + *) + Definition div + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + "mul", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Div" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output D F)); ("div", InstanceField.Method (div D F)) ]. + End Impl_core_ops_arith_Div_where_p3_field_extension_BinomiallyExtendable_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + + Module Impl_core_ops_arith_DivAssign_where_p3_field_extension_BinomiallyExtendable_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + (* + fn div_assign(&mut self, rhs: Self) { + *self = *self / rhs; + } + *) + Definition div_assign + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_trait_method (| + "core::ops::arith::Div", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + "div", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::DivAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F) + (* Instance *) [ ("div_assign", InstanceField.Method (div_assign D F)) ]. + End Impl_core_ops_arith_DivAssign_where_p3_field_extension_BinomiallyExtendable_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + + Module Impl_rand_distr_distribution_Distribution_where_p3_field_extension_BinomiallyExtendable_F_where_rand_distr_distribution_Distribution_rand_distr_StandardUniform_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_rand_distr_StandardUniform. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := Ty.path "rand::distr::StandardUniform". + + (* + fn sample(&self, rng: &mut R) -> BinomialExtensionField { + BinomialExtensionField::new(array::from_fn(|_| self.sample(rng))) + } + *) + Definition sample + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [ R ], [ self; rng ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rng := M.alloc (| rng |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ F ], + M.get_function (| + "core::array::from_fn", + [ D ], + [ F; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + F, + M.get_trait_method (| + "rand::distr::distribution::Distribution", + Ty.path "rand::distr::StandardUniform", + [], + [ F ], + "sample", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| rng |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "rand::distr::distribution::Distribution" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F) + (* Instance *) [ ("sample", InstanceField.Method (sample D F)) ]. + End Impl_rand_distr_distribution_Distribution_where_p3_field_extension_BinomiallyExtendable_F_where_rand_distr_distribution_Distribution_rand_distr_StandardUniform_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_rand_distr_StandardUniform. + + Module Impl_p3_field_field_TwoAdicField_where_p3_field_field_Field_F_where_p3_field_extension_HasTwoAdicBinomialExtension_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]. + + (* const TWO_ADICITY: usize = F::EXT_TWO_ADICITY; *) + (* Ty.path "usize" *) + Definition value_TWO_ADICITY + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + ltac:(M.monadic + (get_constant (| + "p3_field::extension::HasTwoAdicBinomialExtension::EXT_TWO_ADICITY", + Ty.path "usize" + |))). + + (* + fn two_adic_generator(bits: usize) -> Self { + Self::new(F::ext_two_adic_generator(bits)) + } + *) + Definition two_adic_generator + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ F ], + M.get_trait_method (| + "p3_field::extension::HasTwoAdicBinomialExtension", + F, + [ D ], + [], + "ext_two_adic_generator", + [], + [] + |), + [ M.read (| bits |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::field::TwoAdicField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F) + (* Instance *) + [ + ("value_TWO_ADICITY", InstanceField.Method (value_TWO_ADICITY D F)); + ("two_adic_generator", InstanceField.Method (two_adic_generator D F)) + ]. + End Impl_p3_field_field_TwoAdicField_where_p3_field_field_Field_F_where_p3_field_extension_HasTwoAdicBinomialExtension_F_for_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F. + + (* + pub(crate) fn vector_add< + R: PrimeCharacteristicRing + Add, + R2: Clone, + const D: usize, + >( + a: &[R; D], + b: &[R2; D], + ) -> [R; D] { + array::from_fn(|i| a[i].clone() + b[i].clone()) + } + *) + Definition vector_add (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ D ], [ R; R2 ], [ a; b ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let b := M.alloc (| b |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ R ], + M.get_function (| + "core::array::from_fn", + [ D ], + [ R; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] R ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] R ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R2 ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + M.read (| i |) + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + M.read (| i |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_vector_add : + M.IsFunction.C "p3_field::extension::binomial_extension::vector_add" vector_add. + Admitted. + Global Typeclasses Opaque vector_add. + + (* + pub(crate) fn vector_sub< + R: PrimeCharacteristicRing + Sub, + R2: Clone, + const D: usize, + >( + a: &[R; D], + b: &[R2; D], + ) -> [R; D] { + array::from_fn(|i| a[i].clone() - b[i].clone()) + } + *) + Definition vector_sub (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ D ], [ R; R2 ], [ a; b ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let b := M.alloc (| b |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ R ], + M.get_function (| + "core::array::from_fn", + [ D ], + [ R; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] R ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] R ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R2 ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + M.read (| i |) + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + M.read (| i |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_vector_sub : + M.IsFunction.C "p3_field::extension::binomial_extension::vector_sub" vector_sub. + Admitted. + Global Typeclasses Opaque vector_sub. + + (* + pub(super) fn binomial_mul< + F: Field, + R: Algebra + Mul, + R2: Add + Clone, + const D: usize, + >( + a: &[R; D], + b: &[R2; D], + res: &mut [R; D], + w: F, + ) { + match D { + 2 => { + res[0] = a[0].clone() * b[0].clone() + a[1].clone() * w * b[1].clone(); + res[1] = a[0].clone() * b[1].clone() + a[1].clone() * b[0].clone(); + } + 3 => cubic_mul(a, b, res, w), + _ => + { + #[allow(clippy::needless_range_loop)] + for i in 0..D { + for j in 0..D { + if i + j >= D { + res[i + j - D] += a[i].clone() * w * b[j].clone(); + } else { + res[i + j] += a[i].clone() * b[j].clone(); + } + } + } + } + } + } + *) + Definition binomial_mul (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ D ], [ F; R; R2 ], [ a; b; res; w ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let b := M.alloc (| b |) in + let res := M.alloc (| res |) in + let w := M.alloc (| w |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| D |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R2 ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R2 ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.read (| w |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R2 ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R2 ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 3 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::extension::binomial_extension::cubic_mul", + [ D ], + [ F; R; R2 ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| b |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| res |) |) |); + M.read (| w |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", D) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 0); + ("end_", D) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let j := M.copy (| γ0_0 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + i + |); + M.read (| + j + |) + ] + |); + D + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + res + |) + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + i + |); + M.read (| + j + |) + ] + |); + D + ] + |) + |) + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R2 ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + a + |) + |), + M.read (| + i + |) + |) + |) + ] + |); + M.read (| + w + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + b + |) + |), + M.read (| + j + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + Value.Tuple [] + |))); + fun γ => + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + res + |) + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + i + |); + M.read (| + j + |) + ] + |) + |) + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R2 ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + a + |) + |), + M.read (| + i + |) + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + b + |) + |), + M.read (| + j + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_binomial_mul : + M.IsFunction.C "p3_field::extension::binomial_extension::binomial_mul" binomial_mul. + Admitted. + Global Typeclasses Opaque binomial_mul. + + (* + fn quadratic_inv(a: &[F; D], res: &mut [F; D], w: F) { + assert_eq!(D, 2); + let scalar = (a[0].square() - w * a[1].square()).inverse(); + res[0] = a[0] * scalar; + res[1] = -a[1] * scalar; + } + *) + Definition quadratic_inv (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ D ], [ F ], [ a; res; w ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let res := M.alloc (| res |) in + let w := M.alloc (| w |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, M.alloc (| D |) |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 2 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ scalar : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| w |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| scalar |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Neg", F, [], [], "neg", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.read (| scalar |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_quadratic_inv : + M.IsFunction.C "p3_field::extension::binomial_extension::quadratic_inv" quadratic_inv. + Admitted. + Global Typeclasses Opaque quadratic_inv. + + (* + fn cubic_inv(a: &[F; D], res: &mut [F; D], w: F) { + assert_eq!(D, 3); + let a0_square = a[0].square(); + let a1_square = a[1].square(); + let a2_w = w * a[2]; + let a0_a1 = a[0] * a[1]; + + // scalar = (a0^3+wa1^3+w^2a2^3-3wa0a1a2)^-1 + let scalar = (a0_square * a[0] + w * a[1] * a1_square + a2_w.square() * a[2] + - (F::ONE + F::TWO) * a2_w * a0_a1) + .inverse(); + + //scalar*[a0^2-wa1a2, wa2^2-a0a1, a1^2-a0a2] + res[0] = scalar * (a0_square - a[1] * a2_w); + res[1] = scalar * (a2_w * a[2] - a0_a1); + res[2] = scalar * (a1_square - a[0] * a[2]); + } + *) + Definition cubic_inv (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ D ], [ F ], [ a; res; w ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let res := M.alloc (| res |) in + let w := M.alloc (| w |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, M.alloc (| D |) |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 3 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ a0_square : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ a1_square : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ a2_w : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| w |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |) in + let~ a0_a1 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ scalar : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| a0_square |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| w |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.read (| a1_square |) + ] + |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, a2_w |) ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + F + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::TWO", + F + |) + |) + ] + |); + M.read (| a2_w |) + ] + |); + M.read (| a0_a1 |) + ] + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| scalar |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.read (| a0_square |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| a2_w |) + ] + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| scalar |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| a2_w |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.read (| a0_a1 |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ + M.read (| scalar |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.read (| a1_square |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_cubic_inv : + M.IsFunction.C "p3_field::extension::binomial_extension::cubic_inv" cubic_inv. + Admitted. + Global Typeclasses Opaque cubic_inv. + + (* + pub(crate) fn cubic_mul< + F: Field, + R: Algebra + Mul, + R2: Add + Clone, + const D: usize, + >( + a: &[R; D], + b: &[R2; D], + res: &mut [R; D], + w: F, + ) { + assert_eq!(D, 3); + + let a0_b0 = a[0].clone() * b[0].clone(); + let a1_b1 = a[1].clone() * b[1].clone(); + let a2_b2 = a[2].clone() * b[2].clone(); + + res[0] = a0_b0.clone() + + ((a[1].clone() + a[2].clone()) * (b[1].clone() + b[2].clone()) + - a1_b1.clone() + - a2_b2.clone()) + * w; + res[1] = (a[0].clone() + a[1].clone()) * (b[0].clone() + b[1].clone()) + - a0_b0.clone() + - a1_b1.clone() + + a2_b2.clone() * w; + res[2] = (a[0].clone() + a[2].clone()) * (b[0].clone() + b[2].clone()) - a0_b0 - a2_b2 + a1_b1; + } + *) + Definition cubic_mul (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ D ], [ F; R; R2 ], [ a; b; res; w ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let b := M.alloc (| b |) in + let res := M.alloc (| res |) in + let w := M.alloc (| w |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, M.alloc (| D |) |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 3 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ a0_b0 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R2 ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| "core::clone::Clone", R2, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) in + let~ a1_b1 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R2 ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| "core::clone::Clone", R2, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) in + let~ a2_b2 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Mul", R, [], [ R2 ], "mul", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| "core::clone::Clone", R2, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, a0_b0 |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R2 ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::ops::arith::Add", + R2, + [], + [ R2 ], + "add", + [], + [] + |), + [ + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, a1_b1 |) ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, a2_b2 |) ] + |) + ] + |); + M.read (| w |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R2 ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::ops::arith::Add", + R2, + [], + [ R2 ], + "add", + [], + [] + |), + [ + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, a0_b0 |) ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, a1_b1 |) ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, a2_b2 |) ] + |); + M.read (| w |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Sub", + R, + [], + [ R ], + "sub", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Mul", + R, + [], + [ R2 ], + "mul", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::ops::arith::Add", + R2, + [], + [ R2 ], + "add", + [], + [] + |), + [ + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R2, + M.get_trait_method (| + "core::clone::Clone", + R2, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| b |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + ] + |); + M.read (| a0_b0 |) + ] + |); + M.read (| a2_b2 |) + ] + |); + M.read (| a1_b1 |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_cubic_mul : + M.IsFunction.C "p3_field::extension::binomial_extension::cubic_mul" cubic_mul. + Admitted. + Global Typeclasses Opaque cubic_mul. + + (* + pub(crate) fn cubic_square, A: Algebra, const D: usize>( + a: &[A; D], + res: &mut [A; D], + ) { + assert_eq!(D, 3); + + let w_a2 = a[2].clone() * F::W; + + res[0] = a[0].square() + (a[1].clone() * w_a2.clone()).double(); + res[1] = w_a2 * a[2].clone() + (a[0].clone() * a[1].clone()).double(); + res[2] = a[1].square() + (a[0].clone() * a[2].clone()).double(); + } + *) + Definition cubic_square (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ D ], [ F; A ], [ a; res ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let res := M.alloc (| res |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, M.alloc (| D |) |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 3 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ w_a2 : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Mul", A, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.read (| + get_constant (| "p3_field::extension::BinomiallyExtendable::W", F |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ A ], + "mul", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, w_a2 |) ] + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ A ], + "mul", + [], + [] + |), + [ + M.read (| w_a2 |); + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ A ], + "mul", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| res |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ A ], + "mul", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_cubic_square : + M.IsFunction.C "p3_field::extension::binomial_extension::cubic_square" cubic_square. + Admitted. + Global Typeclasses Opaque cubic_square. + End binomial_extension. +End extension. diff --git a/CoqOfRust/plonky3/field/src/extension/complex.rs b/CoqOfRust/plonky3/field/src/extension/complex.rs new file mode 100644 index 000000000..6db815157 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/extension/complex.rs @@ -0,0 +1,124 @@ +use super::{BinomialExtensionField, BinomiallyExtendable, HasTwoAdicBinomialExtension}; +use crate::{Algebra, Field, PrimeCharacteristicRing}; + +pub type Complex = BinomialExtensionField; + +/// A field for which `p = 3 (mod 4)`. Equivalently, `-1` is not a square, +/// so the complex extension can be defined `F[i] = F[X]/(X^2+1)`. +pub trait ComplexExtendable: Field { + /// The two-adicity of `p+1`, the order of the circle group. + const CIRCLE_TWO_ADICITY: usize; + + const COMPLEX_GENERATOR: Complex; + + fn circle_two_adic_generator(bits: usize) -> Complex; +} + +impl BinomiallyExtendable<2> for F { + const W: Self = F::NEG_ONE; + + // since `p = 3 (mod 4)`, `(p-1)/2` is always odd, + // so `(-1)^((p-1)/2) = -1` + const DTH_ROOT: Self = F::NEG_ONE; + + const EXT_GENERATOR: [Self; 2] = F::COMPLEX_GENERATOR.value; +} + +/// Convenience methods for complex extensions +impl Complex { + #[inline(always)] + pub const fn new_complex(real: R, imag: R) -> Self { + Self::new([real, imag]) + } + + #[inline(always)] + pub const fn new_real(real: R) -> Self { + Self::new_complex(real, R::ZERO) + } + + #[inline(always)] + pub const fn new_imag(imag: R) -> Self { + Self::new_complex(R::ZERO, imag) + } + + #[inline(always)] + pub fn real(&self) -> R { + self.value[0].clone() + } + + #[inline(always)] + pub fn imag(&self) -> R { + self.value[1].clone() + } + + #[inline(always)] + pub fn conjugate(&self) -> Self { + Self::new_complex(self.real(), self.imag().neg()) + } + + #[inline] + pub fn norm(&self) -> R { + self.real().square() + self.imag().square() + } + + #[inline(always)] + pub fn to_array(&self) -> [R; 2] { + self.value.clone() + } + + // Sometimes we want to rotate over an extension that's not necessarily ComplexExtendable, + // but still on the circle. + pub fn rotate>(&self, rhs: &Complex) -> Complex { + Complex::::new_complex( + rhs.real() * self.real() - rhs.imag() * self.imag(), + rhs.imag() * self.real() + rhs.real() * self.imag(), + ) + } +} + +/// The complex extension of this field has a binomial extension. +/// +/// This exists if the polynomial ring `F[i][X]` has an irreducible polynomial `X^d-W` +/// allowing us to define the binomial extension field `F[i][X]/(X^d-W)`. +pub trait HasComplexBinomialExtension: ComplexExtendable { + const W: Complex; + + // DTH_ROOT = W^((n - 1)/D). + // n is the order of base field. + // Only works when exists k such that n = kD + 1. + const DTH_ROOT: Complex; + + const EXT_GENERATOR: [Complex; D]; +} + +impl BinomiallyExtendable for Complex +where + F: HasComplexBinomialExtension, +{ + const W: Self = >::W; + + const DTH_ROOT: Self = >::DTH_ROOT; + + const EXT_GENERATOR: [Self; D] = F::EXT_GENERATOR; +} + +/// The complex extension of this field has a two-adic binomial extension. +pub trait HasTwoAdicComplexBinomialExtension: + HasComplexBinomialExtension +{ + const COMPLEX_EXT_TWO_ADICITY: usize; + + fn complex_ext_two_adic_generator(bits: usize) -> [Complex; D]; +} + +impl HasTwoAdicBinomialExtension for Complex +where + F: HasTwoAdicComplexBinomialExtension, +{ + const EXT_TWO_ADICITY: usize = F::COMPLEX_EXT_TWO_ADICITY; + + #[inline(always)] + fn ext_two_adic_generator(bits: usize) -> [Self; D] { + F::complex_ext_two_adic_generator(bits) + } +} diff --git a/CoqOfRust/plonky3/field/src/extension/complex.v b/CoqOfRust/plonky3/field/src/extension/complex.v new file mode 100644 index 000000000..bb863ab6e --- /dev/null +++ b/CoqOfRust/plonky3/field/src/extension/complex.v @@ -0,0 +1,880 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module extension. + Module complex. + Axiom Complex : + forall (F : Ty.t), + (Ty.apply (Ty.path "p3_field::extension::complex::Complex") [] [ F ]) = + (Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ]). + + (* Trait *) + (* Empty module 'ComplexExtendable' *) + + Module Impl_p3_field_extension_BinomiallyExtendable_where_p3_field_extension_complex_ComplexExtendable_F_Usize_2_for_F. + Definition Self (F : Ty.t) : Ty.t := F. + + (* const W: Self = F::NEG_ONE; *) + (* F *) + Definition value_W (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + ltac:(M.monadic + (get_constant (| "p3_field::field::PrimeCharacteristicRing::NEG_ONE", F |))). + + (* const DTH_ROOT: Self = F::NEG_ONE; *) + (* F *) + Definition value_DTH_ROOT + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + ltac:(M.monadic + (get_constant (| "p3_field::field::PrimeCharacteristicRing::NEG_ONE", F |))). + + (* const EXT_GENERATOR: [Self; 2] = F::COMPLEX_GENERATOR.value; *) + (* Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ F ] *) + Definition value_EXT_GENERATOR + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + ltac:(M.monadic + (M.SubPointer.get_struct_record_field (| + get_constant (| + "p3_field::extension::complex::ComplexExtendable::COMPLEX_GENERATOR", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ] + |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |))). + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_field::extension::BinomiallyExtendable" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 2 ] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ + ("value_W", InstanceField.Method (value_W F)); + ("value_DTH_ROOT", InstanceField.Method (value_DTH_ROOT F)); + ("value_EXT_GENERATOR", InstanceField.Method (value_EXT_GENERATOR F)) + ]. + End Impl_p3_field_extension_BinomiallyExtendable_where_p3_field_extension_complex_ComplexExtendable_F_Usize_2_for_F. + + Module Impl_p3_field_extension_binomial_extension_BinomialExtensionField_Usize_2_R_R. + Definition Self (R : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ]. + + (* + pub const fn new_complex(real: R, imag: R) -> Self { + Self::new([real, imag]) + } + *) + Definition new_complex (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ real; imag ] => + ltac:(M.monadic + (let real := M.alloc (| real |) in + let imag := M.alloc (| imag |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "new", + [], + [] + |), + [ Value.Array [ M.read (| real |); M.read (| imag |) ] ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_complex : + forall (R : Ty.t), + M.IsAssociatedFunction.C (Self R) "new_complex" (new_complex R). + Admitted. + Global Typeclasses Opaque new_complex. + + (* + pub const fn new_real(real: R) -> Self { + Self::new_complex(real, R::ZERO) + } + *) + Definition new_real (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ real ] => + ltac:(M.monadic + (let real := M.alloc (| real |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "new_complex", + [], + [] + |), + [ + M.read (| real |); + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", R |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_real : + forall (R : Ty.t), + M.IsAssociatedFunction.C (Self R) "new_real" (new_real R). + Admitted. + Global Typeclasses Opaque new_real. + + (* + pub const fn new_imag(imag: R) -> Self { + Self::new_complex(R::ZERO, imag) + } + *) + Definition new_imag (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ imag ] => + ltac:(M.monadic + (let imag := M.alloc (| imag |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "new_complex", + [], + [] + |), + [ + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", R |) |); + M.read (| imag |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_imag : + forall (R : Ty.t), + M.IsAssociatedFunction.C (Self R) "new_imag" (new_imag R). + Admitted. + Global Typeclasses Opaque new_imag. + + (* + pub fn real(&self) -> R { + self.value[0].clone() + } + *) + Definition real (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_real : + forall (R : Ty.t), + M.IsAssociatedFunction.C (Self R) "real" (real R). + Admitted. + Global Typeclasses Opaque real. + + (* + pub fn imag(&self) -> R { + self.value[1].clone() + } + *) + Definition imag (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_imag : + forall (R : Ty.t), + M.IsAssociatedFunction.C (Self R) "imag" (imag R). + Admitted. + Global Typeclasses Opaque imag. + + (* + pub fn conjugate(&self) -> Self { + Self::new_complex(self.real(), self.imag().neg()) + } + *) + Definition conjugate (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "new_complex", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "real", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Neg", R, [], [], "neg", [], [] |), + [ + M.call_closure (| + R, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "imag", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_conjugate : + forall (R : Ty.t), + M.IsAssociatedFunction.C (Self R) "conjugate" (conjugate R). + Admitted. + Global Typeclasses Opaque conjugate. + + (* + pub fn norm(&self) -> R { + self.real().square() + self.imag().square() + } + *) + Definition norm (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "real", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "imag", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_norm : + forall (R : Ty.t), + M.IsAssociatedFunction.C (Self R) "norm" (norm R). + Admitted. + Global Typeclasses Opaque norm. + + (* + pub fn to_array(&self) -> [R; 2] { + self.value.clone() + } + *) + Definition to_array (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ R ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ R ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_array : + forall (R : Ty.t), + M.IsAssociatedFunction.C (Self R) "to_array" (to_array R). + Admitted. + Global Typeclasses Opaque to_array. + + (* + pub fn rotate>(&self, rhs: &Complex) -> Complex { + Complex::::new_complex( + rhs.real() * self.real() - rhs.imag() * self.imag(), + rhs.imag() * self.real() + rhs.real() * self.imag(), + ) + } + *) + Definition rotate (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [ Ext ], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ext; Ext ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ext; Ext ], + "new_complex", + [], + [] + |), + [ + M.call_closure (| + Ext, + M.get_trait_method (| "core::ops::arith::Sub", Ext, [], [ Ext ], "sub", [], [] |), + [ + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Mul", + Ext, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ext, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ext; Ext ], + "real", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| rhs |) |) |) ] + |); + M.call_closure (| + R, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "real", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |); + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Mul", + Ext, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ext, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ext; Ext ], + "imag", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| rhs |) |) |) ] + |); + M.call_closure (| + R, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "imag", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + ] + |); + M.call_closure (| + Ext, + M.get_trait_method (| "core::ops::arith::Add", Ext, [], [ Ext ], "add", [], [] |), + [ + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Mul", + Ext, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ext, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ext; Ext ], + "imag", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| rhs |) |) |) ] + |); + M.call_closure (| + R, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "real", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |); + M.call_closure (| + Ext, + M.get_trait_method (| + "core::ops::arith::Mul", + Ext, + [], + [ R ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ext, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ext; Ext ], + "real", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| rhs |) |) |) ] + |); + M.call_closure (| + R, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ R; R ], + "imag", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_rotate : + forall (R : Ty.t), + M.IsAssociatedFunction.C (Self R) "rotate" (rotate R). + Admitted. + Global Typeclasses Opaque rotate. + End Impl_p3_field_extension_binomial_extension_BinomialExtensionField_Usize_2_R_R. + + (* Trait *) + (* Empty module 'HasComplexBinomialExtension' *) + + Module Impl_p3_field_extension_BinomiallyExtendable_where_p3_field_extension_complex_HasComplexBinomialExtension_F_D_for_p3_field_extension_binomial_extension_BinomialExtensionField_Usize_2_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ]. + + (* const W: Self = >::W; *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ] *) + Definition value_W + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + ltac:(M.monadic + (get_constant (| + "p3_field::extension::complex::HasComplexBinomialExtension::W", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ] + |))). + + (* const DTH_ROOT: Self = >::DTH_ROOT; *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ] *) + Definition value_DTH_ROOT + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + ltac:(M.monadic + (get_constant (| + "p3_field::extension::complex::HasComplexBinomialExtension::DTH_ROOT", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ] + |))). + + (* const EXT_GENERATOR: [Self; D] = F::EXT_GENERATOR; *) + (* Ty.apply + (Ty.path "array") + [ D ] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ] + ] *) + Definition value_EXT_GENERATOR + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + ltac:(M.monadic + (get_constant (| + "p3_field::extension::complex::HasComplexBinomialExtension::EXT_GENERATOR", + Ty.apply + (Ty.path "array") + [ D ] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ] + ] + |))). + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::extension::BinomiallyExtendable" + (* Trait polymorphic consts *) [ D ] + (* Trait polymorphic types *) [] + (Self D F) + (* Instance *) + [ + ("value_W", InstanceField.Method (value_W D F)); + ("value_DTH_ROOT", InstanceField.Method (value_DTH_ROOT D F)); + ("value_EXT_GENERATOR", InstanceField.Method (value_EXT_GENERATOR D F)) + ]. + End Impl_p3_field_extension_BinomiallyExtendable_where_p3_field_extension_complex_HasComplexBinomialExtension_F_D_for_p3_field_extension_binomial_extension_BinomialExtensionField_Usize_2_F_F. + + (* Trait *) + (* Empty module 'HasTwoAdicComplexBinomialExtension' *) + + Module Impl_p3_field_extension_HasTwoAdicBinomialExtension_where_p3_field_extension_complex_HasTwoAdicComplexBinomialExtension_F_D_for_p3_field_extension_binomial_extension_BinomialExtensionField_Usize_2_F_F. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ]. + + (* const EXT_TWO_ADICITY: usize = F::COMPLEX_EXT_TWO_ADICITY; *) + (* Ty.path "usize" *) + Definition value_EXT_TWO_ADICITY + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + ltac:(M.monadic + (get_constant (| + "p3_field::extension::complex::HasTwoAdicComplexBinomialExtension::COMPLEX_EXT_TWO_ADICITY", + Ty.path "usize" + |))). + + (* + fn ext_two_adic_generator(bits: usize) -> [Self; D] { + F::complex_ext_two_adic_generator(bits) + } + *) + Definition ext_two_adic_generator + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ D ] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ F; F ] + ], + M.get_trait_method (| + "p3_field::extension::complex::HasTwoAdicComplexBinomialExtension", + F, + [ D ], + [], + "complex_ext_two_adic_generator", + [], + [] + |), + [ M.read (| bits |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::extension::HasTwoAdicBinomialExtension" + (* Trait polymorphic consts *) [ D ] + (* Trait polymorphic types *) [] + (Self D F) + (* Instance *) + [ + ("value_EXT_TWO_ADICITY", InstanceField.Method (value_EXT_TWO_ADICITY D F)); + ("ext_two_adic_generator", InstanceField.Method (ext_two_adic_generator D F)) + ]. + End Impl_p3_field_extension_HasTwoAdicBinomialExtension_where_p3_field_extension_complex_HasTwoAdicComplexBinomialExtension_F_D_for_p3_field_extension_binomial_extension_BinomialExtensionField_Usize_2_F_F. + End complex. +End extension. diff --git a/CoqOfRust/plonky3/field/src/extension/mod.rs b/CoqOfRust/plonky3/field/src/extension/mod.rs new file mode 100644 index 000000000..b58a31d6a --- /dev/null +++ b/CoqOfRust/plonky3/field/src/extension/mod.rs @@ -0,0 +1,50 @@ +use core::iter; + +use crate::ExtensionField; +use crate::field::Field; + +mod binomial_extension; +mod complex; +mod packed_binomial_extension; + +use alloc::vec::Vec; + +pub use binomial_extension::*; +pub use complex::*; +pub use packed_binomial_extension::*; + +/// Binomial extension field trait. +/// +/// This exists if the polynomial ring `F[X]` has an irreducible polynomial `X^d-W` +/// allowing us to define the binomial extension field `F[X]/(X^d-W)`. +pub trait BinomiallyExtendable: Field { + const W: Self; + + /// DTH_ROOT = W^((n - 1)/D). + /// n is the order of base field. + /// Only works when exists k such that n = kD + 1. + const DTH_ROOT: Self; + + const EXT_GENERATOR: [Self; D]; +} + +pub trait HasFrobenius: ExtensionField { + fn frobenius(&self) -> Self; + fn repeated_frobenius(&self, count: usize) -> Self; + fn frobenius_inv(&self) -> Self; + + fn galois_orbit(self) -> Vec { + iter::successors(Some(self), |x| Some(x.frobenius())) + .take(Self::DIMENSION) + .collect() + } +} + +/// Optional trait for implementing Two Adic Binomial Extension Field. +pub trait HasTwoAdicBinomialExtension: BinomiallyExtendable { + const EXT_TWO_ADICITY: usize; + + /// Assumes the multiplicative group size has at least `bits` powers of two, otherwise the + /// behavior is undefined. + fn ext_two_adic_generator(bits: usize) -> [Self; D]; +} diff --git a/CoqOfRust/plonky3/field/src/extension/mod.v b/CoqOfRust/plonky3/field/src/extension/mod.v new file mode 100644 index 000000000..1ee625198 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/extension/mod.v @@ -0,0 +1,168 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module extension. + (* Trait *) + (* Empty module 'BinomiallyExtendable' *) + + (* Trait *) + Module HasFrobenius. + Definition galois_orbit + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Self; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "core::iter::sources::successors::Successors") + [] + [ + Self; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Self ] ] ] + (Ty.apply (Ty.path "core::option::Option") [] [ Self ]) + ] + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ Self; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "core::iter::sources::successors::Successors") + [] + [ + Self; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Self ] ] ] + (Ty.apply (Ty.path "core::option::Option") [] [ Self ]) + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::sources::successors::Successors") + [] + [ + Self; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Self ] ] ] + (Ty.apply (Ty.path "core::option::Option") [] [ Self ]) + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::sources::successors::Successors") + [] + [ + Self; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Self ] ] ] + (Ty.apply (Ty.path "core::option::Option") [] [ Self ]) + ], + M.get_function (| + "core::iter::sources::successors::successors", + [], + [ + Self; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Self ] ] ] + (Ty.apply (Ty.path "core::option::Option") [] [ Self ]) + ] + |), + [ + Value.StructTuple "core::option::Option::Some" [ M.read (| self |) ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Self ] ] ] + (Ty.apply (Ty.path "core::option::Option") [] [ Self ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::extension::HasFrobenius", + Self, + [], + [ F ], + "frobenius", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x |) |) + |) + ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_galois_orbit : + forall (F : Ty.t), + M.IsProvidedMethod "p3_field::extension::HasFrobenius" "galois_orbit" (galois_orbit F). + End HasFrobenius. + + (* Trait *) + (* Empty module 'HasTwoAdicBinomialExtension' *) +End extension. diff --git a/CoqOfRust/plonky3/field/src/extension/packed_binomial_extension.rs b/CoqOfRust/plonky3/field/src/extension/packed_binomial_extension.rs new file mode 100644 index 000000000..b5791ebfb --- /dev/null +++ b/CoqOfRust/plonky3/field/src/extension/packed_binomial_extension.rs @@ -0,0 +1,507 @@ +use alloc::vec::Vec; +use core::array; +use core::fmt::Debug; +use core::iter::{Product, Sum}; +use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; + +use itertools::Itertools; +use p3_util::{flatten_to_base, reconstitute_from_base}; +use serde::{Deserialize, Serialize}; + +use super::{BinomialExtensionField, binomial_mul, cubic_square, vector_add, vector_sub}; +use crate::extension::BinomiallyExtendable; +use crate::{ + Algebra, BasedVectorSpace, Field, PackedField, PackedFieldExtension, PackedValue, Powers, + PrimeCharacteristicRing, field_to_array, +}; + +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize, PartialOrd, Ord)] +#[repr(transparent)] // Needed to make various casts safe. +pub struct PackedBinomialExtensionField, const D: usize> { + #[serde( + with = "p3_util::array_serialization", + bound(serialize = "PF: Serialize", deserialize = "PF: Deserialize<'de>") + )] + pub(crate) value: [PF; D], +} + +impl, const D: usize> PackedBinomialExtensionField { + const fn new(value: [PF; D]) -> Self { + Self { value } + } +} + +impl, const D: usize> Default + for PackedBinomialExtensionField +{ + #[inline] + fn default() -> Self { + Self { + value: array::from_fn(|_| PF::ZERO), + } + } +} + +impl, const D: usize> From> + for PackedBinomialExtensionField +{ + #[inline] + fn from(x: BinomialExtensionField) -> Self { + Self { + value: x.value.map(Into::into), + } + } +} + +impl, const D: usize> From + for PackedBinomialExtensionField +{ + #[inline] + fn from(x: PF) -> Self { + Self { + value: field_to_array(x), + } + } +} + +impl, PF: PackedField, const D: usize> + Algebra> for PackedBinomialExtensionField +{ +} + +impl, PF: PackedField, const D: usize> Algebra + for PackedBinomialExtensionField +{ +} + +impl PrimeCharacteristicRing for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type PrimeSubfield = PF::PrimeSubfield; + + const ZERO: Self = Self { + value: [PF::ZERO; D], + }; + + const ONE: Self = Self { + value: field_to_array(PF::ONE), + }; + + const TWO: Self = Self { + value: field_to_array(PF::TWO), + }; + + const NEG_ONE: Self = Self { + value: field_to_array(PF::NEG_ONE), + }; + + #[inline] + fn from_prime_subfield(val: Self::PrimeSubfield) -> Self { + PF::from_prime_subfield(val).into() + } + + #[inline] + fn from_bool(b: bool) -> Self { + PF::from_bool(b).into() + } + + #[inline(always)] + fn square(&self) -> Self { + match D { + 2 => { + let a = self.value; + let mut res = Self::default(); + res.value[0] = a[0].square() + a[1].square() * F::W; + res.value[1] = a[0] * a[1].double(); + res + } + 3 => { + let mut res = Self::default(); + cubic_square(&self.value, &mut res.value); + res + } + _ => *self * *self, + } + } + + #[inline] + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(PF::zero_vec(len * D)) } + } +} + +impl BasedVectorSpace for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + const DIMENSION: usize = D; + + #[inline] + fn as_basis_coefficients_slice(&self) -> &[PF] { + &self.value + } + + #[inline] + fn from_basis_coefficients_fn PF>(f: Fn) -> Self { + Self { + value: array::from_fn(f), + } + } + + #[inline] + fn from_basis_coefficients_iter>(mut iter: I) -> Option { + (iter.len() == D).then(|| Self::new(array::from_fn(|_| iter.next().unwrap()))) // The unwrap is safe as we just checked the length of iter. + } + + #[inline] + fn flatten_to_base(vec: Vec) -> Vec { + unsafe { + // Safety: + // As `Self` is a `repr(transparent)`, it is stored identically in memory to `[PF; D]` + flatten_to_base::(vec) + } + } + + #[inline] + fn reconstitute_from_base(vec: Vec) -> Vec { + unsafe { + // Safety: + // As `Self` is a `repr(transparent)`, it is stored identically in memory to `[PF; D]` + reconstitute_from_base::(vec) + } + } +} + +impl PackedFieldExtension> + for PackedBinomialExtensionField +where + F: BinomiallyExtendable, +{ + #[inline] + fn from_ext_slice(ext_slice: &[BinomialExtensionField]) -> Self { + let width = F::Packing::WIDTH; + assert_eq!(ext_slice.len(), width); + + let res = array::from_fn(|i| F::Packing::from_fn(|j| ext_slice[j].value[i])); + Self::new(res) + } + + #[inline] + fn to_ext_iter( + iter: impl IntoIterator, + ) -> impl Iterator> { + let width = F::Packing::WIDTH; + iter.into_iter().flat_map(move |x| { + (0..width).map(move |i| { + let values = array::from_fn(|j| x.value[j].as_slice()[i]); + BinomialExtensionField::new(values) + }) + }) + } + + #[inline] + fn packed_ext_powers(base: BinomialExtensionField) -> crate::Powers { + let width = F::Packing::WIDTH; + let powers = base.powers().take(width + 1).collect_vec(); + // Transpose first WIDTH powers + let current = Self::from_ext_slice(&powers[..width]); + + // Broadcast self^WIDTH + let multiplier = powers[width].into(); + + Powers { + base: multiplier, + current, + } + } +} + +impl Neg for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type Output = Self; + + #[inline] + fn neg(self) -> Self { + Self { + value: self.value.map(PF::neg), + } + } +} + +impl Add for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type Output = Self; + + #[inline] + fn add(self, rhs: Self) -> Self { + let value = vector_add(&self.value, &rhs.value); + Self { value } + } +} + +impl Add> + for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type Output = Self; + + #[inline] + fn add(self, rhs: BinomialExtensionField) -> Self { + let value = vector_add(&self.value, &rhs.value); + Self { value } + } +} + +impl Add for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type Output = Self; + + #[inline] + fn add(mut self, rhs: PF) -> Self { + self.value[0] += rhs; + self + } +} + +impl AddAssign for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn add_assign(&mut self, rhs: Self) { + for i in 0..D { + self.value[i] += rhs.value[i]; + } + } +} + +impl AddAssign> + for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn add_assign(&mut self, rhs: BinomialExtensionField) { + for i in 0..D { + self.value[i] += rhs.value[i]; + } + } +} + +impl AddAssign for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn add_assign(&mut self, rhs: PF) { + self.value[0] += rhs; + } +} + +impl Sum for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn sum>(iter: I) -> Self { + iter.reduce(|acc, x| acc + x).unwrap_or(Self::ZERO) + } +} + +impl Sub for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type Output = Self; + + #[inline] + fn sub(self, rhs: Self) -> Self { + let value = vector_sub(&self.value, &rhs.value); + Self { value } + } +} + +impl Sub> + for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type Output = Self; + + #[inline] + fn sub(self, rhs: BinomialExtensionField) -> Self { + let value = vector_sub(&self.value, &rhs.value); + Self { value } + } +} + +impl Sub for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type Output = Self; + + #[inline] + fn sub(self, rhs: PF) -> Self { + let mut res = self.value; + res[0] -= rhs; + Self { value: res } + } +} + +impl SubAssign for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} + +impl SubAssign> + for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn sub_assign(&mut self, rhs: BinomialExtensionField) { + *self = *self - rhs; + } +} + +impl SubAssign for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn sub_assign(&mut self, rhs: PF) { + *self = *self - rhs; + } +} + +impl Mul for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type Output = Self; + + #[inline] + fn mul(self, rhs: Self) -> Self { + let a = self.value; + let b = rhs.value; + let mut res = Self::default(); + let w = F::W; + + binomial_mul(&a, &b, &mut res.value, w); + + res + } +} + +impl Mul> + for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type Output = Self; + + #[inline] + fn mul(self, rhs: BinomialExtensionField) -> Self { + let a = self.value; + let b = rhs.value; + let mut res = Self::default(); + let w = F::W; + + binomial_mul(&a, &b, &mut res.value, w); + + res + } +} + +impl Mul for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + type Output = Self; + + #[inline] + fn mul(self, rhs: PF) -> Self { + Self { + value: self.value.map(|x| x * rhs), + } + } +} + +impl Product for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn product>(iter: I) -> Self { + iter.reduce(|acc, x| acc * x).unwrap_or(Self::ZERO) + } +} + +impl MulAssign for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} + +impl MulAssign> + for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn mul_assign(&mut self, rhs: BinomialExtensionField) { + *self = *self * rhs; + } +} + +impl MulAssign for PackedBinomialExtensionField +where + F: BinomiallyExtendable, + PF: PackedField, +{ + #[inline] + fn mul_assign(&mut self, rhs: PF) { + *self = *self * rhs; + } +} diff --git a/CoqOfRust/plonky3/field/src/extension/packed_binomial_extension.v b/CoqOfRust/plonky3/field/src/extension/packed_binomial_extension.v new file mode 100644 index 000000000..4df1af638 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/extension/packed_binomial_extension.v @@ -0,0 +1,5944 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module extension. + Module packed_binomial_extension. + (* StructRecord + { + name := "PackedBinomialExtensionField"; + const_params := [ "D" ]; + ty_params := [ "F"; "PF" ]; + fields := [ ("value", Ty.apply (Ty.path "array") [ D ] [ PF ]) ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_F_where_p3_field_field_Field_F_where_core_marker_Copy_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_F_where_p3_field_field_Field_F_where_core_marker_Copy_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* Clone *) + Definition clone + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ D ] [ PF ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) [ ("clone", InstanceField.Method (clone D F PF)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_cmp_Eq_where_core_cmp_Eq_F_where_p3_field_field_Field_F_where_core_cmp_Eq_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* Eq *) + Definition assert_receiver_is_total_eq + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) + [ + ("assert_receiver_is_total_eq", + InstanceField.Method (assert_receiver_is_total_eq D F PF)) + ]. + End Impl_core_cmp_Eq_where_core_cmp_Eq_F_where_p3_field_field_Field_F_where_core_cmp_Eq_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_marker_StructuralPartialEq_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_where_p3_field_field_Field_F_where_core_cmp_PartialEq_PF_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* PartialEq *) + Definition eq + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ D ] [ PF ], + [], + [ Ty.apply (Ty.path "array") [ D ] [ PF ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + (Self D F PF) + (* Instance *) [ ("eq", InstanceField.Method (eq D F PF)) ]. + End Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_where_p3_field_field_Field_F_where_core_cmp_PartialEq_PF_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_hash_Hash_where_core_hash_Hash_F_where_p3_field_field_Field_F_where_core_hash_Hash_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* Hash *) + Definition hash + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply (Ty.path "array") [ D ] [ PF ], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) [ ("hash", InstanceField.Method (hash D F PF)) ]. + End Impl_core_hash_Hash_where_core_hash_Hash_F_where_p3_field_field_Field_F_where_core_hash_Hash_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_where_core_fmt_Debug_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* Debug *) + Definition fmt + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "PackedBinomialExtensionField" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "value" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) [ ("fmt", InstanceField.Method (fmt D F PF)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_where_core_fmt_Debug_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module underscore. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_where_serde_ser_Serialize_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* Serialize *) + Definition serialize + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "PackedBinomialExtensionField" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::_::serialize::__SerializeWith") + [ D ] + [ F; PF ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "value" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructRecord + "p3_field::extension::packed_binomial_extension::_::serialize::__SerializeWith" + [ + ("values", + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |) + ]); + ("phantom", + Value.StructTuple "core::marker::PhantomData" []) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) [ ("serialize", InstanceField.Method (serialize D F PF)) ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_where_serde_ser_Serialize_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_where_serde_de_Deserialize_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* Deserialize *) + Definition deserialize + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::_'1::deserialize::__Visitor") + [ D ] + [ F; PF ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "PackedBinomialExtensionField" |); + M.read (| + get_constant (| + "p3_field::extension::packed_binomial_extension::_'1::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_field::extension::packed_binomial_extension::_'1::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize D F PF)) ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_where_serde_de_Deserialize_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + End underscore. + + + Module Impl_core_cmp_PartialOrd_where_core_cmp_PartialOrd_F_where_p3_field_field_Field_F_where_core_cmp_PartialOrd_PF_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* PartialOrd *) + Definition partial_cmp + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "array") [ D ] [ PF ], + [], + [ Ty.apply (Ty.path "array") [ D ] [ PF ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + (Self D F PF) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp D F PF)) ]. + End Impl_core_cmp_PartialOrd_where_core_cmp_PartialOrd_F_where_p3_field_field_Field_F_where_core_cmp_PartialOrd_PF_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_cmp_Ord_where_core_cmp_Ord_F_where_p3_field_field_Field_F_where_core_cmp_Ord_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* Ord *) + Definition cmp + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply (Ty.path "array") [ D ] [ PF ], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) [ ("cmp", InstanceField.Method (cmp D F PF)) ]. + End Impl_core_cmp_Ord_where_core_cmp_Ord_F_where_p3_field_field_Field_F_where_core_cmp_Ord_PF_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + const fn new(value: [PF; D]) -> Self { + Self { value } + } + *) + Definition new + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ ("value", M.read (| value |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (D : Value.t) (F PF : Ty.t), + M.IsAssociatedFunction.C (Self D F PF) "new" (new D F PF). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_default_Default_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn default() -> Self { + Self { + value: array::from_fn(|_| PF::ZERO), + } + } + *) + Definition default + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| + "core::array::from_fn", + [ D ], + [ PF; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] PF ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] PF ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + PF + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) [ ("default", InstanceField.Method (default D F PF)) ]. + End Impl_core_default_Default_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_convert_From_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn from(x: BinomialExtensionField) -> Self { + Self { + value: x.value.map(Into::into), + } + } + *) + Definition from + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ D ] [ F ], + "map", + [], + [ Ty.function [ F ] PF; PF ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + x, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |); + M.get_trait_method (| "core::convert::Into", F, [], [ PF ], "into", [], [] |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F PF) + (* Instance *) [ ("from", InstanceField.Method (from D F PF)) ]. + End Impl_core_convert_From_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_convert_From_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn from(x: PF) -> Self { + Self { + value: field_to_array(x), + } + } + *) + Definition from + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| "p3_field::helpers::field_to_array", [ D ], [ PF ] |), + [ M.read (| x |) ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ PF ] + (Self D F PF) + (* Instance *) [ ("from", InstanceField.Method (from D F PF)) ]. + End Impl_core_convert_From_where_p3_field_field_Field_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_p3_field_field_Algebra_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "p3_field::field::Algebra" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F PF) + (* Instance *) []. + End Impl_p3_field_field_Algebra_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_p3_field_field_Algebra_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "p3_field::field::Algebra" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ PF ] + (Self D F PF) + (* Instance *) []. + End Impl_p3_field_field_Algebra_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_p3_field_field_PrimeCharacteristicRing_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type PrimeSubfield = PF::PrimeSubfield; *) + Definition _PrimeSubfield (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_field::field::PrimeCharacteristicRing" [] [] PF "PrimeSubfield". + + (* + const ZERO: Self = Self { + value: [PF::ZERO; D], + }; + *) + (* Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] *) + Definition value_ZERO + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + ltac:(M.monadic + (M.alloc (| + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + repeat (| + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", PF |) + |), + D + |)) + ] + |))). + + (* + const ONE: Self = Self { + value: field_to_array(PF::ONE), + }; + *) + (* Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] *) + Definition value_ONE + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + ltac:(M.monadic + (M.alloc (| + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| "p3_field::helpers::field_to_array", [ D ], [ PF ] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", PF |) + |) + ] + |)) + ] + |))). + + (* + const TWO: Self = Self { + value: field_to_array(PF::TWO), + }; + *) + (* Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] *) + Definition value_TWO + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + ltac:(M.monadic + (M.alloc (| + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| "p3_field::helpers::field_to_array", [ D ], [ PF ] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", PF |) + |) + ] + |)) + ] + |))). + + (* + const NEG_ONE: Self = Self { + value: field_to_array(PF::NEG_ONE), + }; + *) + (* Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] *) + Definition value_NEG_ONE + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + ltac:(M.monadic + (M.alloc (| + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| "p3_field::helpers::field_to_array", [ D ], [ PF ] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::NEG_ONE", PF |) + |) + ] + |)) + ] + |))). + + (* + fn from_prime_subfield(val: Self::PrimeSubfield) -> Self { + PF::from_prime_subfield(val).into() + } + *) + Definition from_prime_subfield + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ val ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::convert::Into", + PF, + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + "into", + [], + [] + |), + [ + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ M.read (| val |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_bool(b: bool) -> Self { + PF::from_bool(b).into() + } + *) + Definition from_bool + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ b ] => + ltac:(M.monadic + (let b := M.alloc (| b |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::convert::Into", + PF, + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + "into", + [], + [] + |), + [ + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "from_bool", + [], + [] + |), + [ M.read (| b |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn square(&self) -> Self { + match D { + 2 => { + let a = self.value; + let mut res = Self::default(); + res.value[0] = a[0].square() + a[1].square() * F::W; + res.value[1] = a[0] * a[1].double(); + res + } + 3 => { + let mut res = Self::default(); + cubic_square(&self.value, &mut res.value); + res + } + _ => *self * *self, + } + } + *) + Definition square + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + M.alloc (| D |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + let~ a : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ PF ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Add", + PF, + [], + [ PF ], + "add", + [], + [] + |), + [ + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + a, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + a, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::extension::BinomiallyExtendable::W", + F + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ PF ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + a, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + PF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + a, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) + |) in + res)); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 3 + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::extension::binomial_extension::cubic_square", + [ D ], + [ F; PF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |) + |) in + res)); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + "mul", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| self |) |) |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(PF::zero_vec(len * D)) } + } + *) + Definition zero_vec + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ len ] => + ltac:(M.monadic + (let len := M.alloc (| len |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_util::reconstitute_from_base", + [], + [ + PF; + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ PF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + PF, + [], + [], + "zero_vec", + [], + [] + |), + [ M.call_closure (| Ty.path "usize", BinOp.Wrap.mul, [ M.read (| len |); D ] |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "p3_field::field::PrimeCharacteristicRing" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) + [ + ("PrimeSubfield", InstanceField.Ty (_PrimeSubfield D F PF)); + ("value_ZERO", InstanceField.Method (value_ZERO D F PF)); + ("value_ONE", InstanceField.Method (value_ONE D F PF)); + ("value_TWO", InstanceField.Method (value_TWO D F PF)); + ("value_NEG_ONE", InstanceField.Method (value_NEG_ONE D F PF)); + ("from_prime_subfield", InstanceField.Method (from_prime_subfield D F PF)); + ("from_bool", InstanceField.Method (from_bool D F PF)); + ("square", InstanceField.Method (square D F PF)); + ("zero_vec", InstanceField.Method (zero_vec D F PF)) + ]. + End Impl_p3_field_field_PrimeCharacteristicRing_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_p3_field_field_BasedVectorSpace_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* const DIMENSION: usize = D; *) + (* Ty.path "usize" *) + Definition value_DIMENSION + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + ltac:(M.monadic (M.alloc (| D |))). + + (* + fn as_basis_coefficients_slice(&self) -> &[PF] { + &self.value + } + *) + Definition as_basis_coefficients_slice + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_basis_coefficients_fn PF>(f: Fn) -> Self { + Self { + value: array::from_fn(f), + } + } + *) + Definition from_basis_coefficients_fn + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [ Fn ], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| "core::array::from_fn", [ D ], [ PF; Fn ] |), + [ M.read (| f |) ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_basis_coefficients_iter>(mut iter: I) -> Option { + (iter.len() == D).then(|| Self::new(array::from_fn(|_| iter.next().unwrap()))) // The unwrap is safe as we just checked the length of iter. + } + *) + Definition from_basis_coefficients_iter + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]; + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]) + ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::iter::traits::exact_size::ExactSizeIterator", + I, + [], + [], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, iter |) ] + |); + D + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| + "core::array::from_fn", + [ D ], + [ PF; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] PF ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + PF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + PF, + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ PF ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ PF ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn flatten_to_base(vec: Vec) -> Vec { + unsafe { + // Safety: + // As `Self` is a `repr(transparent)`, it is stored identically in memory to `[PF; D]` + flatten_to_base::(vec) + } + } + *) + Definition flatten_to_base + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ vec ] => + ltac:(M.monadic + (let vec := M.alloc (| vec |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ PF; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_util::flatten_to_base", + [], + [ + PF; + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + |), + [ M.read (| vec |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn reconstitute_from_base(vec: Vec) -> Vec { + unsafe { + // Safety: + // As `Self` is a `repr(transparent)`, it is stored identically in memory to `[PF; D]` + reconstitute_from_base::(vec) + } + } + *) + Definition reconstitute_from_base + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ vec ] => + ltac:(M.monadic + (let vec := M.alloc (| vec |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_util::reconstitute_from_base", + [], + [ + PF; + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + |), + [ M.read (| vec |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "p3_field::field::BasedVectorSpace" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ PF ] + (Self D F PF) + (* Instance *) + [ + ("value_DIMENSION", InstanceField.Method (value_DIMENSION D F PF)); + ("as_basis_coefficients_slice", + InstanceField.Method (as_basis_coefficients_slice D F PF)); + ("from_basis_coefficients_fn", + InstanceField.Method (from_basis_coefficients_fn D F PF)); + ("from_basis_coefficients_iter", + InstanceField.Method (from_basis_coefficients_iter D F PF)); + ("flatten_to_base", InstanceField.Method (flatten_to_base D F PF)); + ("reconstitute_from_base", InstanceField.Method (reconstitute_from_base D F PF)) + ]. + End Impl_p3_field_field_BasedVectorSpace_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_p3_field_packed_PackedFieldExtension_where_p3_field_extension_BinomiallyExtendable_F_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_associated_in_trait_p3_field_field_Field___F_Packing. + Definition Self (D : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ]. + + (* + fn from_ext_slice(ext_slice: &[BinomialExtensionField]) -> Self { + let width = F::Packing::WIDTH; + assert_eq!(ext_slice.len(), width); + + let res = array::from_fn(|i| F::Packing::from_fn(|j| ext_slice[j].value[i])); + Self::new(res) + } + *) + Definition from_ext_slice + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ ext_slice ] => + ltac:(M.monadic + (let ext_slice := M.alloc (| ext_slice |) in + M.read (| + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| ext_slice |) |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, width |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ D ] + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ D ] + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + M.get_function (| + "core::array::from_fn", + [ D ], + [ + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing"; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing", + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing", + [], + [], + "from_fn", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| ext_slice |) + |), + M.read (| j |) + |), + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + M.read (| i |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + "new", + [], + [] + |), + [ M.read (| res |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn to_ext_iter( + iter: impl IntoIterator, + ) -> impl Iterator> { + let width = F::Packing::WIDTH; + iter.into_iter().flat_map(move |x| { + (0..width).map(move |i| { + let values = array::from_fn(|j| x.value[j].as_slice()[i]); + BinomialExtensionField::new(values) + }) + }) + } + *) + Definition to_ext_iter + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [ impl_IntoIterator_Item___Self_ ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.read (| + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + impl_IntoIterator_Item___Self_ + "IntoIter"; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ + F; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]) + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + impl_IntoIterator_Item___Self_ + "IntoIter", + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ + F; + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]) + ]) + ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + impl_IntoIterator_Item___Self_ + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + impl_IntoIterator_Item___Self_, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| iter |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ + F; + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]) + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| width |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + let~ values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ D ] + [ F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ D ] + [ F ], + M.get_function (| + "core::array::from_fn", + [ D ], + [ + F; + Ty.function + [ + Ty.tuple + [ Ty.path "usize" ] + ] + F + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := + M.copy (| + γ + |) in + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + F + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing", + [], + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + x, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |), + M.read (| + j + |) + |) + |) + ] + |) + |), + M.read (| + i + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + "new", + [], + [] + |), + [ M.read (| values |) ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn packed_ext_powers(base: BinomialExtensionField) -> crate::Powers { + let width = F::Packing::WIDTH; + let powers = base.powers().take(width + 1).collect_vec(); + // Transpose first WIDTH powers + let current = Self::from_ext_slice(&powers[..width]); + + // Broadcast self^WIDTH + let multiplier = powers[width].into(); + + Powers { + base: multiplier, + current, + } + } + *) + Definition packed_ext_powers + (D : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F in + match ε, τ, α with + | [], [], [ base ] => + ltac:(M.monadic + (let base := M.alloc (| base |) in + M.read (| + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) in + let~ powers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, base |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| width |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + ] + |) + |) in + let~ current : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + M.get_trait_method (| + "p3_field::packed::PackedFieldExtension", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + [], + [ + F; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + "from_ext_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, powers |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", M.read (| width |)) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ multiplier : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ] + ], + "into", + [], + [] + |), + [ + M.read (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, powers |); M.read (| width |) ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_field::field::Powers" + [ ("base", M.read (| multiplier |)); ("current", M.read (| current |)) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::packed::PackedFieldExtension" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + F; + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F) + (* Instance *) + [ + ("from_ext_slice", InstanceField.Method (from_ext_slice D F)); + ("to_ext_iter", InstanceField.Method (to_ext_iter D F)); + ("packed_ext_powers", InstanceField.Method (packed_ext_powers D F)) + ]. + End Impl_p3_field_packed_PackedFieldExtension_where_p3_field_extension_BinomiallyExtendable_F_F_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_associated_in_trait_p3_field_field_Field___F_Packing. + + Module Impl_core_ops_arith_Neg_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn neg(self) -> Self { + Self { + value: self.value.map(PF::neg), + } + } + *) + Definition neg + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + "map", + [], + [ + Ty.function + [ PF ] + (Ty.associated_in_trait "core::ops::arith::Neg" [] [] PF "Output"); + PF + ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |); + M.get_trait_method (| "core::ops::arith::Neg", PF, [], [], "neg", [], [] |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self D F PF) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output D F PF)); + ("neg", InstanceField.Method (neg D F PF)) + ]. + End Impl_core_ops_arith_Neg_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_Add_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn add(self, rhs: Self) -> Self { + let value = vector_add(&self.value, &rhs.value); + Self { value } + } + *) + Definition add + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ value : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ PF ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| + "p3_field::extension::binomial_extension::vector_add", + [ D ], + [ PF; PF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ ("value", M.read (| value |)) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + (Self D F PF) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output D F PF)); + ("add", InstanceField.Method (add D F PF)) + ]. + End Impl_core_ops_arith_Add_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_Add_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn add(self, rhs: BinomialExtensionField) -> Self { + let value = vector_add(&self.value, &rhs.value); + Self { value } + } + *) + Definition add + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ value : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ PF ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| + "p3_field::extension::binomial_extension::vector_add", + [ D ], + [ PF; F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ ("value", M.read (| value |)) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F PF) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output D F PF)); + ("add", InstanceField.Method (add D F PF)) + ]. + End Impl_core_ops_arith_Add_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_Add_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn add(mut self, rhs: PF) -> Self { + self.value[0] += rhs; + self + } + *) + Definition add + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| rhs |) + ] + |) + |) in + self + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ PF ] + (Self D F PF) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output D F PF)); + ("add", InstanceField.Method (add D F PF)) + ]. + End Impl_core_ops_arith_Add_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_AddAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn add_assign(&mut self, rhs: Self) { + for i in 0..D { + self.value[i] += rhs.value[i]; + } + } + *) + Definition add_assign + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", D) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |), + M.read (| i |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + (Self D F PF) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign D F PF)) ]. + End Impl_core_ops_arith_AddAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_AddAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn add_assign(&mut self, rhs: BinomialExtensionField) { + for i in 0..D { + self.value[i] += rhs.value[i]; + } + } + *) + Definition add_assign + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", D) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |), + M.read (| i |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F PF) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign D F PF)) ]. + End Impl_core_ops_arith_AddAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_AddAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn add_assign(&mut self, rhs: PF) { + self.value[0] += rhs; + } + *) + Definition add_assign + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + PF, + [], + [ PF ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| rhs |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ PF ] + (Self D F PF) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign D F PF)) ]. + End Impl_core_ops_arith_AddAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_iter_traits_accum_Sum_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn sum>(iter: I) -> Self { + iter.reduce(|acc, x| acc + x).unwrap_or(Self::ZERO) + } + *) + Definition sum + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]; + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]; + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]; + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + "add", + [], + [] + |), + [ M.read (| acc |); M.read (| x |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Sum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + (Self D F PF) + (* Instance *) [ ("sum", InstanceField.Method (sum D F PF)) ]. + End Impl_core_iter_traits_accum_Sum_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_Sub_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn sub(self, rhs: Self) -> Self { + let value = vector_sub(&self.value, &rhs.value); + Self { value } + } + *) + Definition sub + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ value : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ PF ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| + "p3_field::extension::binomial_extension::vector_sub", + [ D ], + [ PF; PF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ ("value", M.read (| value |)) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + (Self D F PF) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output D F PF)); + ("sub", InstanceField.Method (sub D F PF)) + ]. + End Impl_core_ops_arith_Sub_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_Sub_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn sub(self, rhs: BinomialExtensionField) -> Self { + let value = vector_sub(&self.value, &rhs.value); + Self { value } + } + *) + Definition sub + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ value : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ PF ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_function (| + "p3_field::extension::binomial_extension::vector_sub", + [ D ], + [ PF; F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ ("value", M.read (| value |)) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F PF) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output D F PF)); + ("sub", InstanceField.Method (sub D F PF)) + ]. + End Impl_core_ops_arith_Sub_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_Sub_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn sub(self, rhs: PF) -> Self { + let mut res = self.value; + res[0] -= rhs; + Self { value: res } + } + *) + Definition sub + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ res : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ PF ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + PF, + [], + [ PF ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| res, Value.Integer IntegerKind.Usize 0 |) + |); + M.read (| rhs |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ ("value", M.read (| res |)) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ PF ] + (Self D F PF) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output D F PF)); + ("sub", InstanceField.Method (sub D F PF)) + ]. + End Impl_core_ops_arith_Sub_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_SubAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } + *) + Definition sub_assign + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + "sub", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + (Self D F PF) + (* Instance *) [ ("sub_assign", InstanceField.Method (sub_assign D F PF)) ]. + End Impl_core_ops_arith_SubAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_SubAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn sub_assign(&mut self, rhs: BinomialExtensionField) { + *self = *self - rhs; + } + *) + Definition sub_assign + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + "sub", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F PF) + (* Instance *) [ ("sub_assign", InstanceField.Method (sub_assign D F PF)) ]. + End Impl_core_ops_arith_SubAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_SubAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn sub_assign(&mut self, rhs: PF) { + *self = *self - rhs; + } + *) + Definition sub_assign + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [ PF ], + "sub", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ PF ] + (Self D F PF) + (* Instance *) [ ("sub_assign", InstanceField.Method (sub_assign D F PF)) ]. + End Impl_core_ops_arith_SubAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_Mul_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn mul(self, rhs: Self) -> Self { + let a = self.value; + let b = rhs.value; + let mut res = Self::default(); + let w = F::W; + + binomial_mul(&a, &b, &mut res.value, w); + + res + } + *) + Definition mul + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ a : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ PF ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) in + let~ b : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ PF ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ w : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| get_constant (| "p3_field::extension::BinomiallyExtendable::W", F |) |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::extension::binomial_extension::binomial_mul", + [ D ], + [ F; PF; PF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, a |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, b |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |); + M.read (| w |) + ] + |) + |) in + res + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + (Self D F PF) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output D F PF)); + ("mul", InstanceField.Method (mul D F PF)) + ]. + End Impl_core_ops_arith_Mul_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_Mul_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn mul(self, rhs: BinomialExtensionField) -> Self { + let a = self.value; + let b = rhs.value; + let mut res = Self::default(); + let w = F::W; + + binomial_mul(&a, &b, &mut res.value, w); + + res + } + *) + Definition mul + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ a : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ PF ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) in + let~ b : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ D ] [ F ] ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_field::extension::binomial_extension::BinomialExtensionField", + "value" + |) + |) in + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ w : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| get_constant (| "p3_field::extension::BinomiallyExtendable::W", F |) |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_field::extension::binomial_extension::binomial_mul", + [ D ], + [ F; PF; F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, a |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, b |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + res, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |) + |) + |); + M.read (| w |) + ] + |) + |) in + res + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F PF) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output D F PF)); + ("mul", InstanceField.Method (mul D F PF)) + ]. + End Impl_core_ops_arith_Mul_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_Mul_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* type Output = Self; *) + Definition _Output (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn mul(self, rhs: PF) -> Self { + Self { + value: self.value.map(|x| x * rhs), + } + } + *) + Definition mul + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructRecord + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ D ] [ PF ], + "map", + [], + [ Ty.function [ Ty.tuple [ PF ] ] PF; PF ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField", + "value" + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ PF ] ] PF ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + PF, + M.get_trait_method (| + "core::ops::arith::Mul", + PF, + [], + [ PF ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| rhs |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ PF ] + (Self D F PF) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output D F PF)); + ("mul", InstanceField.Method (mul D F PF)) + ]. + End Impl_core_ops_arith_Mul_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_iter_traits_accum_Product_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn product>(iter: I) -> Self { + iter.reduce(|acc, x| acc * x).unwrap_or(Self::ZERO) + } + *) + Definition product + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]; + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]; + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]; + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + "mul", + [], + [] + |), + [ M.read (| acc |); M.read (| x |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Product" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + (Self D F PF) + (* Instance *) [ ("product", InstanceField.Method (product D F PF)) ]. + End Impl_core_iter_traits_accum_Product_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_MulAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } + *) + Definition mul_assign + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ], + "mul", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ] + ] + (Self D F PF) + (* Instance *) [ ("mul_assign", InstanceField.Method (mul_assign D F PF)) ]. + End Impl_core_ops_arith_MulAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_MulAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn mul_assign(&mut self, rhs: BinomialExtensionField) { + *self = *self * rhs; + } + *) + Definition mul_assign + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ], + "mul", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ D ] + [ F; F ] + ] + (Self D F PF) + (* Instance *) [ ("mul_assign", InstanceField.Method (mul_assign D F PF)) ]. + End Impl_core_ops_arith_MulAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_p3_field_extension_binomial_extension_BinomialExtensionField_D_F_F_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + + Module Impl_core_ops_arith_MulAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + Definition Self (D : Value.t) (F PF : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ]. + + (* + fn mul_assign(&mut self, rhs: PF) { + *self = *self * rhs; + } + *) + Definition mul_assign + (D : Value.t) + (F PF : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D F PF in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::packed_binomial_extension::PackedBinomialExtensionField") + [ D ] + [ F; PF ], + [], + [ PF ], + "mul", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (F PF : Ty.t), + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ PF ] + (Self D F PF) + (* Instance *) [ ("mul_assign", InstanceField.Method (mul_assign D F PF)) ]. + End Impl_core_ops_arith_MulAssign_where_p3_field_extension_BinomiallyExtendable_F_where_p3_field_packed_PackedField_PF_PF_for_p3_field_extension_packed_binomial_extension_PackedBinomialExtensionField_D_F_PF. + End packed_binomial_extension. +End extension. diff --git a/CoqOfRust/plonky3/field/src/field.rs b/CoqOfRust/plonky3/field/src/field.rs new file mode 100644 index 000000000..794e03987 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/field.rs @@ -0,0 +1,846 @@ +use alloc::vec; +use alloc::vec::Vec; +use core::fmt::{Debug, Display}; +use core::hash::Hash; +use core::iter::{Product, Sum}; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; +use core::slice; + +use num_bigint::BigUint; +use serde::Serialize; +use serde::de::DeserializeOwned; + +use crate::exponentiation::bits_u64; +use crate::integers::{QuotientMap, from_integer_types}; +use crate::packed::PackedField; +use crate::{Packable, PackedFieldExtension}; + +/// A commutative ring, `R`, with prime characteristic, `p`. +/// +/// This permits elements like: +/// - A single finite field element. +/// - A symbolic expression which would evaluate to a field element. +/// - An array of finite field elements. +/// - A polynomial with coefficients in a finite field. +/// +/// ### Mathematical Description +/// +/// Mathematically, a commutative ring is a set of objects which supports an addition-like +/// like operation, `+`, and a multiplication-like operation `*`. +/// +/// Let `x, y, z` denote arbitrary elements of the set. +/// +/// Then, an operation is addition-like if it satisfies the following properties: +/// - Commutativity => `x + y = y + x` +/// - Associativity => `x + (y + z) = (x + y) + z` +/// - Unit => There exists an identity element `ZERO` satisfying `x + ZERO = x`. +/// - Inverses => For every `x` there exists a unique inverse `(-x)` satisfying `x + (-x) = ZERO` +/// +/// Similarly, an operation is multiplication-like if it satisfies the following properties: +/// - Commutativity => `x * y = y * x` +/// - Associativity => `x * (y * z) = (x * y) * z` +/// - Unit => There exists an identity element `ONE` satisfying `x * ONE = x`. +/// - Distributivity => The two operations `+` and `*` must together satisfy `x * (y + z) = (x * y) + (x * z)` +/// +/// Unlike in the addition case, we do not require inverses to exist with respect to `*`. +/// +/// The simplest examples of commutative rings are the integers (`ℤ`), and the integers mod `N` (`ℤ/N`). +/// +/// The characteristic of a ring is the smallest positive integer `r` such that `0 = r . 1 = 1 + 1 + ... + 1 (r times)`. +/// For example, the characteristic of the modulo ring `ℤ/N` is `N`. +/// +/// Rings with prime characteristic are particularly special due to their close relationship with finite fields. +pub trait PrimeCharacteristicRing: + Sized + + Default + + Clone + + Add + + AddAssign + + Sub + + SubAssign + + Neg + + Mul + + MulAssign + + Sum + + Product + + Debug +{ + /// The field `ℤ/p` where the characteristic of this ring is p. + type PrimeSubfield: PrimeField; + + /// The additive identity of the ring. + /// + /// For every element `a` in the ring we require the following properties: + /// + /// `a + ZERO = ZERO + a = a,` + /// + /// `a + (-a) = (-a) + a = ZERO.` + const ZERO: Self; + + /// The multiplicative identity of the ring. + /// + /// For every element `a` in the ring we require the following property: + /// + /// `a*ONE = ONE*a = a.` + const ONE: Self; + + /// The element in the ring given by `ONE + ONE`. + /// + /// This is provided as a convenience as `TWO` occurs regularly in + /// the proving system. This also is slightly faster than computing + /// it via addition. Note that multiplication by `TWO` is discouraged. + /// Instead of `a * TWO` use `a.double()` which will be faster. + /// + /// If the field has characteristic 2 this is equal to ZERO. + const TWO: Self; + + /// The element in the ring given by `-ONE`. + /// + /// This is provided as a convenience as `NEG_ONE` occurs regularly in + /// the proving system. This also is slightly faster than computing + /// it via negation. Note that where possible `NEG_ONE` should be absorbed + /// into mathematical operations. For example `a - b` will be faster + /// than `a + NEG_ONE * b` and similarly `(-b)` is faster than `NEG_ONE * b`. + /// + /// If the field has characteristic 2 this is equal to ONE. + const NEG_ONE: Self; + + /// Embed an element of the prime field `ℤ/p` into the ring `R`. + /// + /// Given any element `[r] ∈ ℤ/p`, represented by an integer `r` between `0` and `p - 1` + /// `from_prime_subfield([r])` will be equal to: + /// + /// `Self::ONE + ... + Self::ONE (r times)` + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self; + + /// Return `Self::ONE` if `b` is `true` and `Self::ZERO` if `b` is `false`. + #[must_use] + #[inline(always)] + fn from_bool(b: bool) -> Self { + // Some rings might reimplement this to avoid the branch. + if b { Self::ONE } else { Self::ZERO } + } + + from_integer_types!( + u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize + ); + + /// The elementary function `double(a) = 2*a`. + /// + /// This function should be preferred over calling `a + a` or `TWO * a` as a faster implementation may be available for some rings. + /// If the field has characteristic 2 then this returns 0. + #[must_use] + #[inline(always)] + fn double(&self) -> Self { + self.clone() + self.clone() + } + + /// The elementary function `square(a) = a^2`. + /// + /// This function should be preferred over calling `a * a`, as a faster implementation may be available for some rings. + #[must_use] + #[inline(always)] + fn square(&self) -> Self { + self.clone() * self.clone() + } + + /// The elementary function `cube(a) = a^3`. + /// + /// This function should be preferred over calling `a * a * a`, as a faster implementation may be available for some rings. + #[must_use] + #[inline(always)] + fn cube(&self) -> Self { + self.square() * self.clone() + } + + /// Computes the arithmetic generalization of boolean `xor`. + /// + /// For boolean inputs, `x ^ y = x + y - 2 xy`. + #[must_use] + #[inline(always)] + fn xor(&self, y: &Self) -> Self { + self.clone() + y.clone() - self.clone() * y.clone().double() + } + + /// Computes the arithmetic generalization of a triple `xor`. + /// + /// For boolean inputs `x ^ y ^ z = x + y + z - 2(xy + xz + yz) + 4xyz`. + #[must_use] + #[inline(always)] + fn xor3(&self, y: &Self, z: &Self) -> Self { + self.xor(y).xor(z) + } + + /// Computes the arithmetic generalization of `andnot`. + /// + /// For boolean inputs `(!x) & y = (1 - x)y`. + #[must_use] + #[inline(always)] + fn andn(&self, y: &Self) -> Self { + (Self::ONE - self.clone()) * y.clone() + } + + /// The vanishing polynomial for boolean values: `x * (1 - x)`. + /// + /// This is a polynomial of degree `2` that evaluates to `0` if the input is `0` or `1`. + /// If our space is a field, then this will be nonzero on all other inputs. + #[must_use] + #[inline(always)] + fn bool_check(&self) -> Self { + // We use `x * (1 - x)` instead of `x * (x - 1)` as this lets us delegate to the `andn` function. + self.andn(self) + } + + /// Exponentiation by a `u64` power. + /// + /// This uses the standard square and multiply approach. + /// For specific powers regularly used and known in advance, + /// this will be slower than custom addition chain exponentiation. + #[must_use] + #[inline] + fn exp_u64(&self, power: u64) -> Self { + let mut current = self.clone(); + let mut product = Self::ONE; + + for j in 0..bits_u64(power) { + if (power >> j) & 1 != 0 { + product *= current.clone(); + } + current = current.square(); + } + product + } + + /// Exponentiation by a small constant power. + /// + /// For a collection of small values we implement custom multiplication chain circuits which can be faster than the + /// simpler square and multiply approach. + /// + /// For large values this defaults back to `self.exp_u64`. + #[must_use] + #[inline(always)] + fn exp_const_u64(&self) -> Self { + match POWER { + 0 => Self::ONE, + 1 => self.clone(), + 2 => self.square(), + 3 => self.cube(), + 4 => self.square().square(), + 5 => self.square().square() * self.clone(), + 6 => self.square().cube(), + 7 => { + let x2 = self.square(); + let x3 = x2.clone() * self.clone(); + let x4 = x2.square(); + x3 * x4 + } + _ => self.exp_u64(POWER), + } + } + + /// The elementary function `exp_power_of_2(a, power_log) = a^{2^power_log}`. + /// + /// Computed via repeated squaring. + #[must_use] + #[inline] + fn exp_power_of_2(&self, power_log: usize) -> Self { + let mut res = self.clone(); + for _ in 0..power_log { + res = res.square(); + } + res + } + + /// The elementary function `mul_2exp_u64(a, exp) = a * 2^{exp}`. + /// + /// Here `2^{exp}` is computed using the square and multiply approach. + #[must_use] + #[inline] + fn mul_2exp_u64(&self, exp: u64) -> Self { + self.clone() * Self::TWO.exp_u64(exp) + } + + /// Construct an iterator which returns powers of `self`: `self^0, self^1, self^2, ...`. + #[must_use] + #[inline] + fn powers(&self) -> Powers { + self.shifted_powers(Self::ONE) + } + + /// Construct an iterator which returns powers of `self` shifted by `start`: `start, start*self^1, start*self^2, ...`. + #[must_use] + #[inline] + fn shifted_powers(&self, start: Self) -> Powers { + Powers { + base: self.clone(), + current: start, + } + } + + /// Compute the dot product of two vectors. + #[must_use] + #[inline] + fn dot_product(u: &[Self; N], v: &[Self; N]) -> Self { + u.iter().zip(v).map(|(x, y)| x.clone() * y.clone()).sum() + } + + /// Compute the sum of a slice of elements whose length is a compile time constant. + /// + /// The rust compiler doesn't realize that add is associative + /// so we help it out and minimize the dependency chains by hand. + /// Thus while this function has the same throughput as `input.iter().sum()`, + /// it will usually have much lower latency. + /// + /// # Panics + /// + /// May panic if the length of the input slice is not equal to `N`. + #[must_use] + #[inline] + fn sum_array(input: &[Self]) -> Self { + // It looks a little strange but using a const parameter and an assert_eq! instead of + // using input.len() leads to a significant performance improvement. + // We could make this input &[Self; N] but that would require sticking .try_into().unwrap() everywhere. + // Checking godbolt, the compiler seems to unroll everything anyway. + assert_eq!(N, input.len()); + + // For `N <= 8` we implement a tree sum structure and for `N > 8` we break the input into + // chunks of `8`, perform a tree sum on each chunk and sum the results. The parameter `8` + // was determined experimentally by testing the speed of the poseidon2 internal layer computations. + // This is a useful benchmark as we have a mix of summations of size 15, 23 with other work in between. + // I only tested this on `AVX2` though so there might be a better value for other architectures. + match N { + 0 => Self::ZERO, + 1 => input[0].clone(), + 2 => input[0].clone() + input[1].clone(), + 3 => input[0].clone() + input[1].clone() + input[2].clone(), + 4 => (input[0].clone() + input[1].clone()) + (input[2].clone() + input[3].clone()), + 5 => Self::sum_array::<4>(&input[..4]) + Self::sum_array::<1>(&input[4..]), + 6 => Self::sum_array::<4>(&input[..4]) + Self::sum_array::<2>(&input[4..]), + 7 => Self::sum_array::<4>(&input[..4]) + Self::sum_array::<3>(&input[4..]), + 8 => Self::sum_array::<4>(&input[..4]) + Self::sum_array::<4>(&input[4..]), + _ => { + // We know that N > 8 here so this saves an add over the usual + // initialisation of acc to Self::ZERO. + let mut acc = Self::sum_array::<8>(&input[..8]); + for i in (16..=N).step_by(8) { + acc += Self::sum_array::<8>(&input[(i - 8)..i]) + } + // This would be much cleaner if we could use const generic expressions but + // this will do for now. + match N & 7 { + 0 => acc, + 1 => acc + Self::sum_array::<1>(&input[(8 * (N / 8))..]), + 2 => acc + Self::sum_array::<2>(&input[(8 * (N / 8))..]), + 3 => acc + Self::sum_array::<3>(&input[(8 * (N / 8))..]), + 4 => acc + Self::sum_array::<4>(&input[(8 * (N / 8))..]), + 5 => acc + Self::sum_array::<5>(&input[(8 * (N / 8))..]), + 6 => acc + Self::sum_array::<6>(&input[(8 * (N / 8))..]), + 7 => acc + Self::sum_array::<7>(&input[(8 * (N / 8))..]), + _ => unreachable!(), + } + } + } + } + + /// Allocates a vector of zero elements of length `len`. Many operating systems zero pages + /// before assigning them to a userspace process. In that case, our process should not need to + /// write zeros, which would be redundant. However, the compiler may not always recognize this. + /// + /// In particular, `vec![Self::ZERO; len]` appears to result in redundant userspace zeroing. + /// This is the default implementation, but implementors may wish to provide their own + /// implementation which transmutes something like `vec![0u32; len]`. + #[must_use] + #[inline] + fn zero_vec(len: usize) -> Vec { + vec![Self::ZERO; len] + } +} + +/// A vector space `V` over `F` with a fixed basis. Fixing the basis allows elements of `V` to be +/// converted to and from `DIMENSION` many elements of `F` which are interpreted as basis coefficients. +/// +/// We usually expect `F` to be a field but do not enforce this and so allow it to be just a ring. +/// This lets every ring implement `BasedVectorSpace` and is useful in a couple of other cases. +/// +/// ## Safety +/// We make no guarantees about consistency of the choice of basis across different versions of Plonky3. +/// If this choice of basis changes, the behaviour of `BasedVectorSpace` will also change. Due to this, +/// we recommend avoiding using this trait unless absolutely necessary. +/// +/// ### Mathematical Description +/// Given a vector space, `A` over `F`, a basis is a set of elements `B = {b_0, ..., b_{n-1}}` +/// in `A` such that, given any element `a`, we can find a unique set of `n` elements of `F`, +/// `f_0, ..., f_{n - 1}` satisfying `a = f_0 b_0 + ... + f_{n - 1} b_{n - 1}`. Thus the choice +/// of `B` gives rise to a natural linear map between the vector space `A` and the canonical +/// `n` dimensional vector space `F^n`. +/// +/// This allows us to map between elements of `A` and arrays of `n` elements of `F`. +/// Clearly this map depends entirely on the choice of basis `B` which may change +/// across versions of Plonky3. +/// +/// The situation is slightly more complicated in cases where `F` is not a field but boils down +/// to an identical description once we enforce that `A` is a free module over `F`. +pub trait BasedVectorSpace: Sized { + /// The dimension of the vector space, i.e. the number of elements in + /// its basis. + const DIMENSION: usize; + + /// Fixes a basis for the algebra `A` and uses this to + /// map an element of `A` to a slice of `DIMENSION` `F` elements. + /// + /// # Safety + /// + /// The value produced by this function fundamentally depends + /// on the choice of basis. Care must be taken + /// to ensure portability if these values might ever be passed to + /// (or rederived within) another compilation environment where a + /// different basis might have been used. + #[must_use] + fn as_basis_coefficients_slice(&self) -> &[F]; + + /// Fixes a basis for the algebra `A` and uses this to + /// map `DIMENSION` `F` elements to an element of `A`. + /// + /// # Safety + /// + /// The value produced by this function fundamentally depends + /// on the choice of basis. Care must be taken + /// to ensure portability if these values might ever be passed to + /// (or rederived within) another compilation environment where a + /// different basis might have been used. + /// + /// Returns `None` if the length of the slice is different to `DIMENSION`. + #[must_use] + #[inline] + fn from_basis_coefficients_slice(slice: &[F]) -> Option { + Self::from_basis_coefficients_iter(slice.iter().cloned()) + } + + /// Fixes a basis for the algebra `A` and uses this to + /// map `DIMENSION` `F` elements to an element of `A`. Similar + /// to `core:array::from_fn`, the `DIMENSION` `F` elements are + /// given by `Fn(0), ..., Fn(DIMENSION - 1)` called in that order. + /// + /// # Safety + /// + /// The value produced by this function fundamentally depends + /// on the choice of basis. Care must be taken + /// to ensure portability if these values might ever be passed to + /// (or rederived within) another compilation environment where a + /// different basis might have been used. + #[must_use] + fn from_basis_coefficients_fn F>(f: Fn) -> Self; + + /// Fixes a basis for the algebra `A` and uses this to + /// map `DIMENSION` `F` elements to an element of `A`. + /// + /// # Safety + /// + /// The value produced by this function fundamentally depends + /// on the choice of basis. Care must be taken + /// to ensure portability if these values might ever be passed to + /// (or rederived within) another compilation environment where a + /// different basis might have been used. + /// + /// Returns `None` if the length of the iterator is different to `DIMENSION`. + #[must_use] + fn from_basis_coefficients_iter>(iter: I) -> Option; + + /// Given a basis for the Algebra `A`, return the i'th basis element. + /// + /// # Safety + /// + /// The value produced by this function fundamentally depends + /// on the choice of basis. Care must be taken + /// to ensure portability if these values might ever be passed to + /// (or rederived within) another compilation environment where a + /// different basis might have been used. + /// + /// Returns `None` if `i` is greater than or equal to `DIMENSION`. + #[must_use] + #[inline] + fn ith_basis_element(i: usize) -> Option { + (i < Self::DIMENSION).then(|| Self::from_basis_coefficients_fn(|j| F::from_bool(i == j))) + } + + /// Convert from a vector of `Self` to a vector of `F` by flattening the basis coefficients. + /// + /// Depending on the `BasedVectorSpace` this may be essentially a no-op and should certainly + /// be reimplemented in those cases. + /// + /// # Safety + /// + /// The value produced by this function fundamentally depends + /// on the choice of basis. Care must be taken + /// to ensure portability if these values might ever be passed to + /// (or rederived within) another compilation environment where a + /// different basis might have been used. + #[must_use] + #[inline] + fn flatten_to_base(vec: Vec) -> Vec { + vec.into_iter() + .flat_map(|x| x.as_basis_coefficients_slice().to_vec()) + .collect() + } + + /// Convert from a vector of `F` to a vector of `Self` by combining the basis coefficients. + /// + /// Depending on the `BasedVectorSpace` this may be essentially a no-op and should certainly + /// be reimplemented in those cases. + /// + /// # Panics + /// This will panic if the length of `vec` is not a multiple of `Self::DIMENSION`. + /// + /// # Safety + /// + /// The value produced by this function fundamentally depends + /// on the choice of basis. Care must be taken + /// to ensure portability if these values might ever be passed to + /// (or rederived within) another compilation environment where a + /// different basis might have been used. + #[must_use] + #[inline] + fn reconstitute_from_base(vec: Vec) -> Vec { + assert_eq!(vec.len() % Self::DIMENSION, 0); + + vec.chunks_exact(Self::DIMENSION) + .flat_map(|chunk| Self::from_basis_coefficients_slice(chunk)) + .collect() + } +} + +impl BasedVectorSpace for F { + const DIMENSION: usize = 1; + + #[inline] + fn as_basis_coefficients_slice(&self) -> &[F] { + slice::from_ref(self) + } + + #[inline] + fn from_basis_coefficients_fn F>(mut f: Fn) -> Self { + f(0) + } + + #[inline] + fn from_basis_coefficients_iter>(mut iter: I) -> Option { + (iter.len() == 1).then(|| iter.next().unwrap()) // Unwrap will not panic as we know the length is 1. + } + + #[must_use] + #[inline] + fn flatten_to_base(vec: Vec) -> Vec { + vec + } + + #[must_use] + #[inline] + fn reconstitute_from_base(vec: Vec) -> Vec { + vec + } +} + +/// A ring implements `InjectiveMonomial` if the algebraic function +/// `f(x) = x^N` is an injective map on elements of the ring. +/// +/// We do not enforce that this map be invertible as there are useful +/// cases such as polynomials or symbolic expressions where no inverse exists. +/// +/// However, if the ring is a field with order `q` or an array of such field elements, +/// then `f(x) = x^N` will be injective if and only if it is invertible and so in +/// such cases this monomial acts as a permutation. Moreover, this will occur +/// exactly when `N` and `q - 1` are relatively prime i.e. `gcd(N, q - 1) = 1`. +pub trait InjectiveMonomial: PrimeCharacteristicRing { + /// Compute `x -> x^n` for a given `n > 1` such that this + /// map is injective. + #[must_use] + #[inline] + fn injective_exp_n(&self) -> Self { + self.exp_const_u64::() + } +} + +/// A ring implements `PermutationMonomial` if the algebraic function +/// `f(x) = x^N` is invertible and thus acts as a permutation on elements of the ring. +/// +/// In all cases we care about, this means that we can find another integer `K` such +/// that `x = x^{NK}` for all elements of our ring. +pub trait PermutationMonomial: InjectiveMonomial { + /// Compute `x -> x^K` for a given `K > 1` such that + /// `x^{NK} = x` for all elements `x`. + #[must_use] + fn injective_exp_root_n(&self) -> Self; +} + +/// A ring `R` implements `Algebra` if there is an injective homomorphism +/// from `F` into `R`; in particular only `F::ZERO` maps to `R::ZERO`. +/// +/// For the most part, we will usually expect `F` to be a field but there +/// are a few cases where it is handy to allow it to just be a ring. In +/// particular, every ring naturally implements `Algebra`. +/// +/// ### Mathematical Description +/// +/// Let `x` and `y` denote arbitrary elements of `F`. Then +/// we require that our map `from` has the properties: +/// - Preserves Identity: `from(F::ONE) = R::ONE` +/// - Commutes with Addition: `from(x + y) = from(x) + from(y)` +/// - Commutes with Multiplication: `from(x * y) = from(x) * from(y)` +/// +/// Such maps are known as ring homomorphisms and are injective if the +/// only element which maps to `R::ZERO` is `F::ZERO`. +/// +/// The existence of this map makes `R` into an `F`-module and hence an `F`-algebra. +/// If, additionally, `R` is a field, then this makes `R` a field extension of `F`. +pub trait Algebra: + PrimeCharacteristicRing + + From + + Add + + AddAssign + + Sub + + SubAssign + + Mul + + MulAssign +{ +} + +// Every ring is an algebra over itself. +impl Algebra for R {} + +/// A field `F`. This permits both modular fields `ℤ/p` along with their field extensions. +/// +/// A ring is a field if every element `x` has a unique multiplicative inverse `x^{-1}` +/// which satisfies `x * x^{-1} = F::ONE`. +pub trait Field: + Algebra + + Packable + + 'static + + Copy + + Div + + Eq + + Hash + + Send + + Sync + + Display + + Serialize + + DeserializeOwned +{ + type Packing: PackedField; + + /// A generator of this field's multiplicative group. + const GENERATOR: Self; + + /// Check if the given field element is equal to the unique additive identity (ZERO). + #[must_use] + #[inline] + fn is_zero(&self) -> bool { + *self == Self::ZERO + } + + /// Check if the given field element is equal to the unique multiplicative identity (ONE). + #[must_use] + #[inline] + fn is_one(&self) -> bool { + *self == Self::ONE + } + + /// The multiplicative inverse of this field element, if it exists. + /// + /// NOTE: The inverse of `0` is undefined and will return `None`. + #[must_use] + fn try_inverse(&self) -> Option; + + /// The multiplicative inverse of this field element. + /// + /// # Panics + /// The function will panic if the field element is `0`. + /// Use try_inverse if you want to handle this case. + #[must_use] + fn inverse(&self) -> Self { + self.try_inverse().expect("Tried to invert zero") + } + + /// The elementary function `halve(a) = a/2`. + /// + /// # Panics + /// The function will panic if the field has characteristic 2. + #[must_use] + fn halve(&self) -> Self { + // This should be overwritten by most field implementations. + let half = Self::from_prime_subfield( + Self::PrimeSubfield::TWO + .try_inverse() + .expect("Cannot divide by 2 in fields with characteristic 2"), + ); + *self * half + } + + /// Divide by a given power of two. `div_2exp_u64(a, exp) = a/2^exp` + /// + /// # Panics + /// The function will panic if the field has characteristic 2. + #[must_use] + #[inline] + fn div_2exp_u64(&self, exp: u64) -> Self { + // This should be overwritten by most field implementations. + *self + * Self::from_prime_subfield( + Self::PrimeSubfield::TWO + .try_inverse() + .expect("Cannot divide by 2 in fields with characteristic 2") + .exp_u64(exp), + ) + } + + /// The number of elements in the field. + /// + /// This will either be prime if the field is a PrimeField or a power of a + /// prime if the field is an extension field. + #[must_use] + fn order() -> BigUint; + + /// The number of bits required to define an element of this field. + /// + /// Usually due to storage and practical reasons the memory size of + /// a field element will be a little larger than bits(). + #[must_use] + #[inline] + fn bits() -> usize { + Self::order().bits() as usize + } +} + +/// A field isomorphic to `ℤ/p` for some prime `p`. +/// +/// There is a natural map from `ℤ` to `ℤ/p` which sends an integer `r` to its conjugacy class `[r]`. +/// Canonically, each conjugacy class `[r]` can be represented by the unique integer `s` in `[0, p - 1)` +/// satisfying `s = r mod p`. This however is often not the most convenient computational representation +/// and so internal representations of field elements might differ from this and may change over time. +pub trait PrimeField: + Field + + Ord + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap + + QuotientMap +{ + /// Return the representative of `value` in canonical form + /// which lies in the range `0 <= x < self.order()`. + #[must_use] + fn as_canonical_biguint(&self) -> BigUint; +} + +/// A prime field `ℤ/p` with order, `p < 2^64`. +pub trait PrimeField64: PrimeField { + const ORDER_U64: u64; + + /// Return the representative of `value` in canonical form + /// which lies in the range `0 <= x < ORDER_U64`. + #[must_use] + fn as_canonical_u64(&self) -> u64; + + /// Convert a field element to a `u64` such that any two field elements + /// are converted to the same `u64` if and only if they represent the same value. + /// + /// This will be the fastest way to convert a field element to a `u64` and + /// is intended for use in hashing. It will also be consistent across different targets. + #[must_use] + #[inline(always)] + fn to_unique_u64(&self) -> u64 { + // A simple default which is optimal for some fields. + self.as_canonical_u64() + } +} + +/// A prime field `ℤ/p` with order `p < 2^32`. +pub trait PrimeField32: PrimeField64 { + const ORDER_U32: u32; + + /// Return the representative of `value` in canonical form + /// which lies in the range `0 <= x < ORDER_U64`. + #[must_use] + fn as_canonical_u32(&self) -> u32; + + /// Convert a field element to a `u32` such that any two field elements + /// are converted to the same `u32` if and only if they represent the same value. + /// + /// This will be the fastest way to convert a field element to a `u32` and + /// is intended for use in hashing. It will also be consistent across different targets. + #[must_use] + #[inline(always)] + fn to_unique_u32(&self) -> u32 { + // A simple default which is optimal for some fields. + self.as_canonical_u32() + } +} + +/// A field `EF` which is also an algebra over a field `F`. +/// +/// This provides a couple of convenience methods on top of the +/// standard methods provided by `Field`, `Algebra` and `BasedVectorSpace`. +/// +/// It also provides a type which handles packed vectors of extension field elements. +pub trait ExtensionField: Field + Algebra + BasedVectorSpace { + type ExtensionPacking: PackedFieldExtension + 'static + Copy + Send + Sync; + + /// Determine if the given element lies in the base field. + #[must_use] + fn is_in_basefield(&self) -> bool; + + /// If the element lies in the base field project it down. + /// Otherwise return None. + #[must_use] + fn as_base(&self) -> Option; +} + +// Every field is trivially a one dimensional extension over itself. +impl ExtensionField for F { + type ExtensionPacking = F::Packing; + + #[inline] + fn is_in_basefield(&self) -> bool { + true + } + + #[inline] + fn as_base(&self) -> Option { + Some(*self) + } +} + +/// A field which supplies information like the two-adicity of its multiplicative group, and methods +/// for obtaining two-adic generators. +pub trait TwoAdicField: Field { + /// The number of factors of two in this field's multiplicative group. + const TWO_ADICITY: usize; + + /// Returns a generator of the multiplicative group of order `2^bits`. + /// Assumes `bits <= TWO_ADICITY`, otherwise the result is undefined. + #[must_use] + fn two_adic_generator(bits: usize) -> Self; +} + +/// An iterator which returns the powers of a base element `b` shifted by current `c`: `c, c * b, c * b^2, ...`. +#[derive(Clone, Debug)] +pub struct Powers { + pub base: F, + pub current: F, +} + +impl Iterator for Powers { + type Item = R; + + fn next(&mut self) -> Option { + let result = self.current.clone(); + self.current *= self.base.clone(); + Some(result) + } +} diff --git a/CoqOfRust/plonky3/field/src/field.v b/CoqOfRust/plonky3/field/src/field.v new file mode 100644 index 000000000..7e9f4049c --- /dev/null +++ b/CoqOfRust/plonky3/field/src/field.v @@ -0,0 +1,5533 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module field. + (* Trait *) + Module PrimeCharacteristicRing. + Definition from_bool (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ b ] => + ltac:(M.monadic + (let b := M.alloc (| b |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Self ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use b in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Self |))); + fun γ => + ltac:(M.monadic + (get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", Self |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_bool : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_bool" from_bool. + Definition from_u8 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "u8" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_u8 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_u8" from_u8. + Definition from_u16 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "u16" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_u16 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_u16" from_u16. + Definition from_u32 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "u32" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_u32 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_u32" from_u32. + Definition from_u64 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "u64" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_u64 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_u64" from_u64. + Definition from_u128 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "u128" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_u128 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_u128" from_u128. + Definition from_usize (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "usize" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_usize : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_usize" from_usize. + Definition from_i8 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "i8" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_i8 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_i8" from_i8. + Definition from_i16 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "i16" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_i16 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_i16" from_i16. + Definition from_i32 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "i32" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_i32 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_i32" from_i32. + Definition from_i64 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "i64" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_i64 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_i64" from_i64. + Definition from_i128 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "i128" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_i128 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_i128" from_i128. + Definition from_isize (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [ Ty.path "isize" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_isize : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "from_isize" from_isize. + Definition double (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Add", Self, [], [ Self ], "add", [], [] |), + [ + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_double : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "double" double. + Definition square (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Mul", Self, [], [ Self ], "mul", [], [] |), + [ + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_square : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "square" square. + Definition cube (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Mul", Self, [], [ Self ], "mul", [], [] |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_cube : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "cube" cube. + Definition xor (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; y ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let y := M.alloc (| y |) in + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Sub", Self, [], [ Self ], "sub", [], [] |), + [ + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Add", Self, [], [ Self ], "add", [], [] |), + [ + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| y |) |) |) ] + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Mul", Self, [], [ Self ], "mul", [], [] |), + [ + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| y |) |) |) ] + |) + |) + |) + ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_xor : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "xor" xor. + Definition xor3 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; y; z ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let y := M.alloc (| y |) in + let z := M.alloc (| z |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| y |) |) |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| z |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_xor3 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "xor3" xor3. + Definition andn (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; y ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let y := M.alloc (| y |) in + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Mul", Self, [], [ Self ], "mul", [], [] |), + [ + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Sub", Self, [], [ Self ], "sub", [], [] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Self |) + |); + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| y |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_andn : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "andn" andn. + Definition bool_check (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "andn", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_bool_check : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "bool_check" bool_check. + Definition exp_u64 (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; power ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let power := M.alloc (| power |) in + M.read (| + let~ current : Ty.apply (Ty.path "*") [] [ Self ] := + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ product : Ty.apply (Ty.path "*") [] [ Self ] := + M.copy (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Self |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_field::exponentiation::bits_u64", [], [] |), + [ M.read (| power |) ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let j := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shr, + [ M.read (| power |); M.read (| j |) + ] + |); + Value.Integer IntegerKind.U64 1 + ] + |); + Value.Integer IntegerKind.U64 0 + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Self, + [], + [ Self ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, product |); + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, current |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + current, + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, current |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + product + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_exp_u64 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "exp_u64" exp_u64. + Definition exp_const_u64 + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ POWER ], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Self ], + M.alloc (| POWER |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 0 + |) in + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Self |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 1 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 2 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 3 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "cube", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 4 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 5 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Mul", + Self, + [], + [ Self ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 6 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "cube", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 7 + |) in + let~ x2 : Ty.apply (Ty.path "*") [] [ Self ] := + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ x3 : Ty.apply (Ty.path "*") [] [ Self ] := + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Mul", + Self, + [], + [ Self ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x2 |) ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + |) in + let~ x4 : Ty.apply (Ty.path "*") [] [ Self ] := + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x2 |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Mul", + Self, + [], + [ Self ], + "mul", + [], + [] + |), + [ M.read (| x3 |); M.read (| x4 |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "exp_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); POWER ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_exp_const_u64 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "exp_const_u64" exp_const_u64. + Definition exp_power_of_2 + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; power_log ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let power_log := M.alloc (| power_log |) in + M.read (| + let~ res : Ty.apply (Ty.path "*") [] [ Self ] := + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| power_log |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + res, + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, res |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + res + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_exp_power_of_2 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "exp_power_of_2" exp_power_of_2. + Definition mul_2exp_u64 + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Mul", Self, [], [ Self ], "mul", [], [] |), + [ + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", Self |) + |); + M.read (| exp |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_mul_2exp_u64 : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "mul_2exp_u64" mul_2exp_u64. + Definition powers (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ Self ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "shifted_powers", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Self |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_powers : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "powers" powers. + Definition shifted_powers + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; start ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let start := M.alloc (| start |) in + Value.StructRecord + "p3_field::field::Powers" + [ + ("base", + M.call_closure (| + Self, + M.get_trait_method (| "core::clone::Clone", Self, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |)); + ("current", M.read (| start |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_shifted_powers : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "shifted_powers" shifted_powers. + Definition dot_product + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ N ], [], [ u; v ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + let v := M.alloc (| v |) in + M.call_closure (| + Self, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Self ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Self ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Self ]; Ty.apply (Ty.path "&") [] [ Self ] + ] + ] + ] + Self + ], + [], + [], + "sum", + [], + [ Self ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Self ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Self ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Self ]; + Ty.apply (Ty.path "&") [] [ Self ] + ] + ] + ] + Self + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Self ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Self ] + ], + [], + [], + "map", + [], + [ + Self; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Self ]; + Ty.apply (Ty.path "&") [] [ Self ] + ] + ] + ] + Self + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Self ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Self ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Self ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Self ] ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Self ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Self ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| u |) |) |)) + ] + |); + M.read (| v |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Self ]; + Ty.apply (Ty.path "&") [] [ Self ] + ] + ] + ] + Self + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Mul", + Self, + [], + [ Self ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x |) |) + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| y |) |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_dot_product : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "dot_product" dot_product. + Definition sum_array (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Self ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Self ], + M.alloc (| N |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 0 + |) in + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", Self |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 1 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 3 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 4 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "core::clone::Clone", + Self, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 5 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 6 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 7 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 8 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ acc : Ty.apply (Ty.path "*") [] [ Self ] := + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 8) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::ops::range::RangeInclusive") + [] + [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::ops::range::RangeInclusive") + [] + [ Ty.path "usize" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::ops::range::RangeInclusive") + [] + [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::RangeInclusive") + [] + [ Ty.path "usize" ], + [], + [], + "step_by", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::RangeInclusive") + [] + [ Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::ops::range::RangeInclusive") + [] + [ Ty.path "usize" ], + "new", + [], + [] + |), + [ Value.Integer IntegerKind.Usize 16; N ] + |); + Value.Integer IntegerKind.Usize 8 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::ops::range::RangeInclusive") + [] + [ Ty.path "usize" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Self, + [], + [ Self ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, acc |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Self ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ Self ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| input |) + |) + |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| i |); + Value.Integer + IntegerKind.Usize + 8 + ] + |)); + ("end_", M.read (| i |)) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Self ], + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ N; Value.Integer IntegerKind.Usize 7 ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 0 + |) in + acc)); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 1 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.read (| acc |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 8; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ N; Value.Integer IntegerKind.Usize 8 + ] + |) + ] + |)) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.read (| acc |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 8; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ N; Value.Integer IntegerKind.Usize 8 + ] + |) + ] + |)) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 3 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.read (| acc |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 8; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ N; Value.Integer IntegerKind.Usize 8 + ] + |) + ] + |)) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 4 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.read (| acc |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 8; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ N; Value.Integer IntegerKind.Usize 8 + ] + |) + ] + |)) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 5 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.read (| acc |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 5 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 8; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ N; Value.Integer IntegerKind.Usize 8 + ] + |) + ] + |)) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 6 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.read (| acc |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 6 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 8; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ N; Value.Integer IntegerKind.Usize 8 + ] + |) + ] + |)) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 7 + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Add", + Self, + [], + [ Self ], + "add", + [], + [] + |), + [ + M.read (| acc |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 7 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Self ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 8; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ N; Value.Integer IntegerKind.Usize 8 + ] + |) + ] + |)) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "internal error: entered unreachable code" |) ] + |) + |) + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_sum_array : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "sum_array" sum_array. + Definition zero_vec (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ len ] => + ltac:(M.monadic + (let len := M.alloc (| len |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Self; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloc::vec::from_elem", [], [ Self ] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", Self |) + |); + M.read (| len |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_zero_vec : + M.IsProvidedMethod "p3_field::field::PrimeCharacteristicRing" "zero_vec" zero_vec. + End PrimeCharacteristicRing. + + (* Trait *) + Module BasedVectorSpace. + Definition from_basis_coefficients_slice + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Self ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + Self, + [], + [ F ], + "from_basis_coefficients_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "cloned", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_from_basis_coefficients_slice : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_field::field::BasedVectorSpace" + "from_basis_coefficients_slice" + (from_basis_coefficients_slice F). + Definition ith_basis_element + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ i ] => + ltac:(M.monadic + (let i := M.alloc (| i |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Self ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ Self; Ty.function [ Ty.tuple [] ] Self ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| i |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [] ] Self ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + Self, + [], + [ F ], + "from_basis_coefficients_fn", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_bool", + [], + [] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| i |); M.read (| j |) ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_ith_basis_element : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_field::field::BasedVectorSpace" + "ith_basis_element" + (ith_basis_element F). + Definition flatten_to_base + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ vec ] => + ltac:(M.monadic + (let vec := M.alloc (| vec |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Self; Ty.path "alloc::alloc::Global" ]; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ Self ] ] + (Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]) + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Self; Ty.path "alloc::alloc::Global" ]; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ Self ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Self; Ty.path "alloc::alloc::Global" ], + [], + [], + "flat_map", + [], + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ Self ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Self; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Self; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| vec |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Self ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + Self, + [], + [ F ], + "as_basis_coefficients_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_flatten_to_base : + forall (F : Ty.t), + M.IsProvidedMethod "p3_field::field::BasedVectorSpace" "flatten_to_base" (flatten_to_base F). + Definition reconstitute_from_base + (F Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ vec ] => + ltac:(M.monadic + (let vec := M.alloc (| vec |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec |) ] + |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 0 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Self; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksExact") [] [ F ]; + Ty.apply (Ty.path "core::option::Option") [] [ Self ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + ] + (Ty.apply (Ty.path "core::option::Option") [] [ Self ]) + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ Self; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksExact") [] [ F ]; + Ty.apply (Ty.path "core::option::Option") [] [ Self ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + ] + (Ty.apply (Ty.path "core::option::Option") [] [ Self ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::ChunksExact") [] [ F ], + [], + [], + "flat_map", + [], + [ + Ty.apply (Ty.path "core::option::Option") [] [ Self ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + ] + (Ty.apply (Ty.path "core::option::Option") [] [ Self ]) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExact") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "chunks_exact", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec |) ] + |) + |) + |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + (Ty.apply (Ty.path "core::option::Option") [] [ Self ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let chunk := M.copy (| γ |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Self ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + Self, + [], + [ F ], + "from_basis_coefficients_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| chunk |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_reconstitute_from_base : + forall (F : Ty.t), + M.IsProvidedMethod + "p3_field::field::BasedVectorSpace" + "reconstitute_from_base" + (reconstitute_from_base F). + End BasedVectorSpace. + + Module Impl_p3_field_field_BasedVectorSpace_where_p3_field_field_PrimeCharacteristicRing_F_F_for_F. + Definition Self (F : Ty.t) : Ty.t := F. + + (* const DIMENSION: usize = 1; *) + (* Ty.path "usize" *) + Definition value_DIMENSION + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 1 |))). + + (* + fn as_basis_coefficients_slice(&self) -> &[F] { + slice::from_ref(self) + } + *) + Definition as_basis_coefficients_slice + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_function (| "core::slice::raw::from_ref", [], [ F ] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_basis_coefficients_fn F>(mut f: Fn) -> Self { + f(0) + } + *) + Definition from_basis_coefficients_fn + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ Fn ], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::function::FnMut", + Fn, + [], + [ Ty.tuple [ Ty.path "usize" ] ], + "call_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, f |); + Value.Tuple [ Value.Integer IntegerKind.Usize 0 ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_basis_coefficients_iter>(mut iter: I) -> Option { + (iter.len() == 1).then(|| iter.next().unwrap()) // Unwrap will not panic as we know the length is 1. + } + *) + Definition from_basis_coefficients_iter + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ F; Ty.function [ Ty.tuple [] ] F ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::iter::traits::exact_size::ExactSizeIterator", + I, + [], + [], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, iter |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + F, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "next", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, iter |) ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn flatten_to_base(vec: Vec) -> Vec { + vec + } + *) + Definition flatten_to_base + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ vec ] => + ltac:(M.monadic + (let vec := M.alloc (| vec |) in + M.read (| vec |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn reconstitute_from_base(vec: Vec) -> Vec { + vec + } + *) + Definition reconstitute_from_base + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ vec ] => + ltac:(M.monadic + (let vec := M.alloc (| vec |) in + M.read (| vec |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_field::field::BasedVectorSpace" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) + [ + ("value_DIMENSION", InstanceField.Method (value_DIMENSION F)); + ("as_basis_coefficients_slice", InstanceField.Method (as_basis_coefficients_slice F)); + ("from_basis_coefficients_fn", InstanceField.Method (from_basis_coefficients_fn F)); + ("from_basis_coefficients_iter", InstanceField.Method (from_basis_coefficients_iter F)); + ("flatten_to_base", InstanceField.Method (flatten_to_base F)); + ("reconstitute_from_base", InstanceField.Method (reconstitute_from_base F)) + ]. + End Impl_p3_field_field_BasedVectorSpace_where_p3_field_field_PrimeCharacteristicRing_F_F_for_F. + + (* Trait *) + Module InjectiveMonomial. + Definition injective_exp_n + (N : Value.t) + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "exp_const_u64", + [ N ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_injective_exp_n : + forall (N : Value.t), + M.IsProvidedMethod "p3_field::field::InjectiveMonomial" "injective_exp_n" (injective_exp_n N). + End InjectiveMonomial. + + (* Trait *) + (* Empty module 'PermutationMonomial' *) + + (* Trait *) + (* Empty module 'Algebra' *) + + Module Impl_p3_field_field_Algebra_where_p3_field_field_PrimeCharacteristicRing_R_R_for_R. + Definition Self (R : Ty.t) : Ty.t := R. + + Axiom Implements : + forall (R : Ty.t), + M.IsTraitInstance + "p3_field::field::Algebra" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ R ] + (Self R) + (* Instance *) []. + End Impl_p3_field_field_Algebra_where_p3_field_field_PrimeCharacteristicRing_R_R_for_R. + + (* Trait *) + Module Field. + Definition is_zero (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| "core::cmp::PartialEq", Self, [], [ Self ], "eq", [], [] |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", Self |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_is_zero : M.IsProvidedMethod "p3_field::field::Field" "is_zero" is_zero. + Definition is_one (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| "core::cmp::PartialEq", Self, [], [ Self ], "eq", [], [] |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Self |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_is_one : M.IsProvidedMethod "p3_field::field::Field" "is_one" is_one. + Definition inverse (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Self, + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Self ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Self ], + M.get_trait_method (| + "p3_field::field::Field", + Self, + [], + [], + "try_inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Tried to invert zero" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_inverse : M.IsProvidedMethod "p3_field::field::Field" "inverse" inverse. + Definition halve (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ half : Ty.apply (Ty.path "*") [] [ Self ] := + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield" + ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [], + "try_inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::TWO", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield" + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| "Cannot divide by 2 in fields with characteristic 2" |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Mul", Self, [], [ Self ], "mul", [], [] |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| half |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_halve : M.IsProvidedMethod "p3_field::field::Field" "halve" halve. + Definition div_2exp_u64 + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.call_closure (| + Self, + M.get_trait_method (| "core::ops::arith::Mul", Self, [], [ Self ], "mul", [], [] |), + [ + M.read (| M.deref (| M.read (| self |) |) |); + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield" + ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield", + [], + [], + "try_inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::TWO", + Ty.associated_in_trait + "p3_field::field::PrimeCharacteristicRing" + [] + [] + Self + "PrimeSubfield" + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| "Cannot divide by 2 in fields with characteristic 2" |) + |) + |) + ] + |) + |) + |); + M.read (| exp |) + ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_div_2exp_u64 : + M.IsProvidedMethod "p3_field::field::Field" "div_2exp_u64" div_2exp_u64. + Definition bits (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u64", + M.get_associated_function (| + Ty.path "num_bigint::biguint::BigUint", + "bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "p3_field::field::Field", + Self, + [], + [], + "order", + [], + [] + |), + [] + |) + |) + |) + ] + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_bits : M.IsProvidedMethod "p3_field::field::Field" "bits" bits. + End Field. + + (* Trait *) + (* Empty module 'PrimeField' *) + + (* Trait *) + Module PrimeField64. + Definition to_unique_u64 + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Self, + [], + [], + "as_canonical_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_to_unique_u64 : + M.IsProvidedMethod "p3_field::field::PrimeField64" "to_unique_u64" to_unique_u64. + End PrimeField64. + + (* Trait *) + Module PrimeField32. + Definition to_unique_u32 + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Self, + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_to_unique_u32 : + M.IsProvidedMethod "p3_field::field::PrimeField32" "to_unique_u32" to_unique_u32. + End PrimeField32. + + (* Trait *) + (* Empty module 'ExtensionField' *) + + Module Impl_p3_field_field_ExtensionField_where_p3_field_field_Field_F_F_for_F. + Definition Self (F : Ty.t) : Ty.t := F. + + (* type ExtensionPacking = F::Packing; *) + Definition _ExtensionPacking (F : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing". + + (* + fn is_in_basefield(&self) -> bool { + true + } + *) + Definition is_in_basefield + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Bool true)) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn as_base(&self) -> Option { + Some( *self) + } + *) + Definition as_base (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "core::option::Option::Some" + [ M.read (| M.deref (| M.read (| self |) |) |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_field::field::ExtensionField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) + [ + ("ExtensionPacking", InstanceField.Ty (_ExtensionPacking F)); + ("is_in_basefield", InstanceField.Method (is_in_basefield F)); + ("as_base", InstanceField.Method (as_base F)) + ]. + End Impl_p3_field_field_ExtensionField_where_p3_field_field_Field_F_F_for_F. + + (* Trait *) + (* Empty module 'TwoAdicField' *) + + (* StructRecord + { + name := "Powers"; + const_params := []; + ty_params := [ "F" ]; + fields := [ ("base", F); ("current", F) ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_field_field_Powers_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_field::field::Powers" + [ + ("base", + M.call_closure (| + F, + M.get_trait_method (| "core::clone::Clone", F, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::field::Powers", + "base" + |) + |) + |) + |) + ] + |)); + ("current", + M.call_closure (| + F, + M.get_trait_method (| "core::clone::Clone", F, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::field::Powers", + "current" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_field_field_Powers_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_field_field_Powers_F. + Definition Self (F : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Powers" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "base" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::field::Powers", + "base" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "current" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::field::Powers", + "current" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_field_field_Powers_F. + + Module Impl_core_iter_traits_iterator_Iterator_where_p3_field_field_PrimeCharacteristicRing_R_for_p3_field_field_Powers_R. + Definition Self (R : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_field::field::Powers") [] [ R ]. + + (* type Item = R; *) + Definition _Item (R : Ty.t) : Ty.t := R. + + (* + fn next(&mut self) -> Option { + let result = self.current.clone(); + self.current *= self.base.clone(); + Some(result) + } + *) + Definition next (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ result : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::field::Powers", + "current" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + R, + [], + [ R ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::field::Powers", + "current" + |) + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_field::field::Powers", + "base" + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.StructTuple "core::option::Option::Some" [ M.read (| result |) ] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (R : Ty.t), + M.IsTraitInstance + "core::iter::traits::iterator::Iterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self R) + (* Instance *) + [ ("Item", InstanceField.Ty (_Item R)); ("next", InstanceField.Method (next R)) ]. + End Impl_core_iter_traits_iterator_Iterator_where_p3_field_field_PrimeCharacteristicRing_R_for_p3_field_field_Powers_R. +End field. diff --git a/CoqOfRust/plonky3/field/src/helpers.rs b/CoqOfRust/plonky3/field/src/helpers.rs new file mode 100644 index 000000000..03ce54405 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/helpers.rs @@ -0,0 +1,140 @@ +use alloc::vec::Vec; +use core::iter::Sum; +use core::mem::MaybeUninit; +use core::ops::Mul; + +use p3_maybe_rayon::prelude::{IntoParallelRefMutIterator, ParallelIterator}; + +use crate::field::Field; +use crate::{PackedValue, PrimeCharacteristicRing, PrimeField, PrimeField32, TwoAdicField}; + +/// Computes `Z_H(x)`, where `Z_H` is the vanishing polynomial of a multiplicative subgroup of order `2^log_n`. +pub fn two_adic_subgroup_vanishing_polynomial(log_n: usize, x: F) -> F { + x.exp_power_of_2(log_n) - F::ONE +} + +/// Computes `Z_{sH}(x)`, where `Z_{sH}` is the vanishing polynomial of the given coset of a multiplicative +/// subgroup of order `2^log_n`. +pub fn two_adic_coset_vanishing_polynomial(log_n: usize, shift: F, x: F) -> F { + x.exp_power_of_2(log_n) - shift.exp_power_of_2(log_n) +} + +/// Computes a multiplicative subgroup whose order is known in advance. +pub fn cyclic_subgroup_known_order( + generator: F, + order: usize, +) -> impl Iterator + Clone { + generator.powers().take(order) +} + +/// Computes a coset of a multiplicative subgroup whose order is known in advance. +pub fn cyclic_subgroup_coset_known_order( + generator: F, + shift: F, + order: usize, +) -> impl Iterator + Clone { + generator.shifted_powers(shift).take(order) +} + +pub fn scale_vec(s: F, vec: Vec) -> Vec { + vec.into_iter().map(|x| s * x).collect() +} + +pub fn scale_slice_in_place(s: F, slice: &mut [F]) { + let (packed, sfx) = F::Packing::pack_slice_with_suffix_mut(slice); + let packed_s: F::Packing = s.into(); + packed.par_iter_mut().for_each(|x| *x *= packed_s); + sfx.iter_mut().for_each(|x| *x *= s); +} + +/// `x += y * s`, where `s` is a scalar. +pub fn add_scaled_slice_in_place(x: &mut [F], y: Y, s: F) +where + F: Field, + Y: Iterator, +{ + // TODO: Use PackedField + x.iter_mut().zip(y).for_each(|(x_i, y_i)| *x_i += y_i * s); +} + +/// Extend a ring `R` element `x` to an array of length `D` +/// by filling zeros. +#[inline] +pub const fn field_to_array(x: R) -> [R; D] { + let mut arr: [_; D] = [const { MaybeUninit::uninit() }; D]; + arr[0] = MaybeUninit::new(x); + let mut i = 1; + while i < D { + arr[i] = MaybeUninit::new(R::ZERO); + i += 1; + } + unsafe { core::mem::transmute_copy::<_, [R; D]>(&arr) } +} + +/// Given an element x from a 32 bit field F_P compute x/2. +#[inline] +pub const fn halve_u32(x: u32) -> u32 { + let shift = (P + 1) >> 1; + let half = x >> 1; + if x & 1 == 0 { half } else { half + shift } +} + +/// Given an element x from a 64 bit field F_P compute x/2. +#[inline] +pub const fn halve_u64(x: u64) -> u64 { + let shift = (P + 1) >> 1; + let half = x >> 1; + if x & 1 == 0 { half } else { half + shift } +} + +/// Reduce a slice of 32-bit field elements into a single element of a larger field. +/// +/// Uses base-$2^{32}$ decomposition: +/// +/// ```math +/// \begin{equation} +/// \text{reduce\_32}(vals) = \sum_{i=0}^{n-1} a_i \cdot 2^{32i} +/// \end{equation} +/// ``` +pub fn reduce_32(vals: &[SF]) -> TF { + // If the characteristic of TF is > 2^64, from_int and from_canonical_unchecked act identically + let base = TF::from_int(1u64 << 32); + vals.iter().rev().fold(TF::ZERO, |acc, val| { + acc * base + TF::from_int(val.as_canonical_u32()) + }) +} + +/// Split a large field element into `n` base-$2^{64}$ chunks and map each into a 32-bit field. +/// +/// Converts: +/// ```math +/// \begin{equation} +/// x = \sum_{i=0}^{n-1} d_i \cdot 2^{64i} +/// \end{equation} +/// ``` +/// +/// Pads with zeros if needed. +pub fn split_32(val: SF, n: usize) -> Vec { + let mut result: Vec = val + .as_canonical_biguint() + .to_u64_digits() + .iter() + .take(n) + .map(|d| TF::from_u64(*d)) + .collect(); + + // Pad with zeros if needed + result.resize_with(n, || TF::ZERO); + result +} + +/// Maximally generic dot product. +pub fn dot_product(li: LI, ri: RI) -> S +where + LI: Iterator, + RI: Iterator, + LI::Item: Mul, + S: Sum<>::Output>, +{ + li.zip(ri).map(|(l, r)| l * r).sum() +} diff --git a/CoqOfRust/plonky3/field/src/helpers.v b/CoqOfRust/plonky3/field/src/helpers.v new file mode 100644 index 000000000..3a53c6e71 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/helpers.v @@ -0,0 +1,1846 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module helpers. + (* + pub fn two_adic_subgroup_vanishing_polynomial(log_n: usize, x: F) -> F { + x.exp_power_of_2(log_n) - F::ONE + } + *) + Definition two_adic_subgroup_vanishing_polynomial + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ log_n; x ] => + ltac:(M.monadic + (let log_n := M.alloc (| log_n |) in + let x := M.alloc (| x |) in + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Sub", F, [], [ F ], "sub", [], [] |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); M.read (| log_n |) ] + |); + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_two_adic_subgroup_vanishing_polynomial : + M.IsFunction.C + "p3_field::helpers::two_adic_subgroup_vanishing_polynomial" + two_adic_subgroup_vanishing_polynomial. + Admitted. + Global Typeclasses Opaque two_adic_subgroup_vanishing_polynomial. + + (* + pub fn two_adic_coset_vanishing_polynomial(log_n: usize, shift: F, x: F) -> F { + x.exp_power_of_2(log_n) - shift.exp_power_of_2(log_n) + } + *) + Definition two_adic_coset_vanishing_polynomial + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ log_n; shift; x ] => + ltac:(M.monadic + (let log_n := M.alloc (| log_n |) in + let shift := M.alloc (| shift |) in + let x := M.alloc (| x |) in + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Sub", F, [], [ F ], "sub", [], [] |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); M.read (| log_n |) ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, shift |); M.read (| log_n |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_two_adic_coset_vanishing_polynomial : + M.IsFunction.C + "p3_field::helpers::two_adic_coset_vanishing_polynomial" + two_adic_coset_vanishing_polynomial. + Admitted. + Global Typeclasses Opaque two_adic_coset_vanishing_polynomial. + + (* + pub fn cyclic_subgroup_known_order( + generator: F, + order: usize, + ) -> impl Iterator + Clone { + generator.powers().take(order) + } + *) + Definition cyclic_subgroup_known_order + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ generator; order ] => + ltac:(M.monadic + (let generator := M.alloc (| generator |) in + let order := M.alloc (| order |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, generator |) ] + |); + M.read (| order |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_cyclic_subgroup_known_order : + M.IsFunction.C "p3_field::helpers::cyclic_subgroup_known_order" cyclic_subgroup_known_order. + Admitted. + Global Typeclasses Opaque cyclic_subgroup_known_order. + + (* + pub fn cyclic_subgroup_coset_known_order( + generator: F, + shift: F, + order: usize, + ) -> impl Iterator + Clone { + generator.shifted_powers(shift).take(order) + } + *) + Definition cyclic_subgroup_coset_known_order + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ generator; shift; order ] => + ltac:(M.monadic + (let generator := M.alloc (| generator |) in + let shift := M.alloc (| shift |) in + let order := M.alloc (| order |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "shifted_powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, generator |); M.read (| shift |) ] + |); + M.read (| order |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_cyclic_subgroup_coset_known_order : + M.IsFunction.C + "p3_field::helpers::cyclic_subgroup_coset_known_order" + cyclic_subgroup_coset_known_order. + Admitted. + Global Typeclasses Opaque cyclic_subgroup_coset_known_order. + + (* + pub fn scale_vec(s: F, vec: Vec) -> Vec { + vec.into_iter().map(|x| s * x).collect() + } + *) + Definition scale_vec (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ s; vec ] => + ltac:(M.monadic + (let s := M.alloc (| s |) in + let vec := M.alloc (| vec |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.function [ Ty.tuple [ F ] ] F + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.function [ Ty.tuple [ F ] ] F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "map", + [], + [ F; Ty.function [ Ty.tuple [ F ] ] F ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| vec |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ F ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| s |); M.read (| x |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_scale_vec : + M.IsFunction.C "p3_field::helpers::scale_vec" scale_vec. + Admitted. + Global Typeclasses Opaque scale_vec. + + (* + pub fn scale_slice_in_place(s: F, slice: &mut [F]) { + let (packed, sfx) = F::Packing::pack_slice_with_suffix_mut(slice); + let packed_s: F::Packing = s.into(); + packed.par_iter_mut().for_each(|x| *x *= packed_s); + sfx.iter_mut().for_each(|x| *x *= s); + } + *) + Definition scale_slice_in_place (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ s; slice ] => + ltac:(M.monadic + (let s := M.alloc (| s |) in + let slice := M.alloc (| slice |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ] + ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing", + [], + [], + "pack_slice_with_suffix_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| slice |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let packed := M.copy (| γ0_0 |) in + let sfx := M.copy (| γ0_1 |) in + let~ packed_s : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing", + M.get_trait_method (| + "core::convert::Into", + F, + [], + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + "into", + [], + [] + |), + [ M.read (| s |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelRefMutIterator", + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" + ], + [], + [], + "par_iter_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| packed |) |) |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing", + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + F + "Packing" + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| packed_s |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| sfx |) |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ] ] ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + F, + [], + [ F ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| s |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_scale_slice_in_place : + M.IsFunction.C "p3_field::helpers::scale_slice_in_place" scale_slice_in_place. + Admitted. + Global Typeclasses Opaque scale_slice_in_place. + + (* + pub fn add_scaled_slice_in_place(x: &mut [F], y: Y, s: F) + where + F: Field, + Y: Iterator, + { + // TODO: Use PackedField + x.iter_mut().zip(y).for_each(|(x_i, y_i)| *x_i += y_i * s); + } + *) + Definition add_scaled_slice_in_place (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; Y ], [ x; y; s ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + let s := M.alloc (| s |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; Y ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ]; F ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; Y ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "zip", + [], + [ Y ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| x |) |) |) ] + |); + M.read (| y |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ F ]; F ] ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x_i := M.copy (| γ0_0 |) in + let y_i := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x_i |) |) + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| y_i |); M.read (| s |) ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_add_scaled_slice_in_place : + M.IsFunction.C "p3_field::helpers::add_scaled_slice_in_place" add_scaled_slice_in_place. + Admitted. + Global Typeclasses Opaque add_scaled_slice_in_place. + + (* + pub const fn field_to_array(x: R) -> [R; D] { + let mut arr: [_; D] = [const { MaybeUninit::uninit() }; D]; + arr[0] = MaybeUninit::new(x); + let mut i = 1; + while i < D { + arr[i] = MaybeUninit::new(R::ZERO); + i += 1; + } + unsafe { core::mem::transmute_copy::<_, [R; D]>(&arr) } + } + *) + Definition field_to_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ D ], [ R ], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + let~ arr : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ D ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ R ] ] + ] := + M.alloc (| + repeat (| + M.read (| + get_constant (| + "p3_field::helpers::field_to_array_discriminant", + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ R ] + |) + |), + D + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| arr, Value.Integer IntegerKind.Usize 0 |), + M.call_closure (| + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ R ], + "new", + [], + [] + |), + [ M.read (| x |) ] + |) + |) + |) in + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| Ty.path "bool", BinOp.lt, [ M.read (| i |); D ] |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| arr, M.read (| i |) |), + M.call_closure (| + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ R ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ R ], + "new", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + R + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ D ] [ R ], + M.get_function (| + "core::mem::transmute_copy", + [], + [ + Ty.apply + (Ty.path "array") + [ D ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ R ] ]; + Ty.apply (Ty.path "array") [ D ] [ R ] + ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.borrow (| Pointer.Kind.Ref, arr |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_field_to_array : + M.IsFunction.C "p3_field::helpers::field_to_array" field_to_array. + Admitted. + Global Typeclasses Opaque field_to_array. + + (* + pub const fn halve_u32(x: u32) -> u32 { + let shift = (P + 1) >> 1; + let half = x >> 1; + if x & 1 == 0 { half } else { half + shift } + } + *) + Definition halve_u32 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ P ], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + let~ shift : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ P; Value.Integer IntegerKind.U32 1 ] + |); + Value.Integer IntegerKind.I32 1 + ] + |) + |) in + let~ half : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ M.read (| x |); Value.Integer IntegerKind.I32 1 ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ M.read (| x |); Value.Integer IntegerKind.U32 1 ] + |); + Value.Integer IntegerKind.U32 0 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + half)); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ M.read (| half |); M.read (| shift |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_halve_u32 : + M.IsFunction.C "p3_field::helpers::halve_u32" halve_u32. + Admitted. + Global Typeclasses Opaque halve_u32. + + (* + pub const fn halve_u64(x: u64) -> u64 { + let shift = (P + 1) >> 1; + let half = x >> 1; + if x & 1 == 0 { half } else { half + shift } + } + *) + Definition halve_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ P ], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + let~ shift : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ P; Value.Integer IntegerKind.U64 1 ] + |); + Value.Integer IntegerKind.I32 1 + ] + |) + |) in + let~ half : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shr, + [ M.read (| x |); Value.Integer IntegerKind.I32 1 ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u64" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_and, + [ M.read (| x |); Value.Integer IntegerKind.U64 1 ] + |); + Value.Integer IntegerKind.U64 0 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + half)); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ M.read (| half |); M.read (| shift |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_halve_u64 : + M.IsFunction.C "p3_field::helpers::halve_u64" halve_u64. + Admitted. + Global Typeclasses Opaque halve_u64. + + (* + pub fn reduce_32(vals: &[SF]) -> TF { + // If the characteristic of TF is > 2^64, from_int and from_canonical_unchecked act identically + let base = TF::from_int(1u64 << 32); + vals.iter().rev().fold(TF::ZERO, |acc, val| { + acc * base + TF::from_int(val.as_canonical_u32()) + }) + } + *) + Definition reduce_32 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ SF; TF ], [ vals ] => + ltac:(M.monadic + (let vals := M.alloc (| vals |) in + M.read (| + let~ base : Ty.apply (Ty.path "*") [] [ TF ] := + M.alloc (| + M.call_closure (| + TF, + M.get_trait_method (| + "p3_field::integers::QuotientMap", + TF, + [], + [ Ty.path "u64" ], + "from_int", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U64 1; Value.Integer IntegerKind.I32 32 ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + TF, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ SF ] ], + [], + [], + "fold", + [], + [ TF; Ty.function [ Ty.tuple [ TF; Ty.apply (Ty.path "&") [] [ SF ] ] ] TF ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ SF ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ SF ], + [], + [], + "rev", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ SF ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ SF ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| vals |) |) |) ] + |) + ] + |); + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", TF |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ TF; Ty.apply (Ty.path "&") [] [ SF ] ] ] TF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ TF; Ty.apply (Ty.path "&") [] [ SF ] ] ] + TF + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let val := M.copy (| γ |) in + M.call_closure (| + TF, + M.get_trait_method (| + "core::ops::arith::Add", + TF, + [], + [ TF ], + "add", + [], + [] + |), + [ + M.call_closure (| + TF, + M.get_trait_method (| + "core::ops::arith::Mul", + TF, + [], + [ TF ], + "mul", + [], + [] + |), + [ M.read (| acc |); M.read (| base |) ] + |); + M.call_closure (| + TF, + M.get_trait_method (| + "p3_field::integers::QuotientMap", + TF, + [], + [ Ty.path "u32" ], + "from_int", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + SF, + [], + [], + "as_canonical_u32", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| val |) |) + |) + ] + |) + ] + |) + ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_reduce_32 : + M.IsFunction.C "p3_field::helpers::reduce_32" reduce_32. + Admitted. + Global Typeclasses Opaque reduce_32. + + (* + pub fn split_32(val: SF, n: usize) -> Vec { + let mut result: Vec = val + .as_canonical_biguint() + .to_u64_digits() + .iter() + .take(n) + .map(|d| TF::from_u64( *d)) + .collect(); + + // Pad with zeros if needed + result.resize_with(n, || TF::ZERO); + result + } + *) + Definition split_32 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ SF; TF ], [ val; n ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + let n := M.alloc (| n |) in + M.read (| + let~ result : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ TF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ TF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ] ]; + Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.path "u64" ] ] ] TF + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ TF; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ] ]; + Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.path "u64" ] ] ] TF + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ] ], + [], + [], + "map", + [], + [ + TF; + Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.path "u64" ] ] ] TF + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u64" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u64" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u64"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u64"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.path "num_bigint::biguint::BigUint", + "to_u64_digits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "p3_field::field::PrimeField", + SF, + [], + [], + "as_canonical_biguint", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, val |) ] + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.read (| n |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.path "u64" ] ] ] + TF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let d := M.copy (| γ |) in + M.call_closure (| + TF, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + TF, + [], + [], + "from_u64", + [], + [] + |), + [ M.read (| M.deref (| M.read (| d |) |) |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ TF; Ty.path "alloc::alloc::Global" ], + "resize_with", + [], + [ Ty.function [ Ty.tuple [] ] TF ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, result |); + M.read (| n |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [] ] TF ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + TF + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + result + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_split_32 : + M.IsFunction.C "p3_field::helpers::split_32" split_32. + Admitted. + Global Typeclasses Opaque split_32. + + (* + pub fn dot_product(li: LI, ri: RI) -> S + where + LI: Iterator, + RI: Iterator, + LI::Item: Mul, + S: Sum<>::Output>, + { + li.zip(ri).map(|(l, r)| l * r).sum() + } + *) + Definition dot_product (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as S; LI; RI ], [ li; ri ] => + ltac:(M.monadic + (let li := M.alloc (| li |) in + let ri := M.alloc (| ri |) in + M.call_closure (| + S, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::iter::adapters::zip::Zip") [] [ LI; RI ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item"; + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ] + ] + ] + (Ty.associated_in_trait + "core::ops::arith::Mul" + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ] + (Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item") + "Output") + ], + [], + [], + "sum", + [], + [ S ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::iter::adapters::zip::Zip") [] [ LI; RI ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item"; + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ] + ] + ] + (Ty.associated_in_trait + "core::ops::arith::Mul" + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ] + (Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item") + "Output") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::iter::adapters::zip::Zip") [] [ LI; RI ], + [], + [], + "map", + [], + [ + Ty.associated_in_trait + "core::ops::arith::Mul" + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ] + (Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item") + "Output"; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item"; + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ] + ] + ] + (Ty.associated_in_trait + "core::ops::arith::Mul" + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ] + (Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item") + "Output") + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::iter::adapters::zip::Zip") [] [ LI; RI ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + LI, + [], + [], + "zip", + [], + [ RI ] + |), + [ M.read (| li |); M.read (| ri |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item"; + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ] + ] + ] + (Ty.associated_in_trait + "core::ops::arith::Mul" + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ] + (Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item") + "Output") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let l := M.copy (| γ0_0 |) in + let r := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.associated_in_trait + "core::ops::arith::Mul" + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ] + (Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item") + "Output", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + LI + "Item", + [], + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + RI + "Item" + ], + "mul", + [], + [] + |), + [ M.read (| l |); M.read (| r |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dot_product : + M.IsFunction.C "p3_field::helpers::dot_product" dot_product. + Admitted. + Global Typeclasses Opaque dot_product. +End helpers. diff --git a/CoqOfRust/plonky3/field/src/integers.rs b/CoqOfRust/plonky3/field/src/integers.rs new file mode 100644 index 000000000..aaff4f5a6 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/integers.rs @@ -0,0 +1,470 @@ +//! A collection of traits and macros which convert primitive integer types into field elements. + +/// A macro which lets us define the function `from_Int` +/// where `Int` can be replaced by any integer type. +/// +/// Running, `from_integer_types!(Int)` adds the following code to a trait: +/// +/// ```rust,ignore +/// /// Given an integer `r`, return the sum of `r` copies of `ONE`: +/// /// +/// /// `r * Self::ONE = Self::ONE + ... + Self::ONE (r times)`. +/// /// +/// /// Note that the output only depends on `r mod p`. +/// /// +/// /// This should be avoided in performance critical locations. +/// fn from_Int(int: Int) -> Self { +/// Self::from_prime_subfield(Self::PrimeSubfield::from_int(int)) +/// } +/// ``` +/// +/// This macro can be run for any `Int` where `Self::PrimeSubfield` implements `QuotientMap`. +/// It considerably cuts down on the amount of copy/pasted code. +macro_rules! from_integer_types { + ($($type:ty),* $(,)? ) => { + $( paste::paste!{ + /// Given an integer `r`, return the sum of `r` copies of `ONE`: + /// + /// `r * Self::ONE = Self::ONE + ... + Self::ONE (r times)`. + /// + /// Note that the output only depends on `r mod p`. + /// + /// This should be avoided in performance critical locations. + fn [](int: $type) -> Self { + Self::from_prime_subfield(Self::PrimeSubfield::from_int(int)) + } + } + )* + }; +} + +/// Implementation of the quotient map `ℤ -> ℤ/p` which sends an integer `r` to its conjugacy class `[r]`. +/// +/// This is the key trait allowing us to convert integers into field elements. Each prime field +/// should implement this for all primitive integer types. +pub trait QuotientMap: Sized { + /// Convert a given integer into an element of the field `ℤ/p`. + /// + /// This is the most generic method which makes no assumptions on the size of the input. + /// Where possible, this method should be used with the smallest possible integer type. + /// For example, if a 32-bit integer `x` is known to be less than `2^16`, then + /// `from_int(x as u16)` will often be faster than `from_int(x)`. + /// + /// This method is also strongly preferred over `from_canonical_checked/from_canonical_unchecked`. + /// It will usually be identical when `Int` is a small type, e.g. `u8/u16` and is safer for + /// larger types. + fn from_int(int: Int) -> Self; + + /// Convert a given integer into an element of the field `ℤ/p`. The input is checked to + /// ensure it lies within a given range. + /// - If `Int` is an unsigned integer type the input must lie in `[0, p - 1]`. + /// - If `Int` is a signed integer type the input must lie in `[-(p - 1)/2, (p - 1)/2]`. + /// + /// Return `None` if the input lies outside this range and `Some(val)` otherwise. + fn from_canonical_checked(int: Int) -> Option; + + /// Convert a given integer into an element of the field `ℤ/p`. The input is guaranteed + /// to lie within a specific range depending on `p`. If the input lies outside of this + /// range, the output is undefined. + /// + /// In general `from_canonical_unchecked` will be faster for either `signed` or `unsigned` + /// types but the specifics will depend on the field. + /// + /// # Safety + /// - If `Int` is an unsigned integer type then the allowed range will include `[0, p - 1]`. + /// - If `Int` is a signed integer type then the allowed range will include `[-(p - 1)/2, (p - 1)/2]`. + unsafe fn from_canonical_unchecked(int: Int) -> Self; +} + +/// This allows us to avoid some duplication which arises when working with fields which contain a generic parameter. +/// +/// See `quotient_map_small_int` to see what this will expand to/how to call it. This is not intended for use outside of +/// that macro. +#[macro_export] +macro_rules! quotient_map_small_internals { + ($field:ty, $field_size:ty, $small_int:ty) => { + #[doc = concat!("Convert a given `", stringify!($small_int), "` integer into an element of the `", stringify!($field), "` field. + \n Due to the integer type, the input value is always canonical.")] + #[inline] + fn from_int(int: $small_int) -> Self { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + + #[doc = concat!("Convert a given `", stringify!($small_int), "` integer into an element of the `", stringify!($field), "` field. + \n Due to the integer type, the input value is always canonical.")] + #[inline] + fn from_canonical_checked(int: $small_int) -> Option { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + Some(unsafe { + Self::from_canonical_unchecked(int as $field_size) + }) + } + + #[doc = concat!("Convert a given `", stringify!($small_int), "` integer into an element of the `", stringify!($field), "` field. + \n Due to the integer type, the input value is always canonical.")] + #[inline] + unsafe fn from_canonical_unchecked(int: $small_int) -> Self { + // We use debug_assert to ensure this is removed by the compiler in release mode. + debug_assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + }; +} + +/// If the integer type is smaller than the field order all possible inputs are canonical. +/// In such a case we can easily implement `QuotientMap` as all three methods will coincide. +/// +/// The range of acceptable integer types depends on the size of the field: +/// - For 31 bit fields, `SmallInt = u8, u16, i8, i16`. +/// - For 64 bit fields, `SmallInt = u8, u16, u32, i8, i16, i32`. +/// - For large fields (E.g. `Bn254`), `SmallInt` can be anything except for the largest primitive integer type `u128/i128` +/// +/// This macro accepts 3 inputs. +/// - The name of the prime field `P` +/// - The larger integer type `Int` which inputs should be cast to. +/// - A list of smaller integer types to auto implement `QuotientMap`. +/// +/// Then `from_int`, `from_canonical_checked`, `from_canonical_unchecked` are all +/// implemented by casting the input to an `Int` and using the `from_canonical_unchecked` +/// method from `QuotientMap`. +/// +/// For a concrete example, `quotient_map_small_int!(Mersenne31, u32, [u8])` produces the following code: +/// +/// ```rust,ignore +/// impl QuotientMap for Mersenne31 { +/// /// Convert a given `u8` integer into an element of the `Mersenne31` field. +/// /// +/// /// Due to the integer type, the input value is always canonical. +/// #[inline] +/// fn from_int(int: u8) -> Mersenne31 { +/// // Should be removed by the compiler. +/// assert!(size_of::() < size_of::()); +/// unsafe { +/// Self::from_canonical_unchecked(int as u32) +/// } +/// } +/// +/// /// Convert a given `u8` integer into an element of the `Mersenne31` field. +/// /// +/// /// Due to the integer type, the input value is always canonical. +/// #[inline] +/// fn from_canonical_checked(int: u8) -> Option { +/// // Should be removed by the compiler. +/// assert!(size_of::() < size_of::()); +/// Some(unsafe { +/// Self::from_canonical_unchecked(int as u32) +/// }) +/// } +/// +/// /// Convert a given `u8` integer into an element of the `Mersenne31` field. +/// /// +/// /// Due to the integer type, the input value is always canonical. +/// #[inline] +/// unsafe fn from_canonical_unchecked(int: u8) -> Mersenne31 { +/// // We use debug_assert to ensure this is removed by the compiler in release mode. +/// debug_assert!(size_of::() < size_of::()); +/// unsafe { +/// Self::from_canonical_unchecked(int as u32) +/// } +/// } +/// } +///``` +/// +/// Fields will often use this method twice. Once for unsigned ints and once for signed ints. +/// +/// We need two slightly different versions for this macro as MontyField31 uses generic parameters. +#[macro_export] +macro_rules! quotient_map_small_int { + ($field:ty, $field_size:ty, [$($small_int:ty),*] ) => { + $( + paste::paste!{ + impl QuotientMap<$small_int> for $field { + $crate::quotient_map_small_internals!($field, $field_size, $small_int); + } + } + )* + }; + + ($field:ty, $field_size:ty, $field_param:ty, [$($small_int:ty),*] ) => { + $( + paste::paste!{ + impl QuotientMap<$small_int> for $field { + $crate::quotient_map_small_internals!($field, $field_size, $small_int); + } + } + )* + }; +} + +/// If the unsigned integer type is large enough, there is often no method better for `from_int` than +/// just doing a modular reduction to a smaller type. +/// +/// This macro accepts 6 inputs. +/// - The name of the prime field `P` +/// - The smallest natural integer type large enough to contain the field characteristic. +/// - The characteristic of the field. +/// - A string giving the range for which from_canonical_checked produces the correct result. +/// - A string giving the range for which from_canonical_unchecked produces the correct result. +/// - A list of large integer types to auto implement `QuotientMap`. +/// +/// For a concrete example, `quotient_map_large_uint!(Mersenne31, u32, Mersenne31::ORDER_U32, "`\[0, 2^31 - 2\]`", "`\[0, 2^31 - 1\]`", [u128])` would produce the following code: +/// +/// ```rust,ignore +/// impl QuotientMap for Mersenne31 { +/// /// Convert a given `u128` integer into an element of the `Mersenne31` field. +/// /// +/// /// Uses a modular reduction to reduce to canonical form. +/// /// This should be avoided in performance critical locations. +/// #[inline] +/// fn from_int(int: u128) -> Mersenne31 { +/// // Should be removed by the compiler. +/// assert!(size_of::() > size_of::()); +/// let red = (int % (Mersenne31::ORDER_U32 as u128)) as u32; +/// unsafe { +/// // This is safe as red is less than the field order by assumption. +/// Self::from_canonical_unchecked(red) +/// } +/// } +/// +/// /// Convert a given `u128` integer into an element of the `Mersenne31` field. +/// /// +/// /// Returns `None` if the input does not lie in the range: [0, 2^31 - 2]. +/// #[inline] +/// fn from_canonical_checked(int: u128) -> Option { +/// if int < Mersenne31::ORDER_U32 as u128 { +/// unsafe { +/// // This is safe as we just checked that int is less than the field order. +/// Some(Self::from_canonical_unchecked(int as u32)) +/// } +/// } else { +/// None +/// } +/// } +/// +/// /// Convert a given `u128` integer into an element of the `Mersenne31` field. +/// /// +/// /// # Safety +/// /// The input must lie in the range:", [0, 2^31 - 1]. +/// #[inline] +/// unsafe fn from_canonical_unchecked(int: u128) -> Mersenne31 { +/// unsafe { +/// Self::from_canonical_unchecked(int as u32) +/// } +/// } +/// } +///``` +#[macro_export] +macro_rules! quotient_map_large_uint { + ($field:ty, $field_size:ty, $field_order:expr, $checked_bounds:literal, $unchecked_bounds:literal, [$($large_int:ty),*] ) => { + $( + impl QuotientMap<$large_int> for $field { + #[doc = concat!("Convert a given `", stringify!($large_int), "` integer into an element of the `", stringify!($field), "` field. + \n Uses a modular reduction to reduce to canonical form. \n This should be avoided in performance critical locations.")] + #[inline] + fn from_int(int: $large_int) -> $field { + assert!(size_of::<$large_int>() > size_of::<$field_size>()); + let red = (int % ($field_order as $large_int)) as $field_size; + unsafe { + // This is safe as red is less than the field order by assumption. + Self::from_canonical_unchecked(red) + } + } + + #[doc = concat!("Convert a given `", stringify!($large_int), "` integer into an element of the `", stringify!($field), "` field. + \n Returns `None` if the input does not lie in the range:", $checked_bounds, ".")] + #[inline] + fn from_canonical_checked(int: $large_int) -> Option<$field> { + if int < $field_order as $large_int { + unsafe { + // This is safe as we just checked that int is less than the field order. + Some(Self::from_canonical_unchecked(int as $field_size)) + } + } else { + None + } + } + + #[doc = concat!("Convert a given `", stringify!($large_int), "` integer into an element of the `", stringify!($field), "` field.")] + /// + /// # Safety + #[doc = concat!("The input must lie in the range:", $unchecked_bounds, ".")] + #[inline] + unsafe fn from_canonical_unchecked(int: $large_int) -> $field { + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + } + )* + }; +} + +/// For large signed integer types, a simple method which is usually good enough is to simply check the sign and use this to +/// pass to the equivalent unsigned method. +/// +/// This will often not be the fastest implementation but should be good enough for most cases. +/// +/// This macro accepts 4 inputs. +/// - The name of the prime field `P`. +/// - The smallest natural integer type large enough to contain the field characteristic. +/// - A string giving the range for which from_canonical_checked produces the correct result. +/// - A string giving the range for which from_canonical_unchecked produces the correct result. +/// - A list of pairs of large sign and unsigned integer types to auto implement `QuotientMap`. +/// +/// For a concrete example, `quotient_map_large_iint!(Mersenne31, i32, "`\[-2^30, 2^30\]`", "`\[1 - 2^31, 2^31 - 1\]`", [(i128, u128)])` would produce the following code: +/// +/// ```rust,ignore +/// impl QuotientMap for Mersenne31 { +/// /// Convert a given `i128` integer into an element of the `Mersenne31` field. +/// /// +/// /// This checks the sign and then makes use of the equivalent method for unsigned integers. +/// /// This should be avoided in performance critical locations. +/// #[inline] +/// fn from_int(int: i128) -> Mersenne31 { +/// if int >= 0 { +/// Self::from_int(int as u128) +/// } else { +/// -Self::from_int(-int as u128) +/// } +/// } +/// +/// /// Convert a given `i128` integer into an element of the `Mersenne31` field. +/// /// +/// /// Returns `None` if the input does not lie in the range: `[-2^30, 2^30]`. +/// #[inline] +/// fn from_canonical_checked(int: i128) -> Option { +/// // We just check that int fits into an i32 now and then use the i32 method. +/// let int_small = TryInto::::try_into(int); +/// if int_small.is_ok() { +/// Self::from_canonical_checked(int_small.unwrap()) +/// } else { +/// None +/// } +/// } +/// +/// /// Convert a given `i128` integer into an element of the `Mersenne31` field. +/// /// +/// /// # Safety +/// /// The input must lie in the range:", `[1 - 2^31, 2^31 - 1]`. +/// #[inline] +/// unsafe fn from_canonical_unchecked(int: i128) -> Mersenne31 { +/// unsafe { +/// Self::from_canonical_unchecked(int as i32) +/// } +/// } +/// } +///``` +#[macro_export] +macro_rules! quotient_map_large_iint { + ($field:ty, $field_size:ty, $checked_bounds:literal, $unchecked_bounds:literal, [$(($large_signed_int:ty, $large_int:ty)),*] ) => { + $( + impl QuotientMap<$large_signed_int> for $field { + #[doc = concat!("Convert a given `", stringify!($large_signed_int), "` integer into an element of the `", stringify!($field), "` field. + \n This checks the sign and then makes use of the equivalent method for unsigned integers. \n This should be avoided in performance critical locations.")] + #[inline] + fn from_int(int: $large_signed_int) -> $field { + if int >= 0 { + Self::from_int(int as $large_int) + } else { + -Self::from_int(-int as $large_int) + } + } + + #[doc = concat!("Convert a given `", stringify!($large_int), "` integer into an element of the `", stringify!($field), "` field. + \n Returns `None` if the input does not lie in the range:", $checked_bounds, ".")] + #[inline] + fn from_canonical_checked(int: $large_signed_int) -> Option<$field> { + let int_small = TryInto::<$field_size>::try_into(int).ok(); + + // The type of the following is Option>. + // We use the ? operator to convert it to Option<$field>, with + // None and Some(None) both becoming None. + int_small.map(Self::from_canonical_checked)? + } + + #[doc = concat!("Convert a given `", stringify!($large_int), "` integer into an element of the `", stringify!($field), "` field.")] + /// + /// # Safety + #[doc = concat!("The input must lie in the range:", $unchecked_bounds, ".")] + #[inline] + unsafe fn from_canonical_unchecked(int: $large_signed_int) -> $field { + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + } + )* + }; +} + +/// We implement `QuotientMap` (`QuotientMap`) by matching against the size of `usize` (`isize`) +/// and then converting `usize` (`isize`) into the equivalent matching integer type. +/// +/// The code is identical for both `usize` and `isize` outside of replacing some u's by i's so we use a macro +/// to avoid the copy and paste. +macro_rules! impl_u_i_size { + ($intsize:ty, $int8:ty, $int16:ty, $int32:ty, $int64:ty, $int128:ty) => { + impl< + F: QuotientMap<$int8> + + QuotientMap<$int16> + + QuotientMap<$int32> + + QuotientMap<$int64> + + QuotientMap<$int128>, + > QuotientMap<$intsize> for F + { + #[doc = concat!("We use the `from_int` method of the primitive integer type identical to `", stringify!($intsize), "` on this machine")] + fn from_int(int: $intsize) -> Self { + match size_of::<$intsize>() { + 1 => Self::from_int(int as $int8), + 2 => Self::from_int(int as $int16), + 4 => Self::from_int(int as $int32), + 8 => Self::from_int(int as $int64), + 16 => Self::from_int(int as $int128), + _ => unreachable!(concat!(stringify!($intsize), "is not equivalent to any primitive integer types.")), + } + } + + #[doc = concat!("We use the `from_canonical_checked` method of the primitive integer type identical to `", stringify!($intsize), "` on this machine")] + fn from_canonical_checked(int: $intsize) -> Option { + match size_of::<$intsize>() { + 1 => Self::from_canonical_checked(int as $int8), + 2 => Self::from_canonical_checked(int as $int16), + 4 => Self::from_canonical_checked(int as $int32), + 8 => Self::from_canonical_checked(int as $int64), + 16 => Self::from_canonical_checked(int as $int128), + _ => unreachable!(concat!(stringify!($intsize), " is not equivalent to any primitive integer types.")), + } + } + + #[doc = concat!("We use the `from_canonical_unchecked` method of the primitive integer type identical to `", stringify!($intsize), "` on this machine")] + unsafe fn from_canonical_unchecked(int: $intsize) -> Self { + unsafe { + match size_of::<$intsize>() { + 1 => Self::from_canonical_unchecked(int as $int8), + 2 => Self::from_canonical_unchecked(int as $int16), + 4 => Self::from_canonical_unchecked(int as $int32), + 8 => Self::from_canonical_unchecked(int as $int64), + 16 => Self::from_canonical_unchecked(int as $int128), + _ => unreachable!(concat!(stringify!($intsize), " is not equivalent to any primitive integer types.")), + } + } + } + } + }; +} + +impl_u_i_size!(usize, u8, u16, u32, u64, u128); +impl_u_i_size!(isize, i8, i16, i32, i64, i128); + +// The only general type for which we do not provide a macro is for large signed integers. +// This is because different field will usually want to handle large signed integers in +// their own way. +pub(crate) use from_integer_types; +pub use {quotient_map_large_iint, quotient_map_large_uint, quotient_map_small_int}; diff --git a/CoqOfRust/plonky3/field/src/integers.v b/CoqOfRust/plonky3/field/src/integers.v new file mode 100644 index 000000000..d68c12ccf --- /dev/null +++ b/CoqOfRust/plonky3/field/src/integers.v @@ -0,0 +1,2202 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module Impl_p3_field_integers_QuotientMap_u8_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn from_int(int: $small_int) -> Self { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u8" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: $small_int) -> Option { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + Some(unsafe { + Self::from_canonical_unchecked(int as $field_size) + }) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u8" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: $small_int) -> Self { + // We use debug_assert to ensure this is removed by the compiler in release mode. + debug_assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "u8" ] + |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "u128" ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: size_of::() < size_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u8" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. +End Impl_p3_field_integers_QuotientMap_u8_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_integers_QuotientMap_u16_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn from_int(int: $small_int) -> Self { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u16" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: $small_int) -> Option { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + Some(unsafe { + Self::from_canonical_unchecked(int as $field_size) + }) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u16" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: $small_int) -> Self { + // We use debug_assert to ensure this is removed by the compiler in release mode. + debug_assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "u16" ] + |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "u128" ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: size_of::() < size_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u16" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. +End Impl_p3_field_integers_QuotientMap_u16_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_integers_QuotientMap_u32_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn from_int(int: $small_int) -> Self { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u32" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: $small_int) -> Option { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + Some(unsafe { + Self::from_canonical_unchecked(int as $field_size) + }) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u32" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: $small_int) -> Self { + // We use debug_assert to ensure this is removed by the compiler in release mode. + debug_assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "u32" ] + |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "u128" ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: size_of::() < size_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u32" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. +End Impl_p3_field_integers_QuotientMap_u32_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_integers_QuotientMap_u64_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn from_int(int: $small_int) -> Self { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u64" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: $small_int) -> Option { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + Some(unsafe { + Self::from_canonical_unchecked(int as $field_size) + }) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u64" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "u128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: $small_int) -> Self { + // We use debug_assert to ensure this is removed by the compiler in release mode. + debug_assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "u64" ] + |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "u128" ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: size_of::() < size_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "u128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "u128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. +End Impl_p3_field_integers_QuotientMap_u64_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_integers_QuotientMap_i8_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn from_int(int: $small_int) -> Self { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i8" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: $small_int) -> Option { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + Some(unsafe { + Self::from_canonical_unchecked(int as $field_size) + }) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i8" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: $small_int) -> Self { + // We use debug_assert to ensure this is removed by the compiler in release mode. + debug_assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "i8" ] + |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "i128" ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: size_of::() < size_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i8" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. +End Impl_p3_field_integers_QuotientMap_i8_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_integers_QuotientMap_i16_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn from_int(int: $small_int) -> Self { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i16" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: $small_int) -> Option { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + Some(unsafe { + Self::from_canonical_unchecked(int as $field_size) + }) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i16" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: $small_int) -> Self { + // We use debug_assert to ensure this is removed by the compiler in release mode. + debug_assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "i16" ] + |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "i128" ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: size_of::() < size_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i16" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. +End Impl_p3_field_integers_QuotientMap_i16_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_integers_QuotientMap_i32_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn from_int(int: $small_int) -> Self { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i32" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: $small_int) -> Option { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + Some(unsafe { + Self::from_canonical_unchecked(int as $field_size) + }) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i32" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: $small_int) -> Self { + // We use debug_assert to ensure this is removed by the compiler in release mode. + debug_assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "i32" ] + |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "i128" ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: size_of::() < size_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i32" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. +End Impl_p3_field_integers_QuotientMap_i32_for_p3_bn254_fr_Bn254Fr. + +Module Impl_p3_field_integers_QuotientMap_i64_for_p3_bn254_fr_Bn254Fr. + Definition Self : Ty.t := Ty.path "p3_bn254_fr::Bn254Fr". + + (* + fn from_int(int: $small_int) -> Self { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i64" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: $small_int) -> Option { + // Should be removed by the compiler. + assert!(size_of::<$small_int>() < size_of::<$field_size>()); + Some(unsafe { + Self::from_canonical_unchecked(int as $field_size) + }) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i64" ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Ty.path "i128" ] |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: size_of::() < size_of::()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: $small_int) -> Self { + // We use debug_assert to ensure this is removed by the compiler in release mode. + debug_assert!(size_of::<$small_int>() < size_of::<$field_size>()); + unsafe { + Self::from_canonical_unchecked(int as $field_size) + } + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "i64" ] + |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "i128" ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: size_of::() < size_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_bn254_fr::Bn254Fr", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_bn254_fr::Bn254Fr", + [], + [ Ty.path "i128" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.cast (Ty.path "i128") (M.read (| int |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i64" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. +End Impl_p3_field_integers_QuotientMap_i64_for_p3_bn254_fr_Bn254Fr. diff --git a/CoqOfRust/plonky3/field/src/lib.rs b/CoqOfRust/plonky3/field/src/lib.rs new file mode 100644 index 000000000..dbd619783 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/lib.rs @@ -0,0 +1,21 @@ +//! A framework for finite fields. + +#![no_std] + +extern crate alloc; + +mod array; +mod batch_inverse; +pub mod coset; +pub mod exponentiation; +pub mod extension; +mod field; +mod helpers; +pub mod integers; +mod packed; + +pub use array::*; +pub use batch_inverse::*; +pub use field::*; +pub use helpers::*; +pub use packed::*; diff --git a/CoqOfRust/plonky3/field/src/packed.rs b/CoqOfRust/plonky3/field/src/packed.rs new file mode 100644 index 000000000..02c7140f4 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/packed.rs @@ -0,0 +1,331 @@ +use alloc::vec::Vec; +use core::mem::MaybeUninit; +use core::ops::Div; +use core::{array, slice}; + +use crate::field::Field; +use crate::{Algebra, BasedVectorSpace, ExtensionField, Powers, PrimeCharacteristicRing}; + +/// A trait to constrain types that can be packed into a packed value. +/// +/// The `Packable` trait allows us to specify implementations for potentially conflicting types. +pub trait Packable: 'static + Default + Copy + Send + Sync + PartialEq + Eq {} + +/// # Safety +/// - If `P` implements `PackedField` then `P` must be castable to/from `[P::Value; P::WIDTH]` +/// without UB. +pub unsafe trait PackedValue: 'static + Copy + Send + Sync { + type Value: Packable; + + const WIDTH: usize; + + fn from_slice(slice: &[Self::Value]) -> &Self; + fn from_slice_mut(slice: &mut [Self::Value]) -> &mut Self; + + /// Similar to `core:array::from_fn`. + fn from_fn(f: F) -> Self + where + F: FnMut(usize) -> Self::Value; + + fn as_slice(&self) -> &[Self::Value]; + fn as_slice_mut(&mut self) -> &mut [Self::Value]; + + fn pack_slice(buf: &[Self::Value]) -> &[Self] { + // Sources vary, but this should be true on all platforms we care about. + // This should be a const assert, but trait methods can't access `Self` in a const context, + // even with inner struct instantiation. So we will trust LLVM to optimize this out. + assert!(align_of::() <= align_of::()); + assert!( + buf.len() % Self::WIDTH == 0, + "Slice length (got {}) must be a multiple of packed field width ({}).", + buf.len(), + Self::WIDTH + ); + let buf_ptr = buf.as_ptr().cast::(); + let n = buf.len() / Self::WIDTH; + unsafe { slice::from_raw_parts(buf_ptr, n) } + } + + fn pack_slice_with_suffix(buf: &[Self::Value]) -> (&[Self], &[Self::Value]) { + let (packed, suffix) = buf.split_at(buf.len() - buf.len() % Self::WIDTH); + (Self::pack_slice(packed), suffix) + } + + fn pack_slice_mut(buf: &mut [Self::Value]) -> &mut [Self] { + assert!(align_of::() <= align_of::()); + assert!( + buf.len() % Self::WIDTH == 0, + "Slice length (got {}) must be a multiple of packed field width ({}).", + buf.len(), + Self::WIDTH + ); + let buf_ptr = buf.as_mut_ptr().cast::(); + let n = buf.len() / Self::WIDTH; + unsafe { slice::from_raw_parts_mut(buf_ptr, n) } + } + + fn pack_maybe_uninit_slice_mut( + buf: &mut [MaybeUninit], + ) -> &mut [MaybeUninit] { + assert!(align_of::() <= align_of::()); + assert!( + buf.len() % Self::WIDTH == 0, + "Slice length (got {}) must be a multiple of packed field width ({}).", + buf.len(), + Self::WIDTH + ); + let buf_ptr = buf.as_mut_ptr().cast::>(); + let n = buf.len() / Self::WIDTH; + unsafe { slice::from_raw_parts_mut(buf_ptr, n) } + } + + fn pack_slice_with_suffix_mut(buf: &mut [Self::Value]) -> (&mut [Self], &mut [Self::Value]) { + let (packed, suffix) = buf.split_at_mut(buf.len() - buf.len() % Self::WIDTH); + (Self::pack_slice_mut(packed), suffix) + } + + fn pack_maybe_uninit_slice_with_suffix_mut( + buf: &mut [MaybeUninit], + ) -> (&mut [MaybeUninit], &mut [MaybeUninit]) { + let (packed, suffix) = buf.split_at_mut(buf.len() - buf.len() % Self::WIDTH); + (Self::pack_maybe_uninit_slice_mut(packed), suffix) + } + + fn unpack_slice(buf: &[Self]) -> &[Self::Value] { + assert!(align_of::() >= align_of::()); + let buf_ptr = buf.as_ptr().cast::(); + let n = buf.len() * Self::WIDTH; + unsafe { slice::from_raw_parts(buf_ptr, n) } + } +} + +unsafe impl PackedValue for [T; WIDTH] { + type Value = T; + const WIDTH: usize = WIDTH; + + fn from_slice(slice: &[Self::Value]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + slice.try_into().unwrap() + } + + fn from_slice_mut(slice: &mut [Self::Value]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + slice.try_into().unwrap() + } + + fn from_fn(f: F) -> Self + where + F: FnMut(usize) -> Self::Value, + { + core::array::from_fn(f) + } + + fn as_slice(&self) -> &[Self::Value] { + self + } + + fn as_slice_mut(&mut self) -> &mut [Self::Value] { + self + } +} + +/// An array of field elements which can be packed into a vector for SIMD operations. +/// +/// # Safety +/// - See `PackedValue` above. +pub unsafe trait PackedField: Algebra + + PackedValue + // TODO: Implement packed / packed division + + Div +{ + type Scalar: Field; + + /// Construct an iterator which returns powers of `base` packed into packed field elements. + /// + /// E.g. if `Self::WIDTH = 4`, returns: `[base^0, base^1, base^2, base^3], [base^4, base^5, base^6, base^7], ...`. + #[must_use] + fn packed_powers(base: Self::Scalar) -> Powers { + Self::packed_shifted_powers(base, Self::Scalar::ONE) + } + + /// Construct an iterator which returns powers of `base` multiplied by `start` and packed into packed field elements. + /// + /// E.g. if `Self::WIDTH = 4`, returns: `[start, start*base, start*base^2, start*base^3], [start*base^4, start*base^5, start*base^6, start*base^7], ...`. + #[must_use] + fn packed_shifted_powers(base: Self::Scalar, start: Self::Scalar) -> Powers { + let mut current: Self = start.into(); + let slice = current.as_slice_mut(); + for i in 1..Self::WIDTH { + slice[i] = slice[i - 1] * base; + } + + Powers { + base: base.exp_u64(Self::WIDTH as u64).into(), + current, + } + } + + /// Compute a linear combination of a slice of base field elements and + /// a slice of packed field elements. The slices must have equal length + /// and it must be a compile time constant. + /// + /// # Panics + /// + /// May panic if the length of either slice is not equal to `N`. + fn packed_linear_combination(coeffs: &[Self::Scalar], vecs: &[Self]) -> Self { + assert_eq!(coeffs.len(), N); + assert_eq!(vecs.len(), N); + let combined: [Self; N] = array::from_fn(|i| vecs[i] * coeffs[i]); + Self::sum_array::(&combined) + } +} + +/// # Safety +/// - `WIDTH` is assumed to be a power of 2. +pub unsafe trait PackedFieldPow2: PackedField { + /// Take interpret two vectors as chunks of `block_len` elements. Unpack and interleave those + /// chunks. This is best seen with an example. If we have: + /// ```text + /// A = [x0, y0, x1, y1] + /// B = [x2, y2, x3, y3] + /// ``` + /// + /// then + /// + /// ```text + /// interleave(A, B, 1) = ([x0, x2, x1, x3], [y0, y2, y1, y3]) + /// ``` + /// + /// Pairs that were adjacent in the input are at corresponding positions in the output. + /// + /// `r` lets us set the size of chunks we're interleaving. If we set `block_len = 2`, then for + /// + /// ```text + /// A = [x0, x1, y0, y1] + /// B = [x2, x3, y2, y3] + /// ``` + /// + /// we obtain + /// + /// ```text + /// interleave(A, B, block_len) = ([x0, x1, x2, x3], [y0, y1, y2, y3]) + /// ``` + /// + /// We can also think about this as stacking the vectors, dividing them into 2x2 matrices, and + /// transposing those matrices. + /// + /// When `block_len = WIDTH`, this operation is a no-op. + /// + /// # Panics + /// This may panic if `block_len` does not divide `WIDTH`. Since `WIDTH` is specified to be a power of 2, + /// `block_len` must also be a power of 2. It cannot be 0 and it cannot exceed `WIDTH`. + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self); +} + +/// Fix a field `F` a packing width `W` and an extension field `EF` of `F`. +/// +/// By choosing a basis `B`, `EF` can be transformed into an array `[F; D]`. +/// +/// A type should implement PackedFieldExtension if it can be transformed into `[F::Packing; D] ~ [[F; W]; D]` +/// +/// This is interpreted by taking a transpose to get `[[F; D]; W]` which can then be reinterpreted +/// as `[EF; W]` by making use of the chosen basis `B` again. +pub trait PackedFieldExtension< + BaseField: Field, + ExtField: ExtensionField, +>: Algebra + Algebra + BasedVectorSpace +{ + /// Given a slice of extension field `EF` elements of length `W`, + /// convert into the array `[[F; D]; W]` transpose to + /// `[[F; W]; D]` and then pack to get `[PF; D]`. + fn from_ext_slice(ext_slice: &[ExtField]) -> Self; + + /// Given a iterator of packed extension field elements, convert to an iterator of + /// extension field elements. + /// + /// This performs the inverse transformation to `from_ext_slice`. + #[inline] + fn to_ext_iter(iter: impl IntoIterator) -> impl Iterator { + iter.into_iter().flat_map(|x| { + let packed_coeffs = x.as_basis_coefficients_slice(); + (0..BaseField::Packing::WIDTH) + .map(|i| ExtField::from_basis_coefficients_fn(|j| packed_coeffs[j].as_slice()[i])) + .collect::>() // PackedFieldExtension's should reimplement this to avoid this allocation. + }) + } + + /// Similar to `packed_powers`, construct an iterator which returns + /// powers of `base` packed into `PackedFieldExtension` elements. + fn packed_ext_powers(base: ExtField) -> Powers; + + /// Similar to `packed_ext_powers` but only returns `unpacked_len` powers of `base`. + /// + /// Note that the length of the returned iterator will be `unpacked_len / WIDTH` and + /// not `len` as the iterator is over packed extension field elements. If `unpacked_len` + /// is not divisible by `WIDTH`, `unpacked_len` will be rounded up to the next multiple of `WIDTH`. + fn packed_ext_powers_capped(base: ExtField, unpacked_len: usize) -> impl Iterator { + Self::packed_ext_powers(base).take(unpacked_len.div_ceil(BaseField::Packing::WIDTH)) + } +} + +unsafe impl PackedValue for T { + type Value = Self; + + const WIDTH: usize = 1; + + fn from_slice(slice: &[Self::Value]) -> &Self { + &slice[0] + } + + fn from_slice_mut(slice: &mut [Self::Value]) -> &mut Self { + &mut slice[0] + } + + fn from_fn(mut f: Fn) -> Self + where + Fn: FnMut(usize) -> Self::Value, + { + f(0) + } + + fn as_slice(&self) -> &[Self::Value] { + slice::from_ref(self) + } + + fn as_slice_mut(&mut self) -> &mut [Self::Value] { + slice::from_mut(self) + } +} + +unsafe impl PackedField for F { + type Scalar = Self; +} + +unsafe impl PackedFieldPow2 for F { + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { + match block_len { + 1 => (*self, other), + _ => panic!("unsupported block length"), + } + } +} + +impl PackedFieldExtension for F::Packing { + fn from_ext_slice(ext_slice: &[F]) -> Self { + ext_slice[0].into() + } + + fn packed_ext_powers(base: F) -> Powers { + F::Packing::packed_powers(base) + } +} + +impl Packable for u8 {} + +impl Packable for u16 {} + +impl Packable for u32 {} + +impl Packable for u64 {} + +impl Packable for u128 {} diff --git a/CoqOfRust/plonky3/field/src/packed.v b/CoqOfRust/plonky3/field/src/packed.v new file mode 100644 index 000000000..c6f4b71e6 --- /dev/null +++ b/CoqOfRust/plonky3/field/src/packed.v @@ -0,0 +1,3970 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module packed. + (* Trait *) + (* Empty module 'Packable' *) + + (* Trait *) + Module PackedValue. + Definition pack_slice (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ buf ] => + ltac:(M.monadic + (let buf := M.alloc (| buf |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::align_of", [], [ Self ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::align_of", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: align_of::() <= align_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| buf |) |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "Slice length (got " |); + mk_str (| + ") must be a multiple of packed field width (" + |); + mk_str (| ")." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| buf |) |) + |) + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ buf_ptr : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "*const") [] [ Self ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "*const") [] [ Self ], + M.get_associated_function (| + Ty.apply + (Ty.path "*const") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] Self "Value" ], + "cast", + [], + [ Self ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "*const") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] Self "Value" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "as_ptr", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |) + ] + |) + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |); + M.read (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |) + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_function (| "core::slice::raw::from_raw_parts", [], [ Self ] |), + [ M.read (| buf_ptr |); M.read (| n |) ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_pack_slice : + M.IsProvidedMethod "p3_field::packed::PackedValue" "pack_slice" pack_slice. + Definition pack_slice_with_suffix + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ buf ] => + ltac:(M.monadic + (let buf := M.alloc (| buf |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Self ] ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] Self "Value" ], + "split_at", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |); + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let packed := M.copy (| γ0_0 |) in + let suffix := M.copy (| γ0_1 |) in + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Self, + [], + [], + "pack_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| packed |) |) |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| suffix |) |) |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_pack_slice_with_suffix : + M.IsProvidedMethod + "p3_field::packed::PackedValue" + "pack_slice_with_suffix" + pack_slice_with_suffix. + Definition pack_slice_mut + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ buf ] => + ltac:(M.monadic + (let buf := M.alloc (| buf |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::align_of", [], [ Self ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::align_of", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: align_of::() <= align_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| buf |) |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "Slice length (got " |); + mk_str (| + ") must be a multiple of packed field width (" + |); + mk_str (| ")." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| buf |) |) + |) + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ buf_ptr : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "*mut") [] [ Self ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ Self ], + M.get_associated_function (| + Ty.apply + (Ty.path "*mut") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "cast", + [], + [ Self ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "*mut") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "as_mut_ptr", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| buf |) |) |) ] + |) + ] + |) + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |); + M.read (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |) + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_function (| + "core::slice::raw::from_raw_parts_mut", + [], + [ Self ] + |), + [ M.read (| buf_ptr |); M.read (| n |) ] + |) + |) + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_pack_slice_mut : + M.IsProvidedMethod "p3_field::packed::PackedValue" "pack_slice_mut" pack_slice_mut. + Definition pack_maybe_uninit_slice_mut + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ buf ] => + ltac:(M.monadic + (let buf := M.alloc (| buf |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::align_of", [], [ Self ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::align_of", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: align_of::() <= align_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| buf |) |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "Slice length (got " |); + mk_str (| + ") must be a multiple of packed field width (" + |); + mk_str (| ")." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| buf |) |) + |) + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ buf_ptr : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ Self ] ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ Self ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "*mut") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ], + "cast", + [], + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ Self ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "*mut") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ], + "as_mut_ptr", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| buf |) |) |) ] + |) + ] + |) + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |); + M.read (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |) + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ Self ] + ] + ], + M.get_function (| + "core::slice::raw::from_raw_parts_mut", + [], + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ Self ] + ] + |), + [ M.read (| buf_ptr |); M.read (| n |) ] + |) + |) + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_pack_maybe_uninit_slice_mut : + M.IsProvidedMethod + "p3_field::packed::PackedValue" + "pack_maybe_uninit_slice_mut" + pack_maybe_uninit_slice_mut. + Definition pack_slice_with_suffix_mut + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ buf ] => + ltac:(M.monadic + (let buf := M.alloc (| buf |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Self ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] Self "Value" ], + "split_at_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| buf |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |); + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let packed := M.copy (| γ0_0 |) in + let suffix := M.copy (| γ0_1 |) in + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Self ] ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Self, + [], + [], + "pack_slice_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| packed |) |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| suffix |) |) |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_pack_slice_with_suffix_mut : + M.IsProvidedMethod + "p3_field::packed::PackedValue" + "pack_slice_with_suffix_mut" + pack_slice_with_suffix_mut. + Definition pack_maybe_uninit_slice_with_suffix_mut + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ buf ] => + ltac:(M.monadic + (let buf := M.alloc (| buf |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ Self ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ], + "split_at_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| buf |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |); + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let packed := M.copy (| γ0_0 |) in + let suffix := M.copy (| γ0_1 |) in + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ Self ] + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Self, + [], + [], + "pack_maybe_uninit_slice_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| packed |) |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| suffix |) |) |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_pack_maybe_uninit_slice_with_suffix_mut : + M.IsProvidedMethod + "p3_field::packed::PackedValue" + "pack_maybe_uninit_slice_with_suffix_mut" + pack_maybe_uninit_slice_with_suffix_mut. + Definition unpack_slice + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ buf ] => + ltac:(M.monadic + (let buf := M.alloc (| buf |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::align_of", [], [ Self ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::align_of", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + |), + [] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: align_of::() >= align_of::()" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ buf_ptr : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "*const") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] Self "Value" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "*const") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] Self "Value" ], + M.get_associated_function (| + Ty.apply (Ty.path "*const") [] [ Self ], + "cast", + [], + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] Self "Value" ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "*const") [] [ Self ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Self ], + "as_ptr", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |) + ] + |) + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Self ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) ] + |); + M.read (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |) + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + Self + "Value" + ] + ], + M.get_function (| + "core::slice::raw::from_raw_parts", + [], + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] Self "Value" ] + |), + [ M.read (| buf_ptr |); M.read (| n |) ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_unpack_slice : + M.IsProvidedMethod "p3_field::packed::PackedValue" "unpack_slice" unpack_slice. + End PackedValue. + + Module Impl_p3_field_packed_PackedValue_where_p3_field_packed_Packable_T_for_array_WIDTH_T. + Definition Self (WIDTH : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "array") [ WIDTH ] [ T ]. + + (* type Value = T; *) + Definition _Value (WIDTH : Value.t) (T : Ty.t) : Ty.t := T. + + (* const WIDTH: usize = WIDTH; *) + (* Ty.path "usize" *) + Definition value_WIDTH + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + ltac:(M.monadic (M.alloc (| WIDTH |))). + + (* + fn from_slice(slice: &[Self::Value]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + slice.try_into().unwrap() + } + *) + Definition from_slice + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ] ], + "try_into", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_slice_mut(slice: &mut [Self::Value]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + slice.try_into().unwrap() + } + *) + Definition from_slice_mut + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ] + ], + "try_into", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| slice |) |) |) ] + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_fn(f: F) -> Self + where + F: FnMut(usize) -> Self::Value, + { + core::array::from_fn(f) + } + *) + Definition from_fn + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [ F ], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ T ], + M.get_function (| "core::array::from_fn", [ WIDTH ], [ T; F ] |), + [ M.read (| f |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn as_slice(&self) -> &[Self::Value] { + self + } + *) + Definition as_slice + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + (* Unsize *) + M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn as_slice_mut(&mut self) -> &mut [Self::Value] { + self + } + *) + Definition as_slice_mut + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |)) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (T : Ty.t), + M.IsTraitInstance + "p3_field::packed::PackedValue" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH T) + (* Instance *) + [ + ("Value", InstanceField.Ty (_Value WIDTH T)); + ("value_WIDTH", InstanceField.Method (value_WIDTH WIDTH T)); + ("from_slice", InstanceField.Method (from_slice WIDTH T)); + ("from_slice_mut", InstanceField.Method (from_slice_mut WIDTH T)); + ("from_fn", InstanceField.Method (from_fn WIDTH T)); + ("as_slice", InstanceField.Method (as_slice WIDTH T)); + ("as_slice_mut", InstanceField.Method (as_slice_mut WIDTH T)) + ]. + End Impl_p3_field_packed_PackedValue_where_p3_field_packed_Packable_T_for_array_WIDTH_T. + + (* Trait *) + Module PackedField. + Definition packed_powers + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ base ] => + ltac:(M.monadic + (let base := M.alloc (| base |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ Self ], + M.get_trait_method (| + "p3_field::packed::PackedField", + Self, + [], + [], + "packed_shifted_powers", + [], + [] + |), + [ + M.read (| base |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.associated_in_trait "p3_field::packed::PackedField" [] [] Self "Scalar" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_packed_powers : + M.IsProvidedMethod "p3_field::packed::PackedField" "packed_powers" packed_powers. + Definition packed_shifted_powers + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ base; start ] => + ltac:(M.monadic + (let base := M.alloc (| base |) in + let start := M.alloc (| start |) in + M.read (| + let~ current : Ty.apply (Ty.path "*") [] [ Self ] := + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait "p3_field::packed::PackedField" [] [] Self "Scalar", + [], + [ Self ], + "into", + [], + [] + |), + [ M.read (| start |) ] + |) + |) in + let~ slice : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + Self + "Scalar" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_field::packed::PackedField" [] [] Self "Scalar" + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Self, + [], + [], + "as_slice_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, current |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 1); + ("end_", + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| slice |) |), + M.read (| i |) + |), + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + Self + "Scalar", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + Self + "Scalar", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + Self + "Scalar" + ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| slice |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |); + M.read (| base |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + Value.StructRecord + "p3_field::field::Powers" + [ + ("base", + M.call_closure (| + Self, + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait "p3_field::packed::PackedField" [] [] Self "Scalar", + [], + [ Self ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + Self + "Scalar", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + Self + "Scalar", + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, base |); + M.cast + (Ty.path "u64") + (M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |)) + ] + |) + ] + |)); + ("current", M.read (| current |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_packed_shifted_powers : + M.IsProvidedMethod + "p3_field::packed::PackedField" + "packed_shifted_powers" + packed_shifted_powers. + Definition packed_linear_combination + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ N ], [], [ coeffs; vecs ] => + ltac:(M.monadic + (let coeffs := M.alloc (| coeffs |) in + let vecs := M.alloc (| vecs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + Self + "Scalar" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| coeffs |) |) |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Self ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| vecs |) |) |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ combined : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ N ] [ Self ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ Self ], + M.get_function (| + "core::array::from_fn", + [ N ], + [ Self; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] Self ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] Self ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Self, + M.get_trait_method (| + "core::ops::arith::Mul", + Self, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + Self + "Scalar" + ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| vecs |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| coeffs |) |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Self, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Self, + [], + [], + "sum_array", + [ N ], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, combined |) |) + |)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_packed_linear_combination : + M.IsProvidedMethod + "p3_field::packed::PackedField" + "packed_linear_combination" + packed_linear_combination. + End PackedField. + + (* Trait *) + (* Empty module 'PackedFieldPow2' *) + + (* Trait *) + Module PackedFieldExtension. + Definition to_ext_iter + (BaseField ExtField Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ impl_IntoIterator_Item___Self_ ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + impl_IntoIterator_Item___Self_ + "IntoIter"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ ExtField; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ Self ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ ExtField; Ty.path "alloc::alloc::Global" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + impl_IntoIterator_Item___Self_ + "IntoIter", + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ ExtField; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ Self ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ ExtField; Ty.path "alloc::alloc::Global" ]) + ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + impl_IntoIterator_Item___Self_ + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + impl_IntoIterator_Item___Self_, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| iter |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Self ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ ExtField; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.read (| + let~ packed_coeffs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + BaseField + "Packing" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + BaseField + "Packing" + ] + ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + Self, + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + BaseField + "Packing" + ], + "as_basis_coefficients_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ ExtField; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] ExtField + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ ExtField; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] ExtField + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + ExtField; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] ExtField + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + ExtField + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + ExtField, + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + ExtField, + [], + [ BaseField ], + "from_basis_coefficients_fn", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] + ] + BaseField + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + BaseField + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := + M.copy (| + γ + |) in + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + BaseField + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + BaseField + "Packing", + [], + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + packed_coeffs + |) + |), + M.read (| + j + |) + |) + |) + ] + |) + |), + M.read (| + i + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_to_ext_iter : + forall (BaseField ExtField : Ty.t), + M.IsProvidedMethod + "p3_field::packed::PackedFieldExtension" + "to_ext_iter" + (to_ext_iter BaseField ExtField). + Definition packed_ext_powers_capped + (BaseField ExtField Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ base; unpacked_len ] => + ltac:(M.monadic + (let base := M.alloc (| base |) in + let unpacked_len := M.alloc (| unpacked_len |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ Self ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ Self ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ Self ], + M.get_trait_method (| + "p3_field::packed::PackedFieldExtension", + Self, + [], + [ BaseField; ExtField ], + "packed_ext_powers", + [], + [] + |), + [ M.read (| base |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "div_ceil", [], [] |), + [ + M.read (| unpacked_len |); + M.read (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_packed_ext_powers_capped : + forall (BaseField ExtField : Ty.t), + M.IsProvidedMethod + "p3_field::packed::PackedFieldExtension" + "packed_ext_powers_capped" + (packed_ext_powers_capped BaseField ExtField). + End PackedFieldExtension. + + Module Impl_p3_field_packed_PackedValue_where_p3_field_packed_Packable_T_for_T. + Definition Self (T : Ty.t) : Ty.t := T. + + (* type Value = Self; *) + Definition _Value (T : Ty.t) : Ty.t := T. + + (* const WIDTH: usize = 1; *) + (* Ty.path "usize" *) + Definition value_WIDTH (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 1 |))). + + (* + fn from_slice(slice: &[Self::Value]) -> &Self { + &slice[0] + } + *) + Definition from_slice (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| slice |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_slice_mut(slice: &mut [Self::Value]) -> &mut Self { + &mut slice[0] + } + *) + Definition from_slice_mut + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| slice |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_fn(mut f: Fn) -> Self + where + Fn: FnMut(usize) -> Self::Value, + { + f(0) + } + *) + Definition from_fn (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [ Fn ], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.call_closure (| + T, + M.get_trait_method (| + "core::ops::function::FnMut", + Fn, + [], + [ Ty.tuple [ Ty.path "usize" ] ], + "call_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, f |); + Value.Tuple [ Value.Integer IntegerKind.Usize 0 ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn as_slice(&self) -> &[Self::Value] { + slice::from_ref(self) + } + *) + Definition as_slice (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_function (| "core::slice::raw::from_ref", [], [ T ] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn as_slice_mut(&mut self) -> &mut [Self::Value] { + slice::from_mut(self) + } + *) + Definition as_slice_mut (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_function (| "core::slice::raw::from_mut", [], [ T ] |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "p3_field::packed::PackedValue" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) + [ + ("Value", InstanceField.Ty (_Value T)); + ("value_WIDTH", InstanceField.Method (value_WIDTH T)); + ("from_slice", InstanceField.Method (from_slice T)); + ("from_slice_mut", InstanceField.Method (from_slice_mut T)); + ("from_fn", InstanceField.Method (from_fn T)); + ("as_slice", InstanceField.Method (as_slice T)); + ("as_slice_mut", InstanceField.Method (as_slice_mut T)) + ]. + End Impl_p3_field_packed_PackedValue_where_p3_field_packed_Packable_T_for_T. + + Module Impl_p3_field_packed_PackedField_where_p3_field_field_Field_F_for_F. + Definition Self (F : Ty.t) : Ty.t := F. + + (* type Scalar = Self; *) + Definition _Scalar (F : Ty.t) : Ty.t := F. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_field::packed::PackedField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("Scalar", InstanceField.Ty (_Scalar F)) ]. + End Impl_p3_field_packed_PackedField_where_p3_field_field_Field_F_for_F. + + Module Impl_p3_field_packed_PackedFieldPow2_where_p3_field_field_Field_F_for_F. + Definition Self (F : Ty.t) : Ty.t := F. + + (* + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { + match block_len { + 1 => ( *self, other), + _ => panic!("unsupported block length"), + } + } + *) + Definition interleave (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; other; block_len ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + let block_len := M.alloc (| block_len |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [ F; F ] ], + block_len, + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 1 + |) in + M.alloc (| + Value.Tuple + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| other |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ mk_str (| "unsupported block length" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_field::packed::PackedFieldPow2" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("interleave", InstanceField.Method (interleave F)) ]. + End Impl_p3_field_packed_PackedFieldPow2_where_p3_field_field_Field_F_for_F. + + Module Impl_p3_field_packed_PackedFieldExtension_where_p3_field_field_Field_F_F_F_for_associated_in_trait_p3_field_field_Field___F_Packing. + Definition Self (F : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing". + + (* + fn from_ext_slice(ext_slice: &[F]) -> Self { + ext_slice[0].into() + } + *) + Definition from_ext_slice + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ ext_slice ] => + ltac:(M.monadic + (let ext_slice := M.alloc (| ext_slice |) in + M.call_closure (| + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing", + M.get_trait_method (| + "core::convert::Into", + F, + [], + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| ext_slice |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn packed_ext_powers(base: F) -> Powers { + F::Packing::packed_powers(base) + } + *) + Definition packed_ext_powers + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ base ] => + ltac:(M.monadic + (let base := M.alloc (| base |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing" ], + M.get_trait_method (| + "p3_field::packed::PackedField", + Ty.associated_in_trait "p3_field::field::Field" [] [] F "Packing", + [], + [], + "packed_powers", + [], + [] + |), + [ M.read (| base |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_field::packed::PackedFieldExtension" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F; F ] + (Self F) + (* Instance *) + [ + ("from_ext_slice", InstanceField.Method (from_ext_slice F)); + ("packed_ext_powers", InstanceField.Method (packed_ext_powers F)) + ]. + End Impl_p3_field_packed_PackedFieldExtension_where_p3_field_field_Field_F_F_F_for_associated_in_trait_p3_field_field_Field___F_Packing. + + Module Impl_p3_field_packed_Packable_for_u8. + Definition Self : Ty.t := Ty.path "u8". + + Axiom Implements : + M.IsTraitInstance + "p3_field::packed::Packable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_field_packed_Packable_for_u8. + + Module Impl_p3_field_packed_Packable_for_u16. + Definition Self : Ty.t := Ty.path "u16". + + Axiom Implements : + M.IsTraitInstance + "p3_field::packed::Packable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_field_packed_Packable_for_u16. + + Module Impl_p3_field_packed_Packable_for_u32. + Definition Self : Ty.t := Ty.path "u32". + + Axiom Implements : + M.IsTraitInstance + "p3_field::packed::Packable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_field_packed_Packable_for_u32. + + Module Impl_p3_field_packed_Packable_for_u64. + Definition Self : Ty.t := Ty.path "u64". + + Axiom Implements : + M.IsTraitInstance + "p3_field::packed::Packable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_field_packed_Packable_for_u64. + + Module Impl_p3_field_packed_Packable_for_u128. + Definition Self : Ty.t := Ty.path "u128". + + Axiom Implements : + M.IsTraitInstance + "p3_field::packed::Packable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_field_packed_Packable_for_u128. +End packed. diff --git a/CoqOfRust/plonky3/fri/src/config.rs b/CoqOfRust/plonky3/fri/src/config.rs new file mode 100644 index 000000000..154c28bcd --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/config.rs @@ -0,0 +1,86 @@ +use alloc::vec::Vec; +use core::fmt::Debug; + +use p3_field::Field; +use p3_matrix::Matrix; + +#[derive(Debug)] +pub struct FriConfig { + pub log_blowup: usize, + // TODO: This parameter and FRI early stopping are not yet implemented in `CirclePcs`. + pub log_final_poly_len: usize, + pub num_queries: usize, + pub proof_of_work_bits: usize, + pub mmcs: M, +} + +impl FriConfig { + pub const fn blowup(&self) -> usize { + 1 << self.log_blowup + } + + pub const fn final_poly_len(&self) -> usize { + 1 << self.log_final_poly_len + } + + /// Returns the soundness bits of this FRI instance based on the + /// [ethSTARK](https://eprint.iacr.org/2021/582) conjecture. + /// + /// Certain users may instead want to look at proven soundness, a more complex calculation which + /// isn't currently supported by this crate. + pub const fn conjectured_soundness_bits(&self) -> usize { + self.log_blowup * self.num_queries + self.proof_of_work_bits + } +} + +/// Whereas `FriConfig` encompasses parameters the end user can set, `FriGenericConfig` is +/// set by the PCS calling FRI, and abstracts over implementation details of the PCS. +pub trait FriGenericConfig { + type InputProof; + type InputError: Debug; + + /// We can ask FRI to sample extra query bits (LSB) for our own purposes. + /// They will be passed to our callbacks, but ignored (shifted off) by FRI. + fn extra_query_index_bits(&self) -> usize; + + /// Fold a row, returning a single column. + /// Right now the input row will always be 2 columns wide, + /// but we may support higher folding arity in the future. + fn fold_row( + &self, + index: usize, + log_height: usize, + beta: F, + evals: impl Iterator, + ) -> F; + + /// Same as applying fold_row to every row, possibly faster. + fn fold_matrix>(&self, beta: F, m: M) -> Vec; +} + +/// Creates a minimal `FriConfig` for testing purposes. +/// This configuration is designed to reduce computational cost during tests. +pub const fn create_test_fri_config( + mmcs: Mmcs, + log_final_poly_len: usize, +) -> FriConfig { + FriConfig { + log_blowup: 2, + log_final_poly_len, + num_queries: 2, + proof_of_work_bits: 1, + mmcs, + } +} + +/// Creates a `FriConfig` suitable for benchmarking. +/// This configuration represents typical settings used in production-like scenarios. +pub const fn create_benchmark_fri_config(mmcs: Mmcs) -> FriConfig { + FriConfig { + log_blowup: 1, + log_final_poly_len: 0, + num_queries: 100, + proof_of_work_bits: 16, + mmcs, + } +} diff --git a/CoqOfRust/plonky3/fri/src/config.v b/CoqOfRust/plonky3/fri/src/config.v new file mode 100644 index 000000000..d24e4f95d --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/config.v @@ -0,0 +1,359 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module config. + (* StructRecord + { + name := "FriConfig"; + const_params := []; + ty_params := [ "M_" ]; + fields := + [ + ("log_blowup", Ty.path "usize"); + ("log_final_poly_len", Ty.path "usize"); + ("num_queries", Ty.path "usize"); + ("proof_of_work_bits", Ty.path "usize"); + ("mmcs", M_) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_M__for_p3_fri_config_FriConfig_M_. + Definition Self (M_ : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_fri::config::FriConfig") [] [ M_ ]. + + (* Debug *) + Definition fmt (M_ : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self M_ in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field5_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "FriConfig" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "log_blowup" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "log_final_poly_len" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::config::FriConfig", + "log_final_poly_len" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "num_queries" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::config::FriConfig", + "num_queries" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "proof_of_work_bits" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::config::FriConfig", + "proof_of_work_bits" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "mmcs" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (M_ : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self M_) + (* Instance *) [ ("fmt", InstanceField.Method (fmt M_)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_M__for_p3_fri_config_FriConfig_M_. + + Module Impl_p3_fri_config_FriConfig_M_. + Definition Self (M_ : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_fri::config::FriConfig") [] [ M_ ]. + + (* + pub const fn blowup(&self) -> usize { + 1 << self.log_blowup + } + *) + Definition blowup (M_ : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_blowup : + forall (M_ : Ty.t), + M.IsAssociatedFunction.C (Self M_) "blowup" (blowup M_). + Admitted. + Global Typeclasses Opaque blowup. + + (* + pub const fn final_poly_len(&self) -> usize { + 1 << self.log_final_poly_len + } + *) + Definition final_poly_len + (M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::config::FriConfig", + "log_final_poly_len" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_final_poly_len : + forall (M_ : Ty.t), + M.IsAssociatedFunction.C (Self M_) "final_poly_len" (final_poly_len M_). + Admitted. + Global Typeclasses Opaque final_poly_len. + + (* + pub const fn conjectured_soundness_bits(&self) -> usize { + self.log_blowup * self.num_queries + self.proof_of_work_bits + } + *) + Definition conjectured_soundness_bits + (M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::config::FriConfig", + "num_queries" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::config::FriConfig", + "proof_of_work_bits" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_conjectured_soundness_bits : + forall (M_ : Ty.t), + M.IsAssociatedFunction.C + (Self M_) + "conjectured_soundness_bits" + (conjectured_soundness_bits M_). + Admitted. + Global Typeclasses Opaque conjectured_soundness_bits. + End Impl_p3_fri_config_FriConfig_M_. + + (* Trait *) + (* Empty module 'FriGenericConfig' *) + + (* + pub const fn create_test_fri_config( + mmcs: Mmcs, + log_final_poly_len: usize, + ) -> FriConfig { + FriConfig { + log_blowup: 2, + log_final_poly_len, + num_queries: 2, + proof_of_work_bits: 1, + mmcs, + } + } + *) + Definition create_test_fri_config (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ Mmcs ], [ mmcs; log_final_poly_len ] => + ltac:(M.monadic + (let mmcs := M.alloc (| mmcs |) in + let log_final_poly_len := M.alloc (| log_final_poly_len |) in + Value.StructRecord + "p3_fri::config::FriConfig" + [ + ("log_blowup", Value.Integer IntegerKind.Usize 2); + ("log_final_poly_len", M.read (| log_final_poly_len |)); + ("num_queries", Value.Integer IntegerKind.Usize 2); + ("proof_of_work_bits", Value.Integer IntegerKind.Usize 1); + ("mmcs", M.read (| mmcs |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_create_test_fri_config : + M.IsFunction.C "p3_fri::config::create_test_fri_config" create_test_fri_config. + Admitted. + Global Typeclasses Opaque create_test_fri_config. + + (* + pub const fn create_benchmark_fri_config(mmcs: Mmcs) -> FriConfig { + FriConfig { + log_blowup: 1, + log_final_poly_len: 0, + num_queries: 100, + proof_of_work_bits: 16, + mmcs, + } + } + *) + Definition create_benchmark_fri_config + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ Mmcs ], [ mmcs ] => + ltac:(M.monadic + (let mmcs := M.alloc (| mmcs |) in + Value.StructRecord + "p3_fri::config::FriConfig" + [ + ("log_blowup", Value.Integer IntegerKind.Usize 1); + ("log_final_poly_len", Value.Integer IntegerKind.Usize 0); + ("num_queries", Value.Integer IntegerKind.Usize 100); + ("proof_of_work_bits", Value.Integer IntegerKind.Usize 16); + ("mmcs", M.read (| mmcs |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_create_benchmark_fri_config : + M.IsFunction.C "p3_fri::config::create_benchmark_fri_config" create_benchmark_fri_config. + Admitted. + Global Typeclasses Opaque create_benchmark_fri_config. +End config. diff --git a/CoqOfRust/plonky3/fri/src/fold_even_odd.rs b/CoqOfRust/plonky3/fri/src/fold_even_odd.rs new file mode 100644 index 000000000..2fc9b7320 --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/fold_even_odd.rs @@ -0,0 +1,97 @@ +use alloc::vec::Vec; + +use itertools::Itertools; +use p3_field::TwoAdicField; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_maybe_rayon::prelude::*; +use p3_util::{log2_strict_usize, reverse_slice_index_bits}; +use tracing::instrument; + +/// Fold a polynomial +/// ```ignore +/// p(x) = p_even(x^2) + x p_odd(x^2) +/// ``` +/// into +/// ```ignore +/// p_even(x) + beta p_odd(x) +/// ``` +/// Expects input to be bit-reversed evaluations. +#[instrument(skip_all, level = "debug")] +pub fn fold_even_odd(poly: Vec, beta: F) -> Vec { + // We use the fact that + // p_e(x^2) = (p(x) + p(-x)) / 2 + // p_o(x^2) = (p(x) - p(-x)) / (2 x) + // that is, + // p_e(g^(2i)) = (p(g^i) + p(g^(n/2 + i))) / 2 + // p_o(g^(2i)) = (p(g^i) - p(g^(n/2 + i))) / (2 g^i) + // so + // result(g^(2i)) = p_e(g^(2i)) + beta p_o(g^(2i)) + // = (1/2 + beta/2 g_inv^i) p(g^i) + // + (1/2 - beta/2 g_inv^i) p(g^(n/2 + i)) + let m = RowMajorMatrix::new(poly, 2); + let g_inv = F::two_adic_generator(log2_strict_usize(m.height()) + 1).inverse(); + let one_half = F::ONE.halve(); + let half_beta = beta * one_half; + + // TODO: vectorize this (after we have packed extension fields) + + // beta/2 times successive powers of g_inv + let mut powers = g_inv + .shifted_powers(half_beta) + .take(m.height()) + .collect_vec(); + reverse_slice_index_bits(&mut powers); + + m.par_rows() + .zip(powers) + .map(|(mut row, power)| { + let (r0, r1) = row.next_tuple().unwrap(); + (one_half + power) * r0 + (one_half - power) * r1 + }) + .collect() +} + +#[cfg(test)] +mod tests { + use itertools::izip; + use p3_baby_bear::BabyBear; + use p3_dft::{Radix2Dit, TwoAdicSubgroupDft}; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + + #[test] + fn test_fold_even_odd() { + type F = BabyBear; + + let mut rng = SmallRng::seed_from_u64(1); + + let log_n = 10; + let n = 1 << log_n; + let coeffs = (0..n).map(|_| rng.random::()).collect::>(); + + let dft = Radix2Dit::default(); + let evals = dft.dft(coeffs.clone()); + + let even_coeffs = coeffs.iter().copied().step_by(2).collect_vec(); + let even_evals = dft.dft(even_coeffs); + + let odd_coeffs = coeffs.iter().copied().skip(1).step_by(2).collect_vec(); + let odd_evals = dft.dft(odd_coeffs); + + let beta = rng.random::(); + let expected = izip!(even_evals, odd_evals) + .map(|(even, odd)| even + beta * odd) + .collect::>(); + + // fold_even_odd takes and returns in bitrev order. + let mut folded = evals; + reverse_slice_index_bits(&mut folded); + folded = fold_even_odd(folded, beta); + reverse_slice_index_bits(&mut folded); + + assert_eq!(expected, folded); + } +} diff --git a/CoqOfRust/plonky3/fri/src/fold_even_odd.v b/CoqOfRust/plonky3/fri/src/fold_even_odd.v new file mode 100644 index 000000000..a811a2959 --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/fold_even_odd.v @@ -0,0 +1,1217 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module fold_even_odd. + (* #[instrument(skip_all, level = "debug")] *) + Definition fold_even_odd (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ poly; beta ] => + ltac:(M.monadic + (let poly := M.alloc (| poly |) in + let beta := M.alloc (| beta |) in + M.catch_return + (Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::fold_even_odd::fold_even_odd::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::fold_even_odd::fold_even_odd::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::fold_even_odd::fold_even_odd::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::fold_even_odd::fold_even_odd::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ m : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| poly |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ g_inv : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, m |) ] + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |) + ] + |) + |) in + let~ one_half : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "halve", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) + |) + ] + |) + |) in + let~ half_beta : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| beta |); M.read (| one_half |) ] + |) + |) in + let~ powers : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "shifted_powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, g_inv |); M.read (| half_beta |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, m |) ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, powers |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ]; + F + ] + ] + ] + F + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ]; + F + ] + ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ]; + F + ] + ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_unknown; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "par_rows", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, m |) ] + |); + M.read (| powers |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ]; + F + ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let row := M.copy (| γ0_0 |) in + let power := M.copy (| γ0_1 |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ F ], + M.alloc (| + M.call_closure (| + Ty.tuple [ F; F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ F; F ] ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ F; F ] ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "next_tuple", + [], + [ Ty.tuple [ F; F ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, row |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let r0 := M.copy (| γ0_0 |) in + let r1 := M.copy (| γ0_1 |) in + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.read (| one_half |); + M.read (| power |) + ] + |); + M.read (| r0 |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.read (| one_half |); + M.read (| power |) + ] + |); + M.read (| r1 |) + ] + |) + ] + |) + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_fold_even_odd : + M.IsFunction.C "p3_fri::fold_even_odd::fold_even_odd" fold_even_odd. + Admitted. + Global Typeclasses Opaque fold_even_odd. +End fold_even_odd. diff --git a/CoqOfRust/plonky3/fri/src/hiding_pcs.rs b/CoqOfRust/plonky3/fri/src/hiding_pcs.rs new file mode 100644 index 000000000..4a2dff77f --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/hiding_pcs.rs @@ -0,0 +1,228 @@ +use alloc::vec::Vec; +use core::cell::RefCell; +use core::fmt::Debug; + +use p3_challenger::{CanObserve, FieldChallenger, GrindingChallenger}; +use p3_commit::{Mmcs, OpenedValues, Pcs}; +use p3_dft::TwoAdicSubgroupDft; +use p3_field::coset::TwoAdicMultiplicativeCoset; +use p3_field::{ExtensionField, Field, TwoAdicField}; +use p3_matrix::Matrix; +use p3_matrix::bitrev::BitReversalPerm; +use p3_matrix::dense::{DenseMatrix, RowMajorMatrix}; +use p3_matrix::horizontally_truncated::HorizontallyTruncated; +use p3_matrix::row_index_mapped::RowIndexMappedView; +use p3_util::zip_eq::zip_eq; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; +use tracing::instrument; + +use crate::verifier::FriError; +use crate::{BatchOpening, FriConfig, FriProof, TwoAdicFriPcs}; + +/// A hiding FRI PCS. Both MMCSs must also be hiding; this is not enforced at compile time so it's +/// the user's responsibility to configure. +#[derive(Debug)] +pub struct HidingFriPcs { + inner: TwoAdicFriPcs, + num_random_codewords: usize, + rng: RefCell, +} + +impl HidingFriPcs { + pub fn new( + dft: Dft, + mmcs: InputMmcs, + fri: FriConfig, + num_random_codewords: usize, + rng: R, + ) -> Self { + let inner = TwoAdicFriPcs::new(dft, mmcs, fri); + Self { + inner, + num_random_codewords, + rng: rng.into(), + } + } +} + +impl Pcs + for HidingFriPcs +where + Val: TwoAdicField, + StandardUniform: Distribution, + Dft: TwoAdicSubgroupDft, + InputMmcs: Mmcs, + FriMmcs: Mmcs, + Challenge: TwoAdicField + ExtensionField, + Challenger: + FieldChallenger + CanObserve + GrindingChallenger, + R: Rng + Send + Sync, +{ + type Domain = TwoAdicMultiplicativeCoset; + type Commitment = InputMmcs::Commitment; + type ProverData = InputMmcs::ProverData>; + type EvaluationsOnDomain<'a> = HorizontallyTruncated< + Val, + RowIndexMappedView>, + >; + /// The first item contains the openings of the random polynomials added by this wrapper. + /// The second item is the usual FRI proof. + type Proof = ( + OpenedValues, + FriProof>>, + ); + type Error = FriError; + + fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain { + as Pcs>::natural_domain_for_degree( + &self.inner, degree) + } + + fn commit( + &self, + evaluations: Vec<(Self::Domain, RowMajorMatrix)>, + ) -> (Self::Commitment, Self::ProverData) { + let randomized_evaluations = evaluations + .into_iter() + .map(|(domain, mat)| { + ( + domain, + add_random_cols(mat, self.num_random_codewords, &mut *self.rng.borrow_mut()), + ) + }) + .collect(); + as Pcs>::commit( + &self.inner, + randomized_evaluations, + ) + } + + fn get_evaluations_on_domain<'a>( + &self, + prover_data: &'a Self::ProverData, + idx: usize, + domain: Self::Domain, + ) -> Self::EvaluationsOnDomain<'a> { + let inner_evals = as Pcs< + Challenge, + Challenger, + >>::get_evaluations_on_domain( + &self.inner, prover_data, idx, domain + ); + let inner_width = inner_evals.width(); + // Truncate off the columns representing random codewords we added in `commit` above. + HorizontallyTruncated::new(inner_evals, inner_width - self.num_random_codewords) + } + + fn open( + &self, + // For each round, + rounds: Vec<( + &Self::ProverData, + // for each matrix, + Vec< + // points to open + Vec, + >, + )>, + challenger: &mut Challenger, + ) -> (OpenedValues, Self::Proof) { + let (mut inner_opened_values, inner_proof) = self.inner.open(rounds, challenger); + + // inner_opened_values includes opened values for the random codewords. Those should be + // hidden from our caller, so we split them off and store them in the proof. + let opened_values_rand = inner_opened_values + .iter_mut() + .map(|opened_values_for_round| { + opened_values_for_round + .iter_mut() + .map(|opened_values_for_mat| { + opened_values_for_mat + .iter_mut() + .map(|opened_values_for_point| { + let split = + opened_values_for_point.len() - self.num_random_codewords; + opened_values_for_point.drain(split..).collect() + }) + .collect() + }) + .collect() + }) + .collect(); + + (inner_opened_values, (opened_values_rand, inner_proof)) + } + + fn verify( + &self, + // For each round: + mut rounds: Vec<( + Self::Commitment, + // for each matrix: + Vec<( + // its domain, + Self::Domain, + // for each point: + Vec<( + // the point, + Challenge, + // values at the point + Vec, + )>, + )>, + )>, + proof: &Self::Proof, + challenger: &mut Challenger, + ) -> Result<(), Self::Error> { + let (opened_values_for_rand_cws, inner_proof) = proof; + // Now we merge `opened_values_for_rand_cws` into the opened values in `rounds`, undoing + // the split that we did in `open`, to get a complete set of opened values for the inner PCS + // to check. + for (round, rand_round) in zip_eq( + rounds.iter_mut(), + opened_values_for_rand_cws, + FriError::InvalidProofShape, + )? { + for (mat, rand_mat) in + zip_eq(round.1.iter_mut(), rand_round, FriError::InvalidProofShape)? + { + for (point, rand_point) in + zip_eq(mat.1.iter_mut(), rand_mat, FriError::InvalidProofShape)? + { + point.1.extend(rand_point); + } + } + } + self.inner.verify(rounds, inner_proof, challenger) + } +} + +#[instrument(level = "debug", skip_all)] +fn add_random_cols( + mat: RowMajorMatrix, + num_random_codewords: usize, + mut rng: R, +) -> RowMajorMatrix +where + Val: Field, + R: Rng + Send + Sync, + StandardUniform: Distribution, +{ + let old_w = mat.width(); + let new_w = old_w + num_random_codewords; + let h = mat.height(); + + let new_values = Val::zero_vec(new_w * h); + let mut result = RowMajorMatrix::new(new_values, new_w); + // Can be parallelized by adding par_, but there are some complications with the RNG. + // We could just use rng(), but ideally we want to keep it generic... + result + .rows_mut() + .zip(mat.row_slices()) + .for_each(|(new_row, old_row)| { + new_row[..old_w].copy_from_slice(old_row); + new_row[old_w..].iter_mut().for_each(|v| *v = rng.random()); + }); + result +} diff --git a/CoqOfRust/plonky3/fri/src/hiding_pcs.v b/CoqOfRust/plonky3/fri/src/hiding_pcs.v new file mode 100644 index 000000000..83576025b --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/hiding_pcs.v @@ -0,0 +1,7753 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module hiding_pcs. + (* StructRecord + { + name := "HidingFriPcs"; + const_params := []; + ty_params := [ "Val"; "Dft"; "InputMmcs"; "FriMmcs"; "R" ]; + fields := + [ + ("inner", + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs ]); + ("num_random_codewords", Ty.path "usize"); + ("rng", Ty.apply (Ty.path "core::cell::RefCell") [] [ R ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Val_where_core_fmt_Debug_Dft_where_core_fmt_Debug_InputMmcs_where_core_fmt_Debug_FriMmcs_where_core_fmt_Debug_R_for_p3_fri_hiding_pcs_HidingFriPcs_Val_Dft_InputMmcs_FriMmcs_R. + Definition Self (Val Dft InputMmcs FriMmcs R : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::hiding_pcs::HidingFriPcs") [] [ Val; Dft; InputMmcs; FriMmcs; R ]. + + (* Debug *) + Definition fmt + (Val Dft InputMmcs FriMmcs R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs R in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "HidingFriPcs" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inner" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::hiding_pcs::HidingFriPcs", + "inner" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "num_random_codewords" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::hiding_pcs::HidingFriPcs", + "num_random_codewords" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "rng" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::hiding_pcs::HidingFriPcs", + "rng" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Dft InputMmcs FriMmcs R : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val Dft InputMmcs FriMmcs R) + (* Instance *) [ ("fmt", InstanceField.Method (fmt Val Dft InputMmcs FriMmcs R)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Val_where_core_fmt_Debug_Dft_where_core_fmt_Debug_InputMmcs_where_core_fmt_Debug_FriMmcs_where_core_fmt_Debug_R_for_p3_fri_hiding_pcs_HidingFriPcs_Val_Dft_InputMmcs_FriMmcs_R. + + Module Impl_p3_fri_hiding_pcs_HidingFriPcs_Val_Dft_InputMmcs_FriMmcs_R. + Definition Self (Val Dft InputMmcs FriMmcs R : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::hiding_pcs::HidingFriPcs") [] [ Val; Dft; InputMmcs; FriMmcs; R ]. + + (* + pub fn new( + dft: Dft, + mmcs: InputMmcs, + fri: FriConfig, + num_random_codewords: usize, + rng: R, + ) -> Self { + let inner = TwoAdicFriPcs::new(dft, mmcs, fri); + Self { + inner, + num_random_codewords, + rng: rng.into(), + } + } + *) + Definition new + (Val Dft InputMmcs FriMmcs R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs R in + match ε, τ, α with + | [], [], [ dft; mmcs; fri; num_random_codewords; rng ] => + ltac:(M.monadic + (let dft := M.alloc (| dft |) in + let mmcs := M.alloc (| mmcs |) in + let fri := M.alloc (| fri |) in + let num_random_codewords := M.alloc (| num_random_codewords |) in + let rng := M.alloc (| rng |) in + M.read (| + let~ inner : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs ], + "new", + [], + [] + |), + [ M.read (| dft |); M.read (| mmcs |); M.read (| fri |) ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_fri::hiding_pcs::HidingFriPcs" + [ + ("inner", M.read (| inner |)); + ("num_random_codewords", M.read (| num_random_codewords |)); + ("rng", + M.call_closure (| + Ty.apply (Ty.path "core::cell::RefCell") [] [ R ], + M.get_trait_method (| + "core::convert::Into", + R, + [], + [ Ty.apply (Ty.path "core::cell::RefCell") [] [ R ] ], + "into", + [], + [] + |), + [ M.read (| rng |) ] + |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (Val Dft InputMmcs FriMmcs R : Ty.t), + M.IsAssociatedFunction.C + (Self Val Dft InputMmcs FriMmcs R) + "new" + (new Val Dft InputMmcs FriMmcs R). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_fri_hiding_pcs_HidingFriPcs_Val_Dft_InputMmcs_FriMmcs_R. + + Module Impl_p3_commit_pcs_Pcs_where_p3_field_field_TwoAdicField_Val_where_rand_distr_distribution_Distribution_rand_distr_StandardUniform_Val_where_p3_dft_traits_TwoAdicSubgroupDft_Dft_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_p3_field_field_TwoAdicField_Challenge_where_p3_field_field_ExtensionField_Challenge_Val_where_p3_challenger_FieldChallenger_Challenger_Val_where_p3_challenger_CanObserve_Challenger_associated_in_trait_p3_commit_mmcs_Mmcs__Challenge_FriMmcs_Commitment_where_p3_challenger_grinding_challenger_GrindingChallenger_Challenger_where_rand_rng_Rng_R_where_core_marker_Send_R_where_core_marker_Sync_R_Challenge_Challenger_for_p3_fri_hiding_pcs_HidingFriPcs_Val_Dft_InputMmcs_FriMmcs_R. + Definition Self (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::hiding_pcs::HidingFriPcs") [] [ Val; Dft; InputMmcs; FriMmcs; R ]. + + (* type Domain = TwoAdicMultiplicativeCoset; *) + Definition _Domain (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ]. + + (* type Commitment = InputMmcs::Commitment; *) + Definition _Commitment (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Commitment". + + (* type ProverData = InputMmcs::ProverData>; *) + Definition _ProverData (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ] ] + ] + InputMmcs + "ProverData". + + (* + type EvaluationsOnDomain<'a> = HorizontallyTruncated< + Val, + RowIndexMappedView>, + >; + *) + Definition _EvaluationsOnDomain + (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_matrix::horizontally_truncated::HorizontallyTruncated") + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] ] + ] + ]. + + (* + type Proof = ( + OpenedValues, + FriProof>>, + ); + *) + Definition _Proof (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) : Ty.t := + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::proof::FriProof") + [] + [ + Challenge; + FriMmcs; + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::two_adic_pcs::BatchOpening") [] [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]. + + (* type Error = FriError; *) + Definition _Error (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] FriMmcs "Error"; + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Error" + ]. + + (* + fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain { + as Pcs>::natural_domain_for_degree( + &self.inner, degree) + } + *) + Definition natural_domain_for_degree + (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs Challenge Challenger R in + match ε, τ, α with + | [], [], [ self; degree ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let degree := M.alloc (| degree |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs ], + [], + [ Challenge; Challenger ], + "natural_domain_for_degree", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::hiding_pcs::HidingFriPcs", + "inner" + |) + |) + |) + |); + M.read (| degree |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn commit( + &self, + evaluations: Vec<(Self::Domain, RowMajorMatrix)>, + ) -> (Self::Commitment, Self::ProverData) { + let randomized_evaluations = evaluations + .into_iter() + .map(|(domain, mat)| { + ( + domain, + add_random_cols(mat, self.num_random_codewords, &mut *self.rng.borrow_mut()), + ) + }) + .collect(); + as Pcs>::commit( + &self.inner, + randomized_evaluations, + ) + } + *) + Definition commit + (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs Challenge Challenger R in + match ε, τ, α with + | [], [], [ self; evaluations ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let evaluations := M.alloc (| evaluations |) in + M.read (| + let~ randomized_evaluations : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| evaluations |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let domain := M.copy (| γ0_0 |) in + let mat := M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| domain |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + M.get_function (| + "p3_fri::hiding_pcs::add_random_cols", + [], + [ Val; Ty.apply (Ty.path "&mut") [] [ R ] ] + |), + [ + M.read (| mat |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::hiding_pcs::HidingFriPcs", + "num_random_codewords" + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ R ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ R ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ R ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ R ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_fri::hiding_pcs::HidingFriPcs", + "rng" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ], + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs ], + [], + [ Challenge; Challenger ], + "commit", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::hiding_pcs::HidingFriPcs", + "inner" + |) + |) + |) + |); + M.read (| randomized_evaluations |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn get_evaluations_on_domain<'a>( + &self, + prover_data: &'a Self::ProverData, + idx: usize, + domain: Self::Domain, + ) -> Self::EvaluationsOnDomain<'a> { + let inner_evals = as Pcs< + Challenge, + Challenger, + >>::get_evaluations_on_domain( + &self.inner, prover_data, idx, domain + ); + let inner_width = inner_evals.width(); + // Truncate off the columns representing random codewords we added in `commit` above. + HorizontallyTruncated::new(inner_evals, inner_width - self.num_random_codewords) + } + *) + Definition get_evaluations_on_domain + (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs Challenge Challenger R in + match ε, τ, α with + | [], [], [ self; prover_data; idx; domain ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let prover_data := M.alloc (| prover_data |) in + let idx := M.alloc (| idx |) in + let domain := M.alloc (| domain |) in + M.read (| + let~ inner_evals : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] ] + ], + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs ], + [], + [ Challenge; Challenger ], + "get_evaluations_on_domain", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::hiding_pcs::HidingFriPcs", + "inner" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| prover_data |) |) |); + M.read (| idx |); + M.read (| domain |) + ] + |) + |) in + let~ inner_width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ], + [], + [ Val ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inner_evals |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::horizontally_truncated::HorizontallyTruncated") + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::horizontally_truncated::HorizontallyTruncated") + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ], + "new", + [], + [] + |), + [ + M.read (| inner_evals |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| inner_width |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::hiding_pcs::HidingFriPcs", + "num_random_codewords" + |) + |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn open( + &self, + // For each round, + rounds: Vec<( + &Self::ProverData, + // for each matrix, + Vec< + // points to open + Vec, + >, + )>, + challenger: &mut Challenger, + ) -> (OpenedValues, Self::Proof) { + let (mut inner_opened_values, inner_proof) = self.inner.open(rounds, challenger); + + // inner_opened_values includes opened values for the random codewords. Those should be + // hidden from our caller, so we split them off and store them in the proof. + let opened_values_rand = inner_opened_values + .iter_mut() + .map(|opened_values_for_round| { + opened_values_for_round + .iter_mut() + .map(|opened_values_for_mat| { + opened_values_for_mat + .iter_mut() + .map(|opened_values_for_point| { + let split = + opened_values_for_point.len() - self.num_random_codewords; + opened_values_for_point.drain(split..).collect() + }) + .collect() + }) + .collect() + }) + .collect(); + + (inner_opened_values, (opened_values_rand, inner_proof)) + } + *) + Definition open + (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs Challenge Challenger R in + match ε, τ, α with + | [], [], [ self; rounds; challenger ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rounds := M.alloc (| rounds |) in + let challenger := M.alloc (| challenger |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::proof::FriProof") + [] + [ + Challenge; + FriMmcs; + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::proof::FriProof") + [] + [ + Challenge; + FriMmcs; + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs ], + [], + [ Challenge; Challenger ], + "open", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::hiding_pcs::HidingFriPcs", + "inner" + |) + |); + M.read (| rounds |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let inner_opened_values := M.copy (| γ0_0 |) in + let inner_proof := M.copy (| γ0_1 |) in + let~ opened_values_rand : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, inner_opened_values |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let opened_values_for_round := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + opened_values_for_round + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let + opened_values_for_mat := + M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + opened_values_for_mat + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ + with + | [ α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + opened_values_for_point := + M.copy (| + γ + |) in + M.read (| + let~ + split : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path + "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + opened_values_for_point + |) + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_fri::hiding_pcs::HidingFriPcs", + "num_random_codewords" + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::drain::Drain") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::drain::Drain") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + "drain", + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ + Ty.path + "usize" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + opened_values_for_point + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.read (| + split + |)) + ] + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.read (| inner_opened_values |); + Value.Tuple [ M.read (| opened_values_rand |); M.read (| inner_proof |) ] + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn verify( + &self, + // For each round: + mut rounds: Vec<( + Self::Commitment, + // for each matrix: + Vec<( + // its domain, + Self::Domain, + // for each point: + Vec<( + // the point, + Challenge, + // values at the point + Vec, + )>, + )>, + )>, + proof: &Self::Proof, + challenger: &mut Challenger, + ) -> Result<(), Self::Error> { + let (opened_values_for_rand_cws, inner_proof) = proof; + // Now we merge `opened_values_for_rand_cws` into the opened values in `rounds`, undoing + // the split that we did in `open`, to get a complete set of opened values for the inner PCS + // to check. + for (round, rand_round) in zip_eq( + rounds.iter_mut(), + opened_values_for_rand_cws, + FriError::InvalidProofShape, + )? { + for (mat, rand_mat) in + zip_eq(round.1.iter_mut(), rand_round, FriError::InvalidProofShape)? + { + for (point, rand_point) in + zip_eq(mat.1.iter_mut(), rand_mat, FriError::InvalidProofShape)? + { + point.1.extend(rand_point); + } + } + } + self.inner.verify(rounds, inner_proof, challenger) + } + *) + Definition verify + (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs Challenge Challenger R in + match ε, τ, α with + | [], [], [ self; rounds; proof; challenger ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rounds := M.alloc (| rounds |) in + let proof := M.alloc (| proof |) in + let challenger := M.alloc (| challenger |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ Challenge; Challenger ] + (Ty.apply + (Ty.path "p3_fri::hiding_pcs::HidingFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs; R ]) + "Error" + ]) (| + ltac:(M.monadic + (M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ] + ], + proof, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let opened_values_for_rand_cws := M.alloc (| γ1_0 |) in + let inner_proof := M.alloc (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ]; + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rounds + |) + ] + |) + |) + |) + ] + |); + M.read (| opened_values_for_rand_cws |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let round := M.copy (| γ1_0 |) in + let rand_round := M.copy (| γ1_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_tuple_field (| + M.deref (| + M.read (| + round + |) + |), + 1 + |) + |) + ] + |) + |) + |) + ] + |); + M.read (| rand_round |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := + M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val + ] + InputMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := + M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let mat := + M.copy (| γ1_0 |) in + let rand_mat := + M.copy (| γ1_1 |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_tuple_field (| + M.deref (| + M.read (| + mat + |) + |), + 1 + |) + |) + ] + |) + |) + |) + ] + |); + M.read (| + rand_mat + |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let + residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let + val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| + γ + |) in + M.loop (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let + point := + M.copy (| + γ1_0 + |) in + let + rand_point := + M.copy (| + γ1_1 + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ], + "extend", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_tuple_field (| + M.deref (| + M.read (| + point + |) + |), + 1 + |) + |); + M.read (| + rand_point + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs ], + [], + [ Challenge; Challenger ], + "verify", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::hiding_pcs::HidingFriPcs", + "inner" + |) + |); + M.read (| rounds |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| inner_proof |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |) + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Dft InputMmcs FriMmcs Challenge Challenger R : Ty.t), + M.IsTraitInstance + "p3_commit::pcs::Pcs" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Challenge; Challenger ] + (Self Val Dft InputMmcs FriMmcs Challenge Challenger R) + (* Instance *) + [ + ("Domain", InstanceField.Ty (_Domain Val Dft InputMmcs FriMmcs Challenge Challenger R)); + ("Commitment", + InstanceField.Ty (_Commitment Val Dft InputMmcs FriMmcs Challenge Challenger R)); + ("ProverData", + InstanceField.Ty (_ProverData Val Dft InputMmcs FriMmcs Challenge Challenger R)); + ("EvaluationsOnDomain", + InstanceField.Ty + (_EvaluationsOnDomain Val Dft InputMmcs FriMmcs Challenge Challenger R)); + ("Proof", InstanceField.Ty (_Proof Val Dft InputMmcs FriMmcs Challenge Challenger R)); + ("Error", InstanceField.Ty (_Error Val Dft InputMmcs FriMmcs Challenge Challenger R)); + ("natural_domain_for_degree", + InstanceField.Method + (natural_domain_for_degree Val Dft InputMmcs FriMmcs Challenge Challenger R)); + ("commit", + InstanceField.Method (commit Val Dft InputMmcs FriMmcs Challenge Challenger R)); + ("get_evaluations_on_domain", + InstanceField.Method + (get_evaluations_on_domain Val Dft InputMmcs FriMmcs Challenge Challenger R)); + ("open", InstanceField.Method (open Val Dft InputMmcs FriMmcs Challenge Challenger R)); + ("verify", InstanceField.Method (verify Val Dft InputMmcs FriMmcs Challenge Challenger R)) + ]. + End Impl_p3_commit_pcs_Pcs_where_p3_field_field_TwoAdicField_Val_where_rand_distr_distribution_Distribution_rand_distr_StandardUniform_Val_where_p3_dft_traits_TwoAdicSubgroupDft_Dft_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_p3_field_field_TwoAdicField_Challenge_where_p3_field_field_ExtensionField_Challenge_Val_where_p3_challenger_FieldChallenger_Challenger_Val_where_p3_challenger_CanObserve_Challenger_associated_in_trait_p3_commit_mmcs_Mmcs__Challenge_FriMmcs_Commitment_where_p3_challenger_grinding_challenger_GrindingChallenger_Challenger_where_rand_rng_Rng_R_where_core_marker_Send_R_where_core_marker_Sync_R_Challenge_Challenger_for_p3_fri_hiding_pcs_HidingFriPcs_Val_Dft_InputMmcs_FriMmcs_R. + + (* #[instrument(level = "debug", skip_all)] *) + Definition add_random_cols (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ Val; R ], [ mat; num_random_codewords; rng ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let num_random_codewords := M.alloc (| num_random_codewords |) in + let rng := M.alloc (| rng |) in + M.catch_return + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::hiding_pcs::add_random_cols::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::hiding_pcs::add_random_cols::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::hiding_pcs::add_random_cols::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::hiding_pcs::add_random_cols::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ old_w : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + [], + [ Val ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ new_w : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| old_w |); M.read (| num_random_codewords |) ] + |) + |) in + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + [], + [ Val ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ new_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Val, + [], + [], + "zero_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| new_w |); M.read (| h |) ] + |) + ] + |) + |) in + let~ result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| new_values |); M.read (| new_w |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ Ty.associated_unknown; Ty.associated_unknown ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ Ty.associated_unknown; Ty.associated_unknown ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "zip", + [], + [ Ty.associated_unknown ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + "rows_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, result |) ] + |); + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + "row_slices", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let new_row := M.copy (| γ0_0 |) in + let old_row := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Val ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply (Ty.path "slice") [] [ Val ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| new_row |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", M.read (| old_w |)) ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| old_row |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Val ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&mut") [] [ Val ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Val ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Val ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply (Ty.path "slice") [] [ Val ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| new_row |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", M.read (| old_w |)) ] + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Val ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let v := M.copy (| γ |) in + M.write (| + M.deref (| M.read (| v |) |), + M.call_closure (| + Val, + M.get_trait_method (| + "rand::rng::Rng", + R, + [], + [], + "random", + [], + [ Val ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rng + |) + ] + |) + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + result + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_add_random_cols : + M.IsFunction.C "p3_fri::hiding_pcs::add_random_cols" add_random_cols. + Admitted. + Global Typeclasses Opaque add_random_cols. +End hiding_pcs. diff --git a/CoqOfRust/plonky3/fri/src/lib.rs b/CoqOfRust/plonky3/fri/src/lib.rs new file mode 100644 index 000000000..fc7ed8189 --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/lib.rs @@ -0,0 +1,19 @@ +//! An implementation of the FRI low-degree test (LDT). + +#![no_std] + +extern crate alloc; + +mod config; +mod fold_even_odd; +mod hiding_pcs; +mod proof; +pub mod prover; +mod two_adic_pcs; +pub mod verifier; + +pub use config::*; +pub use fold_even_odd::*; +pub use hiding_pcs::*; +pub use proof::*; +pub use two_adic_pcs::*; diff --git a/CoqOfRust/plonky3/fri/src/proof.rs b/CoqOfRust/plonky3/fri/src/proof.rs new file mode 100644 index 000000000..584faee2a --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/proof.rs @@ -0,0 +1,40 @@ +use alloc::vec::Vec; + +use p3_commit::Mmcs; +use p3_field::Field; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone)] +#[serde(bound( + serialize = "Witness: Serialize, InputProof: Serialize", + deserialize = "Witness: Deserialize<'de>, InputProof: Deserialize<'de>" +))] +pub struct FriProof, Witness, InputProof> { + pub commit_phase_commits: Vec, + pub query_proofs: Vec>, + pub final_poly: Vec, + pub pow_witness: Witness, +} + +#[derive(Serialize, Deserialize, Clone)] +#[serde(bound( + serialize = "InputProof: Serialize", + deserialize = "InputProof: Deserialize<'de>", +))] +pub struct QueryProof, InputProof> { + pub input_proof: InputProof, + /// For each commit phase commitment, this contains openings of a commit phase codeword at the + /// queried location, along with an opening proof. + pub commit_phase_openings: Vec>, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(bound = "")] +pub struct CommitPhaseProofStep> { + /// The opening of the commit phase codeword at the sibling location. + // This may change to Vec if the library is generalized to support other FRI + // folding arities besides 2, meaning that there can be multiple siblings. + pub sibling_value: F, + + pub opening_proof: M::Proof, +} diff --git a/CoqOfRust/plonky3/fri/src/proof.v b/CoqOfRust/plonky3/fri/src/proof.v new file mode 100644 index 000000000..2f0c98456 --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/proof.v @@ -0,0 +1,2925 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module proof. + (* StructRecord + { + name := "FriProof"; + const_params := []; + ty_params := [ "F"; "M_"; "Witness"; "InputProof" ]; + fields := + [ + ("commit_phase_commits", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Commitment"; + Ty.path "alloc::alloc::Global" + ]); + ("query_proofs", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::QueryProof") [] [ F; M_; InputProof ]; + Ty.path "alloc::alloc::Global" + ]); + ("final_poly", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]); + ("pow_witness", Witness) + ]; + } *) + + Module underscore. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_ser_Serialize_Witness_where_serde_ser_Serialize_InputProof_for_p3_fri_proof_FriProof_F_M__Witness_InputProof. + Definition Self (F M_ Witness InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::proof::FriProof") [] [ F; M_; Witness; InputProof ]. + + (* Serialize *) + Definition serialize + (F M_ Witness InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ Witness InputProof in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "FriProof" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "commit_phase_commits" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::FriProof", + "commit_phase_commits" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ F; M_; InputProof ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "query_proofs" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::FriProof", + "query_proofs" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "final_poly" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::FriProof", + "final_poly" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Witness ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "pow_witness" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::FriProof", + "pow_witness" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ Witness InputProof : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ Witness InputProof) + (* Instance *) + [ ("serialize", InstanceField.Method (serialize F M_ Witness InputProof)) ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_ser_Serialize_Witness_where_serde_ser_Serialize_InputProof_for_p3_fri_proof_FriProof_F_M__Witness_InputProof. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_de_Deserialize_Witness_where_serde_de_Deserialize_InputProof_for_p3_fri_proof_FriProof_F_M__Witness_InputProof. + Definition Self (F M_ Witness InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::proof::FriProof") [] [ F; M_; Witness; InputProof ]. + + (* Deserialize *) + Definition deserialize + (F M_ Witness InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ Witness InputProof in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::FriProof") [] [ F; M_; Witness; InputProof ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_fri::proof::_'1::deserialize::__Visitor") + [] + [ F; M_; Witness; InputProof ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "FriProof" |); + M.read (| + get_constant (| + "p3_fri::proof::_'1::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_fri::proof::_'1::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ Witness InputProof : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ Witness InputProof) + (* Instance *) + [ ("deserialize", InstanceField.Method (deserialize F M_ Witness InputProof)) ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_de_Deserialize_Witness_where_serde_de_Deserialize_InputProof_for_p3_fri_proof_FriProof_F_M__Witness_InputProof. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_ser_Serialize_InputProof_for_p3_fri_proof_QueryProof_F_M__InputProof. + Definition Self (F M_ InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::proof::QueryProof") [] [ F; M_; InputProof ]. + + (* Serialize *) + Definition serialize + (F M_ InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ InputProof in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "QueryProof" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ InputProof ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "input_proof" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::QueryProof", + "input_proof" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::CommitPhaseProofStep") + [] + [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "commit_phase_openings" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::QueryProof", + "commit_phase_openings" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ InputProof : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ InputProof) + (* Instance *) [ ("serialize", InstanceField.Method (serialize F M_ InputProof)) ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_ser_Serialize_InputProof_for_p3_fri_proof_QueryProof_F_M__InputProof. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_de_Deserialize_InputProof_for_p3_fri_proof_QueryProof_F_M__InputProof. + Definition Self (F M_ InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::proof::QueryProof") [] [ F; M_; InputProof ]. + + (* Deserialize *) + Definition deserialize + (F M_ InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ InputProof in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::QueryProof") [] [ F; M_; InputProof ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_fri::proof::_'3::deserialize::__Visitor") + [] + [ F; M_; InputProof ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "QueryProof" |); + M.read (| + get_constant (| + "p3_fri::proof::_'3::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_fri::proof::_'3::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ InputProof : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ InputProof) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize F M_ InputProof)) ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_where_serde_de_Deserialize_InputProof_for_p3_fri_proof_QueryProof_F_M__InputProof. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_for_p3_fri_proof_CommitPhaseProofStep_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]. + + (* Serialize *) + Definition serialize + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "CommitPhaseProofStep" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "sibling_value" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::CommitPhaseProofStep", + "sibling_value" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Proof" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "opening_proof" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::CommitPhaseProofStep", + "opening_proof" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_) + (* Instance *) [ ("serialize", InstanceField.Method (serialize F M_)) ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_for_p3_fri_proof_CommitPhaseProofStep_F_M_. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_for_p3_fri_proof_CommitPhaseProofStep_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]. + + (* Deserialize *) + Definition deserialize + (F M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ Ty.apply (Ty.path "p3_fri::proof::_'5::deserialize::__Visitor") [] [ F; M_ ] ] + |), + [ + M.read (| __deserializer |); + mk_str (| "CommitPhaseProofStep" |); + M.read (| + get_constant (| + "p3_fri::proof::_'5::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_fri::proof::_'5::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize F M_)) ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_F_where_p3_commit_mmcs_Mmcs_M__F_for_p3_fri_proof_CommitPhaseProofStep_F_M_. + End underscore. + + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_Witness_where_core_clone_Clone_InputProof_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Commitment_for_p3_fri_proof_FriProof_F_M__Witness_InputProof. + Definition Self (F M_ Witness InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::proof::FriProof") [] [ F; M_; Witness; InputProof ]. + + (* Clone *) + Definition clone + (F M_ Witness InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ Witness InputProof in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_fri::proof::FriProof" + [ + ("commit_phase_commits", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Commitment"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Commitment"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::FriProof", + "commit_phase_commits" + |) + |) + |) + |) + ] + |)); + ("query_proofs", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::QueryProof") [] [ F; M_; InputProof ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::QueryProof") [] [ F; M_; InputProof ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::FriProof", + "query_proofs" + |) + |) + |) + |) + ] + |)); + ("final_poly", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::FriProof", + "final_poly" + |) + |) + |) + |) + ] + |)); + ("pow_witness", + M.call_closure (| + Witness, + M.get_trait_method (| "core::clone::Clone", Witness, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::FriProof", + "pow_witness" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ Witness InputProof : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ Witness InputProof) + (* Instance *) [ ("clone", InstanceField.Method (clone F M_ Witness InputProof)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_Witness_where_core_clone_Clone_InputProof_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Commitment_for_p3_fri_proof_FriProof_F_M__Witness_InputProof. + + (* StructRecord + { + name := "QueryProof"; + const_params := []; + ty_params := [ "F"; "M_"; "InputProof" ]; + fields := + [ + ("input_proof", InputProof); + ("commit_phase_openings", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ]) + ]; + } *) + + + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_InputProof_for_p3_fri_proof_QueryProof_F_M__InputProof. + Definition Self (F M_ InputProof : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::proof::QueryProof") [] [ F; M_; InputProof ]. + + (* Clone *) + Definition clone + (F M_ InputProof : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F M_ InputProof in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_fri::proof::QueryProof" + [ + ("input_proof", + M.call_closure (| + InputProof, + M.get_trait_method (| + "core::clone::Clone", + InputProof, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::QueryProof", + "input_proof" + |) + |) + |) + |) + ] + |)); + ("commit_phase_openings", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::QueryProof", + "commit_phase_openings" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ InputProof : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_ InputProof) + (* Instance *) [ ("clone", InstanceField.Method (clone F M_ InputProof)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_InputProof_for_p3_fri_proof_QueryProof_F_M__InputProof. + + (* StructRecord + { + name := "CommitPhaseProofStep"; + const_params := []; + ty_params := [ "F"; "M_" ]; + fields := + [ + ("sibling_value", F); + ("opening_proof", Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Proof") + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_where_core_fmt_Debug_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_fmt_Debug_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Proof_for_p3_fri_proof_CommitPhaseProofStep_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]. + + (* Debug *) + Definition fmt (F M_ : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "CommitPhaseProofStep" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "sibling_value" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::CommitPhaseProofStep", + "sibling_value" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "opening_proof" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::CommitPhaseProofStep", + "opening_proof" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F M_)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_where_core_fmt_Debug_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_fmt_Debug_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Proof_for_p3_fri_proof_CommitPhaseProofStep_F_M_. + + + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Proof_for_p3_fri_proof_CommitPhaseProofStep_F_M_. + Definition Self (F M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]. + + (* Clone *) + Definition clone (F M_ : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_fri::proof::CommitPhaseProofStep" + [ + ("sibling_value", + M.call_closure (| + F, + M.get_trait_method (| "core::clone::Clone", F, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::CommitPhaseProofStep", + "sibling_value" + |) + |) + |) + |) + ] + |)); + ("opening_proof", + M.call_closure (| + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Proof", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Proof", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::proof::CommitPhaseProofStep", + "opening_proof" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F M_ : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F M_) + (* Instance *) [ ("clone", InstanceField.Method (clone F M_)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_where_core_clone_Clone_M__where_p3_commit_mmcs_Mmcs_M__F_where_core_clone_Clone_associated_in_trait_p3_commit_mmcs_Mmcs__F_M__Proof_for_p3_fri_proof_CommitPhaseProofStep_F_M_. +End proof. diff --git a/CoqOfRust/plonky3/fri/src/prover.rs b/CoqOfRust/plonky3/fri/src/prover.rs new file mode 100644 index 000000000..d4dfbf340 --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/prover.rs @@ -0,0 +1,178 @@ +use alloc::vec; +use alloc::vec::Vec; +use core::iter; + +use itertools::{Itertools, izip}; +use p3_challenger::{CanObserve, FieldChallenger, GrindingChallenger}; +use p3_commit::Mmcs; +use p3_dft::{Radix2Dit, TwoAdicSubgroupDft}; +use p3_field::{ExtensionField, Field, TwoAdicField}; +use p3_matrix::dense::RowMajorMatrix; +use p3_util::{log2_strict_usize, reverse_slice_index_bits}; +use tracing::{debug_span, info_span, instrument}; + +use crate::{CommitPhaseProofStep, FriConfig, FriGenericConfig, FriProof, QueryProof}; + +#[instrument(name = "FRI prover", skip_all)] +pub fn prove( + g: &G, + config: &FriConfig, + inputs: Vec>, + challenger: &mut Challenger, + open_input: impl Fn(usize) -> G::InputProof, +) -> FriProof +where + Val: Field, + Challenge: ExtensionField + TwoAdicField, + M: Mmcs, + Challenger: FieldChallenger + GrindingChallenger + CanObserve, + G: FriGenericConfig, +{ + assert!(!inputs.is_empty()); + assert!( + inputs + .iter() + .tuple_windows() + .all(|(l, r)| l.len() >= r.len()), + "Inputs are not sorted in descending order of length." + ); + + let log_max_height = log2_strict_usize(inputs[0].len()); + let log_min_height = log2_strict_usize(inputs.last().unwrap().len()); + if config.log_final_poly_len > 0 { + assert!(log_min_height > config.log_final_poly_len + config.log_blowup); + } + + let commit_phase_result = commit_phase(g, config, inputs, challenger); + + let pow_witness = challenger.grind(config.proof_of_work_bits); + + let query_proofs = info_span!("query phase").in_scope(|| { + iter::repeat_with(|| challenger.sample_bits(log_max_height + g.extra_query_index_bits())) + .take(config.num_queries) + .map(|index| QueryProof { + input_proof: open_input(index), + commit_phase_openings: answer_query( + config, + &commit_phase_result.data, + index >> g.extra_query_index_bits(), + ), + }) + .collect() + }); + + FriProof { + commit_phase_commits: commit_phase_result.commits, + query_proofs, + final_poly: commit_phase_result.final_poly, + pow_witness, + } +} + +struct CommitPhaseResult> { + commits: Vec, + data: Vec>>, + final_poly: Vec, +} + +#[instrument(name = "commit phase", skip_all)] +fn commit_phase( + g: &G, + config: &FriConfig, + inputs: Vec>, + challenger: &mut Challenger, +) -> CommitPhaseResult +where + Val: Field, + Challenge: ExtensionField + TwoAdicField, + M: Mmcs, + Challenger: FieldChallenger + CanObserve, + G: FriGenericConfig, +{ + let mut inputs_iter = inputs.into_iter().peekable(); + let mut folded = inputs_iter.next().unwrap(); + let mut commits = vec![]; + let mut data = vec![]; + + while folded.len() > config.blowup() * config.final_poly_len() { + let leaves = RowMajorMatrix::new(folded, 2); + let (commit, prover_data) = config.mmcs.commit_matrix(leaves); + challenger.observe(commit.clone()); + + let beta: Challenge = challenger.sample_algebra_element(); + // We passed ownership of `current` to the MMCS, so get a reference to it + let leaves = config.mmcs.get_matrices(&prover_data).pop().unwrap(); + folded = g.fold_matrix(beta, leaves.as_view()); + + commits.push(commit); + data.push(prover_data); + + if let Some(v) = inputs_iter.next_if(|v| v.len() == folded.len()) { + izip!(&mut folded, v).for_each(|(c, x)| *c += x); + } + } + + // After repeated folding steps, we end up working over a coset hJ instead of the original + // domain. The IDFT we apply operates over a subgroup J, not hJ. This means the polynomial we + // recover is G(x), where G(x) = F(hx), and F is the polynomial whose evaluations we actually + // observed. For our current construction, this does not cause issues since degree properties + // and zero-checks remain valid. If we changed our domain construction (e.g., using multiple + // cosets), we would need to carefully reconsider these assumptions. + + reverse_slice_index_bits(&mut folded); + // TODO: For better performance, we could run the IDFT on only the first half + // (or less, depending on `log_blowup`) of `final_poly`. + let final_poly = debug_span!("idft final poly").in_scope(|| Radix2Dit::default().idft(folded)); + + // The evaluation domain is "blown-up" relative to the polynomial degree of `final_poly`, + // so all coefficients after the first final_poly_len should be zero. + debug_assert!( + final_poly + .iter() + .skip(1 << config.log_final_poly_len) + .all(|x| x.is_zero()), + "All coefficients beyond final_poly_len must be zero" + ); + + // Observe all coefficients of the final polynomial. + for &x in &final_poly { + challenger.observe_algebra_element(x); + } + + CommitPhaseResult { + commits, + data, + final_poly, + } +} + +fn answer_query( + config: &FriConfig, + commit_phase_commits: &[M::ProverData>], + index: usize, +) -> Vec> +where + F: Field, + M: Mmcs, +{ + commit_phase_commits + .iter() + .enumerate() + .map(|(i, commit)| { + let index_i = index >> i; + let index_i_sibling = index_i ^ 1; + let index_pair = index_i >> 1; + + let (mut opened_rows, opening_proof) = config.mmcs.open_batch(index_pair, commit); + assert_eq!(opened_rows.len(), 1); + let opened_row = opened_rows.pop().unwrap(); + assert_eq!(opened_row.len(), 2, "Committed data should be in pairs"); + let sibling_value = opened_row[index_i_sibling % 2]; + + CommitPhaseProofStep { + sibling_value, + opening_proof, + } + }) + .collect() +} diff --git a/CoqOfRust/plonky3/fri/src/prover.v b/CoqOfRust/plonky3/fri/src/prover.v new file mode 100644 index 000000000..08d0b6e5c --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/prover.v @@ -0,0 +1,6517 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module prover. + (* #[instrument(name = "FRI prover", skip_all)] *) + Definition prove (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], + [ G; Val; Challenge; M_; Challenger; impl_Fn_usize__arrow_G_InputProof ], + [ g; config; inputs; challenger; open_input ] => + ltac:(M.monadic + (let g := M.alloc (| g |) in + let config := M.alloc (| config |) in + let inputs := M.alloc (| inputs |) in + let challenger := M.alloc (| challenger |) in + let open_input := M.alloc (| open_input |) in + M.catch_return + (Ty.apply + (Ty.path "p3_fri::proof::FriProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::FriProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + "is_empty", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inputs |) ] + |) + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: !inputs.is_empty()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ], + [], + [], + "all", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "tuple_windows", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inputs |) ] + |) + |) + |) + ] + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let l := M.copy (| γ0_0 |) in + let r := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| l |) |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| r |) |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Inputs are not sorted in descending order of length." + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, inputs |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ log_min_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + "last", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inputs |) ] + |) + |) + |) + ] + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "log_final_poly_len" + |) + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.read (| log_min_height |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "log_final_poly_len" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: log_min_height > config.log_final_poly_len + config.log_blowup" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ commit_phase_result : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_fri::prover::CommitPhaseResult") [] [ Challenge; M_ ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_fri::prover::CommitPhaseResult") [] [ Challenge; M_ ], + M.get_function (| + "p3_fri::prover::commit_phase", + [], + [ G; Val; Challenge; M_; Challenger ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| g |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| config |) |) |); + M.read (| inputs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |) + ] + |) + |) in + let~ pow_witness : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_challenger::grinding_challenger::GrindingChallenger" + [] + [] + Challenger + "Witness", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Challenger, + [], + [], + "grind", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "proof_of_work_bits" + |) + |) + ] + |) + |) in + let~ query_proofs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ]); + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ] + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ] + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::sources::repeat_with::RepeatWith") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ], + M.get_function (| + "core::iter::sources::repeat_with::repeat_with", + [], + [ + Ty.path "usize"; + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "usize") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_challenger::CanSampleBits", + Challenger, + [], + [ Ty.path "usize" ], + "sample_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + challenger + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + log_max_height + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ Challenge ], + "extra_query_index_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + g + |) + |) + |) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "num_queries" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let index := M.copy (| γ |) in + Value.StructRecord + "p3_fri::proof::QueryProof" + [ + ("input_proof", + M.call_closure (| + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof", + M.get_trait_method (| + "core::ops::function::Fn", + impl_Fn_usize__arrow_G_InputProof, + [], + [ + Ty.tuple + [ Ty.path "usize" ] + ], + "call", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + open_input + |); + Value.Tuple + [ M.read (| index |) ] + ] + |)); + ("commit_phase_openings", + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_fri::proof::CommitPhaseProofStep") + [] + [ Challenge; M_ ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_function (| + "p3_fri::prover::answer_query", + [], + [ Challenge; M_ ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| config |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + M_ + "ProverData" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + M_ + "ProverData"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + commit_phase_result, + "p3_fri::prover::CommitPhaseResult", + "data" + |) + |) + |) + |) + ] + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.read (| index |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ Challenge ], + "extra_query_index_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + g + |) + |) + |) + ] + |) + ] + |) + ] + |)) + ])) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_fri::proof::FriProof" + [ + ("commit_phase_commits", + M.read (| + M.SubPointer.get_struct_record_field (| + commit_phase_result, + "p3_fri::prover::CommitPhaseResult", + "commits" + |) + |)); + ("query_proofs", M.read (| query_proofs |)); + ("final_poly", + M.read (| + M.SubPointer.get_struct_record_field (| + commit_phase_result, + "p3_fri::prover::CommitPhaseResult", + "final_poly" + |) + |)); + ("pow_witness", M.read (| pow_witness |)) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_prove : M.IsFunction.C "p3_fri::prover::prove" prove. + Admitted. + Global Typeclasses Opaque prove. + + (* StructRecord + { + name := "CommitPhaseResult"; + const_params := []; + ty_params := [ "F"; "M_" ]; + fields := + [ + ("commits", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Commitment"; + Ty.path "alloc::alloc::Global" + ]); + ("data", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData"; + Ty.path "alloc::alloc::Global" + ]); + ("final_poly", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]) + ]; + } *) + + (* #[instrument(name = "commit phase", skip_all)] *) + Definition commit_phase (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ G; Val; Challenge; M_; Challenger ], [ g; config; inputs; challenger ] => + ltac:(M.monadic + (let g := M.alloc (| g |) in + let config := M.alloc (| config |) in + let inputs := M.alloc (| inputs |) in + let challenger := M.alloc (| challenger |) in + M.catch_return + (Ty.apply (Ty.path "p3_fri::prover::CommitPhaseResult") [] [ Challenge; M_ ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::commit_phase::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::commit_phase::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::commit_phase::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::commit_phase::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::prover::CommitPhaseResult") + [] + [ Challenge; M_ ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ inputs_iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "peekable", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| inputs |) ] + |) + ] + |) + |) in + let~ folded : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "next", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, inputs_iter |) ] + |) + ] + |) + |) in + let~ commits : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + let~ data : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData"; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData"; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, folded |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_fri::config::FriConfig") + [] + [ M_ ], + "blowup", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| config |) |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_fri::config::FriConfig") + [] + [ M_ ], + "final_poly_len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| config |) |) + |) + ] + |) + ] + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ leaves : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| folded |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + M_, + [], + [ Challenge ], + "commit_matrix", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.read (| leaves |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let commit := M.copy (| γ0_0 |) in + let prover_data := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Challenger, + [], + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, commit |) ] + |) + ] + |) + |) in + let~ beta : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "sample_algebra_element", + [], + [ Challenge ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |) + ] + |) + |) in + let~ leaves : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "pop", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + M_, + [], + [ Challenge ], + "get_matrices", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + prover_data + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + folded, + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ Challenge ], + "fold_matrix", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Challenge ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| g |) |) + |); + M.read (| beta |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Challenge ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ], + "as_view", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| leaves |) |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, commits |); + M.read (| commit |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + M_ + "ProverData"; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, data |); + M.read (| prover_data |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "next_if", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, inputs_iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let v := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| v |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + folded + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let v := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Challenge ]; + Challenge + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Challenge ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Challenge ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + folded + |) + ] + |); + M.read (| v |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Challenge ]; + Challenge + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let c := M.copy (| γ0_0 |) in + let x := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Challenge, + [], + [ Challenge ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| c |) + |) + |); + M.read (| x |) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ Challenge ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Challenge ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, folded |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ final_poly : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]); + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::commit_phase::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::commit_phase::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::commit_phase::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::prover::commit_phase::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Ty.apply + (Ty.path "p3_dft::radix_2_dit::Radix2Dit") + [] + [ Challenge ], + [], + [ Challenge ], + "idft", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_dft::radix_2_dit::Radix2Dit") + [] + [ Challenge ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "p3_dft::radix_2_dit::Radix2Dit") + [] + [ Challenge ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) + |); + M.read (| folded |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Challenge ] + ], + [], + [], + "all", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Challenge ] ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Challenge ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Challenge ], + [], + [], + "skip", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Challenge ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Challenge ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Challenge ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + final_poly + |) + ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "log_final_poly_len" + |) + |) + ] + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Challenge ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + Challenge, + [], + [], + "is_zero", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "All coefficients beyond final_poly_len must be zero" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Challenge ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, final_poly |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Challenge ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Challenge ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let x := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "observe_algebra_element", + [], + [ Challenge ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.read (| x |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + Value.StructRecord + "p3_fri::prover::CommitPhaseResult" + [ + ("commits", M.read (| commits |)); + ("data", M.read (| data |)); + ("final_poly", M.read (| final_poly |)) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_commit_phase : + M.IsFunction.C "p3_fri::prover::commit_phase" commit_phase. + Admitted. + Global Typeclasses Opaque commit_phase. + + (* + fn answer_query( + config: &FriConfig, + commit_phase_commits: &[M::ProverData>], + index: usize, + ) -> Vec> + where + F: Field, + M: Mmcs, + { + commit_phase_commits + .iter() + .enumerate() + .map(|(i, commit)| { + let index_i = index >> i; + let index_i_sibling = index_i ^ 1; + let index_pair = index_i >> 1; + + let (mut opened_rows, opening_proof) = config.mmcs.open_batch(index_pair, commit); + assert_eq!(opened_rows.len(), 1); + let opened_row = opened_rows.pop().unwrap(); + assert_eq!(opened_row.len(), 2, "Committed data should be in pairs"); + let sibling_value = opened_row[index_i_sibling % 2]; + + CommitPhaseProofStep { + sibling_value, + opening_proof, + } + }) + .collect() + } + *) + Definition answer_query (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; M_ ], [ config; commit_phase_commits; index ] => + ltac:(M.monadic + (let config := M.alloc (| config |) in + let commit_phase_commits := M.alloc (| commit_phase_commits |) in + let index := M.alloc (| index |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ] + ] + ] + (Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ] + ] + ] + (Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ] + ] + ] + (Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| commit_phase_commits |) |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + F; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + M_ + "ProverData" + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_fri::proof::CommitPhaseProofStep") + [] + [ F; M_ ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let i := M.copy (| γ0_0 |) in + let commit := M.copy (| γ0_1 |) in + M.read (| + let~ index_i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| index |); M.read (| i |) ] + |) + |) in + let~ index_i_sibling : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_xor, + [ M.read (| index_i |); Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ index_pair : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| index_i |); Value.Integer IntegerKind.I32 1 ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::CommitPhaseProofStep") + [] + [ F; M_ ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Proof" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + M_, + [], + [ F ], + "open_batch", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.read (| index_pair |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| commit |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let opened_rows := M.copy (| γ0_0 |) in + let opening_proof := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + opened_rows + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ opened_row : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + "pop", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + opened_rows + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + opened_row + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Committed data should be in pairs" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ sibling_value : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ F ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, opened_row |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.read (| index_i_sibling |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |) + |) in + M.alloc (| + Value.StructRecord + "p3_fri::proof::CommitPhaseProofStep" + [ + ("sibling_value", M.read (| sibling_value |)); + ("opening_proof", M.read (| opening_proof |)) + ] + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_answer_query : + M.IsFunction.C "p3_fri::prover::answer_query" answer_query. + Admitted. + Global Typeclasses Opaque answer_query. +End prover. diff --git a/CoqOfRust/plonky3/fri/src/two_adic_pcs.rs b/CoqOfRust/plonky3/fri/src/two_adic_pcs.rs new file mode 100644 index 000000000..8278f6460 --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/two_adic_pcs.rs @@ -0,0 +1,602 @@ +use alloc::collections::BTreeMap; +use alloc::vec; +use alloc::vec::Vec; +use core::fmt::Debug; +use core::marker::PhantomData; + +use itertools::{Itertools, izip}; +use p3_challenger::{CanObserve, FieldChallenger, GrindingChallenger}; +use p3_commit::{Mmcs, OpenedValues, Pcs}; +use p3_dft::TwoAdicSubgroupDft; +use p3_field::coset::TwoAdicMultiplicativeCoset; +use p3_field::{ + ExtensionField, Field, PackedFieldExtension, TwoAdicField, batch_multiplicative_inverse, + cyclic_subgroup_coset_known_order, dot_product, +}; +use p3_interpolation::interpolate_coset; +use p3_matrix::bitrev::{BitReversalPerm, BitReversedMatrixView, BitReversibleMatrix}; +use p3_matrix::dense::{DenseMatrix, RowMajorMatrix}; +use p3_matrix::{Dimensions, Matrix}; +use p3_maybe_rayon::prelude::*; +use p3_util::linear_map::LinearMap; +use p3_util::zip_eq::zip_eq; +use p3_util::{log2_strict_usize, reverse_bits_len, reverse_slice_index_bits}; +use serde::{Deserialize, Serialize}; +use tracing::{info_span, instrument}; + +use crate::verifier::{self, FriError}; +use crate::{FriConfig, FriGenericConfig, FriProof, prover}; + +#[derive(Debug)] +pub struct TwoAdicFriPcs { + dft: Dft, + mmcs: InputMmcs, + fri: FriConfig, + _phantom: PhantomData, +} + +impl TwoAdicFriPcs { + pub const fn new(dft: Dft, mmcs: InputMmcs, fri: FriConfig) -> Self { + Self { + dft, + mmcs, + fri, + _phantom: PhantomData, + } + } +} + +#[derive(Serialize, Deserialize, Clone)] +#[serde(bound = "")] +pub struct BatchOpening> { + pub opened_values: Vec>, + pub opening_proof: >::Proof, +} + +pub struct TwoAdicFriGenericConfig( + pub PhantomData<(InputProof, InputError)>, +); + +pub type TwoAdicFriGenericConfigForMmcs = + TwoAdicFriGenericConfig>, >::Error>; + +impl FriGenericConfig + for TwoAdicFriGenericConfig +{ + type InputProof = InputProof; + type InputError = InputError; + + fn extra_query_index_bits(&self) -> usize { + 0 + } + + fn fold_row( + &self, + index: usize, + log_height: usize, + beta: F, + evals: impl Iterator, + ) -> F { + let arity = 2; + let log_arity = 1; + let (e0, e1) = evals + .collect_tuple() + .expect("TwoAdicFriFolder only supports arity=2"); + // If performance critical, make this API stateful to avoid this + // This is a bit more math than is necessary, but leaving it here + // in case we want higher arity in the future + let subgroup_start = F::two_adic_generator(log_height + log_arity) + .exp_u64(reverse_bits_len(index, log_height) as u64); + let mut xs = F::two_adic_generator(log_arity) + .shifted_powers(subgroup_start) + .take(arity) + .collect_vec(); + reverse_slice_index_bits(&mut xs); + assert_eq!(log_arity, 1, "can only interpolate two points for now"); + // interpolate and evaluate at beta + e0 + (beta - xs[0]) * (e1 - e0) / (xs[1] - xs[0]) + } + + fn fold_matrix>(&self, beta: F, m: M) -> Vec { + // We use the fact that + // p_e(x^2) = (p(x) + p(-x)) / 2 + // p_o(x^2) = (p(x) - p(-x)) / (2 x) + // that is, + // p_e(g^(2i)) = (p(g^i) + p(g^(n/2 + i))) / 2 + // p_o(g^(2i)) = (p(g^i) - p(g^(n/2 + i))) / (2 g^i) + // so + // result(g^(2i)) = p_e(g^(2i)) + beta p_o(g^(2i)) + // = (1/2 + beta/2 g_inv^i) p(g^i) + // + (1/2 - beta/2 g_inv^i) p(g^(n/2 + i)) + let g_inv = F::two_adic_generator(log2_strict_usize(m.height()) + 1).inverse(); + let one_half = F::ONE.halve(); + let half_beta = beta * one_half; + + // TODO: vectorize this (after we have packed extension fields) + + // beta/2 times successive powers of g_inv + let mut powers = g_inv + .shifted_powers(half_beta) + .take(m.height()) + .collect_vec(); + reverse_slice_index_bits(&mut powers); + + m.par_rows() + .zip(powers) + .map(|(mut row, power)| { + let (lo, hi) = row.next_tuple().unwrap(); + (one_half + power) * lo + (one_half - power) * hi + }) + .collect() + } +} + +impl Pcs + for TwoAdicFriPcs +where + Val: TwoAdicField, + Dft: TwoAdicSubgroupDft, + InputMmcs: Mmcs, + FriMmcs: Mmcs, + Challenge: TwoAdicField + ExtensionField, + Challenger: + FieldChallenger + CanObserve + GrindingChallenger, +{ + type Domain = TwoAdicMultiplicativeCoset; + type Commitment = InputMmcs::Commitment; + type ProverData = InputMmcs::ProverData>; + type EvaluationsOnDomain<'a> = BitReversedMatrixView>; + type Proof = FriProof>>; + type Error = FriError; + + fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain { + // This panics if (and only if) `degree` is not a power of 2 or `degree` + // > `1 << Val::TWO_ADICITY`. + TwoAdicMultiplicativeCoset::new(Val::ONE, log2_strict_usize(degree)).unwrap() + } + + fn commit( + &self, + evaluations: Vec<(Self::Domain, RowMajorMatrix)>, + ) -> (Self::Commitment, Self::ProverData) { + let ldes: Vec<_> = evaluations + .into_iter() + .map(|(domain, evals)| { + assert_eq!(domain.size(), evals.height()); + let shift = Val::GENERATOR / domain.shift(); + // Commit to the bit-reversed LDE. + self.dft + .coset_lde_batch(evals, self.fri.log_blowup, shift) + .bit_reverse_rows() + .to_row_major_matrix() + }) + .collect(); + + self.mmcs.commit(ldes) + } + + fn get_evaluations_on_domain<'a>( + &self, + prover_data: &'a Self::ProverData, + idx: usize, + domain: Self::Domain, + ) -> Self::EvaluationsOnDomain<'a> { + // todo: handle extrapolation for LDEs we don't have + assert_eq!(domain.shift(), Val::GENERATOR); + let lde = self.mmcs.get_matrices(prover_data)[idx]; + assert!(lde.height() >= domain.size()); + lde.split_rows(domain.size()).0.bit_reverse_rows() + } + + fn open( + &self, + // For each round, + rounds: Vec<( + &Self::ProverData, + // for each matrix, + Vec< + // points to open + Vec, + >, + )>, + challenger: &mut Challenger, + ) -> (OpenedValues, Self::Proof) { + /* + + A quick rundown of the optimizations in this function: + We are trying to compute sum_i alpha^i * (p(X) - y)/(X - z), + for each z an opening point, y = p(z). Each p(X) is given as evaluations in bit-reversed order + in the columns of the matrices. y is computed by barycentric interpolation. + X and p(X) are in the base field; alpha, y and z are in the extension. + The primary goal is to minimize extension multiplications. + + - Instead of computing all alpha^i, we just compute alpha^i for i up to the largest width + of a matrix, then multiply by an "alpha offset" when accumulating. + a^0 x0 + a^1 x1 + a^2 x2 + a^3 x3 + ... + = a^0 ( a^0 x0 + a^1 x1 ) + a^2 ( a^0 x2 + a^1 x3 ) + ... + (see `alpha_pows`, `alpha_pow_offset`, `num_reduced`) + + - For each unique point z, we precompute 1/(X-z) for the largest subgroup opened at this point. + Since we compute it in bit-reversed order, smaller subgroups can simply truncate the vector. + (see `inv_denoms`) + + - Then, for each matrix (with columns p_i) and opening point z, we want: + for each row (corresponding to subgroup element X): + reduced[X] += alpha_offset * sum_i [ alpha^i * inv_denom[X] * (p_i[X] - y[i]) ] + + We can factor out inv_denom, and expand what's left: + reduced[X] += alpha_offset * inv_denom[X] * sum_i [ alpha^i * p_i[X] - alpha^i * y[i] ] + + And separate the sum: + reduced[X] += alpha_offset * inv_denom[X] * [ sum_i [ alpha^i * p_i[X] ] - sum_i [ alpha^i * y[i] ] ] + + And now the last sum doesn't depend on X, so we can precompute that for the matrix, too. + So the hot loop (that depends on both X and i) is just: + sum_i [ alpha^i * p_i[X] ] + + with alpha^i an extension, p_i[X] a base + + */ + + let mats_and_points = rounds + .iter() + .map(|(data, points)| { + let mats = self + .mmcs + .get_matrices(data) + .into_iter() + .map(|m| m.as_view()) + .collect_vec(); + debug_assert_eq!( + mats.len(), + points.len(), + "each matrix should have a corresponding set of evaluation points" + ); + (mats, points) + }) + .collect_vec(); + + // Find the maximum height and the maximum width of matrices in the batch. + // These do not need to correspond to the same matrix. + let (global_max_height, global_max_width) = mats_and_points + .iter() + .flat_map(|(mats, _)| mats.iter().map(|m| (m.height(), m.width()))) + .reduce(|(hmax, wmax), (h, w)| (hmax.max(h), wmax.max(w))) + .expect("No Matrices Supplied?"); + let log_global_max_height = log2_strict_usize(global_max_height); + + // For each unique opening point z, we will find the largest degree bound + // for that point, and precompute 1/(z - X) for the largest subgroup (in bitrev order). + let inv_denoms = compute_inverse_denominators(&mats_and_points, Val::GENERATOR); + + // Evaluate coset representations and write openings to the challenger + let all_opened_values = mats_and_points + .iter() + .map(|(mats, points)| { + izip!(mats.iter(), points.iter()) + .map(|(mat, points_for_mat)| { + points_for_mat + .iter() + .map(|&point| { + let _guard = + info_span!("evaluate matrix", dims = %mat.dimensions()) + .entered(); + + // Use Barycentric interpolation to evaluate the matrix at the given point. + let ys = + info_span!("compute opened values with Lagrange interpolation") + .in_scope(|| { + let h = mat.height() >> self.fri.log_blowup; + let (low_coset, _) = mat.split_rows(h); + let mut inv_denoms = + inv_denoms.get(&point).unwrap()[..h].to_vec(); + reverse_slice_index_bits(&mut inv_denoms); + interpolate_coset( + &BitReversalPerm::new_view(low_coset), + Val::GENERATOR, + point, + Some(&inv_denoms), + ) + }); + ys.iter() + .for_each(|&y| challenger.observe_algebra_element(y)); + ys + }) + .collect_vec() + }) + .collect_vec() + }) + .collect_vec(); + + // Batch combination challenge + // TODO: Should we be computing a different alpha for each height? + let alpha: Challenge = challenger.sample_algebra_element(); + + // We precompute powers of alpha as we need the same powers for each matrix. + // We compute both a vector of unpacked powers and a vector of packed powers. + // TODO: It should be possible to refactor this to only use the packed powers but + // this is not a bottleneck so is not a priority. + let packed_alpha_powers = + Challenge::ExtensionPacking::packed_ext_powers_capped(alpha, global_max_width) + .collect_vec(); + let alpha_powers = + Challenge::ExtensionPacking::to_ext_iter(packed_alpha_powers.iter().copied()) + .collect_vec(); + + // Now that we have sent the openings to the verifier, it remains to prove + // that those openings are correct. + + // Given a low degree polynomial `f(x)` with claimed evaluation `f(zeta)`, we can check + // that `f(zeta)` is correct by doing a low degree test on `(f(zeta) - f(x))/(zeta - x)`. + // We will use `alpha` to batch together both different claimed openings `zeta` and + // different polynomials `f` whose evaluation vectors have the same height. + + // TODO: If we allow different polynomials to have different blow_up factors + // we may need to revisit this and to ensure it is safe to batch them together. + + // num_reduced records the number of reduced function opening point pairs + // of each given `log_height`. + let mut num_reduced = [0; 32]; + + // For each `log_height` from 2^1 -> 2^32, reduced_openings will contain either `None` + // if there are no matrices of that height, or `Some(vec)` where `vec` is equal to + // a sum of `(f(zeta) - f(x))/(zeta - x)` over all `f`'s of that height and + // opening points `zeta` with the sum weighted by powers of alpha. + let mut reduced_openings: [_; 32] = core::array::from_fn(|_| None); + + for ((mats, points), openings_for_round) in + mats_and_points.iter().zip(all_opened_values.iter()) + { + for (mat, points_for_mat, openings_for_mat) in + izip!(mats.iter(), points.iter(), openings_for_round.iter()) + { + let _guard = + info_span!("reduce matrix quotient", dims = %mat.dimensions()).entered(); + + let log_height = log2_strict_usize(mat.height()); + + // If this is our first matrix at this height, initialise reduced_openings to zero. + // Otherwise, get a mutable reference to it. + let reduced_opening_for_log_height = reduced_openings[log_height] + .get_or_insert_with(|| vec![Challenge::ZERO; mat.height()]); + debug_assert_eq!(reduced_opening_for_log_height.len(), mat.height()); + + // Treating our matrix M as the evaluations of functions M0, M1, ... + // Compute the evaluations of `Mred(x) = M0(x) + alpha*M1(x) + ...` + let mat_compressed = info_span!("compress mat").in_scope(|| { + // This will be reused for all points z which M is opened at so we collect into a vector. + mat.rowwise_packed_dot_product::(&packed_alpha_powers) + .collect::>() + }); + + for (&point, openings) in points_for_mat.iter().zip(openings_for_mat) { + // If we have multiple matrices at the same height, we need to scale mat to combine them. + let alpha_pow_offset = alpha.exp_u64(num_reduced[log_height] as u64); + + // As we have all the openings `Mi(z)`, we can combine them using `alpha` + // in an identical way to before to also compute `Mred(z)`. + let reduced_openings: Challenge = + dot_product(alpha_powers.iter().copied(), openings.iter().copied()); + + mat_compressed + .par_iter() + .zip(reduced_opening_for_log_height.par_iter_mut()) + // inv_denoms contains `1/(point - x)` for `x` in a coset `gK`. + // If `|K| =/= mat.height()` we actually want a subset of this + // corresponding to the evaluations over `gH` for `|H| = mat.height()`. + // As inv_denoms is bit reversed, the evaluations over `gH` are exactly + // the evaluations over `gK` at the indices `0..mat.height()`. + // So zip will truncate to the desired smaller length. + .zip(inv_denoms.get(&point).unwrap().par_iter()) + // Map the function `Mred(x) -> (Mred(z) - Mred(x))/(z - x)` + // across the evaluations vector of `Mred(x)`. + .for_each(|((&reduced_row, ro), &inv_denom)| { + *ro += alpha_pow_offset * (reduced_openings - reduced_row) * inv_denom + }); + num_reduced[log_height] += mat.width(); + } + } + } + + let fri_input = reduced_openings.into_iter().rev().flatten().collect_vec(); + + let g: TwoAdicFriGenericConfigForMmcs = + TwoAdicFriGenericConfig(PhantomData); + + let fri_proof = prover::prove(&g, &self.fri, fri_input, challenger, |index| { + rounds + .iter() + .map(|(data, _)| { + let log_max_height = log2_strict_usize(self.mmcs.get_max_height(data)); + let bits_reduced = log_global_max_height - log_max_height; + let reduced_index = index >> bits_reduced; + let (opened_values, opening_proof) = self.mmcs.open_batch(reduced_index, data); + BatchOpening { + opened_values, + opening_proof, + } + }) + .collect() + }); + + (all_opened_values, fri_proof) + } + + fn verify( + &self, + // For each round: + rounds: Vec<( + Self::Commitment, + // for each matrix: + Vec<( + // its domain, + Self::Domain, + // for each point: + Vec<( + // the point, + Challenge, + // values at the point + Vec, + )>, + )>, + )>, + proof: &Self::Proof, + challenger: &mut Challenger, + ) -> Result<(), Self::Error> { + // Write evaluations to challenger + for (_, round) in &rounds { + for (_, mat) in round { + for (_, point) in mat { + point + .iter() + .for_each(|&opening| challenger.observe_algebra_element(opening)); + } + } + } + + // Batch combination challenge + let alpha: Challenge = challenger.sample_algebra_element(); + + let log_global_max_height = + proof.commit_phase_commits.len() + self.fri.log_blowup + self.fri.log_final_poly_len; + + let g: TwoAdicFriGenericConfigForMmcs = + TwoAdicFriGenericConfig(PhantomData); + + verifier::verify(&g, &self.fri, proof, challenger, |index, input_proof| { + // TODO: separate this out into functions + + // log_height -> (alpha_pow, reduced_opening) + let mut reduced_openings = BTreeMap::::new(); + + for (batch_opening, (batch_commit, mats)) in + zip_eq(input_proof, &rounds, FriError::InvalidProofShape)? + { + let batch_heights = mats + .iter() + .map(|(domain, _)| domain.size() << self.fri.log_blowup) + .collect_vec(); + let batch_dims = batch_heights + .iter() + // TODO: MMCS doesn't really need width; we put 0 for now. + .map(|&height| Dimensions { width: 0, height }) + .collect_vec(); + + if let Some(batch_max_height) = batch_heights.iter().max() { + let log_batch_max_height = log2_strict_usize(*batch_max_height); + let bits_reduced = log_global_max_height - log_batch_max_height; + let reduced_index = index >> bits_reduced; + + self.mmcs.verify_batch( + batch_commit, + &batch_dims, + reduced_index, + &batch_opening.opened_values, + &batch_opening.opening_proof, + ) + } else { + // Empty batch? + self.mmcs.verify_batch( + batch_commit, + &[], + 0, + &batch_opening.opened_values, + &batch_opening.opening_proof, + ) + } + .map_err(FriError::InputError)?; + + for (mat_opening, (mat_domain, mat_points_and_values)) in zip_eq( + &batch_opening.opened_values, + mats, + FriError::InvalidProofShape, + )? { + let log_height = log2_strict_usize(mat_domain.size()) + self.fri.log_blowup; + + let bits_reduced = log_global_max_height - log_height; + let rev_reduced_index = reverse_bits_len(index >> bits_reduced, log_height); + + // todo: this can be nicer with domain methods? + + let x = Val::GENERATOR + * Val::two_adic_generator(log_height).exp_u64(rev_reduced_index as u64); + + let (alpha_pow, ro) = reduced_openings + .entry(log_height) + .or_insert((Challenge::ONE, Challenge::ZERO)); + + for (z, ps_at_z) in mat_points_and_values { + for (&p_at_x, &p_at_z) in + zip_eq(mat_opening, ps_at_z, FriError::InvalidProofShape)? + { + let quotient = (-p_at_z + p_at_x) / (-*z + x); + *ro += *alpha_pow * quotient; + *alpha_pow *= alpha; + } + } + } + } + + // `reduced_openings` would have a log_height = log_blowup entry only if there was a + // trace matrix of height 1. In this case the reduced opening can be skipped as it will + // not be checked against any commit phase commit. + if let Some((_alpha_pow, ro)) = reduced_openings.remove(&self.fri.log_blowup) { + assert!(ro.is_zero()); + } + + // Return reduced openings descending by log_height. + Ok(reduced_openings + .into_iter() + .rev() + .map(|(log_height, (_alpha_pow, ro))| (log_height, ro)) + .collect()) + })?; + + Ok(()) + } +} + +#[instrument(skip_all)] +fn compute_inverse_denominators, M: Matrix>( + mats_and_points: &[(Vec, &Vec>)], + coset_shift: F, +) -> LinearMap> { + let mut max_log_height_for_point: LinearMap = LinearMap::new(); + for (mats, points) in mats_and_points { + for (mat, points_for_mat) in izip!(mats, *points) { + let log_height = log2_strict_usize(mat.height()); + for &z in points_for_mat { + if let Some(lh) = max_log_height_for_point.get_mut(&z) { + *lh = core::cmp::max(*lh, log_height); + } else { + max_log_height_for_point.insert(z, log_height); + } + } + } + } + + // Compute the largest subgroup we will use, in bitrev order. + let max_log_height = *max_log_height_for_point.values().max().unwrap(); + let mut subgroup = cyclic_subgroup_coset_known_order( + F::two_adic_generator(max_log_height), + coset_shift, + 1 << max_log_height, + ) + .collect_vec(); + reverse_slice_index_bits(&mut subgroup); + + max_log_height_for_point + .into_iter() + .map(|(z, log_height)| { + ( + z, + batch_multiplicative_inverse( + &subgroup[..(1 << log_height)] + .iter() + .map(|&x| z - x) + .collect_vec(), + ), + ) + }) + .collect() +} diff --git a/CoqOfRust/plonky3/fri/src/two_adic_pcs.v b/CoqOfRust/plonky3/fri/src/two_adic_pcs.v new file mode 100644 index 000000000..4877ab0ec --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/two_adic_pcs.v @@ -0,0 +1,29820 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module two_adic_pcs. + (* StructRecord + { + name := "TwoAdicFriPcs"; + const_params := []; + ty_params := [ "Val"; "Dft"; "InputMmcs"; "FriMmcs" ]; + fields := + [ + ("dft", Dft); + ("mmcs", InputMmcs); + ("fri", Ty.apply (Ty.path "p3_fri::config::FriConfig") [] [ FriMmcs ]); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ Val ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Val_where_core_fmt_Debug_Dft_where_core_fmt_Debug_InputMmcs_where_core_fmt_Debug_FriMmcs_for_p3_fri_two_adic_pcs_TwoAdicFriPcs_Val_Dft_InputMmcs_FriMmcs. + Definition Self (Val Dft InputMmcs FriMmcs : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") [] [ Val; Dft; InputMmcs; FriMmcs ]. + + (* Debug *) + Definition fmt + (Val Dft InputMmcs FriMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field4_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "TwoAdicFriPcs" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "dft" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "dft" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "mmcs" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "mmcs" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "fri" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "fri" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Dft InputMmcs FriMmcs : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val Dft InputMmcs FriMmcs) + (* Instance *) [ ("fmt", InstanceField.Method (fmt Val Dft InputMmcs FriMmcs)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Val_where_core_fmt_Debug_Dft_where_core_fmt_Debug_InputMmcs_where_core_fmt_Debug_FriMmcs_for_p3_fri_two_adic_pcs_TwoAdicFriPcs_Val_Dft_InputMmcs_FriMmcs. + + Module Impl_p3_fri_two_adic_pcs_TwoAdicFriPcs_Val_Dft_InputMmcs_FriMmcs. + Definition Self (Val Dft InputMmcs FriMmcs : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") [] [ Val; Dft; InputMmcs; FriMmcs ]. + + (* + pub const fn new(dft: Dft, mmcs: InputMmcs, fri: FriConfig) -> Self { + Self { + dft, + mmcs, + fri, + _phantom: PhantomData, + } + } + *) + Definition new + (Val Dft InputMmcs FriMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs in + match ε, τ, α with + | [], [], [ dft; mmcs; fri ] => + ltac:(M.monadic + (let dft := M.alloc (| dft |) in + let mmcs := M.alloc (| mmcs |) in + let fri := M.alloc (| fri |) in + Value.StructRecord + "p3_fri::two_adic_pcs::TwoAdicFriPcs" + [ + ("dft", M.read (| dft |)); + ("mmcs", M.read (| mmcs |)); + ("fri", M.read (| fri |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (Val Dft InputMmcs FriMmcs : Ty.t), + M.IsAssociatedFunction.C + (Self Val Dft InputMmcs FriMmcs) + "new" + (new Val Dft InputMmcs FriMmcs). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_fri_two_adic_pcs_TwoAdicFriPcs_Val_Dft_InputMmcs_FriMmcs. + + (* StructRecord + { + name := "BatchOpening"; + const_params := []; + ty_params := [ "Val"; "InputMmcs" ]; + fields := + [ + ("opened_values", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]); + ("opening_proof", + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Proof") + ]; + } *) + + Module underscore. + Module Impl_serde_ser_Serialize_where_p3_field_field_Field_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_fri_two_adic_pcs_BatchOpening_Val_InputMmcs. + Definition Self (Val InputMmcs : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::two_adic_pcs::BatchOpening") [] [ Val; InputMmcs ]. + + (* Serialize *) + Definition serialize + (Val InputMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "BatchOpening" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "opened_values" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::BatchOpening", + "opened_values" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Proof" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "opening_proof" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::BatchOpening", + "opening_proof" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val InputMmcs : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val InputMmcs) + (* Instance *) [ ("serialize", InstanceField.Method (serialize Val InputMmcs)) ]. + End Impl_serde_ser_Serialize_where_p3_field_field_Field_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_fri_two_adic_pcs_BatchOpening_Val_InputMmcs. + Module Impl_serde_de_Deserialize_where_p3_field_field_Field_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_fri_two_adic_pcs_BatchOpening_Val_InputMmcs. + Definition Self (Val InputMmcs : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::two_adic_pcs::BatchOpening") [] [ Val; InputMmcs ]. + + (* Deserialize *) + Definition deserialize + (Val InputMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_fri::two_adic_pcs::BatchOpening") [] [ Val; InputMmcs ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::_'1::deserialize::__Visitor") + [] + [ Val; InputMmcs ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "BatchOpening" |); + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::_'1::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_fri::two_adic_pcs::_'1::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val InputMmcs : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val InputMmcs) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize Val InputMmcs)) ]. + End Impl_serde_de_Deserialize_where_p3_field_field_Field_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_fri_two_adic_pcs_BatchOpening_Val_InputMmcs. + End underscore. + + + Module Impl_core_clone_Clone_where_core_clone_Clone_Val_where_p3_field_field_Field_Val_where_core_clone_Clone_InputMmcs_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_fri_two_adic_pcs_BatchOpening_Val_InputMmcs. + Definition Self (Val InputMmcs : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::two_adic_pcs::BatchOpening") [] [ Val; InputMmcs ]. + + (* Clone *) + Definition clone + (Val InputMmcs : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val InputMmcs in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_fri::two_adic_pcs::BatchOpening" + [ + ("opened_values", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::BatchOpening", + "opened_values" + |) + |) + |) + |) + ] + |)); + ("opening_proof", + M.call_closure (| + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Proof", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Proof", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::BatchOpening", + "opening_proof" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val InputMmcs : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Val InputMmcs) + (* Instance *) [ ("clone", InstanceField.Method (clone Val InputMmcs)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_Val_where_p3_field_field_Field_Val_where_core_clone_Clone_InputMmcs_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_for_p3_fri_two_adic_pcs_BatchOpening_Val_InputMmcs. + + (* StructTuple + { + name := "TwoAdicFriGenericConfig"; + const_params := []; + ty_params := [ "InputProof"; "InputError" ]; + fields := + [ Ty.apply (Ty.path "core::marker::PhantomData") [] [ Ty.tuple [ InputProof; InputError ] ] + ]; + } *) + + Axiom TwoAdicFriGenericConfigForMmcs : + forall (F M_ : Ty.t), + (Ty.apply (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriGenericConfigForMmcs") [] [ F; M_ ]) = + (Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriGenericConfig") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::two_adic_pcs::BatchOpening") [] [ F; M_ ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Error" + ]). + + Module Impl_p3_fri_config_FriGenericConfig_where_p3_field_field_TwoAdicField_F_where_core_fmt_Debug_InputError_F_for_p3_fri_two_adic_pcs_TwoAdicFriGenericConfig_InputProof_InputError. + Definition Self (F InputProof InputError : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriGenericConfig") + [] + [ InputProof; InputError ]. + + (* type InputProof = InputProof; *) + Definition _InputProof (F InputProof InputError : Ty.t) : Ty.t := InputProof. + + (* type InputError = InputError; *) + Definition _InputError (F InputProof InputError : Ty.t) : Ty.t := InputError. + + (* + fn extra_query_index_bits(&self) -> usize { + 0 + } + *) + Definition extra_query_index_bits + (F InputProof InputError : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F InputProof InputError in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Integer IntegerKind.Usize 0)) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn fold_row( + &self, + index: usize, + log_height: usize, + beta: F, + evals: impl Iterator, + ) -> F { + let arity = 2; + let log_arity = 1; + let (e0, e1) = evals + .collect_tuple() + .expect("TwoAdicFriFolder only supports arity=2"); + // If performance critical, make this API stateful to avoid this + // This is a bit more math than is necessary, but leaving it here + // in case we want higher arity in the future + let subgroup_start = F::two_adic_generator(log_height + log_arity) + .exp_u64(reverse_bits_len(index, log_height) as u64); + let mut xs = F::two_adic_generator(log_arity) + .shifted_powers(subgroup_start) + .take(arity) + .collect_vec(); + reverse_slice_index_bits(&mut xs); + assert_eq!(log_arity, 1, "can only interpolate two points for now"); + // interpolate and evaluate at beta + e0 + (beta - xs[0]) * (e1 - e0) / (xs[1] - xs[0]) + } + *) + Definition fold_row + (F InputProof InputError : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F InputProof InputError in + match ε, τ, α with + | [], [ impl_Iterator_Item___F_ ], [ self; index; log_height; beta; evals ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let index := M.alloc (| index |) in + let log_height := M.alloc (| log_height |) in + let beta := M.alloc (| beta |) in + let evals := M.alloc (| evals |) in + M.read (| + let~ arity : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 2 |) in + let~ log_arity : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ F ], + M.alloc (| + M.call_closure (| + Ty.tuple [ F; F ], + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.tuple [ F; F ] ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.tuple [ F; F ] ], + M.get_trait_method (| + "itertools::Itertools", + impl_Iterator_Item___F_, + [], + [], + "collect_tuple", + [], + [ Ty.tuple [ F; F ] ] + |), + [ M.read (| evals |) ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "TwoAdicFriFolder only supports arity=2" |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let e0 := M.copy (| γ0_0 |) in + let e1 := M.copy (| γ0_1 |) in + let~ subgroup_start : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_height |); M.read (| log_arity |) ] + |) + ] + |) + |) + |); + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::reverse_bits_len", [], [] |), + [ M.read (| index |); M.read (| log_height |) ] + |)) + ] + |) + |) in + let~ xs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "shifted_powers", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_arity |) ] + |) + |) + |); + M.read (| subgroup_start |) + ] + |); + M.read (| arity |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, xs |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, log_arity |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 1 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "can only interpolate two points for now" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.read (| e0 |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Div", + F, + [], + [ F ], + "div", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.read (| beta |); + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ F ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, xs |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ M.read (| e1 |); M.read (| e0 |) ] + |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ F ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, xs |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |); + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ F ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, xs |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn fold_matrix>(&self, beta: F, m: M) -> Vec { + // We use the fact that + // p_e(x^2) = (p(x) + p(-x)) / 2 + // p_o(x^2) = (p(x) - p(-x)) / (2 x) + // that is, + // p_e(g^(2i)) = (p(g^i) + p(g^(n/2 + i))) / 2 + // p_o(g^(2i)) = (p(g^i) - p(g^(n/2 + i))) / (2 g^i) + // so + // result(g^(2i)) = p_e(g^(2i)) + beta p_o(g^(2i)) + // = (1/2 + beta/2 g_inv^i) p(g^i) + // + (1/2 - beta/2 g_inv^i) p(g^(n/2 + i)) + let g_inv = F::two_adic_generator(log2_strict_usize(m.height()) + 1).inverse(); + let one_half = F::ONE.halve(); + let half_beta = beta * one_half; + + // TODO: vectorize this (after we have packed extension fields) + + // beta/2 times successive powers of g_inv + let mut powers = g_inv + .shifted_powers(half_beta) + .take(m.height()) + .collect_vec(); + reverse_slice_index_bits(&mut powers); + + m.par_rows() + .zip(powers) + .map(|(mut row, power)| { + let (lo, hi) = row.next_tuple().unwrap(); + (one_half + power) * lo + (one_half - power) * hi + }) + .collect() + } + *) + Definition fold_matrix + (F InputProof InputError : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F InputProof InputError in + match ε, τ, α with + | [], [ M_ ], [ self; beta; m ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let beta := M.alloc (| beta |) in + let m := M.alloc (| m |) in + M.read (| + let~ g_inv : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, m |) ] + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |) + ] + |) + |) in + let~ one_half : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "halve", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) + |) + ] + |) + |) in + let~ half_beta : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| beta |); M.read (| one_half |) ] + |) + |) in + let~ powers : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "shifted_powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, g_inv |); M.read (| half_beta |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, m |) ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, powers |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait "p3_matrix::Matrix" [] [ F ] M_ "{{synthetic}}'1"; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.associated_in_trait "p3_matrix::Matrix" [] [ F ] M_ "Row"; F ] + ] + ] + F + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F ] + M_ + "{{synthetic}}'1"; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.associated_in_trait "p3_matrix::Matrix" [] [ F ] M_ "Row"; F + ] + ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait "p3_matrix::Matrix" [] [ F ] M_ "{{synthetic}}'1"; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.associated_in_trait "p3_matrix::Matrix" [] [ F ] M_ "Row"; F + ] + ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F ] + M_ + "{{synthetic}}'1"; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait "p3_matrix::Matrix" [] [ F ] M_ "{{synthetic}}'1", + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F ] + M_ + "{{synthetic}}'1", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "par_rows", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, m |) ] + |); + M.read (| powers |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F ] + M_ + "Row"; + F + ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let row := M.copy (| γ0_0 |) in + let power := M.copy (| γ0_1 |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ F ], + M.alloc (| + M.call_closure (| + Ty.tuple [ F; F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ F; F ] ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ F; F ] ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ F ] + M_ + "Row", + [], + [], + "next_tuple", + [], + [ Ty.tuple [ F; F ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, row |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let lo := M.copy (| γ0_0 |) in + let hi := M.copy (| γ0_1 |) in + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ + M.read (| one_half |); + M.read (| power |) + ] + |); + M.read (| lo |) + ] + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.read (| one_half |); + M.read (| power |) + ] + |); + M.read (| hi |) + ] + |) + ] + |) + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F InputProof InputError : Ty.t), + M.IsTraitInstance + "p3_fri::config::FriGenericConfig" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F InputProof InputError) + (* Instance *) + [ + ("InputProof", InstanceField.Ty (_InputProof F InputProof InputError)); + ("InputError", InstanceField.Ty (_InputError F InputProof InputError)); + ("extra_query_index_bits", + InstanceField.Method (extra_query_index_bits F InputProof InputError)); + ("fold_row", InstanceField.Method (fold_row F InputProof InputError)); + ("fold_matrix", InstanceField.Method (fold_matrix F InputProof InputError)) + ]. + End Impl_p3_fri_config_FriGenericConfig_where_p3_field_field_TwoAdicField_F_where_core_fmt_Debug_InputError_F_for_p3_fri_two_adic_pcs_TwoAdicFriGenericConfig_InputProof_InputError. + + Module Impl_p3_commit_pcs_Pcs_where_p3_field_field_TwoAdicField_Val_where_p3_dft_traits_TwoAdicSubgroupDft_Dft_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_p3_field_field_TwoAdicField_Challenge_where_p3_field_field_ExtensionField_Challenge_Val_where_p3_challenger_FieldChallenger_Challenger_Val_where_p3_challenger_CanObserve_Challenger_associated_in_trait_p3_commit_mmcs_Mmcs__Challenge_FriMmcs_Commitment_where_p3_challenger_grinding_challenger_GrindingChallenger_Challenger_Challenge_Challenger_for_p3_fri_two_adic_pcs_TwoAdicFriPcs_Val_Dft_InputMmcs_FriMmcs. + Definition Self (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") [] [ Val; Dft; InputMmcs; FriMmcs ]. + + (* type Domain = TwoAdicMultiplicativeCoset; *) + Definition _Domain (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ]. + + (* type Commitment = InputMmcs::Commitment; *) + Definition _Commitment (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Commitment". + + (* type ProverData = InputMmcs::ProverData>; *) + Definition _ProverData (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "alloc::vec::Vec") [] [ Val; Ty.path "alloc::alloc::Global" ] ] + ] + InputMmcs + "ProverData". + + (* type EvaluationsOnDomain<'a> = BitReversedMatrixView>; *) + Definition _EvaluationsOnDomain + (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] ] + ]. + + (* type Proof = FriProof>>; *) + Definition _Proof (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_fri::proof::FriProof") + [] + [ + Challenge; + FriMmcs; + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_fri::two_adic_pcs::BatchOpening") [] [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ]. + + (* type Error = FriError; *) + Definition _Error (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] FriMmcs "Error"; + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Val ] InputMmcs "Error" + ]. + + (* + fn natural_domain_for_degree(&self, degree: usize) -> Self::Domain { + // This panics if (and only if) `degree` is not a power of 2 or `degree` + // > `1 << Val::TWO_ADICITY`. + TwoAdicMultiplicativeCoset::new(Val::ONE, log2_strict_usize(degree)).unwrap() + } + *) + Definition natural_domain_for_degree + (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; degree ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let degree := M.alloc (| degree |) in + M.call_closure (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ] ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ] ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") [] [ Val ], + "new", + [], + [] + |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", Val |) + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| degree |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn commit( + &self, + evaluations: Vec<(Self::Domain, RowMajorMatrix)>, + ) -> (Self::Commitment, Self::ProverData) { + let ldes: Vec<_> = evaluations + .into_iter() + .map(|(domain, evals)| { + assert_eq!(domain.size(), evals.height()); + let shift = Val::GENERATOR / domain.shift(); + // Commit to the bit-reversed LDE. + self.dft + .coset_lde_batch(evals, self.fri.log_blowup, shift) + .bit_reverse_rows() + .to_row_major_matrix() + }) + .collect(); + + self.mmcs.commit(ldes) + } + *) + Definition commit + (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; evaluations ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let evaluations := M.alloc (| evaluations |) in + M.read (| + let~ ldes : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| evaluations |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let domain := M.copy (| γ0_0 |) in + let evals := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + domain + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Val ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, evals |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ shift : Ty.apply (Ty.path "*") [] [ Val ] := + M.alloc (| + M.call_closure (| + Val, + M.get_trait_method (| + "core::ops::arith::Div", + Val, + [], + [ Val ], + "div", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::Field::GENERATOR", + Val + |) + |); + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, domain |) ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_matrix::bitrev::BitReversibleMatrix" + [] + [ Val ] + (Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ Val ] + Dft + "Evaluations") + "BitRev", + [], + [ Val ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::bitrev::BitReversibleMatrix" + [] + [ Val ] + (Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ Val ] + Dft + "Evaluations") + "BitRev", + M.get_trait_method (| + "p3_matrix::bitrev::BitReversibleMatrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ Val ] + Dft + "Evaluations", + [], + [ Val ], + "bit_reverse_rows", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ Val ] + Dft + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ Val ], + "coset_lde_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "dft" + |) + |); + M.read (| evals |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "fri" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |); + M.read (| shift |) + ] + |) + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "commit", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "mmcs" + |) + |); + M.read (| ldes |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn get_evaluations_on_domain<'a>( + &self, + prover_data: &'a Self::ProverData, + idx: usize, + domain: Self::Domain, + ) -> Self::EvaluationsOnDomain<'a> { + // todo: handle extrapolation for LDEs we don't have + assert_eq!(domain.shift(), Val::GENERATOR); + let lde = self.mmcs.get_matrices(prover_data)[idx]; + assert!(lde.height() >= domain.size()); + lde.split_rows(domain.size()).0.bit_reverse_rows() + } + *) + Definition get_evaluations_on_domain + (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; prover_data; idx; domain ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let prover_data := M.alloc (| prover_data |) in + let idx := M.alloc (| idx |) in + let domain := M.alloc (| domain |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "shift", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, domain |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::Field::GENERATOR", Val |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Val, + [], + [ Val ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Val; Val ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ lde : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "get_matrices", + [], + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prover_data |) |) + |) + ] + |) + |) + |); + M.read (| idx |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + [], + [ Val ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| lde |) |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, domain |) ] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: lde.height() >= domain.size()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] ] + ], + M.get_trait_method (| + "p3_matrix::bitrev::BitReversibleMatrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ Val; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Val ] ] ], + [], + [ Val ], + "bit_reverse_rows", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ], + "split_rows", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| lde |) |) |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ], + "size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, domain |) ] + |) + ] + |) + |), + 0 + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn open( + &self, + // For each round, + rounds: Vec<( + &Self::ProverData, + // for each matrix, + Vec< + // points to open + Vec, + >, + )>, + challenger: &mut Challenger, + ) -> (OpenedValues, Self::Proof) { + /* + + A quick rundown of the optimizations in this function: + We are trying to compute sum_i alpha^i * (p(X) - y)/(X - z), + for each z an opening point, y = p(z). Each p(X) is given as evaluations in bit-reversed order + in the columns of the matrices. y is computed by barycentric interpolation. + X and p(X) are in the base field; alpha, y and z are in the extension. + The primary goal is to minimize extension multiplications. + + - Instead of computing all alpha^i, we just compute alpha^i for i up to the largest width + of a matrix, then multiply by an "alpha offset" when accumulating. + a^0 x0 + a^1 x1 + a^2 x2 + a^3 x3 + ... + = a^0 ( a^0 x0 + a^1 x1 ) + a^2 ( a^0 x2 + a^1 x3 ) + ... + (see `alpha_pows`, `alpha_pow_offset`, `num_reduced`) + + - For each unique point z, we precompute 1/(X-z) for the largest subgroup opened at this point. + Since we compute it in bit-reversed order, smaller subgroups can simply truncate the vector. + (see `inv_denoms`) + + - Then, for each matrix (with columns p_i) and opening point z, we want: + for each row (corresponding to subgroup element X): + reduced[X] += alpha_offset * sum_i [ alpha^i * inv_denom[X] * (p_i[X] - y[i]) ] + + We can factor out inv_denom, and expand what's left: + reduced[X] += alpha_offset * inv_denom[X] * sum_i [ alpha^i * p_i[X] - alpha^i * y[i] ] + + And separate the sum: + reduced[X] += alpha_offset * inv_denom[X] * [ sum_i [ alpha^i * p_i[X] ] - sum_i [ alpha^i * y[i] ] ] + + And now the last sum doesn't depend on X, so we can precompute that for the matrix, too. + So the hot loop (that depends on both X and i) is just: + sum_i [ alpha^i * p_i[X] ] + + with alpha^i an extension, p_i[X] a base + + */ + + let mats_and_points = rounds + .iter() + .map(|(data, points)| { + let mats = self + .mmcs + .get_matrices(data) + .into_iter() + .map(|m| m.as_view()) + .collect_vec(); + debug_assert_eq!( + mats.len(), + points.len(), + "each matrix should have a corresponding set of evaluation points" + ); + (mats, points) + }) + .collect_vec(); + + // Find the maximum height and the maximum width of matrices in the batch. + // These do not need to correspond to the same matrix. + let (global_max_height, global_max_width) = mats_and_points + .iter() + .flat_map(|(mats, _)| mats.iter().map(|m| (m.height(), m.width()))) + .reduce(|(hmax, wmax), (h, w)| (hmax.max(h), wmax.max(w))) + .expect("No Matrices Supplied?"); + let log_global_max_height = log2_strict_usize(global_max_height); + + // For each unique opening point z, we will find the largest degree bound + // for that point, and precompute 1/(z - X) for the largest subgroup (in bitrev order). + let inv_denoms = compute_inverse_denominators(&mats_and_points, Val::GENERATOR); + + // Evaluate coset representations and write openings to the challenger + let all_opened_values = mats_and_points + .iter() + .map(|(mats, points)| { + izip!(mats.iter(), points.iter()) + .map(|(mat, points_for_mat)| { + points_for_mat + .iter() + .map(|&point| { + let _guard = + info_span!("evaluate matrix", dims = %mat.dimensions()) + .entered(); + + // Use Barycentric interpolation to evaluate the matrix at the given point. + let ys = + info_span!("compute opened values with Lagrange interpolation") + .in_scope(|| { + let h = mat.height() >> self.fri.log_blowup; + let (low_coset, _) = mat.split_rows(h); + let mut inv_denoms = + inv_denoms.get(&point).unwrap()[..h].to_vec(); + reverse_slice_index_bits(&mut inv_denoms); + interpolate_coset( + &BitReversalPerm::new_view(low_coset), + Val::GENERATOR, + point, + Some(&inv_denoms), + ) + }); + ys.iter() + .for_each(|&y| challenger.observe_algebra_element(y)); + ys + }) + .collect_vec() + }) + .collect_vec() + }) + .collect_vec(); + + // Batch combination challenge + // TODO: Should we be computing a different alpha for each height? + let alpha: Challenge = challenger.sample_algebra_element(); + + // We precompute powers of alpha as we need the same powers for each matrix. + // We compute both a vector of unpacked powers and a vector of packed powers. + // TODO: It should be possible to refactor this to only use the packed powers but + // this is not a bottleneck so is not a priority. + let packed_alpha_powers = + Challenge::ExtensionPacking::packed_ext_powers_capped(alpha, global_max_width) + .collect_vec(); + let alpha_powers = + Challenge::ExtensionPacking::to_ext_iter(packed_alpha_powers.iter().copied()) + .collect_vec(); + + // Now that we have sent the openings to the verifier, it remains to prove + // that those openings are correct. + + // Given a low degree polynomial `f(x)` with claimed evaluation `f(zeta)`, we can check + // that `f(zeta)` is correct by doing a low degree test on `(f(zeta) - f(x))/(zeta - x)`. + // We will use `alpha` to batch together both different claimed openings `zeta` and + // different polynomials `f` whose evaluation vectors have the same height. + + // TODO: If we allow different polynomials to have different blow_up factors + // we may need to revisit this and to ensure it is safe to batch them together. + + // num_reduced records the number of reduced function opening point pairs + // of each given `log_height`. + let mut num_reduced = [0; 32]; + + // For each `log_height` from 2^1 -> 2^32, reduced_openings will contain either `None` + // if there are no matrices of that height, or `Some(vec)` where `vec` is equal to + // a sum of `(f(zeta) - f(x))/(zeta - x)` over all `f`'s of that height and + // opening points `zeta` with the sum weighted by powers of alpha. + let mut reduced_openings: [_; 32] = core::array::from_fn(|_| None); + + for ((mats, points), openings_for_round) in + mats_and_points.iter().zip(all_opened_values.iter()) + { + for (mat, points_for_mat, openings_for_mat) in + izip!(mats.iter(), points.iter(), openings_for_round.iter()) + { + let _guard = + info_span!("reduce matrix quotient", dims = %mat.dimensions()).entered(); + + let log_height = log2_strict_usize(mat.height()); + + // If this is our first matrix at this height, initialise reduced_openings to zero. + // Otherwise, get a mutable reference to it. + let reduced_opening_for_log_height = reduced_openings[log_height] + .get_or_insert_with(|| vec![Challenge::ZERO; mat.height()]); + debug_assert_eq!(reduced_opening_for_log_height.len(), mat.height()); + + // Treating our matrix M as the evaluations of functions M0, M1, ... + // Compute the evaluations of `Mred(x) = M0(x) + alpha*M1(x) + ...` + let mat_compressed = info_span!("compress mat").in_scope(|| { + // This will be reused for all points z which M is opened at so we collect into a vector. + mat.rowwise_packed_dot_product::(&packed_alpha_powers) + .collect::>() + }); + + for (&point, openings) in points_for_mat.iter().zip(openings_for_mat) { + // If we have multiple matrices at the same height, we need to scale mat to combine them. + let alpha_pow_offset = alpha.exp_u64(num_reduced[log_height] as u64); + + // As we have all the openings `Mi(z)`, we can combine them using `alpha` + // in an identical way to before to also compute `Mred(z)`. + let reduced_openings: Challenge = + dot_product(alpha_powers.iter().copied(), openings.iter().copied()); + + mat_compressed + .par_iter() + .zip(reduced_opening_for_log_height.par_iter_mut()) + // inv_denoms contains `1/(point - x)` for `x` in a coset `gK`. + // If `|K| =/= mat.height()` we actually want a subset of this + // corresponding to the evaluations over `gH` for `|H| = mat.height()`. + // As inv_denoms is bit reversed, the evaluations over `gH` are exactly + // the evaluations over `gK` at the indices `0..mat.height()`. + // So zip will truncate to the desired smaller length. + .zip(inv_denoms.get(&point).unwrap().par_iter()) + // Map the function `Mred(x) -> (Mred(z) - Mred(x))/(z - x)` + // across the evaluations vector of `Mred(x)`. + .for_each(|((&reduced_row, ro), &inv_denom)| { + *ro += alpha_pow_offset * (reduced_openings - reduced_row) * inv_denom + }); + num_reduced[log_height] += mat.width(); + } + } + } + + let fri_input = reduced_openings.into_iter().rev().flatten().collect_vec(); + + let g: TwoAdicFriGenericConfigForMmcs = + TwoAdicFriGenericConfig(PhantomData); + + let fri_proof = prover::prove(&g, &self.fri, fri_input, challenger, |index| { + rounds + .iter() + .map(|(data, _)| { + let log_max_height = log2_strict_usize(self.mmcs.get_max_height(data)); + let bits_reduced = log_global_max_height - log_max_height; + let reduced_index = index >> bits_reduced; + let (opened_values, opening_proof) = self.mmcs.open_batch(reduced_index, data); + BatchOpening { + opened_values, + opening_proof, + } + }) + .collect() + }); + + (all_opened_values, fri_proof) + } + *) + Definition open + (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; rounds; challenger ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rounds := M.alloc (| rounds |) in + let challenger := M.alloc (| challenger |) in + M.read (| + let~ mats_and_points : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Val; Ty.path "alloc::alloc::Global" ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rounds |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let data := M.alloc (| γ1_0 |) in + let points := M.alloc (| γ1_1 |) in + M.read (| + let~ mats : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "get_matrices", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| data |) + |) + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := + M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ], + "as_view", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| m |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + mats + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| points |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := + M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path + "usize"; + Ty.path + "usize" + ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "each matrix should have a corresponding set of evaluation points" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.Tuple [ M.read (| mats |); M.read (| points |) ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::proof::FriProof") + [] + [ + Challenge; + FriMmcs; + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ] + ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ] + ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ]) + ], + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]; + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] + ] + ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ] + ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ] + ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ] + ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + ] + ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mats_and_points |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ] + ] + ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let mats := M.alloc (| γ1_0 |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ] + ] + ] + (Ty.tuple + [ Ty.path "usize"; Ty.path "usize" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ] + ] + ] + (Ty.tuple + [ Ty.path "usize"; Ty.path "usize" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| mats |) |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.path "usize"; + Ty.path "usize" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := M.copy (| γ |) in + Value.Tuple + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ], + [], + [ Val ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| m |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ], + [], + [ Val ], + "width", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| m |) + |) + |) + ] + |) + ])) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]; + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] + ] + ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let hmax := M.copy (| γ0_0 |) in + let wmax := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.path "usize"; Ty.path "usize" ]; + Ty.tuple + [ Ty.path "usize"; Ty.path "usize" ] + ] + ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let h := M.copy (| γ0_0 |) in + let w := M.copy (| γ0_1 |) in + Value.Tuple + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "usize", + [], + [], + "max", + [], + [] + |), + [ M.read (| hmax |); M.read (| h |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "usize", + [], + [], + "max", + [], + [] + |), + [ M.read (| wmax |); M.read (| w |) ] + |) + ])) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "No Matrices Supplied?" |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let global_max_height := M.copy (| γ0_0 |) in + let global_max_width := M.copy (| γ0_1 |) in + let~ log_global_max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| global_max_height |) ] + |) + |) in + let~ inv_denoms : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_util::linear_map::LinearMap") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_util::linear_map::LinearMap") + [] + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ], + M.get_function (| + "p3_fri::two_adic_pcs::compute_inverse_denominators", + [], + [ + Val; + Challenge; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, mats_and_points |) |) + |) + ] + |) + |) + |); + M.read (| get_constant (| "p3_field::field::Field::GENERATOR", Val |) |) + ] + |) + |) in + let~ all_opened_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mats_and_points |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let mats := M.alloc (| γ1_0 |) in + let points := M.alloc (| γ1_1 |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| mats |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| + points + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let mat := + M.copy (| γ0_0 |) in + let points_for_mat := + M.copy (| γ0_1 |) in + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + points_for_mat + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ + with + | [ α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + point := + M.copy (| + γ + |) in + M.read (| + let~ + _guard : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing::span::EnteredSpan" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::EnteredSpan", + M.get_associated_function (| + Ty.path + "tracing::span::Span", + "entered", + [], + [] + |), + [ + M.read (| + let~ + interest : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing_core::subscriber::Interest" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing::span::Span" + ], + M.alloc (| + Value.Tuple + [] + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::{{closure}}'3::{{closure}}::{{closure}}::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path + "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::{{closure}}'3::{{closure}}::{{closure}}::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| + interest + |) + ] + |))) + |) + |)) in + let + _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + let~ + meta : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::{{closure}}'3::{{closure}}::{{closure}}::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::Span", + M.get_associated_function (| + Ty.path + "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ + iter : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ], + [], + [ + Val + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun + γ => + ltac:(M.monadic + (let~ + span : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing::span::Span" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::{{closure}}'3::{{closure}}::{{closure}}::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + Value.Tuple + [] + |) in + span)) + ] + |) + |) + ] + |) + |) in + let~ + ys : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.path + "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ + Ty.tuple + [] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]); + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ + interest : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing_core::subscriber::Interest" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing::span::Span" + ], + M.alloc (| + Value.Tuple + [] + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::{{closure}}'3::{{closure}}::{{closure}}::__CALLSITE'1", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path + "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::{{closure}}'3::{{closure}}::{{closure}}::__CALLSITE'1", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| + interest + |) + ] + |))) + |) + |)) in + let + _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + let~ + meta : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::{{closure}}'3::{{closure}}::{{closure}}::__CALLSITE'1", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::Span", + M.get_associated_function (| + Ty.path + "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun + γ => + ltac:(M.monadic + (let~ + span : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing::span::Span" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::{{closure}}'3::{{closure}}::{{closure}}::__CALLSITE'1", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + Value.Tuple + [] + |) in + span)) + ] + |) + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (M.read (| + let~ + h : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path + "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ], + [], + [ + Val + ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "fri" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ]; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ], + "split_rows", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |); + M.read (| + h + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + low_coset := + M.copy (| + γ0_0 + |) in + let~ + inv_denoms : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeTo") + [] + [ + Ty.path + "usize" + ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_util::linear_map::LinearMap") + [] + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + "get", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + inv_denoms + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + point + |) + |) + |) + ] + |) + ] + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.read (| + h + |)) + ] + ] + |) + |) + |) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_function (| + "p3_util::reverse_slice_index_bits", + [], + [ + Challenge + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + inv_denoms + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_function (| + "p3_interpolation::interpolate_coset", + [], + [ + Val; + Challenge; + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path + "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path + "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ], + M.get_associated_function (| + Ty.path + "p3_matrix::bitrev::BitReversalPerm", + "new_view", + [], + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ] + |), + [ + M.read (| + low_coset + |) + ] + |) + |) + |) + |) + |); + M.read (| + get_constant (| + "p3_field::field::Field::GENERATOR", + Val + |) + |); + M.read (| + point + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + inv_denoms + |) + |) + |) + ] + |) + |) + |) + ] + ] + |) + |))) + ] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.tuple + []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + ys + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.tuple + []) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + y := + M.copy (| + γ + |) in + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ + Val + ], + "observe_algebra_element", + [], + [ + Challenge + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + challenger + |) + |) + |); + M.read (| + y + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + ys + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ alpha : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "sample_algebra_element", + [], + [ Challenge ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |) + ] + |) + |) in + let~ packed_alpha_powers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_in_trait + "p3_field::packed::PackedFieldExtension" + [] + [ Val; Challenge ] + (Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking") + "{{synthetic}}'1", + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedFieldExtension" + [] + [ Val; Challenge ] + (Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking") + "{{synthetic}}'1", + M.get_trait_method (| + "p3_field::packed::PackedFieldExtension", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking", + [], + [ Val; Challenge ], + "packed_ext_powers_capped", + [], + [] + |), + [ M.read (| alpha |); M.read (| global_max_width |) ] + |) + ] + |) + |) in + let~ alpha_powers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_in_trait + "p3_field::packed::PackedFieldExtension" + [] + [ + Val; + Challenge; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking" + ] + ] + ] + (Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking") + "{{synthetic}}", + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::packed::PackedFieldExtension" + [] + [ + Val; + Challenge; + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking" + ] + ] + ] + (Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking") + "{{synthetic}}", + M.get_trait_method (| + "p3_field::packed::PackedFieldExtension", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking", + [], + [ Val; Challenge ], + "to_ext_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking" + ], + [], + [], + "copied", + [], + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ Val ] + Challenge + "ExtensionPacking"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, packed_alpha_powers |) + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ num_reduced : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "usize" ] + ] := + M.alloc (| + repeat (| + Value.Integer IntegerKind.Usize 0, + Value.Integer IntegerKind.Usize 32 + |) + |) in + let~ reduced_openings : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 32 ], + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple "core::option::Option::None" [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Val ] ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mats_and_points |) ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, all_opened_values |) ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let γ1_0 := M.read (| γ1_0 |) in + let γ3_0 := + M.SubPointer.get_tuple_field (| γ1_0, 0 |) in + let γ3_1 := + M.SubPointer.get_tuple_field (| γ1_0, 1 |) in + let mats := M.alloc (| γ3_0 |) in + let points := M.alloc (| γ3_1 |) in + let openings_for_round := M.copy (| γ1_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]) + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| mats |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Val ] + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| iter |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| + points + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| iter |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + openings_for_round + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := + M.copy (| + γ1_0 + |) in + let b := + M.copy (| + γ1_1 + |) in + let b := + M.copy (| + γ0_1 + |) in + Value.Tuple + [ + M.read (| + a + |); + M.read (| + b + |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val + ] + ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]) + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ1_2 := + M.SubPointer.get_tuple_field (| + γ0_0, + 2 + |) in + let mat := + M.copy (| γ1_0 |) in + let points_for_mat := + M.copy (| γ1_1 |) in + let openings_for_mat := + M.copy (| γ1_2 |) in + let~ _guard : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "tracing::span::EnteredSpan" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::EnteredSpan", + M.get_associated_function (| + Ty.path + "tracing::span::Span", + "entered", + [], + [] + |), + [ + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "tracing_core::subscriber::Interest" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "tracing::span::Span" + ], + M.alloc (| + Value.Tuple [] + |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path + "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| + interest + |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + let~ meta : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::Span", + M.get_associated_function (| + Ty.path + "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ + iter : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ], + [], + [ + Val + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing::span::Span" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::__CALLSITE", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + Value.Tuple + [] + |) in + span)) + ] + |) + |) + ] + |) + |) in + let~ log_height : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ Val ] + ] + ], + [], + [ Val ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |) + ] + |) + ] + |) + |) in + let~ + reduced_opening_for_log_height : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + "get_or_insert_with", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + reduced_openings, + M.read (| + log_height + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_function (| + "alloc::vec::from_elem", + [], + [ + Challenge + ] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Challenge + |) + |); + M.call_closure (| + Ty.path + "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ], + [], + [ + Val + ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple [] + |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + Value.Bool + true + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] + ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] + ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + reduced_opening_for_log_height + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ], + [], + [ + Val + ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + left_val := + M.copy (| + γ0_0 + |) in + let + right_val := + M.copy (| + γ0_1 + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + Value.Tuple + [] + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let + _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ + kind : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path + "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path + "usize"; + Ty.path + "usize" + ] + |), + [ + M.read (| + kind + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [] + |))) + ] + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |) in + let~ mat_compressed : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.path + "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]); + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "tracing_core::subscriber::Interest" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "tracing::span::Span" + ], + M.alloc (| + Value.Tuple [] + |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::__CALLSITE'1", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path + "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::__CALLSITE'1", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| + interest + |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| + γ + |), + Value.Bool + true + |) in + let~ meta : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::__CALLSITE'1", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::Span", + M.get_associated_function (| + Ty.path + "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + meta + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "tracing::span::Span" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::open::__CALLSITE'1", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + Value.Tuple + [] + |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ], + [], + [ + Val + ], + "rowwise_packed_dot_product", + [], + [ + Challenge + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Val + ] + Challenge + "ExtensionPacking" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Val + ] + Challenge + "ExtensionPacking"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + packed_alpha_powers + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + points_for_mat + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.read (| + openings_for_mat + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let + γ1_0 := + M.read (| + γ1_0 + |) in + let + point := + M.copy (| + γ1_0 + |) in + let + openings := + M.copy (| + γ1_1 + |) in + let~ + alpha_pow_offset : + Ty.apply + (Ty.path + "*") + [] + [ + Challenge + ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Challenge, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + alpha + |); + M.cast + (Ty.path + "u64") + (M.read (| + M.SubPointer.get_array_field (| + num_reduced, + M.read (| + log_height + |) + |) + |)) + ] + |) + |) in + let~ + reduced_openings : + Ty.apply + (Ty.path + "*") + [] + [ + Challenge + ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_function (| + "p3_field::helpers::dot_product", + [], + [ + Challenge; + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + [], + [], + "copied", + [], + [ + Challenge + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + alpha_powers + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + [], + [], + "copied", + [], + [ + Challenge + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + openings + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + ] + (Ty.tuple + []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Challenge + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Challenge + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelRefIterator", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "par_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + mat_compressed + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Challenge + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelRefMutIterator", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "par_iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + reduced_opening_for_log_height + |) + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelRefIterator", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "par_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_util::linear_map::LinearMap") + [] + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ], + "get", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + inv_denoms + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + point + |) + |) + |) + ] + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + ] + (Ty.tuple + []) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let + γ1_0 := + M.read (| + γ1_0 + |) in + let + reduced_row := + M.copy (| + γ1_0 + |) in + let + ro := + M.copy (| + γ1_1 + |) in + let + γ0_1 := + M.read (| + γ0_1 + |) in + let + inv_denom := + M.copy (| + γ0_1 + |) in + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Challenge, + [], + [ + Challenge + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + ro + |) + |) + |); + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Mul", + Challenge, + [], + [ + Challenge + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Mul", + Challenge, + [], + [ + Challenge + ], + "mul", + [], + [] + |), + [ + M.read (| + alpha_pow_offset + |); + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Sub", + Challenge, + [], + [ + Challenge + ], + "sub", + [], + [] + |), + [ + M.read (| + reduced_openings + |); + M.read (| + reduced_row + |) + ] + |) + ] + |); + M.read (| + inv_denom + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + let + β := + M.SubPointer.get_array_field (| + num_reduced, + M.read (| + log_height + |) + |) in + M.write (| + β, + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + β + |); + M.call_closure (| + Ty.path + "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Val + ] + ] + ], + [], + [ + Val + ], + "width", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat + |) + |) + |) + ] + |) + ] + |) + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ fri_input : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::flatten::Flatten") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::Flatten") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ], + [], + [], + "flatten", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ], + [], + [], + "rev", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| reduced_openings |) ] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ g : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriGenericConfig") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ] := + M.alloc (| + Value.StructTuple + "p3_fri::two_adic_pcs::TwoAdicFriGenericConfig" + [ Value.StructTuple "core::marker::PhantomData" [] ] + |) in + let~ fri_proof : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::FriProof") + [] + [ + Challenge; + FriMmcs; + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_fri::proof::FriProof") + [] + [ + Challenge; + FriMmcs; + Val; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_function (| + "p3_fri::prover::prove", + [], + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriGenericConfig") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ]; + Val; + Challenge; + FriMmcs; + Challenger; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, g |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "fri" + |) + |) + |) + |); + M.read (| fri_input |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let index := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + rounds + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + InputMmcs + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let data := + M.alloc (| γ1_0 |) in + M.read (| + let~ log_max_height : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "get_max_height", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| + data + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) in + let~ bits_reduced : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_global_max_height + |); + M.read (| + log_max_height + |) + ] + |) + |) in + let~ reduced_index : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + M.read (| + bits_reduced + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Proof" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ Val ], + "open_batch", + [], + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Val; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "mmcs" + |) + |); + M.read (| + reduced_index + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| + data + |) + |) + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + opened_values := + M.copy (| + γ0_0 + |) in + let + opening_proof := + M.copy (| + γ0_1 + |) in + M.alloc (| + Value.StructRecord + "p3_fri::two_adic_pcs::BatchOpening" + [ + ("opened_values", + M.read (| + opened_values + |)); + ("opening_proof", + M.read (| + opening_proof + |)) + ] + |))) + ] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + Value.Tuple [ M.read (| all_opened_values |); M.read (| fri_proof |) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn verify( + &self, + // For each round: + rounds: Vec<( + Self::Commitment, + // for each matrix: + Vec<( + // its domain, + Self::Domain, + // for each point: + Vec<( + // the point, + Challenge, + // values at the point + Vec, + )>, + )>, + )>, + proof: &Self::Proof, + challenger: &mut Challenger, + ) -> Result<(), Self::Error> { + // Write evaluations to challenger + for (_, round) in &rounds { + for (_, mat) in round { + for (_, point) in mat { + point + .iter() + .for_each(|&opening| challenger.observe_algebra_element(opening)); + } + } + } + + // Batch combination challenge + let alpha: Challenge = challenger.sample_algebra_element(); + + let log_global_max_height = + proof.commit_phase_commits.len() + self.fri.log_blowup + self.fri.log_final_poly_len; + + let g: TwoAdicFriGenericConfigForMmcs = + TwoAdicFriGenericConfig(PhantomData); + + verifier::verify(&g, &self.fri, proof, challenger, |index, input_proof| { + // TODO: separate this out into functions + + // log_height -> (alpha_pow, reduced_opening) + let mut reduced_openings = BTreeMap::::new(); + + for (batch_opening, (batch_commit, mats)) in + zip_eq(input_proof, &rounds, FriError::InvalidProofShape)? + { + let batch_heights = mats + .iter() + .map(|(domain, _)| domain.size() << self.fri.log_blowup) + .collect_vec(); + let batch_dims = batch_heights + .iter() + // TODO: MMCS doesn't really need width; we put 0 for now. + .map(|&height| Dimensions { width: 0, height }) + .collect_vec(); + + if let Some(batch_max_height) = batch_heights.iter().max() { + let log_batch_max_height = log2_strict_usize( *batch_max_height); + let bits_reduced = log_global_max_height - log_batch_max_height; + let reduced_index = index >> bits_reduced; + + self.mmcs.verify_batch( + batch_commit, + &batch_dims, + reduced_index, + &batch_opening.opened_values, + &batch_opening.opening_proof, + ) + } else { + // Empty batch? + self.mmcs.verify_batch( + batch_commit, + &[], + 0, + &batch_opening.opened_values, + &batch_opening.opening_proof, + ) + } + .map_err(FriError::InputError)?; + + for (mat_opening, (mat_domain, mat_points_and_values)) in zip_eq( + &batch_opening.opened_values, + mats, + FriError::InvalidProofShape, + )? { + let log_height = log2_strict_usize(mat_domain.size()) + self.fri.log_blowup; + + let bits_reduced = log_global_max_height - log_height; + let rev_reduced_index = reverse_bits_len(index >> bits_reduced, log_height); + + // todo: this can be nicer with domain methods? + + let x = Val::GENERATOR + * Val::two_adic_generator(log_height).exp_u64(rev_reduced_index as u64); + + let (alpha_pow, ro) = reduced_openings + .entry(log_height) + .or_insert((Challenge::ONE, Challenge::ZERO)); + + for (z, ps_at_z) in mat_points_and_values { + for (&p_at_x, &p_at_z) in + zip_eq(mat_opening, ps_at_z, FriError::InvalidProofShape)? + { + let quotient = (-p_at_z + p_at_x) / (-*z + x); + *ro += *alpha_pow * quotient; + *alpha_pow *= alpha; + } + } + } + } + + // `reduced_openings` would have a log_height = log_blowup entry only if there was a + // trace matrix of height 1. In this case the reduced opening can be skipped as it will + // not be checked against any commit phase commit. + if let Some((_alpha_pow, ro)) = reduced_openings.remove(&self.fri.log_blowup) { + assert!(ro.is_zero()); + } + + // Return reduced openings descending by log_height. + Ok(reduced_openings + .into_iter() + .rev() + .map(|(log_height, (_alpha_pow, ro))| (log_height, ro)) + .collect()) + })?; + + Ok(()) + } + *) + Definition verify + (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Val Dft InputMmcs FriMmcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; rounds; proof; challenger ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rounds := M.alloc (| rounds |) in + let proof := M.alloc (| proof |) in + let challenger := M.alloc (| challenger |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ Challenge; Challenger ] + (Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriPcs") + [] + [ Val; Dft; InputMmcs; FriMmcs ]) + "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rounds |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let round := M.alloc (| γ2_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| round |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let mat := M.alloc (| γ2_1 |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| mat |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] + ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + γ0_0 := + M.read (| + γ0_0 + |) in + let + γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let + point := + M.alloc (| + γ2_1 + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.tuple + []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + point + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ] + (Ty.tuple + []) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + opening := + M.copy (| + γ + |) in + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ + Val + ], + "observe_algebra_element", + [], + [ + Challenge + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + challenger + |) + |) + |); + M.read (| + opening + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ alpha : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "sample_algebra_element", + [], + [ Challenge ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| challenger |) |) |) ] + |) + |) in + let~ log_global_max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_fri::proof::FriProof", + "commit_phase_commits" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "fri" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "fri" + |), + "p3_fri::config::FriConfig", + "log_final_poly_len" + |) + |) + ] + |) + |) in + let~ g : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriGenericConfig") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ] := + M.alloc (| + Value.StructTuple + "p3_fri::two_adic_pcs::TwoAdicFriGenericConfig" + [ Value.StructTuple "core::marker::PhantomData" [] ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + M.get_function (| + "p3_fri::verifier::verify", + [], + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::TwoAdicFriGenericConfig") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ]; + Val; + Challenge; + FriMmcs; + Challenger; + Ty.function + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ]) + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, g |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "fri" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| proof |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let index := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let input_proof := M.copy (| γ |) in + M.read (| + let~ reduced_openings : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple + [ Challenge; Challenge ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple + [ Challenge; Challenge ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple + [ Challenge; Challenge ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ Val; InputMmcs ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ Val ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ] + |), + [ + M.read (| + input_proof + |); + M.borrow (| + Pointer.Kind.Ref, + rounds + |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::two_adic_pcs::BatchOpening") + [] + [ + Val; + InputMmcs + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Commitment"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let + batch_opening := + M.copy (| + γ1_0 + |) in + let γ1_1 := + M.read (| + γ1_1 + |) in + let γ3_0 := + M.SubPointer.get_tuple_field (| + γ1_1, + 0 + |) in + let γ3_1 := + M.SubPointer.get_tuple_field (| + γ1_1, + 1 + |) in + let + batch_commit := + M.alloc (| + γ3_0 + |) in + let mats := + M.alloc (| + γ3_1 + |) in + let~ + batch_heights : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "usize"; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "usize"; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path + "usize") + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path + "usize") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.path + "usize"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path + "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mats + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.path + "usize") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + domain := + M.alloc (| + γ1_0 + |) in + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shl, + [ + M.call_closure (| + Ty.path + "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ], + "size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + domain + |) + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "fri" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ + batch_dims : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ], + [], + [], + "map", + [], + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "usize" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "usize" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "usize"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + batch_heights + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + height := + M.copy (| + γ + |) in + Value.StructRecord + "p3_matrix::Dimensions" + [ + ("width", + Value.Integer + IntegerKind.Usize + 0); + ("height", + M.read (| + height + |)) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ]; + Ty.tuple + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ], + "map_err", + [], + [ + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ]; + Ty.function + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + (Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ]) + ] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + M.alloc (| + Value.Tuple + [] + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ], + [], + [], + "max", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.path + "usize" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "usize" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "usize" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "usize"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + batch_heights + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + batch_max_height := + M.copy (| + γ0_0 + |) in + let~ + log_batch_max_height : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.read (| + M.deref (| + M.read (| + batch_max_height + |) + |) + |) + ] + |) + |) in + let~ + bits_reduced : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_global_max_height + |); + M.read (| + log_batch_max_height + |) + ] + |) + |) in + let~ + reduced_index : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + M.read (| + bits_reduced + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ + Val + ], + "verify_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + batch_commit + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + batch_dims + |) + |) + |) + ] + |) + |) + |); + M.read (| + reduced_index + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + batch_opening + |) + |), + "p3_fri::two_adic_pcs::BatchOpening", + "opened_values" + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + batch_opening + |) + |), + "p3_fri::two_adic_pcs::BatchOpening", + "opening_proof" + |) + |) + |) + |) + ] + |) + |))); + fun + γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + InputMmcs, + [], + [ + Val + ], + "verify_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + batch_commit + |) + |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [] + |) + |) + |) + |)); + Value.Integer + IntegerKind.Usize + 0; + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + batch_opening + |) + |), + "p3_fri::two_adic_pcs::BatchOpening", + "opened_values" + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + batch_opening + |) + |), + "p3_fri::two_adic_pcs::BatchOpening", + "opening_proof" + |) + |) + |) + |) + ] + |) + |))) + ] + |) + |); + M.constructor_as_closure + "p3_fri::verifier::FriError::InputError'1" + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let + residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let + val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + batch_opening + |) + |), + "p3_fri::two_adic_pcs::BatchOpening", + "opened_values" + |) + |); + M.read (| + mats + |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let + residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let + val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let + iter := + M.copy (| + γ + |) in + M.loop (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + ltac:(M.monadic + (let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let + mat_opening := + M.copy (| + γ1_0 + |) in + let + γ1_1 := + M.read (| + γ1_1 + |) in + let + γ3_0 := + M.SubPointer.get_tuple_field (| + γ1_1, + 0 + |) in + let + γ3_1 := + M.SubPointer.get_tuple_field (| + γ1_1, + 1 + |) in + let + mat_domain := + M.alloc (| + γ3_0 + |) in + let + mat_points_and_values := + M.alloc (| + γ3_1 + |) in + let~ + log_height : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::coset::TwoAdicMultiplicativeCoset") + [] + [ + Val + ], + "size", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + mat_domain + |) + |) + |) + ] + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "fri" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |) + |) in + let~ + bits_reduced : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + log_global_max_height + |); + M.read (| + log_height + |) + ] + |) + |) in + let~ + rev_reduced_index : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "usize" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "p3_util::reverse_bits_len", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shr, + [ + M.read (| + index + |); + M.read (| + bits_reduced + |) + ] + |); + M.read (| + log_height + |) + ] + |) + |) in + let~ + x : + Ty.apply + (Ty.path + "*") + [] + [ + Val + ] := + M.alloc (| + M.call_closure (| + Val, + M.get_trait_method (| + "core::ops::arith::Mul", + Val, + [], + [ + Val + ], + "mul", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::Field::GENERATOR", + Val + |) + |); + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Val, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Val, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Val, + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.read (| + log_height + |) + ] + |) + |) + |); + M.cast + (Ty.path + "u64") + (M.read (| + rev_reduced_index + |)) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.tuple + [ + Challenge; + Challenge + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + "or_insert", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::entry::Entry") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + "entry", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + reduced_openings + |); + M.read (| + log_height + |) + ] + |); + Value.Tuple + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Challenge + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Challenge + |) + |) + ] + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + alpha_pow := + M.alloc (| + γ1_0 + |) in + let + ro := + M.alloc (| + γ1_1 + |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + mat_points_and_values + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + iter := + M.copy (| + γ + |) in + M.loop (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + ltac:(M.monadic + (let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Challenge; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + γ0_0 := + M.read (| + γ0_0 + |) in + let + γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let + z := + M.alloc (| + γ2_0 + |) in + let + ps_at_z := + M.alloc (| + γ2_1 + |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Val; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ] + |), + [ + M.read (| + mat_opening + |); + M.read (| + ps_at_z + |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let + residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Val + ] + InputMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let + val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + iter := + M.copy (| + γ + |) in + M.loop (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + ltac:(M.monadic + (let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Challenge + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Val + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let + γ1_0 := + M.read (| + γ1_0 + |) in + let + p_at_x := + M.copy (| + γ1_0 + |) in + let + γ1_1 := + M.read (| + γ1_1 + |) in + let + p_at_z := + M.copy (| + γ1_1 + |) in + let~ + quotient : + Ty.apply + (Ty.path + "*") + [] + [ + Challenge + ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Div", + Challenge, + [], + [ + Challenge + ], + "div", + [], + [] + |), + [ + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Add", + Challenge, + [], + [ + Val + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Neg", + Challenge, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + p_at_z + |) + ] + |); + M.read (| + p_at_x + |) + ] + |); + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Add", + Challenge, + [], + [ + Val + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Neg", + Challenge, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.deref (| + M.read (| + z + |) + |) + |) + ] + |); + M.read (| + x + |) + ] + |) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Challenge, + [], + [ + Challenge + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + ro + |) + |) + |); + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Mul", + Challenge, + [], + [ + Challenge + ], + "mul", + [], + [] + |), + [ + M.read (| + M.deref (| + M.read (| + alpha_pow + |) + |) + |); + M.read (| + quotient + |) + ] + |) + ] + |) + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.call_closure (| + Ty.tuple + [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Challenge, + [], + [ + Challenge + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + alpha_pow + |) + |) + |); + M.read (| + alpha + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + |))) + ] + |)))) + ] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.tuple + [ + Challenge; + Challenge + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + "remove", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + reduced_openings + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + self + |) + |), + "p3_fri::two_adic_pcs::TwoAdicFriPcs", + "fri" + |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + |) + |) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let _alpha_pow := + M.copy (| γ1_0 |) in + let ro := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + Value.Tuple [] + |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "p3_field::field::Field", + Challenge, + [], + [], + "is_zero", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + ro + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic", + [], + [] + |), + [ + mk_str (| + "assertion failed: ro.is_zero()" + |) + ] + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ Ty.path "usize"; Challenge + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ] + ] + ] + ] + (Ty.tuple + [ + Ty.path "usize"; + Challenge + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ] + ] + ] + ] + (Ty.tuple + [ + Ty.path "usize"; + Challenge + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.path "usize"; + Challenge + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ] + ] + ] + ] + (Ty.tuple + [ + Ty.path "usize"; + Challenge + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "rev", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::collections::btree::map::IntoIter") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "alloc::collections::btree::map::BTreeMap") + [] + [ + Ty.path "usize"; + Ty.tuple + [ + Challenge; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + reduced_openings + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.tuple + [ + Challenge; + Challenge + ] + ] + ] + ] + (Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]) + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + log_height := + M.copy (| + γ0_0 + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_1, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_1, + 1 + |) in + let + _alpha_pow := + M.copy (| + γ1_0 + |) in + let ro := + M.copy (| + γ1_1 + |) in + Value.Tuple + [ + M.read (| + log_height + |); + M.read (| + ro + |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + |) + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + FriMmcs + "Error"; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Val ] + InputMmcs + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| Value.StructTuple "core::result::Result::Ok" [ Value.Tuple [] ] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Val Dft InputMmcs FriMmcs Challenge Challenger : Ty.t), + M.IsTraitInstance + "p3_commit::pcs::Pcs" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Challenge; Challenger ] + (Self Val Dft InputMmcs FriMmcs Challenge Challenger) + (* Instance *) + [ + ("Domain", InstanceField.Ty (_Domain Val Dft InputMmcs FriMmcs Challenge Challenger)); + ("Commitment", + InstanceField.Ty (_Commitment Val Dft InputMmcs FriMmcs Challenge Challenger)); + ("ProverData", + InstanceField.Ty (_ProverData Val Dft InputMmcs FriMmcs Challenge Challenger)); + ("EvaluationsOnDomain", + InstanceField.Ty (_EvaluationsOnDomain Val Dft InputMmcs FriMmcs Challenge Challenger)); + ("Proof", InstanceField.Ty (_Proof Val Dft InputMmcs FriMmcs Challenge Challenger)); + ("Error", InstanceField.Ty (_Error Val Dft InputMmcs FriMmcs Challenge Challenger)); + ("natural_domain_for_degree", + InstanceField.Method + (natural_domain_for_degree Val Dft InputMmcs FriMmcs Challenge Challenger)); + ("commit", InstanceField.Method (commit Val Dft InputMmcs FriMmcs Challenge Challenger)); + ("get_evaluations_on_domain", + InstanceField.Method + (get_evaluations_on_domain Val Dft InputMmcs FriMmcs Challenge Challenger)); + ("open", InstanceField.Method (open Val Dft InputMmcs FriMmcs Challenge Challenger)); + ("verify", InstanceField.Method (verify Val Dft InputMmcs FriMmcs Challenge Challenger)) + ]. + End Impl_p3_commit_pcs_Pcs_where_p3_field_field_TwoAdicField_Val_where_p3_dft_traits_TwoAdicSubgroupDft_Dft_Val_where_p3_commit_mmcs_Mmcs_InputMmcs_Val_where_p3_commit_mmcs_Mmcs_FriMmcs_Challenge_where_p3_field_field_TwoAdicField_Challenge_where_p3_field_field_ExtensionField_Challenge_Val_where_p3_challenger_FieldChallenger_Challenger_Val_where_p3_challenger_CanObserve_Challenger_associated_in_trait_p3_commit_mmcs_Mmcs__Challenge_FriMmcs_Commitment_where_p3_challenger_grinding_challenger_GrindingChallenger_Challenger_Challenge_Challenger_for_p3_fri_two_adic_pcs_TwoAdicFriPcs_Val_Dft_InputMmcs_FriMmcs. + + (* #[instrument(skip_all)] *) + Definition compute_inverse_denominators + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F; EF; M_ ], [ mats_and_points; coset_shift ] => + ltac:(M.monadic + (let mats_and_points := M.alloc (| mats_and_points |) in + let coset_shift := M.alloc (| coset_shift |) in + M.catch_return + (Ty.apply + (Ty.path "p3_util::linear_map::LinearMap") + [] + [ EF; Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::compute_inverse_denominators::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::compute_inverse_denominators::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::compute_inverse_denominators::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_fri::two_adic_pcs::compute_inverse_denominators::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_util::linear_map::LinearMap") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ max_log_height_for_point : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ EF; Ty.path "usize" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ EF; Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_util::linear_map::LinearMap") + [] + [ EF; Ty.path "usize" ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| mats_and_points |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let mats := M.alloc (| γ2_0 |) in + let points := M.alloc (| γ2_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ M_ ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ M_ ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ M_ ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ M_ ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ M_ ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| mats |) ] + |); + M.read (| M.deref (| M.read (| points |) |) |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ M_ ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let mat := M.copy (| γ1_0 |) in + let points_for_mat := + M.copy (| γ1_1 |) in + let~ log_height : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::log2_strict_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| mat |) + |) + |) + ] + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ EF ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + points_for_mat + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := + M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] + ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ EF ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ EF ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := + M.read (| + γ0_0 + |) in + let z := + M.copy (| + γ0_0 + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + Value.Tuple + [] + |), + [ + fun γ => + ltac:(M.monadic + (let + γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.path + "usize" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_util::linear_map::LinearMap") + [] + [ + EF; + Ty.path + "usize" + ], + "get_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + max_log_height_for_point + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + z + |) + |) + |) + ] + |) + |) in + let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + lh := + M.copy (| + γ0_0 + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| + lh + |) + |), + M.call_closure (| + Ty.path + "usize", + M.get_function (| + "core::cmp::max", + [], + [ + Ty.path + "usize" + ] + |), + [ + M.read (| + M.deref (| + M.read (| + lh + |) + |) + |); + M.read (| + log_height + |) + ] + |) + |) + |) in + M.alloc (| + Value.Tuple + [] + |))); + fun γ => + ltac:(M.monadic + (let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_util::linear_map::LinearMap") + [] + [ + EF; + Ty.path + "usize" + ], + "insert", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + max_log_height_for_point + |); + M.read (| + z + |); + M.read (| + log_height + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ max_log_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "usize" ] ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "max", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_associated_function (| + Ty.apply + (Ty.path "p3_util::linear_map::LinearMap") + [] + [ EF; Ty.path "usize" ], + "values", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, max_log_height_for_point |) ] + |) + ] + |) + ] + |) + |) + |) in + let~ subgroup : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_unknown, + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_function (| + "p3_field::helpers::cyclic_subgroup_coset_known_order", + [], + [ F ] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| max_log_height |) ] + |); + M.read (| coset_shift |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| max_log_height |) ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, subgroup |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_util::linear_map::LinearMap") + [] + [ + EF; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ EF; Ty.path "usize" ]; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ Ty.tuple [ EF; Ty.path "usize" ] ] ] + (Ty.tuple + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "p3_util::linear_map::LinearMap") + [] + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ EF; Ty.path "usize" ]; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ Ty.tuple [ EF; Ty.path "usize" ] ] ] + (Ty.tuple + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ EF; Ty.path "usize" ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ Ty.tuple [ Ty.tuple [ EF; Ty.path "usize" ] ] ] + (Ty.tuple + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ EF; Ty.path "usize" ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "p3_util::linear_map::LinearMap") + [] + [ EF; Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| max_log_height_for_point |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.tuple [ EF; Ty.path "usize" ] ] ] + (Ty.tuple + [ + EF; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let z := M.copy (| γ0_0 |) in + let log_height := M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| z |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse", + [], + [ EF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + EF; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ] + ] + ] + EF + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ] + ] + ] + EF + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + [], + [], + "map", + [], + [ + EF; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ F ] + ] + ] + EF + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeTo") + [] + [ + Ty.path + "usize" + ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + subgroup + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.shl, + [ + Value.Integer + IntegerKind.Usize + 1; + M.read (| + log_height + |) + ] + |)) + ] + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + F + ] + ] + ] + EF + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let x := + M.copy (| + γ + |) in + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Sub", + EF, + [], + [ F + ], + "sub", + [], + [] + |), + [ + M.read (| + z + |); + M.read (| + x + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_compute_inverse_denominators : + M.IsFunction.C + "p3_fri::two_adic_pcs::compute_inverse_denominators" + compute_inverse_denominators. + Admitted. + Global Typeclasses Opaque compute_inverse_denominators. +End two_adic_pcs. diff --git a/CoqOfRust/plonky3/fri/src/verifier.rs b/CoqOfRust/plonky3/fri/src/verifier.rs new file mode 100644 index 000000000..b3db222e3 --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/verifier.rs @@ -0,0 +1,203 @@ +use alloc::vec; +use alloc::vec::Vec; + +use itertools::Itertools; +use p3_challenger::{CanObserve, FieldChallenger, GrindingChallenger}; +use p3_commit::Mmcs; +use p3_field::{ExtensionField, Field, TwoAdicField}; +use p3_matrix::Dimensions; +use p3_util::reverse_bits_len; +use p3_util::zip_eq::zip_eq; + +use crate::{CommitPhaseProofStep, FriConfig, FriGenericConfig, FriProof}; + +#[derive(Debug)] +pub enum FriError { + InvalidProofShape, + CommitPhaseMmcsError(CommitMmcsErr), + InputError(InputError), + FinalPolyMismatch, + InvalidPowWitness, +} + +pub fn verify( + g: &G, + config: &FriConfig, + proof: &FriProof, + challenger: &mut Challenger, + open_input: impl Fn( + usize, + &G::InputProof, + ) -> Result, FriError>, +) -> Result<(), FriError> +where + Val: Field, + Challenge: ExtensionField + TwoAdicField, + M: Mmcs, + Challenger: FieldChallenger + GrindingChallenger + CanObserve, + G: FriGenericConfig, +{ + let betas: Vec = proof + .commit_phase_commits + .iter() + .map(|comm| { + challenger.observe(comm.clone()); + challenger.sample_algebra_element() + }) + .collect(); + + // Observe all coefficients of the final polynomial. + proof + .final_poly + .iter() + .for_each(|x| challenger.observe_algebra_element(*x)); + + if proof.query_proofs.len() != config.num_queries { + return Err(FriError::InvalidProofShape); + } + + // Check PoW. + if !challenger.check_witness(config.proof_of_work_bits, proof.pow_witness) { + return Err(FriError::InvalidPowWitness); + } + + // The log of the maximum domain size. + let log_max_height = + proof.commit_phase_commits.len() + config.log_blowup + config.log_final_poly_len; + + // The log of the final domain size. + let log_final_height = config.log_blowup + config.log_final_poly_len; + + for qp in &proof.query_proofs { + let index = challenger.sample_bits(log_max_height + g.extra_query_index_bits()); + let ro = open_input(index, &qp.input_proof)?; + + debug_assert!( + ro.iter().tuple_windows().all(|((l, _), (r, _))| l > r), + "reduced openings sorted by height descending" + ); + + let mut domain_index = index >> g.extra_query_index_bits(); + + // Starting at the evaluation at `index` of the initial domain, + // perform fri folds until the domain size reaches the final domain size. + // Check after each fold that the pair of sibling evaluations at the current + // node match the commitment. + let folded_eval = verify_query( + g, + config, + &mut domain_index, + zip_eq( + zip_eq( + &betas, + &proof.commit_phase_commits, + FriError::InvalidProofShape, + )?, + &qp.commit_phase_openings, + FriError::InvalidProofShape, + )?, + ro, + log_max_height, + log_final_height, + )?; + + let mut eval = Challenge::ZERO; + + // We open the final polynomial at index `domain_index`, which corresponds to evaluating + // the polynomial at x^k, where x is the 2-adic generator of order `max_height` and k is + // `reverse_bits_len(domain_index, log_max_height)`. + let x = Challenge::two_adic_generator(log_max_height) + .exp_u64(reverse_bits_len(domain_index, log_max_height) as u64); + let mut x_pow = Challenge::ONE; + + // Evaluate the final polynomial at x. + for coeff in &proof.final_poly { + eval += *coeff * x_pow; + x_pow *= x; + } + + if eval != folded_eval { + return Err(FriError::FinalPolyMismatch); + } + } + + Ok(()) +} + +type CommitStep<'a, F, M> = ( + ( + &'a F, // The challenge point beta used for the next fold of FRI evaluations. + &'a >::Commitment, // A commitment to the FRI evaluations on the current domain. + ), + &'a CommitPhaseProofStep, // The sibling and opening proof for the current FRI node. +); + +/// Verifies a single query chain in the FRI proof. +/// +/// Given an initial `index` corresponding to a point in the initial domain +/// and a series of `reduced_openings` corresponding to evaluations of +/// polynomials to be added in at specific domain sizes, perform the standard +/// sequence of FRI folds, checking at each step that the pair of sibling evaluations +/// match the commitment. +fn verify_query<'a, G, F, M>( + g: &G, + config: &FriConfig, + index: &mut usize, + steps: impl ExactSizeIterator>, + reduced_openings: Vec<(usize, F)>, + log_max_height: usize, + log_final_height: usize, +) -> Result> +where + F: Field, + M: Mmcs + 'a, + G: FriGenericConfig, +{ + let mut folded_eval = F::ZERO; + let mut ro_iter = reduced_openings.into_iter().peekable(); + + // We start with evaluations over a domain of size (1 << log_max_height). We fold + // using FRI until the domain size reaches (1 << log_final_height). + for (log_folded_height, ((&beta, comm), opening)) in zip_eq( + (log_final_height..log_max_height).rev(), + steps, + FriError::InvalidProofShape, + )? { + // If there are new polynomials to roll in at this height, do so. + if let Some((_, ro)) = ro_iter.next_if(|(lh, _)| *lh == log_folded_height + 1) { + folded_eval += ro; + } + + // Get the index of the other sibling of the current fri node. + let index_sibling = *index ^ 1; + + let mut evals = vec![folded_eval; 2]; + evals[index_sibling % 2] = opening.sibling_value; + + let dims = &[Dimensions { + width: 2, + height: 1 << log_folded_height, + }]; + + // Replace index with the index of the parent fri node. + *index >>= 1; + + // Verify the commitment to the evaluations of the sibling nodes. + config + .mmcs + .verify_batch(comm, dims, *index, &[evals.clone()], &opening.opening_proof) + .map_err(FriError::CommitPhaseMmcsError)?; + + // Fold the pair of evaluations of sibling nodes into the evaluation of the parent fri node. + folded_eval = g.fold_row(*index, log_folded_height, beta, evals.into_iter()); + } + + // If ro_iter is not empty, we failed to fold in some polynomial evaluations. + if ro_iter.next().is_some() { + return Err(FriError::InvalidProofShape); + } + + // If we reached this point, we have verified that, starting at the initial index, + // the chain of folds has produced folded_eval. + Ok(folded_eval) +} diff --git a/CoqOfRust/plonky3/fri/src/verifier.v b/CoqOfRust/plonky3/fri/src/verifier.v new file mode 100644 index 000000000..38f7eeca3 --- /dev/null +++ b/CoqOfRust/plonky3/fri/src/verifier.v @@ -0,0 +1,5206 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module verifier. + (* + Enum FriError + { + const_params := []; + ty_params := [ "CommitMmcsErr"; "InputError" ]; + variants := + [ + { + name := "InvalidProofShape"; + item := StructTuple []; + }; + { + name := "CommitPhaseMmcsError"; + item := StructTuple [ CommitMmcsErr ]; + }; + { + name := "InputError"; + item := StructTuple [ InputError ]; + }; + { + name := "FinalPolyMismatch"; + item := StructTuple []; + }; + { + name := "InvalidPowWitness"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_FriError_InvalidProofShape : + M.IsDiscriminant "p3_fri::verifier::FriError::InvalidProofShape" 0. + Axiom IsDiscriminant_FriError_CommitPhaseMmcsError : + M.IsDiscriminant "p3_fri::verifier::FriError::CommitPhaseMmcsError" 1. + Axiom IsDiscriminant_FriError_InputError : + M.IsDiscriminant "p3_fri::verifier::FriError::InputError" 2. + Axiom IsDiscriminant_FriError_FinalPolyMismatch : + M.IsDiscriminant "p3_fri::verifier::FriError::FinalPolyMismatch" 3. + Axiom IsDiscriminant_FriError_InvalidPowWitness : + M.IsDiscriminant "p3_fri::verifier::FriError::InvalidPowWitness" 4. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_CommitMmcsErr_where_core_fmt_Debug_InputError_for_p3_fri_verifier_FriError_CommitMmcsErr_InputError. + Definition Self (CommitMmcsErr InputError : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_fri::verifier::FriError") [] [ CommitMmcsErr; InputError ]. + + (* Debug *) + Definition fmt + (CommitMmcsErr InputError : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self CommitMmcsErr InputError in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| γ, "p3_fri::verifier::FriError::InvalidProofShape" |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "InvalidProofShape" |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_fri::verifier::FriError::CommitPhaseMmcsError", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "CommitPhaseMmcsError" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_fri::verifier::FriError::InputError", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "InputError" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| γ, "p3_fri::verifier::FriError::FinalPolyMismatch" |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "FinalPolyMismatch" |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| γ, "p3_fri::verifier::FriError::InvalidPowWitness" |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "InvalidPowWitness" |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (CommitMmcsErr InputError : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self CommitMmcsErr InputError) + (* Instance *) [ ("fmt", InstanceField.Method (fmt CommitMmcsErr InputError)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_CommitMmcsErr_where_core_fmt_Debug_InputError_for_p3_fri_verifier_FriError_CommitMmcsErr_InputError. + + (* + pub fn verify( + g: &G, + config: &FriConfig, + proof: &FriProof, + challenger: &mut Challenger, + open_input: impl Fn( + usize, + &G::InputProof, + ) -> Result, FriError>, + ) -> Result<(), FriError> + where + Val: Field, + Challenge: ExtensionField + TwoAdicField, + M: Mmcs, + Challenger: FieldChallenger + GrindingChallenger + CanObserve, + G: FriGenericConfig, + { + let betas: Vec = proof + .commit_phase_commits + .iter() + .map(|comm| { + challenger.observe(comm.clone()); + challenger.sample_algebra_element() + }) + .collect(); + + // Observe all coefficients of the final polynomial. + proof + .final_poly + .iter() + .for_each(|x| challenger.observe_algebra_element( *x)); + + if proof.query_proofs.len() != config.num_queries { + return Err(FriError::InvalidProofShape); + } + + // Check PoW. + if !challenger.check_witness(config.proof_of_work_bits, proof.pow_witness) { + return Err(FriError::InvalidPowWitness); + } + + // The log of the maximum domain size. + let log_max_height = + proof.commit_phase_commits.len() + config.log_blowup + config.log_final_poly_len; + + // The log of the final domain size. + let log_final_height = config.log_blowup + config.log_final_poly_len; + + for qp in &proof.query_proofs { + let index = challenger.sample_bits(log_max_height + g.extra_query_index_bits()); + let ro = open_input(index, &qp.input_proof)?; + + debug_assert!( + ro.iter().tuple_windows().all(|((l, _), (r, _))| l > r), + "reduced openings sorted by height descending" + ); + + let mut domain_index = index >> g.extra_query_index_bits(); + + // Starting at the evaluation at `index` of the initial domain, + // perform fri folds until the domain size reaches the final domain size. + // Check after each fold that the pair of sibling evaluations at the current + // node match the commitment. + let folded_eval = verify_query( + g, + config, + &mut domain_index, + zip_eq( + zip_eq( + &betas, + &proof.commit_phase_commits, + FriError::InvalidProofShape, + )?, + &qp.commit_phase_openings, + FriError::InvalidProofShape, + )?, + ro, + log_max_height, + log_final_height, + )?; + + let mut eval = Challenge::ZERO; + + // We open the final polynomial at index `domain_index`, which corresponds to evaluating + // the polynomial at x^k, where x is the 2-adic generator of order `max_height` and k is + // `reverse_bits_len(domain_index, log_max_height)`. + let x = Challenge::two_adic_generator(log_max_height) + .exp_u64(reverse_bits_len(domain_index, log_max_height) as u64); + let mut x_pow = Challenge::ONE; + + // Evaluate the final polynomial at x. + for coeff in &proof.final_poly { + eval += *coeff * x_pow; + x_pow *= x; + } + + if eval != folded_eval { + return Err(FriError::FinalPolyMismatch); + } + } + + Ok(()) + } + *) + Definition verify (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], + [ + G; + Val; + Challenge; + M_; + Challenger; + impl_Fn_usize___G_InputProof__arrow_Result_Vec__usize__Challenge____FriError_M_Error__G_InputError__ + ], + [ g; config; proof; challenger; open_input ] => + ltac:(M.monadic + (let g := M.alloc (| g |) in + let config := M.alloc (| config |) in + let proof := M.alloc (| proof |) in + let challenger := M.alloc (| challenger |) in + let open_input := M.alloc (| open_input |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ Challenge ] M_ "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ betas : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ] + ] + Challenge + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ] + ] + Challenge + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ], + [], + [], + "map", + [], + [ + Challenge; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ] + ] + Challenge + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_fri::proof::FriProof", + "commit_phase_commits" + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ] + ] + Challenge + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let comm := M.copy (| γ |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Challenger, + [], + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ], + "observe", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| comm |) |) + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "sample_algebra_element", + [], + [ Challenge ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Challenge ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Challenge ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Challenge ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Challenge ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Challenge ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_fri::proof::FriProof", + "final_poly" + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Challenge ] ] ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Challenger, + [], + [ Val ], + "observe_algebra_element", + [], + [ Challenge ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.read (| M.deref (| M.read (| x |) |) |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_fri::proof::FriProof", + "query_proofs" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "num_queries" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_challenger::grinding_challenger::GrindingChallenger", + Challenger, + [], + [], + "check_witness", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "proof_of_work_bits" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_fri::proof::FriProof", + "pow_witness" + |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_fri::verifier::FriError::InvalidPowWitness" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment"; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_fri::proof::FriProof", + "commit_phase_commits" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "log_final_poly_len" + |) + |) + ] + |) + |) in + let~ log_final_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "log_blowup" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "log_final_poly_len" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_fri::proof::FriProof", + "query_proofs" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_fri::proof::QueryProof") + [] + [ + Challenge; + M_; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let qp := M.copy (| γ0_0 |) in + let~ index : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_challenger::CanSampleBits", + Challenger, + [], + [ Ty.path "usize" ], + "sample_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| challenger |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| log_max_height |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ Challenge ], + "extra_query_index_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| g |) |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ ro : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ Ty.path "usize"; Challenge ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::function::Fn", + impl_Fn_usize___G_InputProof__arrow_Result_Vec__usize__Challenge____FriError_M_Error__G_InputError__, + [], + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputProof" + ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, open_input |); + Value.Tuple + [ + M.read (| index |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| qp |) |), + "p3_fri::proof::QueryProof", + "input_proof" + |) + |) + |) + |) + ] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Challenge + ] + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ] + ], + [], + [], + "all", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ] + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ], + [], + [], + "tuple_windows", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + ro + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Challenge + ] + ] + ] + ] + ] + (Ty.path + "bool") + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + γ0_0 := + M.read (| + γ0_0 + |) in + let + γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let + γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let l := + M.alloc (| + γ2_0 + |) in + let + γ0_1 := + M.read (| + γ0_1 + |) in + let + γ2_0 := + M.SubPointer.get_tuple_field (| + γ0_1, + 0 + |) in + let + γ2_1 := + M.SubPointer.get_tuple_field (| + γ0_1, + 1 + |) in + let r := + M.alloc (| + γ2_0 + |) in + M.call_closure (| + Ty.path + "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ], + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "usize" + ] + ], + "gt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + l + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + r + |) + |) + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_const", + [ + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "reduced openings sorted by height descending" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ domain_index : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.read (| index |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ Challenge ], + "extra_query_index_bits", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| g |) |) + |) + ] + |) + ] + |) + |) in + let~ folded_eval : + Ty.apply (Ty.path "*") [] [ Challenge ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Challenge ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ]; + Challenge + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Challenge; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_function (| + "p3_fri::verifier::verify_query", + [], + [ + G; + Challenge; + M_; + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::proof::CommitPhaseProofStep") + [] + [ Challenge; M_ ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| g |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| config |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + domain_index + |) + |) + |); + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::proof::CommitPhaseProofStep") + [] + [ Challenge; M_ ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::proof::CommitPhaseProofStep") + [] + [ Challenge; M_ ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::proof::CommitPhaseProofStep") + [] + [ Challenge; M_ ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::proof::CommitPhaseProofStep") + [] + [ Challenge; M_ ] + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_fri::proof::CommitPhaseProofStep") + [] + [ Challenge; M_ ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_fri::proof::CommitPhaseProofStep") + [] + [ Challenge; M_ ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge + ] + M_ + "Commitment" + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Commitment" + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Challenge + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Commitment"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Commitment" + ]; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + betas + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + proof + |) + |), + "p3_fri::proof::FriProof", + "commit_phase_commits" + |) + |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| qp |) + |), + "p3_fri::proof::QueryProof", + "commit_phase_openings" + |) + |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := + M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge + ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ + Challenge + ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ + Challenge + ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |); + M.read (| ro |); + M.read (| log_max_height |); + M.read (| log_final_height |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Challenge ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ Challenge ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ eval : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.copy (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Challenge + |) + |) in + let~ x : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Challenge, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Challenge, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Challenge, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_max_height |) ] + |) + |) + |); + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::reverse_bits_len", + [], + [] + |), + [ + M.read (| domain_index |); + M.read (| log_max_height |) + ] + |)) + ] + |) + |) in + let~ x_pow : Ty.apply (Ty.path "*") [] [ Challenge ] := + M.copy (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Challenge + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Challenge ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Challenge; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_fri::proof::FriProof", + "final_poly" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Challenge ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Challenge ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let coeff := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Challenge, + [], + [ Challenge ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + eval + |); + M.call_closure (| + Challenge, + M.get_trait_method (| + "core::ops::arith::Mul", + Challenge, + [], + [ Challenge ], + "mul", + [], + [] + |), + [ + M.read (| + M.deref (| + M.read (| coeff |) + |) + |); + M.read (| x_pow |) + ] + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Challenge, + [], + [ Challenge ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + x_pow + |); + M.read (| x |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Challenge, + [], + [ Challenge ], + "ne", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, eval |); + M.borrow (| + Pointer.Kind.Ref, + folded_eval + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_fri::verifier::FriError::FinalPolyMismatch" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| Value.StructTuple "core::result::Result::Ok" [ Value.Tuple [] ] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_verify : M.IsFunction.C "p3_fri::verifier::verify" verify. + Admitted. + Global Typeclasses Opaque verify. + + Axiom CommitStep : + forall (F M_ : Ty.t), + (Ty.apply (Ty.path "p3_fri::verifier::CommitStep") [] [ F; M_ ]) = + (Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Commitment" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_fri::proof::CommitPhaseProofStep") [] [ F; M_ ] ] + ]). + + (* + fn verify_query<'a, G, F, M>( + g: &G, + config: &FriConfig, + index: &mut usize, + steps: impl ExactSizeIterator>, + reduced_openings: Vec<(usize, F)>, + log_max_height: usize, + log_final_height: usize, + ) -> Result> + where + F: Field, + M: Mmcs + 'a, + G: FriGenericConfig, + { + let mut folded_eval = F::ZERO; + let mut ro_iter = reduced_openings.into_iter().peekable(); + + // We start with evaluations over a domain of size (1 << log_max_height). We fold + // using FRI until the domain size reaches (1 << log_final_height). + for (log_folded_height, ((&beta, comm), opening)) in zip_eq( + (log_final_height..log_max_height).rev(), + steps, + FriError::InvalidProofShape, + )? { + // If there are new polynomials to roll in at this height, do so. + if let Some((_, ro)) = ro_iter.next_if(|(lh, _)| *lh == log_folded_height + 1) { + folded_eval += ro; + } + + // Get the index of the other sibling of the current fri node. + let index_sibling = *index ^ 1; + + let mut evals = vec![folded_eval; 2]; + evals[index_sibling % 2] = opening.sibling_value; + + let dims = &[Dimensions { + width: 2, + height: 1 << log_folded_height, + }]; + + // Replace index with the index of the parent fri node. + *index >>= 1; + + // Verify the commitment to the evaluations of the sibling nodes. + config + .mmcs + .verify_batch(comm, dims, *index, &[evals.clone()], &opening.opening_proof) + .map_err(FriError::CommitPhaseMmcsError)?; + + // Fold the pair of evaluations of sibling nodes into the evaluation of the parent fri node. + folded_eval = g.fold_row( *index, log_folded_height, beta, evals.into_iter()); + } + + // If ro_iter is not empty, we failed to fold in some polynomial evaluations. + if ro_iter.next().is_some() { + return Err(FriError::InvalidProofShape); + } + + // If we reached this point, we have verified that, starting at the initial index, + // the chain of folds has produced folded_eval. + Ok(folded_eval) + } + *) + Definition verify_query (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], + [ G; F; M_; impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ ], + [ g; config; index; steps; reduced_openings; log_max_height; log_final_height ] => + ltac:(M.monadic + (let g := M.alloc (| g |) in + let config := M.alloc (| config |) in + let index := M.alloc (| index |) in + let steps := M.alloc (| steps |) in + let reduced_openings := M.alloc (| reduced_openings |) in + let log_max_height := M.alloc (| log_max_height |) in + let log_final_height := M.alloc (| log_final_height |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + F; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait "p3_commit::mmcs::Mmcs" [] [ F ] M_ "Error"; + Ty.associated_in_trait "p3_fri::config::FriGenericConfig" [] [ F ] G "InputError" + ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ folded_eval : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) + |) in + let~ ro_iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ Ty.path "usize"; F ]; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ Ty.path "usize"; F ]; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ Ty.path "usize"; F ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "peekable", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ Ty.path "usize"; F ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ Ty.path "usize"; F ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| reduced_openings |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ]; + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ]; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| log_final_height |)); + ("end_", M.read (| log_max_height |)) + ] + ] + |); + M.read (| steps |); + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + F; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + F; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Commitment" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_fri::proof::CommitPhaseProofStep") + [] + [ F; M_ ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + impl_ExactSizeIterator_Item___CommitStep_'a__F__M__ + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let log_folded_height := M.copy (| γ1_0 |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ1_1, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ1_1, 1 |) in + let γ3_0 := M.SubPointer.get_tuple_field (| γ2_0, 0 |) in + let γ3_1 := M.SubPointer.get_tuple_field (| γ2_0, 1 |) in + let γ3_0 := M.read (| γ3_0 |) in + let beta := M.copy (| γ3_0 |) in + let comm := M.copy (| γ3_1 |) in + let opening := M.copy (| γ2_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.path "alloc::alloc::Global" + ] + ], + "next_if", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ Ty.path "usize"; F ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + ro_iter + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + F + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lh := + M.alloc (| γ1_0 |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| lh |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + log_folded_height + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let ro := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + folded_eval + |); + M.read (| ro |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ index_sibling : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_xor, + [ + M.read (| M.deref (| M.read (| index |) |) |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ evals : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "alloc::vec::from_elem", + [], + [ F ] + |), + [ + M.read (| folded_eval |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, evals |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.read (| index_sibling |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| opening |) |), + "p3_fri::proof::CommitPhaseProofStep", + "sibling_value" + |) + |) + |) + |) in + let~ dims : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.StructRecord + "p3_matrix::Dimensions" + [ + ("width", + Value.Integer IntegerKind.Usize 2); + ("height", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| log_folded_height |) + ] + |)) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := M.deref (| M.read (| index |) |) in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| β |); Value.Integer IntegerKind.I32 1 ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error" + ], + "map_err", + [], + [ + Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ]; + Ty.function + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error" + ] + (Ty.apply + (Ty.path "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error" + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + M_, + [], + [ F ], + "verify_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| config |) |), + "p3_fri::config::FriConfig", + "mmcs" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| comm |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| dims |) |) + |)); + M.read (| + M.deref (| M.read (| index |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + evals + |) + ] + |) + ] + |) + |) + |) + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| opening |) + |), + "p3_fri::proof::CommitPhaseProofStep", + "opening_proof" + |) + |) + |) + |) + ] + |); + M.constructor_as_closure + "p3_fri::verifier::FriError::CommitPhaseMmcsError" + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + F; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + F; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_fri::verifier::FriError") + [] + [ + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ F ] + M_ + "Error"; + Ty.associated_in_trait + "p3_fri::config::FriGenericConfig" + [] + [ F ] + G + "InputError" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + folded_eval, + M.call_closure (| + F, + M.get_trait_method (| + "p3_fri::config::FriGenericConfig", + G, + [], + [ F ], + "fold_row", + [], + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| g |) |) + |); + M.read (| M.deref (| M.read (| index |) |) |); + M.read (| log_folded_height |); + M.read (| beta |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| evals |) ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + "is_some", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple [ Ty.path "usize"; F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "next", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, ro_iter |) ] + |) + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_fri::verifier::FriError::InvalidProofShape" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple "core::result::Result::Ok" [ M.read (| folded_eval |) ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_verify_query : + M.IsFunction.C "p3_fri::verifier::verify_query" verify_query. + Admitted. + Global Typeclasses Opaque verify_query. +End verifier. diff --git a/CoqOfRust/plonky3/goldilocks/src/extension.rs b/CoqOfRust/plonky3/goldilocks/src/extension.rs new file mode 100644 index 000000000..5e9a95333 --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/extension.rs @@ -0,0 +1,155 @@ +use p3_field::extension::{BinomiallyExtendable, HasTwoAdicBinomialExtension}; +use p3_field::{PrimeCharacteristicRing, TwoAdicField, field_to_array}; + +use crate::Goldilocks; + +impl BinomiallyExtendable<2> for Goldilocks { + // Verifiable in Sage with + // `R. = GF(p)[]; assert (x^2 - 7).is_irreducible()`. + const W: Self = Self::new(7); + + // DTH_ROOT = W^((p - 1)/2). + const DTH_ROOT: Self = Self::new(18446744069414584320); + + const EXT_GENERATOR: [Self; 2] = [ + Self::new(18081566051660590251), + Self::new(16121475356294670766), + ]; +} + +impl HasTwoAdicBinomialExtension<2> for Goldilocks { + const EXT_TWO_ADICITY: usize = 33; + + fn ext_two_adic_generator(bits: usize) -> [Self; 2] { + assert!(bits <= 33); + + if bits == 33 { + [Self::ZERO, Self::new(15659105665374529263)] + } else { + [Self::two_adic_generator(bits), Self::ZERO] + } + } +} + +impl BinomiallyExtendable<5> for Goldilocks { + // Verifiable via: + // ```sage + // # Define Fp + // p = 2**64 - 2**32 + 1 + // F = GF(p) + + // # Define Fp[z] + // R. = PolynomialRing(F) + + // # The polynomial x^5-3 is irreducible + // assert(R(z^5-3).is_irreducible()) + // ``` + const W: Self = Self::new(3); + + // 5-th root = w^((p - 1)/5) + const DTH_ROOT: Self = Self::new(1041288259238279555); + + // Generator of the extension field + // Obtained by finding the smallest Hamming weight vector + // with appropriate order, starting at [0,1,0,0,0] + const EXT_GENERATOR: [Self; 5] = [Self::TWO, Self::ONE, Self::ZERO, Self::ZERO, Self::ZERO]; +} + +impl HasTwoAdicBinomialExtension<5> for Goldilocks { + const EXT_TWO_ADICITY: usize = 32; + + fn ext_two_adic_generator(bits: usize) -> [Self; 5] { + assert!(bits <= 32); + + field_to_array(Self::two_adic_generator(bits)) + } +} + +#[cfg(test)] +mod test_quadratic_extension { + + use num_bigint::BigUint; + use p3_field::PrimeCharacteristicRing; + use p3_field::extension::BinomialExtensionField; + use p3_field_testing::{test_field, test_two_adic_extension_field}; + + use crate::Goldilocks; + + type F = Goldilocks; + type EF = BinomialExtensionField; + + // There is a redundant representation of zero but we already tested it + // when testing the base field. + const ZEROS: [EF; 1] = [EF::ZERO]; + const ONES: [EF; 1] = [EF::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P^2 - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 9] { + [ + (BigUint::from(2u8), 33), + (BigUint::from(3u8), 1), + (BigUint::from(5u8), 1), + (BigUint::from(7u8), 1), + (BigUint::from(17u8), 1), + (BigUint::from(179u8), 1), + (BigUint::from(257u16), 1), + (BigUint::from(65537u32), 1), + (BigUint::from(7361031152998637u64), 1), + ] + } + + test_field!( + super::EF, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + + test_two_adic_extension_field!(super::F, super::EF); +} + +#[cfg(test)] +mod test_quintic_extension { + + use num_bigint::BigUint; + use p3_field::PrimeCharacteristicRing; + use p3_field::extension::BinomialExtensionField; + use p3_field_testing::{test_field, test_two_adic_extension_field}; + + use crate::Goldilocks; + + type F = Goldilocks; + type EF = BinomialExtensionField; + + // There is a redundant representation of zero but we already tested it + // when testing the base field. + const ZEROS: [EF; 1] = [EF::ZERO]; + const ONES: [EF; 1] = [EF::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P^5 - 1. + fn multiplicative_group_prime_factorization() -> [(num_bigint::BigUint, u32); 10] { + [ + (BigUint::from(2u8), 32), + (BigUint::from(3u8), 1), + (BigUint::from(5u8), 2), + (BigUint::from(17u8), 1), + (BigUint::from(257u16), 1), + (BigUint::from(45971u16), 1), + (BigUint::from(65537u32), 1), + (BigUint::from(255006435240067831u64), 1), + (BigUint::from(280083648770327405561u128), 1), + (BigUint::from(7053197395277272939628824863222181u128), 1), + ] + } + + test_field!( + super::EF, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + + test_two_adic_extension_field!(super::F, super::EF); +} diff --git a/CoqOfRust/plonky3/goldilocks/src/extension.v b/CoqOfRust/plonky3/goldilocks/src/extension.v new file mode 100644 index 000000000..f9da11160 --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/extension.v @@ -0,0 +1,430 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module extension. + Module Impl_p3_field_extension_BinomiallyExtendable_Usize_2_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* const W: Self = Self::new(7); *) + (* Ty.path "p3_goldilocks::goldilocks::Goldilocks" *) + Definition value_W (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 7 ] + |) + |))). + + (* const DTH_ROOT: Self = Self::new(18446744069414584320); *) + (* Ty.path "p3_goldilocks::goldilocks::Goldilocks" *) + Definition value_DTH_ROOT (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 18446744069414584320 ] + |) + |))). + + (* + const EXT_GENERATOR: [Self; 2] = [ + Self::new(18081566051660590251), + Self::new(16121475356294670766), + ]; + *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] *) + Definition value_EXT_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 18081566051660590251 ] + |); + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 16121475356294670766 ] + |) + ] + |))). + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::BinomiallyExtendable" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 2 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_W", InstanceField.Method value_W); + ("value_DTH_ROOT", InstanceField.Method value_DTH_ROOT); + ("value_EXT_GENERATOR", InstanceField.Method value_EXT_GENERATOR) + ]. + End Impl_p3_field_extension_BinomiallyExtendable_Usize_2_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_extension_HasTwoAdicBinomialExtension_Usize_2_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* const EXT_TWO_ADICITY: usize = 33; *) + (* Ty.path "usize" *) + Definition value_EXT_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 33 |))). + + (* + fn ext_two_adic_generator(bits: usize) -> [Self; 2] { + assert!(bits <= 33); + + if bits == 33 { + [Self::ZERO, Self::new(15659105665374529263)] + } else { + [Self::two_adic_generator(bits), Self::ZERO] + } + } + *) + Definition ext_two_adic_generator (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ M.read (| bits |); Value.Integer IntegerKind.Usize 33 ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits <= 33" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| bits |); Value.Integer IntegerKind.Usize 33 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.Array + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + |) + |); + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 15659105665374529263 ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| bits |) ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + |) + |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::HasTwoAdicBinomialExtension" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 2 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_EXT_TWO_ADICITY", InstanceField.Method value_EXT_TWO_ADICITY); + ("ext_two_adic_generator", InstanceField.Method ext_two_adic_generator) + ]. + End Impl_p3_field_extension_HasTwoAdicBinomialExtension_Usize_2_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_extension_BinomiallyExtendable_Usize_5_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* const W: Self = Self::new(3); *) + (* Ty.path "p3_goldilocks::goldilocks::Goldilocks" *) + Definition value_W (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 3 ] + |) + |))). + + (* const DTH_ROOT: Self = Self::new(1041288259238279555); *) + (* Ty.path "p3_goldilocks::goldilocks::Goldilocks" *) + Definition value_DTH_ROOT (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1041288259238279555 ] + |) + |))). + + (* const EXT_GENERATOR: [Self; 5] = [Self::TWO, Self::ONE, Self::ZERO, Self::ZERO, Self::ZERO]; *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] *) + Definition value_EXT_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::TWO", + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + |) + |) + ] + |))). + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::BinomiallyExtendable" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 5 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_W", InstanceField.Method value_W); + ("value_DTH_ROOT", InstanceField.Method value_DTH_ROOT); + ("value_EXT_GENERATOR", InstanceField.Method value_EXT_GENERATOR) + ]. + End Impl_p3_field_extension_BinomiallyExtendable_Usize_5_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_extension_HasTwoAdicBinomialExtension_Usize_5_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* const EXT_TWO_ADICITY: usize = 32; *) + (* Ty.path "usize" *) + Definition value_EXT_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 32 |))). + + (* + fn ext_two_adic_generator(bits: usize) -> [Self; 5] { + assert!(bits <= 32); + + field_to_array(Self::two_adic_generator(bits)) + } + *) + Definition ext_two_adic_generator (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ M.read (| bits |); Value.Integer IntegerKind.Usize 32 ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits <= 32" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_function (| + "p3_field::helpers::field_to_array", + [ Value.Integer IntegerKind.Usize 5 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |), + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| bits |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::HasTwoAdicBinomialExtension" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 5 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_EXT_TWO_ADICITY", InstanceField.Method value_EXT_TWO_ADICITY); + ("ext_two_adic_generator", InstanceField.Method ext_two_adic_generator) + ]. + End Impl_p3_field_extension_HasTwoAdicBinomialExtension_Usize_5_for_p3_goldilocks_goldilocks_Goldilocks. +End extension. diff --git a/CoqOfRust/plonky3/goldilocks/src/goldilocks.rs b/CoqOfRust/plonky3/goldilocks/src/goldilocks.rs new file mode 100644 index 000000000..c6c8e08dd --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/goldilocks.rs @@ -0,0 +1,688 @@ +use alloc::vec; +use alloc::vec::Vec; +use core::fmt; +use core::fmt::{Debug, Display, Formatter}; +use core::hash::{Hash, Hasher}; +use core::iter::{Product, Sum}; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; + +use num_bigint::BigUint; +use p3_field::exponentiation::exp_10540996611094048183; +use p3_field::integers::QuotientMap; +use p3_field::{ + Field, InjectiveMonomial, Packable, PermutationMonomial, PrimeCharacteristicRing, PrimeField, + PrimeField64, TwoAdicField, halve_u64, quotient_map_large_iint, quotient_map_large_uint, + quotient_map_small_int, +}; +use p3_util::{assume, branch_hint, flatten_to_base}; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; +use serde::{Deserialize, Serialize}; + +/// The Goldilocks prime +const P: u64 = 0xFFFF_FFFF_0000_0001; + +/// The prime field known as Goldilocks, defined as `F_p` where `p = 2^64 - 2^32 + 1`. +/// +/// Note that the safety of deriving `Serialize` and `Deserialize` relies on the fact that the internal value can be any u64. +#[derive(Copy, Clone, Default, Serialize, Deserialize)] +#[repr(transparent)] // Important for reasoning about memory layout +pub struct Goldilocks { + /// Not necessarily canonical. + pub(crate) value: u64, +} + +impl Goldilocks { + pub(crate) const fn new(value: u64) -> Self { + Self { value } + } + + /// Convert a constant u64 array into a constant Goldilocks array. + /// + /// This is a const version of `.map(Goldilocks::new)`. + #[inline] + #[must_use] + pub(crate) const fn new_array(input: [u64; N]) -> [Self; N] { + let mut output = [Self::ZERO; N]; + let mut i = 0; + while i < N { + output[i].value = input[i]; + i += 1; + } + output + } + + /// Two's complement of `ORDER`, i.e. `2^64 - ORDER = 2^32 - 1`. + const NEG_ORDER: u64 = Self::ORDER_U64.wrapping_neg(); + + /// A list of generators for the two-adic subgroups of the goldilocks field. + /// + /// These satisfy the properties that `TWO_ADIC_GENERATORS[0] = 1` and `TWO_ADIC_GENERATORS[i+1]^2 = TWO_ADIC_GENERATORS[i]`. + pub const TWO_ADIC_GENERATORS: [Goldilocks; 33] = Goldilocks::new_array([ + 0x0000000000000001, + 0xffffffff00000000, + 0x0001000000000000, + 0xfffffffeff000001, + 0xefffffff00000001, + 0x00003fffffffc000, + 0x0000008000000000, + 0xf80007ff08000001, + 0xbf79143ce60ca966, + 0x1905d02a5c411f4e, + 0x9d8f2ad78bfed972, + 0x0653b4801da1c8cf, + 0xf2c35199959dfcb6, + 0x1544ef2335d17997, + 0xe0ee099310bba1e2, + 0xf6b2cffe2306baac, + 0x54df9630bf79450e, + 0xabd0a6e8aa3d8a0e, + 0x81281a7b05f9beac, + 0xfbd41c6b8caa3302, + 0x30ba2ecd5e93e76d, + 0xf502aef532322654, + 0x4b2a18ade67246b5, + 0xea9d5a1336fbc98b, + 0x86cdcc31c307e171, + 0x4bbaf5976ecfefd8, + 0xed41d05b78d6e286, + 0x10d78dd8915a171d, + 0x59049500004a4485, + 0xdfa8c93ba46d2666, + 0x7e9bd009b86a0845, + 0x400a7f755588e659, + 0x185629dcda58878c, + ]); +} + +impl PartialEq for Goldilocks { + fn eq(&self, other: &Self) -> bool { + self.as_canonical_u64() == other.as_canonical_u64() + } +} + +impl Eq for Goldilocks {} + +impl Packable for Goldilocks {} + +impl Hash for Goldilocks { + fn hash(&self, state: &mut H) { + state.write_u64(self.as_canonical_u64()); + } +} + +impl Ord for Goldilocks { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.as_canonical_u64().cmp(&other.as_canonical_u64()) + } +} + +impl PartialOrd for Goldilocks { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Display for Goldilocks { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Display::fmt(&self.value, f) + } +} + +impl Debug for Goldilocks { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Debug::fmt(&self.value, f) + } +} + +impl Distribution for StandardUniform { + fn sample(&self, rng: &mut R) -> Goldilocks { + loop { + let next_u64 = rng.next_u64(); + let is_canonical = next_u64 < Goldilocks::ORDER_U64; + if is_canonical { + return Goldilocks::new(next_u64); + } + } + } +} + +impl PrimeCharacteristicRing for Goldilocks { + type PrimeSubfield = Self; + + const ZERO: Self = Self::new(0); + const ONE: Self = Self::new(1); + const TWO: Self = Self::new(2); + const NEG_ONE: Self = Self::new(Self::ORDER_U64 - 1); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f + } + + fn from_bool(b: bool) -> Self { + Self::new(b.into()) + } + + #[inline] + fn sum_array(input: &[Self]) -> Self { + assert_eq!(N, input.len()); + // Benchmarking shows that for N <= 3 it's faster to sum the elements directly + // but for N > 3 it's faster to use the .sum() methods which passes through u128's + // allowing for delayed reductions. + match N { + 0 => Self::ZERO, + 1 => input[0], + 2 => input[0] + input[1], + 3 => input[0] + input[1] + input[2], + _ => input.iter().copied().sum(), + } + } + + #[inline] + fn zero_vec(len: usize) -> Vec { + // SAFETY: + // Due to `#[repr(transparent)]`, Goldilocks and u64 have the same size, alignment + // and memory layout making `flatten_to_base` safe. This this will create + // a vector Goldilocks elements with value set to 0. + unsafe { flatten_to_base(vec![0u64; len]) } + } +} + +/// Degree of the smallest permutation polynomial for Goldilocks. +/// +/// As p - 1 = 2^32 * 3 * 5 * 17 * ... the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 7. +impl InjectiveMonomial<7> for Goldilocks {} + +impl PermutationMonomial<7> for Goldilocks { + /// In the field `Goldilocks`, `a^{1/7}` is equal to a^{10540996611094048183}. + /// + /// This follows from the calculation `7*10540996611094048183 = 4*(2^64 - 2**32) + 1 = 1 mod (p - 1)`. + fn injective_exp_root_n(&self) -> Self { + exp_10540996611094048183(*self) + } +} + +impl Field for Goldilocks { + // TODO: Add cfg-guarded Packing for NEON + + #[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) + ))] + type Packing = crate::PackedGoldilocksAVX2; + + #[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ))] + type Packing = crate::PackedGoldilocksAVX512; + #[cfg(not(any( + all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) + ), + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), + )))] + type Packing = Self; + + // Sage: GF(2^64 - 2^32 + 1).multiplicative_generator() + const GENERATOR: Self = Self::new(7); + + fn is_zero(&self) -> bool { + self.value == 0 || self.value == Self::ORDER_U64 + } + + fn try_inverse(&self) -> Option { + if self.is_zero() { + return None; + } + + // From Fermat's little theorem, in a prime field `F_p`, the inverse of `a` is `a^(p-2)`. + // + // compute a^(p - 2) using 72 multiplications + // The exponent p - 2 is represented in binary as: + // 0b1111111111111111111111111111111011111111111111111111111111111111 + // Adapted from: https://github.com/facebook/winterfell/blob/d238a1/math/src/field/f64/mod.rs#L136-L164 + + // compute base^11 + let t2 = self.square() * *self; + + // compute base^111 + let t3 = t2.square() * *self; + + // compute base^111111 (6 ones) + // repeatedly square t3 3 times and multiply by t3 + let t6 = exp_acc::<3>(t3, t3); + let t60 = t6.square(); + let t7 = t60 * *self; + + // compute base^111111111111 (12 ones) + // repeatedly square t6 6 times and multiply by t6 + let t12 = exp_acc::<5>(t60, t6); + + // compute base^111111111111111111111111 (24 ones) + // repeatedly square t12 12 times and multiply by t12 + let t24 = exp_acc::<12>(t12, t12); + + // compute base^1111111111111111111111111111111 (31 ones) + // repeatedly square t24 6 times and multiply by t6 first. then square t30 and + // multiply by base + let t31 = exp_acc::<7>(t24, t7); + + // compute base^111111111111111111111111111111101111111111111111111111111111111 + // repeatedly square t31 32 times and multiply by t31 + let t63 = exp_acc::<32>(t31, t31); + + // compute base^1111111111111111111111111111111011111111111111111111111111111111 + Some(t63.square() * *self) + } + + #[inline] + fn halve(&self) -> Self { + Self::new(halve_u64::

(self.value)) + } + + #[inline] + fn order() -> BigUint { + P.into() + } +} + +// We use macros to implement QuotientMap for all integer types except for u64 and i64. +quotient_map_small_int!(Goldilocks, u64, [u8, u16, u32]); +quotient_map_small_int!(Goldilocks, i64, [i8, i16, i32]); +quotient_map_large_uint!( + Goldilocks, + u64, + Goldilocks::ORDER_U64, + "`[0, 2^64 - 2^32]`", + "`[0, 2^64 - 1]`", + [u128] +); +quotient_map_large_iint!( + Goldilocks, + i64, + "`[-(2^63 - 2^31), 2^63 - 2^31]`", + "`[1 + 2^32 - 2^64, 2^64 - 1]`", + [(i128, u128)] +); + +impl QuotientMap for Goldilocks { + /// Convert a given `u64` integer into an element of the `Goldilocks` field. + /// + /// No reduction is needed as the internal value is allowed + /// to be any u64. + #[inline] + fn from_int(int: u64) -> Self { + Self::new(int) + } + + /// Convert a given `u64` integer into an element of the `Goldilocks` field. + /// + /// Return `None` if the given integer is greater than `p = 2^64 - 2^32 + 1`. + #[inline] + fn from_canonical_checked(int: u64) -> Option { + (int < Self::ORDER_U64).then(|| Self::new(int)) + } + + /// Convert a given `u64` integer into an element of the `Goldilocks` field. + /// + /// # Safety + /// In this case this function is actually always safe as the internal + /// value is allowed to be any u64. + #[inline(always)] + unsafe fn from_canonical_unchecked(int: u64) -> Self { + Self::new(int) + } +} + +impl QuotientMap for Goldilocks { + /// Convert a given `i64` integer into an element of the `Goldilocks` field. + /// + /// We simply need to deal with the sign. + #[inline] + fn from_int(int: i64) -> Self { + if int >= 0 { + Self::new(int as u64) + } else { + Self::new(Self::ORDER_U64.wrapping_add_signed(int)) + } + } + + /// Convert a given `i64` integer into an element of the `Goldilocks` field. + /// + /// Returns none if the input does not lie in the range `(-(2^63 - 2^31), 2^63 - 2^31)`. + #[inline] + fn from_canonical_checked(int: i64) -> Option { + const POS_BOUND: i64 = (P >> 1) as i64; + const NEG_BOUND: i64 = -POS_BOUND; + match int { + 0..=POS_BOUND => Some(Self::new(int as u64)), + NEG_BOUND..0 => Some(Self::new(Self::ORDER_U64.wrapping_add_signed(int))), + _ => None, + } + } + + /// Convert a given `i64` integer into an element of the `Goldilocks` field. + /// + /// # Safety + /// In this case this function is actually always safe as the internal + /// value is allowed to be any u64. + #[inline(always)] + unsafe fn from_canonical_unchecked(int: i64) -> Self { + Self::from_int(int) + } +} + +impl PrimeField for Goldilocks { + fn as_canonical_biguint(&self) -> BigUint { + self.as_canonical_u64().into() + } +} + +impl PrimeField64 for Goldilocks { + const ORDER_U64: u64 = P; + + #[inline] + fn as_canonical_u64(&self) -> u64 { + let mut c = self.value; + // We only need one condition subtraction, since 2 * ORDER would not fit in a u64. + if c >= Self::ORDER_U64 { + c -= Self::ORDER_U64; + } + c + } +} + +impl TwoAdicField for Goldilocks { + const TWO_ADICITY: usize = 32; + + fn two_adic_generator(bits: usize) -> Self { + assert!(bits <= Self::TWO_ADICITY); + Self::TWO_ADIC_GENERATORS[bits] + } +} + +impl Add for Goldilocks { + type Output = Self; + + #[inline] + fn add(self, rhs: Self) -> Self { + let (sum, over) = self.value.overflowing_add(rhs.value); + let (mut sum, over) = sum.overflowing_add(u64::from(over) * Self::NEG_ORDER); + if over { + // NB: self.value > Self::ORDER && rhs.value > Self::ORDER is necessary but not + // sufficient for double-overflow. + // This assume does two things: + // 1. If compiler knows that either self.value or rhs.value <= ORDER, then it can skip + // this check. + // 2. Hints to the compiler how rare this double-overflow is (thus handled better with + // a branch). + assume(self.value > Self::ORDER_U64 && rhs.value > Self::ORDER_U64); + branch_hint(); + sum += Self::NEG_ORDER; // Cannot overflow. + } + Self::new(sum) + } +} + +impl AddAssign for Goldilocks { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} + +impl Sum for Goldilocks { + fn sum>(iter: I) -> Self { + // This is faster than iter.reduce(|x, y| x + y).unwrap_or(Self::ZERO) for iterators of length > 2. + + // This sum will not overflow so long as iter.len() < 2^64. + let sum = iter.map(|x| x.value as u128).sum::(); + reduce128(sum) + } +} + +impl Sub for Goldilocks { + type Output = Self; + + #[inline] + fn sub(self, rhs: Self) -> Self { + let (diff, under) = self.value.overflowing_sub(rhs.value); + let (mut diff, under) = diff.overflowing_sub(u64::from(under) * Self::NEG_ORDER); + if under { + // NB: self.value < NEG_ORDER - 1 && rhs.value > ORDER is necessary but not + // sufficient for double-underflow. + // This assume does two things: + // 1. If compiler knows that either self.value >= NEG_ORDER - 1 or rhs.value <= ORDER, + // then it can skip this check. + // 2. Hints to the compiler how rare this double-underflow is (thus handled better + // with a branch). + assume(self.value < Self::NEG_ORDER - 1 && rhs.value > Self::ORDER_U64); + branch_hint(); + diff -= Self::NEG_ORDER; // Cannot underflow. + } + Self::new(diff) + } +} + +impl SubAssign for Goldilocks { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} + +impl Neg for Goldilocks { + type Output = Self; + + #[inline] + fn neg(self) -> Self::Output { + Self::new(Self::ORDER_U64 - self.as_canonical_u64()) + } +} + +impl Mul for Goldilocks { + type Output = Self; + + #[inline] + fn mul(self, rhs: Self) -> Self { + reduce128(u128::from(self.value) * u128::from(rhs.value)) + } +} + +impl MulAssign for Goldilocks { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} + +impl Product for Goldilocks { + fn product>(iter: I) -> Self { + iter.reduce(|x, y| x * y).unwrap_or(Self::ONE) + } +} + +impl Div for Goldilocks { + type Output = Self; + + #[allow(clippy::suspicious_arithmetic_impl)] + fn div(self, rhs: Self) -> Self { + self * rhs.inverse() + } +} + +/// Squares the base N number of times and multiplies the result by the tail value. +#[inline(always)] +fn exp_acc(base: Goldilocks, tail: Goldilocks) -> Goldilocks { + base.exp_power_of_2(N) * tail +} + +/// Reduces to a 64-bit value. The result might not be in canonical form; it could be in between the +/// field order and `2^64`. +#[inline] +pub(crate) fn reduce128(x: u128) -> Goldilocks { + let (x_lo, x_hi) = split(x); // This is a no-op + let x_hi_hi = x_hi >> 32; + let x_hi_lo = x_hi & Goldilocks::NEG_ORDER; + + let (mut t0, borrow) = x_lo.overflowing_sub(x_hi_hi); + if borrow { + branch_hint(); // A borrow is exceedingly rare. It is faster to branch. + t0 -= Goldilocks::NEG_ORDER; // Cannot underflow. + } + let t1 = x_hi_lo * Goldilocks::NEG_ORDER; + let t2 = unsafe { add_no_canonicalize_trashing_input(t0, t1) }; + Goldilocks::new(t2) +} + +#[inline] +#[allow(clippy::cast_possible_truncation)] +const fn split(x: u128) -> (u64, u64) { + (x as u64, (x >> 64) as u64) +} + +/// Fast addition modulo ORDER for x86-64. +/// This function is marked unsafe for the following reasons: +/// - It is only correct if x + y < 2**64 + ORDER = 0x1ffffffff00000001. +/// - It is only faster in some circumstances. In particular, on x86 it overwrites both inputs in +/// the registers, so its use is not recommended when either input will be used again. +#[inline(always)] +#[cfg(target_arch = "x86_64")] +unsafe fn add_no_canonicalize_trashing_input(x: u64, y: u64) -> u64 { + unsafe { + let res_wrapped: u64; + let adjustment: u64; + core::arch::asm!( + "add {0}, {1}", + // Trick. The carry flag is set iff the addition overflowed. + // sbb x, y does x := x - y - CF. In our case, x and y are both {1:e}, so it simply does + // {1:e} := 0xffffffff on overflow and {1:e} := 0 otherwise. {1:e} is the low 32 bits of + // {1}; the high 32-bits are zeroed on write. In the end, we end up with 0xffffffff in {1} + // on overflow; this happens be NEG_ORDER. + // Note that the CPU does not realize that the result of sbb x, x does not actually depend + // on x. We must write the result to a register that we know to be ready. We have a + // dependency on {1} anyway, so let's use it. + "sbb {1:e}, {1:e}", + inlateout(reg) x => res_wrapped, + inlateout(reg) y => adjustment, + options(pure, nomem, nostack), + ); + assume(x != 0 || (res_wrapped == y && adjustment == 0)); + assume(y != 0 || (res_wrapped == x && adjustment == 0)); + // Add NEG_ORDER == subtract ORDER. + // Cannot overflow unless the assumption if x + y < 2**64 + ORDER is incorrect. + res_wrapped + adjustment + } +} + +#[inline(always)] +#[cfg(not(target_arch = "x86_64"))] +unsafe fn add_no_canonicalize_trashing_input(x: u64, y: u64) -> u64 { + let (res_wrapped, carry) = x.overflowing_add(y); + // Below cannot overflow unless the assumption if x + y < 2**64 + ORDER is incorrect. + res_wrapped + Goldilocks::NEG_ORDER * u64::from(carry) +} + +#[cfg(test)] +mod tests { + use p3_field::extension::BinomialExtensionField; + use p3_field_testing::{ + test_field, test_field_dft, test_prime_field, test_prime_field_64, test_two_adic_field, + }; + + use super::*; + + type F = Goldilocks; + type EF = BinomialExtensionField; + + #[test] + fn test_goldilocks() { + let f = F::new(100); + assert_eq!(f.as_canonical_u64(), 100); + + // Over the Goldilocks field, the following set of equations hold + // p = 0 + // 2^64 - 2^32 + 1 = 0 + // 2^64 = 2^32 - 1 + let f = F::new(u64::MAX); + assert_eq!(f.as_canonical_u64(), u32::MAX as u64 - 1); + + let f = F::from_u64(u64::MAX); + assert_eq!(f.as_canonical_u64(), u32::MAX as u64 - 1); + + // Generator check + let expected_multiplicative_group_generator = F::new(7); + assert_eq!(F::GENERATOR, expected_multiplicative_group_generator); + assert_eq!(F::GENERATOR.as_canonical_u64(), 7_u64); + + // Check on `reduce_u128` + let x = u128::MAX; + let y = reduce128(x); + // The following equality sequence holds, modulo p = 2^64 - 2^32 + 1 + // 2^128 - 1 = (2^64 - 1) * (2^64 + 1) + // = (2^32 - 1 - 1) * (2^32 - 1 + 1) + // = (2^32 - 2) * (2^32) + // = 2^64 - 2 * 2^32 + // = 2^64 - 2^33 + // = 2^32 - 1 - 2^33 + // = - 2^32 - 1 + let expected_result = -F::TWO.exp_power_of_2(5) - F::ONE; + assert_eq!(y, expected_result); + + let f = F::new(100); + assert_eq!(f.injective_exp_n().injective_exp_root_n(), f); + assert_eq!(y.injective_exp_n().injective_exp_root_n(), y); + assert_eq!(F::TWO.injective_exp_n().injective_exp_root_n(), F::TWO); + } + + // Goldilocks has a redundant representation for both 0 and 1. + const ZEROS: [Goldilocks; 2] = [Goldilocks::ZERO, Goldilocks::new(P)]; + const ONES: [Goldilocks; 2] = [Goldilocks::ONE, Goldilocks::new(P + 1)]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 6] { + [ + (BigUint::from(2u8), 32), + (BigUint::from(3u8), 1), + (BigUint::from(5u8), 1), + (BigUint::from(17u8), 1), + (BigUint::from(257u16), 1), + (BigUint::from(65537u32), 1), + ] + } + + test_field!( + crate::Goldilocks, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + test_prime_field!(crate::Goldilocks); + test_prime_field_64!(crate::Goldilocks); + test_two_adic_field!(crate::Goldilocks); + + test_field_dft!( + radix2dit, + crate::Goldilocks, + super::EF, + p3_dft::Radix2Dit<_> + ); + test_field_dft!(bowers, crate::Goldilocks, super::EF, p3_dft::Radix2Bowers); + test_field_dft!( + parallel, + crate::Goldilocks, + super::EF, + p3_dft::Radix2DitParallel + ); +} diff --git a/CoqOfRust/plonky3/goldilocks/src/goldilocks.v b/CoqOfRust/plonky3/goldilocks/src/goldilocks.v new file mode 100644 index 000000000..c404b1f64 --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/goldilocks.v @@ -0,0 +1,4358 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module goldilocks. + Definition value_P (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U64 18446744069414584321 |))). + + Global Instance Instance_IsConstant_value_P : + M.IsFunction.C "p3_goldilocks::goldilocks::P" value_P. + Admitted. + Global Typeclasses Opaque value_P. + + (* StructRecord + { + name := "Goldilocks"; + const_params := []; + ty_params := []; + fields := [ ("value", Ty.path "u64") ]; + } *) + + Module Impl_core_marker_Copy_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_clone_Clone_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_default_Default_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_goldilocks::goldilocks::Goldilocks" + [ + ("value", + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::default::Default", + Ty.path "u64", + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_goldilocks_goldilocks_Goldilocks. + + Module underscore. + Module Impl_serde_ser_Serialize_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* Serialize *) + Definition serialize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "Goldilocks" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Ty.path "u64" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "value" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("serialize", InstanceField.Method serialize) ]. + End Impl_serde_ser_Serialize_for_p3_goldilocks_goldilocks_Goldilocks. + Module Impl_serde_de_Deserialize_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* Deserialize *) + Definition deserialize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ Ty.path "p3_goldilocks::goldilocks::_'1::deserialize::__Visitor" ] + |), + [ + M.read (| __deserializer |); + mk_str (| "Goldilocks" |); + M.read (| + get_constant (| + "p3_goldilocks::goldilocks::_'1::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_goldilocks::goldilocks::_'1::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("deserialize", InstanceField.Method deserialize) ]. + End Impl_serde_de_Deserialize_for_p3_goldilocks_goldilocks_Goldilocks. + End underscore. + + + Module Impl_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + pub(crate) const fn new(value: u64) -> Self { + Self { value } + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructRecord + "p3_goldilocks::goldilocks::Goldilocks" + [ ("value", M.read (| value |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.C Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub(crate) const fn new_array(input: [u64; N]) -> [Self; N] { + let mut output = [Self::ZERO; N]; + let mut i = 0; + while i < N { + output[i].value = input[i]; + i += 1; + } + output + } + *) + Definition new_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] := + M.alloc (| + repeat (| + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + |) + |), + N + |) + |) in + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| Ty.path "bool", BinOp.lt, [ M.read (| i |); N ] |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| output, M.read (| i |) |), + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |), + M.read (| + M.SubPointer.get_array_field (| input, M.read (| i |) |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_array : + M.IsAssociatedFunction.C Self "new_array" new_array. + Admitted. + Global Typeclasses Opaque new_array. + + (* const NEG_ORDER: u64 = Self::ORDER_U64.wrapping_neg(); *) + (* Ty.path "u64" *) + Definition value_NEG_ORDER (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| Ty.path "u64", "wrapping_neg", [], [] |), + [ + M.read (| + get_constant (| "p3_field::field::PrimeField64::ORDER_U64", Ty.path "u64" |) + |) + ] + |) + |))). + + Global Instance AssociatedConstant_value_NEG_ORDER : + M.IsAssociatedFunction.C Self "NEG_ORDER" value_NEG_ORDER. + Admitted. + Global Typeclasses Opaque value_NEG_ORDER. + + (* + pub const TWO_ADIC_GENERATORS: [Goldilocks; 33] = Goldilocks::new_array([ + 0x0000000000000001, + 0xffffffff00000000, + 0x0001000000000000, + 0xfffffffeff000001, + 0xefffffff00000001, + 0x00003fffffffc000, + 0x0000008000000000, + 0xf80007ff08000001, + 0xbf79143ce60ca966, + 0x1905d02a5c411f4e, + 0x9d8f2ad78bfed972, + 0x0653b4801da1c8cf, + 0xf2c35199959dfcb6, + 0x1544ef2335d17997, + 0xe0ee099310bba1e2, + 0xf6b2cffe2306baac, + 0x54df9630bf79450e, + 0xabd0a6e8aa3d8a0e, + 0x81281a7b05f9beac, + 0xfbd41c6b8caa3302, + 0x30ba2ecd5e93e76d, + 0xf502aef532322654, + 0x4b2a18ade67246b5, + 0xea9d5a1336fbc98b, + 0x86cdcc31c307e171, + 0x4bbaf5976ecfefd8, + 0xed41d05b78d6e286, + 0x10d78dd8915a171d, + 0x59049500004a4485, + 0xdfa8c93ba46d2666, + 0x7e9bd009b86a0845, + 0x400a7f755588e659, + 0x185629dcda58878c, + ]); + *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 33 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] *) + Definition value_TWO_ADIC_GENERATORS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 33 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new_array", + [ Value.Integer IntegerKind.Usize 33 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U64 1; + Value.Integer IntegerKind.U64 18446744069414584320; + Value.Integer IntegerKind.U64 281474976710656; + Value.Integer IntegerKind.U64 18446744069397807105; + Value.Integer IntegerKind.U64 17293822564807737345; + Value.Integer IntegerKind.U64 70368744161280; + Value.Integer IntegerKind.U64 549755813888; + Value.Integer IntegerKind.U64 17870292113338400769; + Value.Integer IntegerKind.U64 13797081185216407910; + Value.Integer IntegerKind.U64 1803076106186727246; + Value.Integer IntegerKind.U64 11353340290879379826; + Value.Integer IntegerKind.U64 455906449640507599; + Value.Integer IntegerKind.U64 17492915097719143606; + Value.Integer IntegerKind.U64 1532612707718625687; + Value.Integer IntegerKind.U64 16207902636198568418; + Value.Integer IntegerKind.U64 17776499369601055404; + Value.Integer IntegerKind.U64 6115771955107415310; + Value.Integer IntegerKind.U64 12380578893860276750; + Value.Integer IntegerKind.U64 9306717745644682924; + Value.Integer IntegerKind.U64 18146160046829613826; + Value.Integer IntegerKind.U64 3511170319078647661; + Value.Integer IntegerKind.U64 17654865857378133588; + Value.Integer IntegerKind.U64 5416168637041100469; + Value.Integer IntegerKind.U64 16905767614792059275; + Value.Integer IntegerKind.U64 9713644485405565297; + Value.Integer IntegerKind.U64 5456943929260765144; + Value.Integer IntegerKind.U64 17096174751763063430; + Value.Integer IntegerKind.U64 1213594585890690845; + Value.Integer IntegerKind.U64 6414415596519834757; + Value.Integer IntegerKind.U64 16116352524544190054; + Value.Integer IntegerKind.U64 9123114210336311365; + Value.Integer IntegerKind.U64 4614640910117430873; + Value.Integer IntegerKind.U64 1753635133440165772 + ] + ] + |) + |))). + + Global Instance AssociatedConstant_value_TWO_ADIC_GENERATORS : + M.IsAssociatedFunction.C Self "TWO_ADIC_GENERATORS" value_TWO_ADIC_GENERATORS. + Admitted. + Global Typeclasses Opaque value_TWO_ADIC_GENERATORS. + End Impl_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_cmp_PartialEq_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn eq(&self, other: &Self) -> bool { + self.as_canonical_u64() == other.as_canonical_u64() + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "as_canonical_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "as_canonical_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_cmp_Eq_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_cmp_Eq_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_packed_Packable_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + Axiom Implements : + M.IsTraitInstance + "p3_field::packed::Packable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_field_packed_Packable_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_hash_Hash_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn hash(&self, state: &mut H) { + state.write_u64(self.as_canonical_u64()); + } + *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| "core::hash::Hasher", H, [], [], "write_u64", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "as_canonical_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_cmp_Ord_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.as_canonical_u64().cmp(&other.as_canonical_u64()) + } + *) + Definition cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| "core::cmp::Ord", Ty.path "u64", [], [], "cmp", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "as_canonical_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "as_canonical_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("cmp", InstanceField.Method cmp) ]. + End Impl_core_cmp_Ord_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_cmp_PartialOrd_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_fmt_Display_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Display::fmt(&self.value, f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| "core::fmt::Display", Ty.path "u64", [], [], "fmt", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_fmt_Debug_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Debug::fmt(&self.value, f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| "core::fmt::Debug", Ty.path "u64", [], [], "fmt", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_rand_distr_distribution_Distribution_p3_goldilocks_goldilocks_Goldilocks_for_rand_distr_StandardUniform. + Definition Self : Ty.t := Ty.path "rand::distr::StandardUniform". + + (* + fn sample(&self, rng: &mut R) -> Goldilocks { + loop { + let next_u64 = rng.next_u64(); + let is_canonical = next_u64 < Goldilocks::ORDER_U64; + if is_canonical { + return Goldilocks::new(next_u64); + } + } + } + *) + Definition sample (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ self; rng ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rng := M.alloc (| rng |) in + M.catch_return (Ty.path "p3_goldilocks::goldilocks::Goldilocks") (| + ltac:(M.monadic + (M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic + (let~ next_u64 : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "rand_core::RngCore", + R, + [], + [], + "next_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |) ] + |) + |) in + let~ is_canonical : Ty.apply (Ty.path "*") [] [ Ty.path "bool" ] := + M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| next_u64 |); + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use is_canonical in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ M.read (| next_u64 |) ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "rand::distr::distribution::Distribution" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("sample", InstanceField.Method sample) ]. + End Impl_rand_distr_distribution_Distribution_p3_goldilocks_goldilocks_Goldilocks_for_rand_distr_StandardUniform. + + Module Impl_p3_field_field_PrimeCharacteristicRing_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* type PrimeSubfield = Self; *) + Definition _PrimeSubfield : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* const ZERO: Self = Self::new(0); *) + (* Ty.path "p3_goldilocks::goldilocks::Goldilocks" *) + Definition value_ZERO (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 0 ] + |) + |))). + + (* const ONE: Self = Self::new(1); *) + (* Ty.path "p3_goldilocks::goldilocks::Goldilocks" *) + Definition value_ONE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |))). + + (* const TWO: Self = Self::new(2); *) + (* Ty.path "p3_goldilocks::goldilocks::Goldilocks" *) + Definition value_TWO (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 2 ] + |) + |))). + + (* const NEG_ONE: Self = Self::new(Self::ORDER_U64 - 1); *) + (* Ty.path "p3_goldilocks::goldilocks::Goldilocks" *) + Definition value_NEG_ONE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField64::ORDER_U64", Ty.path "u64" |) + |); + Value.Integer IntegerKind.U64 1 + ] + |) + ] + |) + |))). + + (* + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f + } + *) + Definition from_prime_subfield (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.read (| f |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_bool(b: bool) -> Self { + Self::new(b.into()) + } + *) + Definition from_bool (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ b ] => + ltac:(M.monadic + (let b := M.alloc (| b |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::convert::Into", + Ty.path "bool", + [], + [ Ty.path "u64" ], + "into", + [], + [] + |), + [ M.read (| b |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn sum_array(input: &[Self]) -> Self { + assert_eq!(N, input.len()); + // Benchmarking shows that for N <= 3 it's faster to sum the elements directly + // but for N > 3 it's faster to use the .sum() methods which passes through u128's + // allowing for delayed reductions. + match N { + 0 => Self::ZERO, + 1 => input[0], + 2 => input[0] + input[1], + 3 => input[0] + input[1] + input[2], + _ => input.iter().copied().sum(), + } + } + *) + Definition sum_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.alloc (| N |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 0 + |) in + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 1 + |) in + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 3 + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + [], + [], + "sum", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + [], + [], + "copied", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) + ] + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn zero_vec(len: usize) -> Vec { + // SAFETY: + // Due to `#[repr(transparent)]`, Goldilocks and u64 have the same size, alignment + // and memory layout making `flatten_to_base` safe. This this will create + // a vector Goldilocks elements with value set to 0. + unsafe { flatten_to_base(vec![0u64; len]) } + } + *) + Definition zero_vec (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ len ] => + ltac:(M.monadic + (let len := M.alloc (| len |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_util::flatten_to_base", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; Ty.path "u64" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u64"; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloc::vec::from_elem", [], [ Ty.path "u64" ] |), + [ Value.Integer IntegerKind.U64 0; M.read (| len |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PrimeCharacteristicRing" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("PrimeSubfield", InstanceField.Ty _PrimeSubfield); + ("value_ZERO", InstanceField.Method value_ZERO); + ("value_ONE", InstanceField.Method value_ONE); + ("value_TWO", InstanceField.Method value_TWO); + ("value_NEG_ONE", InstanceField.Method value_NEG_ONE); + ("from_prime_subfield", InstanceField.Method from_prime_subfield); + ("from_bool", InstanceField.Method from_bool); + ("sum_array", InstanceField.Method sum_array); + ("zero_vec", InstanceField.Method zero_vec) + ]. + End Impl_p3_field_field_PrimeCharacteristicRing_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_field_InjectiveMonomial_U64_7_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::InjectiveMonomial" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.U64 7 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_field_field_InjectiveMonomial_U64_7_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_field_PermutationMonomial_U64_7_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn injective_exp_root_n(&self) -> Self { + exp_10540996611094048183( *self) + } + *) + Definition injective_exp_root_n (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_function (| + "p3_field::exponentiation::exp_10540996611094048183", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PermutationMonomial" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.U64 7 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("injective_exp_root_n", InstanceField.Method injective_exp_root_n) ]. + End Impl_p3_field_field_PermutationMonomial_U64_7_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_field_Field_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* type Packing = Self; *) + Definition _Packing : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* const GENERATOR: Self = Self::new(7); *) + (* Ty.path "p3_goldilocks::goldilocks::Goldilocks" *) + Definition value_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U64 7 ] + |) + |))). + + (* + fn is_zero(&self) -> bool { + self.value == 0 || self.value == Self::ORDER_U64 + } + *) + Definition is_zero (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |); + Value.Integer IntegerKind.U64 0 + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |); + M.read (| + get_constant (| "p3_field::field::PrimeField64::ORDER_U64", Ty.path "u64" |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn try_inverse(&self) -> Option { + if self.is_zero() { + return None; + } + + // From Fermat's little theorem, in a prime field `F_p`, the inverse of `a` is `a^(p-2)`. + // + // compute a^(p - 2) using 72 multiplications + // The exponent p - 2 is represented in binary as: + // 0b1111111111111111111111111111111011111111111111111111111111111111 + // Adapted from: https://github.com/facebook/winterfell/blob/d238a1/math/src/field/f64/mod.rs#L136-L164 + + // compute base^11 + let t2 = self.square() * *self; + + // compute base^111 + let t3 = t2.square() * *self; + + // compute base^111111 (6 ones) + // repeatedly square t3 3 times and multiply by t3 + let t6 = exp_acc::<3>(t3, t3); + let t60 = t6.square(); + let t7 = t60 * *self; + + // compute base^111111111111 (12 ones) + // repeatedly square t6 6 times and multiply by t6 + let t12 = exp_acc::<5>(t60, t6); + + // compute base^111111111111111111111111 (24 ones) + // repeatedly square t12 12 times and multiply by t12 + let t24 = exp_acc::<12>(t12, t12); + + // compute base^1111111111111111111111111111111 (31 ones) + // repeatedly square t24 6 times and multiply by t6 first. then square t30 and + // multiply by base + let t31 = exp_acc::<7>(t24, t7); + + // compute base^111111111111111111111111111111101111111111111111111111111111111 + // repeatedly square t31 32 times and multiply by t31 + let t63 = exp_acc::<32>(t31, t31); + + // compute base^1111111111111111111111111111111011111111111111111111111111111111 + Some(t63.square() * *self) + } + *) + Definition try_inverse (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| Value.StructTuple "core::option::Option::None" [] |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ t2 : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.read (| M.deref (| M.read (| self |) |) |) + ] + |) + |) in + let~ t3 : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, t2 |) ] + |); + M.read (| M.deref (| M.read (| self |) |) |) + ] + |) + |) in + let~ t6 : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_function (| + "p3_goldilocks::goldilocks::exp_acc", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ M.read (| t3 |); M.read (| t3 |) ] + |) + |) in + let~ t60 : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, t6 |) ] + |) + |) in + let~ t7 : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "mul", + [], + [] + |), + [ M.read (| t60 |); M.read (| M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ t12 : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_function (| + "p3_goldilocks::goldilocks::exp_acc", + [ Value.Integer IntegerKind.Usize 5 ], + [] + |), + [ M.read (| t60 |); M.read (| t6 |) ] + |) + |) in + let~ t24 : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_function (| + "p3_goldilocks::goldilocks::exp_acc", + [ Value.Integer IntegerKind.Usize 12 ], + [] + |), + [ M.read (| t12 |); M.read (| t12 |) ] + |) + |) in + let~ t31 : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_function (| + "p3_goldilocks::goldilocks::exp_acc", + [ Value.Integer IntegerKind.Usize 7 ], + [] + |), + [ M.read (| t24 |); M.read (| t7 |) ] + |) + |) in + let~ t63 : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_function (| + "p3_goldilocks::goldilocks::exp_acc", + [ Value.Integer IntegerKind.Usize 32 ], + [] + |), + [ M.read (| t31 |); M.read (| t31 |) ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, t63 |) ] + |); + M.read (| M.deref (| M.read (| self |) |) |) + ] + |) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn halve(&self) -> Self { + Self::new(halve_u64::

(self.value)) + } + *) + Definition halve (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + M.get_function (| + "p3_field::helpers::halve_u64", + [ Value.Integer IntegerKind.U64 18446744069414584321 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn order() -> BigUint { + P.into() + } + *) + Definition order (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "core::convert::Into", + Ty.path "u64", + [], + [ Ty.path "num_bigint::biguint::BigUint" ], + "into", + [], + [] + |), + [ M.read (| get_constant (| "p3_goldilocks::goldilocks::P", Ty.path "u64" |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::Field" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Packing", InstanceField.Ty _Packing); + ("value_GENERATOR", InstanceField.Method value_GENERATOR); + ("is_zero", InstanceField.Method is_zero); + ("try_inverse", InstanceField.Method try_inverse); + ("halve", InstanceField.Method halve); + ("order", InstanceField.Method order) + ]. + End Impl_p3_field_field_Field_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_integers_QuotientMap_u64_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn from_int(int: u64) -> Self { + Self::new(int) + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ M.read (| int |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: u64) -> Option { + (int < Self::ORDER_U64).then(|| Self::new(int)) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.function [ Ty.tuple [] ] (Ty.path "p3_goldilocks::goldilocks::Goldilocks") + ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| int |); + M.read (| + get_constant (| "p3_field::field::PrimeField64::ORDER_U64", Ty.path "u64" |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "p3_goldilocks::goldilocks::Goldilocks") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ M.read (| int |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: u64) -> Self { + Self::new(int) + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ M.read (| int |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. + End Impl_p3_field_integers_QuotientMap_u64_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_integers_QuotientMap_i64_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn from_int(int: i64) -> Self { + if int >= 0 { + Self::new(int as u64) + } else { + Self::new(Self::ORDER_U64.wrapping_add_signed(int)) + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| int |); Value.Integer IntegerKind.I64 0 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ M.cast (Ty.path "u64") (M.read (| int |)) ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| + Ty.path "u64", + "wrapping_add_signed", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |); + M.read (| int |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: i64) -> Option { + const POS_BOUND: i64 = (P >> 1) as i64; + const NEG_BOUND: i64 = -POS_BOUND; + match int { + 0..=POS_BOUND => Some(Self::new(int as u64)), + NEG_BOUND..0 => Some(Self::new(Self::ORDER_U64.wrapping_add_signed(int))), + _ => None, + } + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + int, + [ + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ M.cast (Ty.path "u64") (M.read (| int |)) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| + Ty.path "u64", + "wrapping_add_signed", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |); + M.read (| int |) + ] + |) + ] + |) + ] + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: i64) -> Self { + Self::from_int(int) + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "i64" ], + "from_int", + [], + [] + |), + [ M.read (| int |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i64" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. + End Impl_p3_field_integers_QuotientMap_i64_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_field_PrimeField_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn as_canonical_biguint(&self) -> BigUint { + self.as_canonical_u64().into() + } + *) + Definition as_canonical_biguint (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "core::convert::Into", + Ty.path "u64", + [], + [ Ty.path "num_bigint::biguint::BigUint" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "as_canonical_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PrimeField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("as_canonical_biguint", InstanceField.Method as_canonical_biguint) ]. + End Impl_p3_field_field_PrimeField_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_field_PrimeField64_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* const ORDER_U64: u64 = P; *) + (* Ty.path "u64" *) + Definition value_ORDER_U64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (get_constant (| "p3_goldilocks::goldilocks::P", Ty.path "u64" |))). + + (* + fn as_canonical_u64(&self) -> u64 { + let mut c = self.value; + // We only need one condition subtraction, since 2 * ORDER would not fit in a u64. + if c >= Self::ORDER_U64 { + c -= Self::ORDER_U64; + } + c + } + *) + Definition as_canonical_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ c : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| c |); + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := c in + M.write (| + β, + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.read (| β |); + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + c + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PrimeField64" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_ORDER_U64", InstanceField.Method value_ORDER_U64); + ("as_canonical_u64", InstanceField.Method as_canonical_u64) + ]. + End Impl_p3_field_field_PrimeField64_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_p3_field_field_TwoAdicField_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* const TWO_ADICITY: usize = 32; *) + (* Ty.path "usize" *) + Definition value_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 32 |))). + + (* + fn two_adic_generator(bits: usize) -> Self { + assert!(bits <= Self::TWO_ADICITY); + Self::TWO_ADIC_GENERATORS[bits] + } + *) + Definition two_adic_generator (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| bits |); + M.read (| + get_constant (| + "p3_field::field::TwoAdicField::TWO_ADICITY", + Ty.path "usize" + |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits <= Self::TWO_ADICITY" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.SubPointer.get_array_field (| + get_associated_constant (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "TWO_ADIC_GENERATORS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 33 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |), + M.read (| bits |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::TwoAdicField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_TWO_ADICITY", InstanceField.Method value_TWO_ADICITY); + ("two_adic_generator", InstanceField.Method two_adic_generator) + ]. + End Impl_p3_field_field_TwoAdicField_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_ops_arith_Add_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn add(self, rhs: Self) -> Self { + let (sum, over) = self.value.overflowing_add(rhs.value); + let (mut sum, over) = sum.overflowing_add(u64::from(over) * Self::NEG_ORDER); + if over { + // NB: self.value > Self::ORDER && rhs.value > Self::ORDER is necessary but not + // sufficient for double-overflow. + // This assume does two things: + // 1. If compiler knows that either self.value or rhs.value <= ORDER, then it can skip + // this check. + // 2. Hints to the compiler how rare this double-overflow is (thus handled better with + // a branch). + assume(self.value > Self::ORDER_U64 && rhs.value > Self::ORDER_U64); + branch_hint(); + sum += Self::NEG_ORDER; // Cannot overflow. + } + Self::new(sum) + } + *) + Definition add (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u64"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "u64", "overflowing_add", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let sum := M.copy (| γ0_0 |) in + let over := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u64"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "u64", "overflowing_add", [], [] |), + [ + M.read (| sum |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::convert::From", + Ty.path "u64", + [], + [ Ty.path "bool" ], + "from", + [], + [] + |), + [ M.read (| over |) ] + |); + M.read (| + get_associated_constant (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "NEG_ORDER", + Ty.path "u64" + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let sum := M.copy (| γ0_0 |) in + let over := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use over in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::assume", [], [] |), + [ + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + ] + |))) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::branch_hint", [], [] |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := sum in + M.write (| + β, + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ + M.read (| β |); + M.read (| + get_associated_constant (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "NEG_ORDER", + Ty.path "u64" + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ M.read (| sum |) ] + |) + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("add", InstanceField.Method add) ]. + End Impl_core_ops_arith_Add_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_ops_arith_AddAssign_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } + *) + Definition add_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "add", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("add_assign", InstanceField.Method add_assign) ]. + End Impl_core_ops_arith_AddAssign_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_iter_traits_accum_Sum_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn sum>(iter: I) -> Self { + // This is faster than iter.reduce(|x, y| x + y).unwrap_or(Self::ZERO) for iterators of length > 2. + + // This sum will not overflow so long as iter.len() < 2^64. + let sum = iter.map(|x| x.value as u128).sum::(); + reduce128(sum) + } + *) + Definition sum (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.read (| + let~ sum : Ty.apply (Ty.path "*") [] [ Ty.path "u128" ] := + M.alloc (| + M.call_closure (| + Ty.path "u128", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + I; + Ty.function + [ Ty.tuple [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] ] + (Ty.path "u128") + ], + [], + [], + "sum", + [], + [ Ty.path "u128" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + I; + Ty.function + [ Ty.tuple [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] ] + (Ty.path "u128") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "map", + [], + [ + Ty.path "u128"; + Ty.function + [ Ty.tuple [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] ] + (Ty.path "u128") + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + (Ty.path "u128") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.cast + (Ty.path "u128") + (M.read (| + M.SubPointer.get_struct_record_field (| + x, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |)))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_function (| "p3_goldilocks::goldilocks::reduce128", [], [] |), + [ M.read (| sum |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::accum::Sum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("sum", InstanceField.Method sum) ]. + End Impl_core_iter_traits_accum_Sum_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_ops_arith_Sub_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn sub(self, rhs: Self) -> Self { + let (diff, under) = self.value.overflowing_sub(rhs.value); + let (mut diff, under) = diff.overflowing_sub(u64::from(under) * Self::NEG_ORDER); + if under { + // NB: self.value < NEG_ORDER - 1 && rhs.value > ORDER is necessary but not + // sufficient for double-underflow. + // This assume does two things: + // 1. If compiler knows that either self.value >= NEG_ORDER - 1 or rhs.value <= ORDER, + // then it can skip this check. + // 2. Hints to the compiler how rare this double-underflow is (thus handled better + // with a branch). + assume(self.value < Self::NEG_ORDER - 1 && rhs.value > Self::ORDER_U64); + branch_hint(); + diff -= Self::NEG_ORDER; // Cannot underflow. + } + Self::new(diff) + } + *) + Definition sub (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u64"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "u64", "overflowing_sub", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let diff := M.copy (| γ0_0 |) in + let under := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u64"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "u64", "overflowing_sub", [], [] |), + [ + M.read (| diff |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::convert::From", + Ty.path "u64", + [], + [ Ty.path "bool" ], + "from", + [], + [] + |), + [ M.read (| under |) ] + |); + M.read (| + get_associated_constant (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "NEG_ORDER", + Ty.path "u64" + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let diff := M.copy (| γ0_0 |) in + let under := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use under in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::assume", [], [] |), + [ + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.read (| + get_associated_constant (| + Ty.path + "p3_goldilocks::goldilocks::Goldilocks", + "NEG_ORDER", + Ty.path "u64" + |) + |); + Value.Integer IntegerKind.U64 1 + ] + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + ] + |))) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::branch_hint", [], [] |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := diff in + M.write (| + β, + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.read (| β |); + M.read (| + get_associated_constant (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "NEG_ORDER", + Ty.path "u64" + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ M.read (| diff |) ] + |) + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("sub", InstanceField.Method sub) ]. + End Impl_core_ops_arith_Sub_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_ops_arith_SubAssign_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } + *) + Definition sub_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "sub", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("sub_assign", InstanceField.Method sub_assign) ]. + End Impl_core_ops_arith_SubAssign_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_ops_arith_Neg_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn neg(self) -> Self::Output { + Self::new(Self::ORDER_U64 - self.as_canonical_u64()) + } + *) + Definition neg (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField64::ORDER_U64", Ty.path "u64" |) + |); + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "as_canonical_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("neg", InstanceField.Method neg) ]. + End Impl_core_ops_arith_Neg_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_ops_arith_Mul_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn mul(self, rhs: Self) -> Self { + reduce128(u128::from(self.value) * u128::from(rhs.value)) + } + *) + Definition mul (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_function (| "p3_goldilocks::goldilocks::reduce128", [], [] |), + [ + M.call_closure (| + Ty.path "u128", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "u128", + M.get_trait_method (| + "core::convert::From", + Ty.path "u128", + [], + [ Ty.path "u64" ], + "from", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |) + ] + |); + M.call_closure (| + Ty.path "u128", + M.get_trait_method (| + "core::convert::From", + Ty.path "u128", + [], + [ Ty.path "u64" ], + "from", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |) + ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("mul", InstanceField.Method mul) ]. + End Impl_core_ops_arith_Mul_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_ops_arith_MulAssign_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } + *) + Definition mul_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "mul", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("mul_assign", InstanceField.Method mul_assign) ]. + End Impl_core_ops_arith_MulAssign_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_iter_traits_accum_Product_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn product>(iter: I) -> Self { + iter.reduce(|x, y| x * y).unwrap_or(Self::ONE) + } + *) + Definition product (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + ] + ] + (Ty.path "p3_goldilocks::goldilocks::Goldilocks") + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + ] + ] + (Ty.path "p3_goldilocks::goldilocks::Goldilocks") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + ] + ] + (Ty.path "p3_goldilocks::goldilocks::Goldilocks") + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := M.copy (| γ |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.path "p3_goldilocks::goldilocks::Goldilocks" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::accum::Product" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("product", InstanceField.Method product) ]. + End Impl_core_iter_traits_accum_Product_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + Module Impl_core_ops_arith_Div_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_goldilocks::goldilocks::Goldilocks". + + (* + fn div(self, rhs: Self) -> Self { + self * rhs.inverse() + } + *) + Definition div (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "mul", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "p3_field::field::Field", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Div" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("div", InstanceField.Method div) ]. + End Impl_core_ops_arith_Div_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_goldilocks_Goldilocks. + + (* + fn exp_acc(base: Goldilocks, tail: Goldilocks) -> Goldilocks { + base.exp_power_of_2(N) * tail + } + *) + Definition exp_acc (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [ base; tail ] => + ltac:(M.monadic + (let base := M.alloc (| base |) in + let tail := M.alloc (| tail |) in + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, base |); N ] + |); + M.read (| tail |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_exp_acc : + M.IsFunction.C "p3_goldilocks::goldilocks::exp_acc" exp_acc. + Admitted. + Global Typeclasses Opaque exp_acc. + + (* + pub(crate) fn reduce128(x: u128) -> Goldilocks { + let (x_lo, x_hi) = split(x); // This is a no-op + let x_hi_hi = x_hi >> 32; + let x_hi_lo = x_hi & Goldilocks::NEG_ORDER; + + let (mut t0, borrow) = x_lo.overflowing_sub(x_hi_hi); + if borrow { + branch_hint(); // A borrow is exceedingly rare. It is faster to branch. + t0 -= Goldilocks::NEG_ORDER; // Cannot underflow. + } + let t1 = x_hi_lo * Goldilocks::NEG_ORDER; + let t2 = unsafe { add_no_canonicalize_trashing_input(t0, t1) }; + Goldilocks::new(t2) + } + *) + Definition reduce128 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u64"; Ty.path "u64" ], + M.get_function (| "p3_goldilocks::goldilocks::split", [], [] |), + [ M.read (| x |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x_lo := M.copy (| γ0_0 |) in + let x_hi := M.copy (| γ0_1 |) in + let~ x_hi_hi : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shr, + [ M.read (| x_hi |); Value.Integer IntegerKind.I32 32 ] + |) + |) in + let~ x_hi_lo : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_and, + [ + M.read (| x_hi |); + M.read (| + get_associated_constant (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "NEG_ORDER", + Ty.path "u64" + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u64"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "u64", "overflowing_sub", [], [] |), + [ M.read (| x_lo |); M.read (| x_hi_hi |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let t0 := M.copy (| γ0_0 |) in + let borrow := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use borrow in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::branch_hint", [], [] |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := t0 in + M.write (| + β, + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.read (| β |); + M.read (| + get_associated_constant (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "NEG_ORDER", + Ty.path "u64" + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ t1 : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.read (| x_hi_lo |); + M.read (| + get_associated_constant (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "NEG_ORDER", + Ty.path "u64" + |) + |) + ] + |) + |) in + let~ t2 : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_function (| + "p3_goldilocks::goldilocks::add_no_canonicalize_trashing_input", + [], + [] + |), + [ M.read (| t0 |); M.read (| t1 |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new", + [], + [] + |), + [ M.read (| t2 |) ] + |) + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_reduce128 : + M.IsFunction.C "p3_goldilocks::goldilocks::reduce128" reduce128. + Admitted. + Global Typeclasses Opaque reduce128. + + (* + const fn split(x: u128) -> (u64, u64) { + (x as u64, (x >> 64) as u64) + } + *) + Definition split (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + Value.Tuple + [ + M.cast (Ty.path "u64") (M.read (| x |)); + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "u128", + BinOp.Wrap.shr, + [ M.read (| x |); Value.Integer IntegerKind.I32 64 ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_split : + M.IsFunction.C "p3_goldilocks::goldilocks::split" split. + Admitted. + Global Typeclasses Opaque split. + + (* + unsafe fn add_no_canonicalize_trashing_input(x: u64, y: u64) -> u64 { + unsafe { + let res_wrapped: u64; + let adjustment: u64; + core::arch::asm!( + "add {0}, {1}", + // Trick. The carry flag is set iff the addition overflowed. + // sbb x, y does x := x - y - CF. In our case, x and y are both {1:e}, so it simply does + // {1:e} := 0xffffffff on overflow and {1:e} := 0 otherwise. {1:e} is the low 32 bits of + // {1}; the high 32-bits are zeroed on write. In the end, we end up with 0xffffffff in {1} + // on overflow; this happens be NEG_ORDER. + // Note that the CPU does not realize that the result of sbb x, x does not actually depend + // on x. We must write the result to a register that we know to be ready. We have a + // dependency on {1} anyway, so let's use it. + "sbb {1:e}, {1:e}", + inlateout(reg) x => res_wrapped, + inlateout(reg) y => adjustment, + options(pure, nomem, nostack), + ); + assume(x != 0 || (res_wrapped == y && adjustment == 0)); + assume(y != 0 || (res_wrapped == x && adjustment == 0)); + // Add NEG_ORDER == subtract ORDER. + // Cannot overflow unless the assumption if x + y < 2**64 + ORDER is incorrect. + res_wrapped + adjustment + } + } + *) + Definition add_no_canonicalize_trashing_input + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ x; y ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + M.read (| + let res_wrapped := M.copy (| Value.DeclaredButUndefined |) in + let adjustment := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := InlineAssembly in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::assume", [], [] |), + [ + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ M.read (| x |); Value.Integer IntegerKind.U64 0 ] + |), + ltac:(M.monadic + (LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| res_wrapped |); M.read (| y |) ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| adjustment |); Value.Integer IntegerKind.U64 0 ] + |))) + |))) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::assume", [], [] |), + [ + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ M.read (| y |); Value.Integer IntegerKind.U64 0 ] + |), + ltac:(M.monadic + (LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| res_wrapped |); M.read (| x |) ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| adjustment |); Value.Integer IntegerKind.U64 0 ] + |))) + |))) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ M.read (| res_wrapped |); M.read (| adjustment |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_add_no_canonicalize_trashing_input : + M.IsFunction.C + "p3_goldilocks::goldilocks::add_no_canonicalize_trashing_input" + add_no_canonicalize_trashing_input. + Admitted. + Global Typeclasses Opaque add_no_canonicalize_trashing_input. +End goldilocks. diff --git a/CoqOfRust/plonky3/goldilocks/src/lib.rs b/CoqOfRust/plonky3/goldilocks/src/lib.rs new file mode 100644 index 000000000..ac5baa8e5 --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/lib.rs @@ -0,0 +1,50 @@ +//! The prime field known as Goldilocks, defined as `F_p` where `p = 2^64 - 2^32 + 1`. + +#![no_std] +#![cfg_attr( + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), + feature(stdarch_x86_avx512) +)] + +extern crate alloc; + +mod extension; +mod goldilocks; +mod mds; +mod poseidon2; + +pub use goldilocks::*; +pub use mds::*; +pub use poseidon2::*; + +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +mod x86_64_avx2; + +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +pub use x86_64_avx2::*; + +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +mod x86_64_avx512; + +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +pub use x86_64_avx512::*; diff --git a/CoqOfRust/plonky3/goldilocks/src/mds.rs b/CoqOfRust/plonky3/goldilocks/src/mds.rs new file mode 100644 index 000000000..79da5f5e5 --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/mds.rs @@ -0,0 +1,775 @@ +//! MDS matrices over the Goldilocks field, and permutations defined by them. +//! +//! NB: Not all sizes have fast implementations of their permutations. +//! Supported sizes: 8, 12, 16, 24, 32, 64, 68. +//! Sizes 8 and 12 are from Plonky2, size 16 was found as part of concurrent +//! work by Angus Gruen and Hamish Ivey-Law. Other sizes are from Ulrich Haböck's +//! database. + +use p3_dft::Radix2Bowers; +use p3_mds::MdsPermutation; +use p3_mds::karatsuba_convolution::Convolve; +use p3_mds::util::{apply_circulant, apply_circulant_fft, first_row_to_first_col}; +use p3_symmetric::Permutation; + +use crate::{Goldilocks, reduce128}; + +#[derive(Clone, Debug, Default)] +pub struct MdsMatrixGoldilocks; + +/// Instantiate convolution for "small" RHS vectors over Goldilocks. +/// +/// Here "small" means N = len(rhs) <= 16 and sum(r for r in rhs) < +/// 2^51, though in practice the sum will be less than 2^9. +#[derive(Debug)] +pub struct SmallConvolveGoldilocks; +impl Convolve for SmallConvolveGoldilocks { + /// Return the lift of a Goldilocks element, 0 <= input.value <= P + /// < 2^64. We widen immediately, since some valid Goldilocks elements + /// don't fit in an i64, and since in any case overflow can occur + /// for even the smallest convolutions. + #[inline(always)] + fn read(input: Goldilocks) -> i128 { + input.value as i128 + } + + /// For a convolution of size N, |x| < N * 2^64 and (as per the + /// assumption above), |y| < 2^51. So the product is at most N * + /// 2^115 which will not overflow for N <= 16. We widen `y` at + /// this point to perform the multiplication. + #[inline(always)] + fn parity_dot(u: [i128; N], v: [i64; N]) -> i128 { + let mut s = 0i128; + for i in 0..N { + s += u[i] * v[i] as i128; + } + s + } + + /// The assumptions above mean z < N^2 * 2^115, which is at most + /// 2^123 when N <= 16. + /// + /// NB: Even though intermediate values could be negative, the + /// output must be non-negative since the inputs were + /// non-negative. + #[inline(always)] + fn reduce(z: i128) -> Goldilocks { + debug_assert!(z >= 0); + reduce128(z as u128) + } +} + +const FFT_ALGO: Radix2Bowers = Radix2Bowers; + +pub(crate) const MATRIX_CIRC_MDS_8_SML_ROW: [i64; 8] = [7, 1, 3, 8, 8, 3, 4, 9]; + +impl Permutation<[Goldilocks; 8]> for MdsMatrixGoldilocks { + fn permute(&self, input: [Goldilocks; 8]) -> [Goldilocks; 8] { + const MATRIX_CIRC_MDS_8_SML_COL: [i64; 8] = + first_row_to_first_col(&MATRIX_CIRC_MDS_8_SML_ROW); + SmallConvolveGoldilocks::apply( + input, + MATRIX_CIRC_MDS_8_SML_COL, + SmallConvolveGoldilocks::conv8, + ) + } + + fn permute_mut(&self, input: &mut [Goldilocks; 8]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixGoldilocks {} + +pub(crate) const MATRIX_CIRC_MDS_12_SML_ROW: [i64; 12] = [1, 1, 2, 1, 8, 9, 10, 7, 5, 9, 4, 10]; + +impl Permutation<[Goldilocks; 12]> for MdsMatrixGoldilocks { + fn permute(&self, input: [Goldilocks; 12]) -> [Goldilocks; 12] { + const MATRIX_CIRC_MDS_12_SML_COL: [i64; 12] = + first_row_to_first_col(&MATRIX_CIRC_MDS_12_SML_ROW); + SmallConvolveGoldilocks::apply( + input, + MATRIX_CIRC_MDS_12_SML_COL, + SmallConvolveGoldilocks::conv12, + ) + } + + fn permute_mut(&self, input: &mut [Goldilocks; 12]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixGoldilocks {} + +pub(crate) const MATRIX_CIRC_MDS_16_SML_ROW: [i64; 16] = + [1, 1, 51, 1, 11, 17, 2, 1, 101, 63, 15, 2, 67, 22, 13, 3]; + +impl Permutation<[Goldilocks; 16]> for MdsMatrixGoldilocks { + fn permute(&self, input: [Goldilocks; 16]) -> [Goldilocks; 16] { + const MATRIX_CIRC_MDS_16_SML_COL: [i64; 16] = + first_row_to_first_col(&MATRIX_CIRC_MDS_16_SML_ROW); + SmallConvolveGoldilocks::apply( + input, + MATRIX_CIRC_MDS_16_SML_COL, + SmallConvolveGoldilocks::conv16, + ) + } + + fn permute_mut(&self, input: &mut [Goldilocks; 16]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixGoldilocks {} + +#[rustfmt::skip] +pub(crate) const MATRIX_CIRC_MDS_24_GOLDILOCKS: [u64; 24] = [ + 0x5FFFFFFFA00AAAAB, 0x24021AB75BBFE656, 0x7BE9082D73B06DF5, 0x2282863E9C3A5A62, + 0xE0071C70DFFC71C8, 0x796CB65AB42A1A63, 0xDBBBBFFADFFDDDE3, 0x23B88EE217C5C9C2, + 0x20030C309FFB6DB7, 0x23C3C64763BE1E1D, 0x0F93B7C9CC51362E, 0xC697A1094BD0850A, + 0xDFFFFFFF1FFC71C8, 0xC15A4FD614950302, 0xC41D883A4C4DEDF2, 0x187879BC23C46462, + 0x5FFCF3CEDFFE79E8, 0x1C41DF105B82398E, 0x64444003DFFDDDDA, 0x76EDDBB6F7E51F95, + 0x1FF8E38E20038E39, 0x214139BD5C40A09D, 0x3065B7CCF3B3B621, 0x23B6F4622485CEDC, +]; + +impl Permutation<[Goldilocks; 24]> for MdsMatrixGoldilocks { + fn permute(&self, input: [Goldilocks; 24]) -> [Goldilocks; 24] { + apply_circulant(&MATRIX_CIRC_MDS_24_GOLDILOCKS, input) + } + + fn permute_mut(&self, input: &mut [Goldilocks; 24]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixGoldilocks {} + +#[rustfmt::skip] +const MATRIX_CIRC_MDS_32_GOLDILOCKS: [u64; 32] = [ + 0x0800000000000000, 0x69249248B4924925, 0x3ABD5EAF15EAF57B, 0x294A5294739CE73A, + 0x59E2D2CEB4B3C5A6, 0x087FBE00FF7C0220, 0xA554AA94A554AA96, 0xF00080FEFFDF8005, + 0x64CCCCCC6666699A, 0x5B13AD8973B139D9, 0xAD4A55ACA54AD5AA, 0xDA496DA3B492DB8A, + 0x4AD696955A5694B5, 0xA4A6B29A25B496D3, 0xA74EA162162BD3A9, 0xC698B3A5662CE98C, + 0xA7FFFFFF55555556, 0x4AAAAAAA5AAAAAAB, 0xB047DC113DC11F71, 0x8BA2E8B99B26C9B3, + 0xD259696C5A5B4D2E, 0xA7D540AA557EA9F6, 0x8B6E922D26DB249C, 0xFAAA805455602AAD, + 0xCB33333266666334, 0xD13B17619B13B277, 0x45B26D9326E9374A, 0x52AB552A5AA9556B, + 0x68ED2D2DB4B87697, 0x8B264C98A74E9D3B, 0x09EC23D83D847B09, 0x2C9A4D26669349A5, +]; + +impl Permutation<[Goldilocks; 32]> for MdsMatrixGoldilocks { + fn permute(&self, input: [Goldilocks; 32]) -> [Goldilocks; 32] { + const ENTRIES: [u64; 32] = first_row_to_first_col(&MATRIX_CIRC_MDS_32_GOLDILOCKS); + apply_circulant_fft(FFT_ALGO, ENTRIES, &input) + } + + fn permute_mut(&self, input: &mut [Goldilocks; 32]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixGoldilocks {} + +#[rustfmt::skip] +const MATRIX_CIRC_MDS_64_GOLDILOCKS: [u64; 64] = [ + 0x07FFFFFFFC000000, 0xFBFFFFFF04000001, 0x436DB6DB25B6DB6E, 0x4AAAAAAA5AAAAAAB, + 0x45B2D96C6D96CB66, 0x3BC7BC7B87BC7BC8, 0x6318C63125294A53, 0xCB3672CCCD9CB368, + 0xB43CB5A12D68796C, 0xFBFBFBFAFBFBFBFD, 0x883DBF107B7E2210, 0x8A7689B59B629DA3, + 0xF7FEFFDF00000001, 0x7B7C83BBC83BC47C, 0xEFF0410107EF7F83, 0x2CD8B3629CB272CA, + 0x9800019900CCCE67, 0xFBFFFBFF07FFFC01, 0x94EC4A758C4EC628, 0xDA5A5B4A6D2D2E1F, + 0xFFEFC080FC003FFF, 0xBC387BC2C783BC79, 0xB492DB686D24B6F3, 0x1DB6925B4B6E2477, + 0x7801E0EF87BFFF10, 0xFC0803FAFBFC0409, 0x3780FE03C086F21C, 0x8B749B224DB22D94, + 0x32648B36B76E9923, 0x3BC3C3C387C3C3C4, 0x79AF286B4FCA1AF3, 0x9E2762758B627628, + 0x52AAAAAA56AAAAAB, 0xFBFFFFFEFC000001, 0xF7FFFFFF08000001, 0x2CCCCCCC9CCCCCCD, + 0xCF286BC946BCA1B0, 0xBC483B7B883B7C49, 0xD9364D9287C1F07D, 0xAD5A94A8A95AD5AA, + 0xFF871002C400F1E1, 0xFC03FC02FC03FC05, 0xD29495A4D6D4B4A6, 0x6C926DD1DD24DB65, + 0x1EDC247B4DB64937, 0x7C7B843B47BC437D, 0xA55A95AAAD5AD52C, 0x4A96D5A45AD694A6, + 0xFE6664CBCD999801, 0xFC0003FF08000401, 0x1EC4F09D64EC4D8A, 0x9E1E1D2C8B4B4A5B, + 0xD9270937709B64DC, 0x3BB77C4448843B78, 0xFFFFFFDF03FF0021, 0x59D8761D2D8A6299, + 0xC3496878A5E5A4B5, 0xFBF80402FC0403F9, 0x5ECD9B360E142851, 0x6D925D6429D64976, + 0xA8AE615C19CC2B99, 0xBC44444388444445, 0xDFE3F1F81CFC7E40, 0xDA4924916D24924A, +]; + +impl Permutation<[Goldilocks; 64]> for MdsMatrixGoldilocks { + fn permute(&self, input: [Goldilocks; 64]) -> [Goldilocks; 64] { + const ENTRIES: [u64; 64] = first_row_to_first_col(&MATRIX_CIRC_MDS_64_GOLDILOCKS); + apply_circulant_fft(FFT_ALGO, ENTRIES, &input) + } + + fn permute_mut(&self, input: &mut [Goldilocks; 64]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixGoldilocks {} + +#[rustfmt::skip] +const MATRIX_CIRC_MDS_68_GOLDILOCKS: [u64; 68] = [ + 0x03C3C3C3FC3C3C3C, 0x6799AFC54A69BC7D, 0xDA8C2C496A74B03B, 0x1E641D7AB35ED229, + 0x9239DA20DA3A2686, 0x6E23D41459EBA8C4, 0x7BC412896E2A6B3A, 0x9082059089ABD4FC, + 0x94A16FA8B0339EEE, 0x85650EC91BB519C9, 0x1600745267E94DE1, 0xFFFD8405C82020AB, + 0x21BDE80429DCED6A, 0x8ACE123AF754E343, 0xFFC7211605D2BDAE, 0xC21187AE15900F4D, + 0x9C4A889708568DC6, 0x65A5A726B5758D8E, 0x949DB90B9AC0D11A, 0x23B6CF7C368BBE52, + 0xD5128DDF59CB5A35, 0xF53BCC5BDADF3A0A, 0xBA7C5112F4BAB1CD, 0x4B93989C5B729351, + 0x6534B7E50E4AD1CB, 0x640061B54C918405, 0x0E66E1F90D2C9311, 0x31C8649B0FE7557F, + 0x0E9190D165F4A8F3, 0x52DF336BB708F919, 0x3C0F6697F14065A5, 0xBE8190942EC50031, + 0x60038E9ACC701118, 0x73F105909A55A88B, 0xFEBEBEBDABEBEBED, 0x6F52163A64B03467, + 0xFBAE131F23A12F56, 0x1950493BC70D0676, 0x2886550DB5A1BBBF, 0x15B003D6E58181D7, + 0x3A4E7D9D44F100F8, 0x6CC3AB896025E6A0, 0x7E23E68456F825E5, 0x079CDD570B591A16, + 0xEC15A830C3D2CCD1, 0xCF4C722D2C0F8A0E, 0xC1BB6F5591B59A26, 0xB63A5931A607BDE0, + 0x43A0AD0B71040187, 0x7E4B492889D1CEE0, 0x734153F3F0C31C5B, 0x98D8D756B2725A5B, + 0x5589D20D74BA00B8, 0xB2DF58DF0A312509, 0xFABC378690D64A3A, 0x700640AFC244B695, + 0xFFA652236547F3BE, 0x2B9CA498A001D059, 0x7DACA6F16787D5DE, 0xAAAD774FAC613EA3, + 0xA88583816975CD56, 0x78B71DC516FF49CA, 0xC7BF095DF702FFA6, 0x78A60B3F971783B3, + 0xCB158EF40BC75CAC, 0xA97E818DBC152B4C, 0x9FC8339D415C3999, 0x006A88C0A0D8201C, +]; + +impl Permutation<[Goldilocks; 68]> for MdsMatrixGoldilocks { + fn permute(&self, input: [Goldilocks; 68]) -> [Goldilocks; 68] { + apply_circulant(&MATRIX_CIRC_MDS_68_GOLDILOCKS, input) + } + + fn permute_mut(&self, input: &mut [Goldilocks; 68]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixGoldilocks {} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + + use super::{Goldilocks, MdsMatrixGoldilocks}; + + #[test] + fn goldilocks8() { + let input: [Goldilocks; 8] = Goldilocks::new_array([ + 2434589605738284713, + 4817685620989478889, + 13397079175138649456, + 11944520631108649751, + 1033251468644039632, + 3092099742268329866, + 7160548811622790454, + 9959569614427134344, + ]); + + let output = MdsMatrixGoldilocks.permute(input); + + let expected: [Goldilocks; 8] = Goldilocks::new_array([ + 16726687146516531007, + 14721040752765534861, + 15566838577475948790, + 9095485010737904250, + 11353934351835864222, + 11056556168691087893, + 4199602889124860181, + 315643510993921470, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn goldilocks12() { + let input: [Goldilocks; 12] = Goldilocks::new_array([ + 14847187883725400244, + 969392934980971521, + 6996647758016470432, + 4674844440624672154, + 264841656685969785, + 1246852265697711623, + 18223868478428473484, + 12122736699239070772, + 11263701854732819430, + 12739925508864285577, + 11648637570857932167, + 14090978315217600393, + ]); + + let output = MdsMatrixGoldilocks.permute(input); + + let expected: [Goldilocks; 12] = Goldilocks::new_array([ + 9322351889214742299, + 8700136572060418355, + 4881757876459003977, + 9899544690241851021, + 480548822895830465, + 5445915149371405525, + 14955363277757168581, + 6672733082273363313, + 190938676320003294, + 1613225933948270736, + 3549006224849989171, + 12169032187873197425, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn goldilocks16() { + let input: [Goldilocks; 16] = Goldilocks::new_array([ + 13216135600341032847, + 15626390207663319651, + 2052474569300149934, + 4375663431730581786, + 16596827905941257435, + 10019626608444427271, + 7831946179065963230, + 17104499871144693506, + 9021930732511690478, + 6899419210615882449, + 8131182521761419514, + 432489675596019804, + 8508050013409958723, + 14134506582804571789, + 13283546413390931641, + 14711125975653831032, + ]); + + let output = MdsMatrixGoldilocks.permute(input); + + let expected: [Goldilocks; 16] = Goldilocks::new_array([ + 9484392671298797780, + 149770626972189150, + 12125722600598304117, + 15945232149672903756, + 13199929870021500593, + 18443980893262804946, + 317150800081307627, + 16910019239751125049, + 1996802739033818490, + 11668458913264624237, + 11078800762167869397, + 13758408662406282356, + 11119677412113674380, + 7344117715971661026, + 4202436890275702092, + 681166793519210465, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn goldilocks24() { + let input: [Goldilocks; 24] = Goldilocks::new_array([ + 11426771245122339662, + 5975488243963332229, + 11441424994503305651, + 5755561333702259678, + 7295454168648181339, + 16724279929816174064, + 32359231037136391, + 3713621595270370753, + 8421765959140936778, + 12370571593326246544, + 8633733294559731287, + 12765436832373161027, + 15606692828890413034, + 8068160018166226874, + 10719661629577139538, + 13036735610140127982, + 10213543772818211674, + 8041886705706266368, + 12022983417703446028, + 4179370708601587579, + 11125302089484330465, + 9904943018174649533, + 16178194376951442671, + 1545799842160818502, + ]); + + let output = MdsMatrixGoldilocks.permute(input); + + let expected: [Goldilocks; 24] = Goldilocks::new_array([ + 18431075688485197060, + 14823984346528185622, + 7262979358411339215, + 14816911393874702213, + 6721523710303409972, + 10829861327716364029, + 2456948878733883601, + 11088379938350287658, + 3820735023521527858, + 9062288923770492958, + 5159244568306327366, + 1401669669887165869, + 11908734248351870182, + 10640195377186320543, + 6552733980894593378, + 17103376282032495459, + 5204287788603805758, + 17783185518697631139, + 9006863878586007300, + 11122535637762904803, + 5271621316102699962, + 9734499541452484536, + 11778274360927642637, + 3217831681350496533, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn goldilocks32() { + let input: [Goldilocks; 32] = Goldilocks::new_array([ + 8401806579759049284, + 14709608922272986544, + 8130995604641968478, + 7833133203357642391, + 10700492548100684406, + 3941105252506602047, + 8122370916776133262, + 15079919378435648206, + 8774521769784086994, + 16794844316583392853, + 9356562741425567167, + 13317198313361936216, + 7187680218428599522, + 16525662096158660997, + 540453741156061014, + 16543585577270698663, + 3802215918136285729, + 11389297895303247764, + 5133769394766075512, + 1057795099426170863, + 18037861421172314665, + 17632255188776359310, + 17616515088477043142, + 13307921676744533876, + 17602277262015191215, + 15819040654617566738, + 11961318546000835928, + 15593174310433874065, + 9152657050882549004, + 4801868480369948110, + 13202076339494141066, + 726396847460932316, + ]); + + let output = MdsMatrixGoldilocks.permute(input); + + let expected: [Goldilocks; 32] = Goldilocks::new_array([ + 1179701925859507209, + 5543239597787055637, + 5978278622530964070, + 3622388166841103287, + 11383243182536830899, + 14719109850604985734, + 17672601866826623850, + 4879627080283827596, + 7556887460241466109, + 9548493506061808122, + 13980851986825291174, + 2029844508485082398, + 10375517623784134775, + 13067093881736606569, + 6446569064196467795, + 15375603814779462714, + 11307946648742033371, + 1593906954637160608, + 5776169226282316678, + 8167048017892669861, + 3954052226208277367, + 9346878497567392707, + 5570872870988220142, + 10792661164389799960, + 17494962593174487938, + 7080549557843445752, + 14059834522311268132, + 17747288366997773235, + 17158122400620315305, + 6816598002359267850, + 12363049840026116993, + 13313901185845854868, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn goldilocks64() { + let input: [Goldilocks; 64] = Goldilocks::new_array([ + 3471075506106776899, + 4817046918282259009, + 3480368692354016145, + 18110937755057600106, + 3130862083451221140, + 15376650156021437015, + 7997596749112997445, + 7742916918728590149, + 421644639408377358, + 2491271421424548020, + 1940196613872160755, + 7152053147988203177, + 13697425352450853423, + 15877844788345672674, + 17787098720906653510, + 6857627524724866519, + 8541180216786820396, + 10769715704553877654, + 9265712399189924160, + 10220120296438955872, + 18201417281995610945, + 6749698931189855822, + 13700000989116811950, + 13205437213697578097, + 10514342943989454609, + 9926015350795325725, + 2289808224483690257, + 12598806357998460973, + 14393945610969324307, + 4744625557965362093, + 2270701163031951561, + 2927942398784334090, + 5250916386894733430, + 4030189910566345872, + 4953663590324639075, + 1241519685782896035, + 8681312160951359069, + 8236353015475387411, + 4972690458759871996, + 1396852754187463352, + 17512022752774329733, + 14009268822557836700, + 1346736409027879377, + 7609463340861239931, + 10701512803758419515, + 5067199073587389986, + 5030018986055211116, + 17692625804700013551, + 9992938630604785132, + 15350127009762647067, + 10247405821493235386, + 15172888833500531069, + 14657693742399622179, + 7391511805216089127, + 2035742693690795598, + 4047216012963057952, + 12602085105939403203, + 16985723692990258059, + 12141021186082151434, + 3174646196626212833, + 16484520987666295947, + 10579720164460442970, + 9596917135039689219, + 13761818390665814258, + ]); + + let output = MdsMatrixGoldilocks.permute(input); + + let expected: [Goldilocks; 64] = Goldilocks::new_array([ + 9158798369861934356, + 9224859686427886689, + 16948559910286211274, + 15765762765140902574, + 16202509467561200764, + 1911749439284071529, + 4607026757869726805, + 8473827004973131317, + 13716800466551879373, + 6670177022201597800, + 17416833238376299449, + 14953676562252669578, + 5828107070718286209, + 17980287408679531241, + 2220583438808757820, + 14564318040622847100, + 3950519594558514416, + 12164610170526828198, + 457385640833960098, + 14068973922383216628, + 9614382247226943793, + 3932756878771319222, + 12728498054939249570, + 9435109056498897661, + 7283114805836756402, + 1720178259138435097, + 11496602000538177285, + 7736206812858942065, + 14289784438950643645, + 12052665489155550962, + 12918409840610303255, + 5224324424989208352, + 7826309014606327907, + 11657314889847733528, + 13899641072303006348, + 7501780959676548477, + 1064261716045449147, + 1487682458939665452, + 10894217148983862136, + 12785338167343566981, + 8043323074629160032, + 10852328074701301213, + 15029722608724150267, + 2611937278660861263, + 13995790409949796943, + 7103138700054564899, + 12756778219044204581, + 4147399997707606088, + 11930966590061754579, + 16708700985380478903, + 2370160521342035603, + 14893791582608133454, + 15313288276425450946, + 16224601303711716386, + 4488931442519177087, + 7443169181907410918, + 12381442753785370161, + 16366345507676500076, + 8097905256807642731, + 8504207502183388457, + 11400931328719780407, + 10879211614969476303, + 7265889003783205111, + 7322738272300165489, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn goldilocks68() { + let input: [Goldilocks; 68] = Goldilocks::new_array([ + 16450563043143968653, + 3688080826640678185, + 133253417037384537, + 17501558583799613353, + 14920674569425704293, + 5030578721963251055, + 9795600398273758687, + 402012644192671817, + 10657312189068414445, + 9508835336085746575, + 16081669758721272608, + 2072823794278273547, + 16831381326702573736, + 11381683312293543190, + 5679539322738625588, + 9346499485038639332, + 15554202803455984983, + 18373955571490331663, + 11323895584334729789, + 16834542679468148445, + 14751528164286075953, + 3755158780970327991, + 12622814707645103582, + 10329238611694882547, + 7642766530280843057, + 4876120096290984742, + 412912224820604426, + 9118233770240274553, + 3626520971021993076, + 10841049054903806738, + 18205546599950141835, + 7198482606375262809, + 17183313930831625294, + 10181033256431249241, + 1061211413812819905, + 3980261141891682525, + 5674176959446948353, + 6062696542969845681, + 3383081006315025715, + 8812665902421024067, + 3093645099818246186, + 16178737149039707082, + 8204245222345541411, + 11072582337937050490, + 17969785901925882398, + 4670890092981706609, + 12537558683977529426, + 12084598516323376868, + 16293685096019175644, + 10117612240421467846, + 17873102395739074620, + 11220493906741851877, + 4632957003022201019, + 12934229307704669322, + 2152792796882257594, + 12521131928134126701, + 17472006670677761650, + 4560570065837283016, + 6315543803073912887, + 4098689719955359793, + 1784883877365258237, + 6837590090927294950, + 2391417016765166652, + 16389291664603960875, + 12285946887702044436, + 7231705445010258971, + 12976071926225281356, + 8829402645443096358, + ]); + + let output = MdsMatrixGoldilocks.permute(input); + + let expected: [Goldilocks; 68] = Goldilocks::new_array([ + 4984914285749049383, + 10397959071664799177, + 3331616814639908945, + 4252459885611162121, + 5517786723806029201, + 1826620401370703815, + 8257849352373689773, + 1722805960790112693, + 17654983138917187833, + 7542660006721409612, + 1970182718241277021, + 12865815507550811641, + 17507096607056552658, + 7988714902687660369, + 150082662759625574, + 17329095993317360383, + 965880604543562997, + 2820931239306841741, + 1980667983336380501, + 3781794112174728826, + 7323192150179872391, + 12243426826276589932, + 315076483410634889, + 3221894784246078707, + 3515955216509190252, + 964376148920419876, + 7679719864273407732, + 2516714701741920303, + 4837221266652621366, + 15301563603415983061, + 10380321314559647625, + 3023678426639670063, + 12020917879204725519, + 10595808165609787680, + 14199186729378048831, + 4520610719509879248, + 9983949546821718635, + 5066092593424854949, + 13843503196305181790, + 14296362815835302652, + 6766348697864530153, + 13804582129741554661, + 8032169955336281598, + 5198513488794721460, + 10613667919514788349, + 7948289550930596506, + 14118391408956101449, + 4356952068887595371, + 709878153008378134, + 17168579964784489802, + 17840495726541494819, + 2710471020841761312, + 9950159372116756450, + 3909574932971200058, + 2430964021804554670, + 6035162446515244642, + 14656543530572478095, + 1539013407173403800, + 4150113154618904744, + 4904646199269229662, + 17257014030727492672, + 3791823431764085889, + 13680668409434600948, + 12367427987617118934, + 12462908457168650050, + 10891613749697412017, + 6867760775372053830, + 12474954319307005079, + ]); + + assert_eq!(output, expected); + } +} diff --git a/CoqOfRust/plonky3/goldilocks/src/mds.v b/CoqOfRust/plonky3/goldilocks/src/mds.v new file mode 100644 index 000000000..a1899f7c1 --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/mds.v @@ -0,0 +1,1740 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module mds. + (* StructTuple + { + name := "MdsMatrixGoldilocks"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_clone_Clone_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_goldilocks::mds::MdsMatrixGoldilocks" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Module Impl_core_fmt_Debug_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "MdsMatrixGoldilocks" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Module Impl_core_default_Default_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic (Value.StructTuple "p3_goldilocks::mds::MdsMatrixGoldilocks" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + (* StructTuple + { + name := "SmallConvolveGoldilocks"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_fmt_Debug_for_p3_goldilocks_mds_SmallConvolveGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::SmallConvolveGoldilocks". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "SmallConvolveGoldilocks" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_goldilocks_mds_SmallConvolveGoldilocks. + + Module Impl_p3_mds_karatsuba_convolution_Convolve_p3_goldilocks_goldilocks_Goldilocks_i128_i64_i128_for_p3_goldilocks_mds_SmallConvolveGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::SmallConvolveGoldilocks". + + (* + fn read(input: Goldilocks) -> i128 { + input.value as i128 + } + *) + Definition read (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.cast + (Ty.path "i128") + (M.read (| + M.SubPointer.get_struct_record_field (| + input, + "p3_goldilocks::goldilocks::Goldilocks", + "value" + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn parity_dot(u: [i128; N], v: [i64; N]) -> i128 { + let mut s = 0i128; + for i in 0..N { + s += u[i] * v[i] as i128; + } + s + } + *) + Definition parity_dot (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [ u; v ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + let v := M.alloc (| v |) in + M.read (| + let~ s : Ty.apply (Ty.path "*") [] [ Ty.path "i128" ] := + M.alloc (| Value.Integer IntegerKind.I128 0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := s in + M.write (| + β, + M.call_closure (| + Ty.path "i128", + BinOp.Wrap.add, + [ + M.read (| β |); + M.call_closure (| + Ty.path "i128", + BinOp.Wrap.mul, + [ + M.read (| + M.SubPointer.get_array_field (| + u, + M.read (| i |) + |) + |); + M.cast + (Ty.path "i128") + (M.read (| + M.SubPointer.get_array_field (| + v, + M.read (| i |) + |) + |)) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + s + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn reduce(z: i128) -> Goldilocks { + debug_assert!(z >= 0); + reduce128(z as u128) + } + *) + Definition reduce (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ z ] => + ltac:(M.monadic + (let z := M.alloc (| z |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| z |); Value.Integer IntegerKind.I128 0 ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: z >= 0" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + M.get_function (| "p3_goldilocks::goldilocks::reduce128", [], [] |), + [ M.cast (Ty.path "u128") (M.read (| z |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_mds::karatsuba_convolution::Convolve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "i128"; + Ty.path "i64"; + Ty.path "i128" + ] + Self + (* Instance *) + [ + ("read", InstanceField.Method read); + ("parity_dot", InstanceField.Method parity_dot); + ("reduce", InstanceField.Method reduce) + ]. + End Impl_p3_mds_karatsuba_convolution_Convolve_p3_goldilocks_goldilocks_Goldilocks_i128_i64_i128_for_p3_goldilocks_mds_SmallConvolveGoldilocks. + + Definition value_FFT_ALGO (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.StructTuple "p3_dft::radix_2_bowers::Radix2Bowers" [] |))). + + Global Instance Instance_IsConstant_value_FFT_ALGO : + M.IsFunction.C "p3_goldilocks::mds::FFT_ALGO" value_FFT_ALGO. + Admitted. + Global Typeclasses Opaque value_FFT_ALGO. + + Definition value_MATRIX_CIRC_MDS_8_SML_ROW + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 7; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 3; + Value.Integer IntegerKind.I64 8; + Value.Integer IntegerKind.I64 8; + Value.Integer IntegerKind.I64 3; + Value.Integer IntegerKind.I64 4; + Value.Integer IntegerKind.I64 9 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_8_SML_ROW : + M.IsFunction.C "p3_goldilocks::mds::MATRIX_CIRC_MDS_8_SML_ROW" value_MATRIX_CIRC_MDS_8_SML_ROW. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_8_SML_ROW. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_8_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + (* + fn permute(&self, input: [Goldilocks; 8]) -> [Goldilocks; 8] { + const MATRIX_CIRC_MDS_8_SML_COL: [i64; 8] = + first_row_to_first_col(&MATRIX_CIRC_MDS_8_SML_ROW); + SmallConvolveGoldilocks::apply( + input, + MATRIX_CIRC_MDS_8_SML_COL, + SmallConvolveGoldilocks::conv8, + ) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_goldilocks::mds::SmallConvolveGoldilocks", + [], + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "i128"; + Ty.path "i64"; + Ty.path "i128" + ], + "apply", + [ Value.Integer IntegerKind.Usize 8 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "i128" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "i128" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_goldilocks::mds::permute::MATRIX_CIRC_MDS_8_SML_COL", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_goldilocks::mds::SmallConvolveGoldilocks", + [], + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "i128"; + Ty.path "i64"; + Ty.path "i128" + ], + "conv8", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Goldilocks; 8]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_8_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Module Impl_p3_mds_MdsPermutation_Usize_8_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 8 ] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_8_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Definition value_MATRIX_CIRC_MDS_12_SML_ROW + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 2; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 8; + Value.Integer IntegerKind.I64 9; + Value.Integer IntegerKind.I64 10; + Value.Integer IntegerKind.I64 7; + Value.Integer IntegerKind.I64 5; + Value.Integer IntegerKind.I64 9; + Value.Integer IntegerKind.I64 4; + Value.Integer IntegerKind.I64 10 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_12_SML_ROW : + M.IsFunction.C + "p3_goldilocks::mds::MATRIX_CIRC_MDS_12_SML_ROW" + value_MATRIX_CIRC_MDS_12_SML_ROW. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_12_SML_ROW. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_12_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + (* + fn permute(&self, input: [Goldilocks; 12]) -> [Goldilocks; 12] { + const MATRIX_CIRC_MDS_12_SML_COL: [i64; 12] = + first_row_to_first_col(&MATRIX_CIRC_MDS_12_SML_ROW); + SmallConvolveGoldilocks::apply( + input, + MATRIX_CIRC_MDS_12_SML_COL, + SmallConvolveGoldilocks::conv12, + ) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_goldilocks::mds::SmallConvolveGoldilocks", + [], + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "i128"; + Ty.path "i64"; + Ty.path "i128" + ], + "apply", + [ Value.Integer IntegerKind.Usize 12 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "i128" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "i128" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_goldilocks::mds::permute::MATRIX_CIRC_MDS_12_SML_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_goldilocks::mds::SmallConvolveGoldilocks", + [], + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "i128"; + Ty.path "i64"; + Ty.path "i128" + ], + "conv12", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Goldilocks; 12]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_12_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Module Impl_p3_mds_MdsPermutation_Usize_12_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 12 ] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_12_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Definition value_MATRIX_CIRC_MDS_16_SML_ROW + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 51; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 11; + Value.Integer IntegerKind.I64 17; + Value.Integer IntegerKind.I64 2; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 101; + Value.Integer IntegerKind.I64 63; + Value.Integer IntegerKind.I64 15; + Value.Integer IntegerKind.I64 2; + Value.Integer IntegerKind.I64 67; + Value.Integer IntegerKind.I64 22; + Value.Integer IntegerKind.I64 13; + Value.Integer IntegerKind.I64 3 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_16_SML_ROW : + M.IsFunction.C + "p3_goldilocks::mds::MATRIX_CIRC_MDS_16_SML_ROW" + value_MATRIX_CIRC_MDS_16_SML_ROW. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_16_SML_ROW. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_16_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + (* + fn permute(&self, input: [Goldilocks; 16]) -> [Goldilocks; 16] { + const MATRIX_CIRC_MDS_16_SML_COL: [i64; 16] = + first_row_to_first_col(&MATRIX_CIRC_MDS_16_SML_ROW); + SmallConvolveGoldilocks::apply( + input, + MATRIX_CIRC_MDS_16_SML_COL, + SmallConvolveGoldilocks::conv16, + ) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_goldilocks::mds::SmallConvolveGoldilocks", + [], + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "i128"; + Ty.path "i64"; + Ty.path "i128" + ], + "apply", + [ Value.Integer IntegerKind.Usize 16 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "i128" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "i128" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_goldilocks::mds::permute::MATRIX_CIRC_MDS_16_SML_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_goldilocks::mds::SmallConvolveGoldilocks", + [], + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "i128"; + Ty.path "i64"; + Ty.path "i128" + ], + "conv16", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Goldilocks; 16]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_16_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Module Impl_p3_mds_MdsPermutation_Usize_16_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 16 ] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_16_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Definition value_MATRIX_CIRC_MDS_24_GOLDILOCKS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U64 6917529026031168171; + Value.Integer IntegerKind.U64 2594665710139467350; + Value.Integer IntegerKind.U64 8928676727546211829; + Value.Integer IntegerKind.U64 2486697547729099362; + Value.Integer IntegerKind.U64 16142902660452610504; + Value.Integer IntegerKind.U64 8749568676760001123; + Value.Integer IntegerKind.U64 15833459999171796451; + Value.Integer IntegerKind.U64 2573964288754829762; + Value.Integer IntegerKind.U64 2306700837125844407; + Value.Integer IntegerKind.U64 2577121421704437277; + Value.Integer IntegerKind.U64 1122442809489569326; + Value.Integer IntegerKind.U64 14310083402291774730; + Value.Integer IntegerKind.U64 16140901060737528264; + Value.Integer IntegerKind.U64 13932536178110956290; + Value.Integer IntegerKind.U64 14131600989728140786; + Value.Integer IntegerKind.U64 1763293103076435042; + Value.Integer IntegerKind.U64 6916671197581048296; + Value.Integer IntegerKind.U64 2036153767895906702; + Value.Integer IntegerKind.U64 7224970087596154330; + Value.Integer IntegerKind.U64 8569747244845440917; + Value.Integer IntegerKind.U64 2303841408961973817; + Value.Integer IntegerKind.U64 2396259962197155997; + Value.Integer IntegerKind.U64 3487395577358169633; + Value.Integer IntegerKind.U64 2573512939445538524 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_24_GOLDILOCKS : + M.IsFunction.C + "p3_goldilocks::mds::MATRIX_CIRC_MDS_24_GOLDILOCKS" + value_MATRIX_CIRC_MDS_24_GOLDILOCKS. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_24_GOLDILOCKS. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_24_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + (* + fn permute(&self, input: [Goldilocks; 24]) -> [Goldilocks; 24] { + apply_circulant(&MATRIX_CIRC_MDS_24_GOLDILOCKS, input) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_function (| + "p3_mds::util::apply_circulant", + [ Value.Integer IntegerKind.Usize 24 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_goldilocks::mds::MATRIX_CIRC_MDS_24_GOLDILOCKS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u64" ] + |) + |) + |) + |); + M.read (| input |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Goldilocks; 24]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_24_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Module Impl_p3_mds_MdsPermutation_Usize_24_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 24 ] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_24_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Definition value_MATRIX_CIRC_MDS_32_GOLDILOCKS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U64 576460752303423488; + Value.Integer IntegerKind.U64 7576341314108803365; + Value.Integer IntegerKind.U64 4232643330878141819; + Value.Integer IntegerKind.U64 2975281301379934010; + Value.Integer IntegerKind.U64 6476970999348970918; + Value.Integer IntegerKind.U64 612416985841271328; + Value.Integer IntegerKind.U64 11913334469707475606; + Value.Integer IntegerKind.U64 17293964401805590533; + Value.Integer IntegerKind.U64 7263405477305149850; + Value.Integer IntegerKind.U64 6562779887872063961; + Value.Integer IntegerKind.U64 12486887116834002346; + Value.Integer IntegerKind.U64 15729223723444788106; + Value.Integer IntegerKind.U64 5392663172032664757; + Value.Integer IntegerKind.U64 11864366643481450195; + Value.Integer IntegerKind.U64 12055750695168234409; + Value.Integer IntegerKind.U64 14310385338934946188; + Value.Integer IntegerKind.U64 12105675795508581718; + Value.Integer IntegerKind.U64 5380300353489775275; + Value.Integer IntegerKind.U64 12702363240630394737; + Value.Integer IntegerKind.U64 10061860401368713651; + Value.Integer IntegerKind.U64 15157261934985432366; + Value.Integer IntegerKind.U64 12093643474696317430; + Value.Integer IntegerKind.U64 10047128541333234844; + Value.Integer IntegerKind.U64 18062390355220769453; + Value.Integer IntegerKind.U64 14642103105070981940; + Value.Integer IntegerKind.U64 15076669885533893239; + Value.Integer IntegerKind.U64 5022197013251962698; + Value.Integer IntegerKind.U64 5956948572525647211; + Value.Integer IntegerKind.U64 7560749023753696919; + Value.Integer IntegerKind.U64 10026785838912675131; + Value.Integer IntegerKind.U64 714985852497066761; + Value.Integer IntegerKind.U64 3213966111407294885 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_32_GOLDILOCKS : + M.IsFunction.C + "p3_goldilocks::mds::MATRIX_CIRC_MDS_32_GOLDILOCKS" + value_MATRIX_CIRC_MDS_32_GOLDILOCKS. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_32_GOLDILOCKS. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_32_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + (* + fn permute(&self, input: [Goldilocks; 32]) -> [Goldilocks; 32] { + const ENTRIES: [u64; 32] = first_row_to_first_col(&MATRIX_CIRC_MDS_32_GOLDILOCKS); + apply_circulant_fft(FFT_ALGO, ENTRIES, &input) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_function (| + "p3_mds::util::apply_circulant_fft", + [ Value.Integer IntegerKind.Usize 32 ], + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "p3_dft::radix_2_bowers::Radix2Bowers" + ] + |), + [ + M.read (| + get_constant (| + "p3_goldilocks::mds::FFT_ALGO", + Ty.path "p3_dft::radix_2_bowers::Radix2Bowers" + |) + |); + M.read (| + get_constant (| + "p3_goldilocks::mds::permute::ENTRIES", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u64" ] + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.borrow (| Pointer.Kind.Ref, input |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Goldilocks; 32]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_32_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Module Impl_p3_mds_MdsPermutation_Usize_32_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 32 ] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_32_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Definition value_MATRIX_CIRC_MDS_64_GOLDILOCKS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U64 576460752236314624; + Value.Integer IntegerKind.U64 18158513693329981441; + Value.Integer IntegerKind.U64 4858740625349466990; + Value.Integer IntegerKind.U64 5380300353489775275; + Value.Integer IntegerKind.U64 5022315594189818726; + Value.Integer IntegerKind.U64 4307618807347444680; + Value.Integer IntegerKind.U64 7140675123575081555; + Value.Integer IntegerKind.U64 14643017462390240104; + Value.Integer IntegerKind.U64 12987455129285851500; + Value.Integer IntegerKind.U64 18157383378062277629; + Value.Integer IntegerKind.U64 9817212840249795088; + Value.Integer IntegerKind.U64 9977313437574929827; + Value.Integer IntegerKind.U64 17870001704695496705; + Value.Integer IntegerKind.U64 8898131806318740604; + Value.Integer IntegerKind.U64 17289390442159243139; + Value.Integer IntegerKind.U64 3231529968755438282; + Value.Integer IntegerKind.U64 10952756050420092519; + Value.Integer IntegerKind.U64 18158509295350578177; + Value.Integer IntegerKind.U64 10731033880842651176; + Value.Integer IntegerKind.U64 15733988623389634079; + Value.Integer IntegerKind.U64 18442170659321692159; + Value.Integer IntegerKind.U64 13562726354327420025; + Value.Integer IntegerKind.U64 13011703514980988659; + Value.Integer IntegerKind.U64 2141059593666438263; + Value.Integer IntegerKind.U64 8647440078907375376; + Value.Integer IntegerKind.U64 18160769873875829769; + Value.Integer IntegerKind.U64 3999475761173426716; + Value.Integer IntegerKind.U64 10048827240205135252; + Value.Integer IntegerKind.U64 3631180266689435939; + Value.Integer IntegerKind.U64 4306500913260118980; + Value.Integer IntegerKind.U64 8768271440878902003; + Value.Integer IntegerKind.U64 11396185639073510952; + Value.Integer IntegerKind.U64 5956761105726089899; + Value.Integer IntegerKind.U64 18158513693195763713; + Value.Integer IntegerKind.U64 17870283317245378561; + Value.Integer IntegerKind.U64 3228180212093865165; + Value.Integer IntegerKind.U64 14927299477138874800; + Value.Integer IntegerKind.U64 13567159279206235209; + Value.Integer IntegerKind.U64 15651782846710935677; + Value.Integer IntegerKind.U64 12491459968582210986; + Value.Integer IntegerKind.U64 18412703205591937505; + Value.Integer IntegerKind.U64 18159635212236225541; + Value.Integer IntegerKind.U64 15173917579729482918; + Value.Integer IntegerKind.U64 7823436250821745509; + Value.Integer IntegerKind.U64 2223692428017551671; + Value.Integer IntegerKind.U64 8969908472979932029; + Value.Integer IntegerKind.U64 11915000324447458604; + Value.Integer IntegerKind.U64 5374718107188630694; + Value.Integer IntegerKind.U64 18331450159748716545; + Value.Integer IntegerKind.U64 18158518091443602433; + Value.Integer IntegerKind.U64 2217161475366866314; + Value.Integer IntegerKind.U64 11393576184446667355; + Value.Integer IntegerKind.U64 15647485564039161052; + Value.Integer IntegerKind.U64 4303044601692044152; + Value.Integer IntegerKind.U64 18446743932042674209; + Value.Integer IntegerKind.U64 6474054332035261081; + Value.Integer IntegerKind.U64 14071893378084480181; + Value.Integer IntegerKind.U64 18156266308608721913; + Value.Integer IntegerKind.U64 6831286866257651793; + Value.Integer IntegerKind.U64 7895475781513922934; + Value.Integer IntegerKind.U64 12154759492517243801; + Value.Integer IntegerKind.U64 13566043034386449477; + Value.Integer IntegerKind.U64 16133004338111741504; + Value.Integer IntegerKind.U64 15729143380588139082 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_64_GOLDILOCKS : + M.IsFunction.C + "p3_goldilocks::mds::MATRIX_CIRC_MDS_64_GOLDILOCKS" + value_MATRIX_CIRC_MDS_64_GOLDILOCKS. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_64_GOLDILOCKS. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_64_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + (* + fn permute(&self, input: [Goldilocks; 64]) -> [Goldilocks; 64] { + const ENTRIES: [u64; 64] = first_row_to_first_col(&MATRIX_CIRC_MDS_64_GOLDILOCKS); + apply_circulant_fft(FFT_ALGO, ENTRIES, &input) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_function (| + "p3_mds::util::apply_circulant_fft", + [ Value.Integer IntegerKind.Usize 64 ], + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "p3_dft::radix_2_bowers::Radix2Bowers" + ] + |), + [ + M.read (| + get_constant (| + "p3_goldilocks::mds::FFT_ALGO", + Ty.path "p3_dft::radix_2_bowers::Radix2Bowers" + |) + |); + M.read (| + get_constant (| + "p3_goldilocks::mds::permute::ENTRIES", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "u64" ] + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.borrow (| Pointer.Kind.Ref, input |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Goldilocks; 64]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_64_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Module Impl_p3_mds_MdsPermutation_Usize_64_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 64 ] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_64_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Definition value_MATRIX_CIRC_MDS_68_GOLDILOCKS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U64 271275649090206780; + Value.Integer IntegerKind.U64 7465191119235169405; + Value.Integer IntegerKind.U64 15748010690838048827; + Value.Integer IntegerKind.U64 2189907731641455145; + Value.Integer IntegerKind.U64 10536692637845038726; + Value.Integer IntegerKind.U64 7936420152229996740; + Value.Integer IntegerKind.U64 8918273543568517946; + Value.Integer IntegerKind.U64 10412891406777177340; + Value.Integer IntegerKind.U64 10709964159165112046; + Value.Integer IntegerKind.U64 9612105236608260553; + Value.Integer IntegerKind.U64 1585394966113897953; + Value.Integer IntegerKind.U64 18446044809146671275; + Value.Integer IntegerKind.U64 2431354478429793642; + Value.Integer IntegerKind.U64 10001951866903388995; + Value.Integer IntegerKind.U64 18430736378507738542; + Value.Integer IntegerKind.U64 13984107499717922637; + Value.Integer IntegerKind.U64 11261964000454675910; + Value.Integer IntegerKind.U64 7324444153682955662; + Value.Integer IntegerKind.U64 10708918948449014042; + Value.Integer IntegerKind.U64 2573472369486839378; + Value.Integer IntegerKind.U64 15353490070083164725; + Value.Integer IntegerKind.U64 17670942257804425738; + Value.Integer IntegerKind.U64 13437704530023854541; + Value.Integer IntegerKind.U64 5445864171737617233; + Value.Integer IntegerKind.U64 7292655891034853835; + Value.Integer IntegerKind.U64 7205866835094373381; + Value.Integer IntegerKind.U64 1037765223939609361; + Value.Integer IntegerKind.U64 3587227720350127487; + Value.Integer IntegerKind.U64 1049779417187133683; + Value.Integer IntegerKind.U64 5971548168641902873; + Value.Integer IntegerKind.U64 4327790569699960229; + Value.Integer IntegerKind.U64 13727412105316204593; + Value.Integer IntegerKind.U64 6918530248077218072; + Value.Integer IntegerKind.U64 8354464902371715211; + Value.Integer IntegerKind.U64 18356318853051182061; + Value.Integer IntegerKind.U64 8021498326353458279; + Value.Integer IntegerKind.U64 18135453773930245974; + Value.Integer IntegerKind.U64 1824038370176468598; + Value.Integer IntegerKind.U64 2920114925766556607; + Value.Integer IntegerKind.U64 1562753292205916631; + Value.Integer IntegerKind.U64 4201433616803234040; + Value.Integer IntegerKind.U64 7837296383066760864; + Value.Integer IntegerKind.U64 9089361929032967653; + Value.Integer IntegerKind.U64 548556620554639894; + Value.Integer IntegerKind.U64 17011688094859185361; + Value.Integer IntegerKind.U64 14937439602419403278; + Value.Integer IntegerKind.U64 13959873883272485414; + Value.Integer IntegerKind.U64 13130905733325897184; + Value.Integer IntegerKind.U64 4873085061467210119; + Value.Integer IntegerKind.U64 9100447910491967200; + Value.Integer IntegerKind.U64 8305011495029382235; + Value.Integer IntegerKind.U64 11013789656095545947; + Value.Integer IntegerKind.U64 6163688520267989176; + Value.Integer IntegerKind.U64 12889118373529593097; + Value.Integer IntegerKind.U64 18067376856198695482; + Value.Integer IntegerKind.U64 8072210505730930325; + Value.Integer IntegerKind.U64 18421501637782139838; + Value.Integer IntegerKind.U64 3142567615424221273; + Value.Integer IntegerKind.U64 9055796506489509342; + Value.Integer IntegerKind.U64 12298617341496868515; + Value.Integer IntegerKind.U64 12143256562117758294; + Value.Integer IntegerKind.U64 8698453937620994506; + Value.Integer IntegerKind.U64 14393233233280171942; + Value.Integer IntegerKind.U64 8693648498431067059; + Value.Integer IntegerKind.U64 14633759743031073964; + Value.Integer IntegerKind.U64 12213341685221239628; + Value.Integer IntegerKind.U64 11513509197872118169; + Value.Integer IntegerKind.U64 29986708444946460 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_68_GOLDILOCKS : + M.IsFunction.C + "p3_goldilocks::mds::MATRIX_CIRC_MDS_68_GOLDILOCKS" + value_MATRIX_CIRC_MDS_68_GOLDILOCKS. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_68_GOLDILOCKS. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_68_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + (* + fn permute(&self, input: [Goldilocks; 68]) -> [Goldilocks; 68] { + apply_circulant(&MATRIX_CIRC_MDS_68_GOLDILOCKS, input) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 68 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_function (| + "p3_mds::util::apply_circulant", + [ Value.Integer IntegerKind.Usize 68 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_goldilocks::mds::MATRIX_CIRC_MDS_68_GOLDILOCKS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 68 ] + [ Ty.path "u64" ] + |) + |) + |) + |); + M.read (| input |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Goldilocks; 68]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 68 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 68 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 68 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_68_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + + Module Impl_p3_mds_MdsPermutation_Usize_68_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::mds::MdsMatrixGoldilocks". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 68 ] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_68_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_mds_MdsMatrixGoldilocks. +End mds. diff --git a/CoqOfRust/plonky3/goldilocks/src/poseidon2.rs b/CoqOfRust/plonky3/goldilocks/src/poseidon2.rs new file mode 100644 index 000000000..cecc73693 --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/poseidon2.rs @@ -0,0 +1,471 @@ +//! Implementation of Poseidon2, see: https://eprint.iacr.org/2023/323 + +//! For now we recreate the implementation given in: +//! https://github.com/HorizenLabs/poseidon2/blob/main/plain_implementations/src/poseidon2/poseidon2_instance_goldilocks.rs +//! This uses the constants below along with using the 4x4 matrix: +//! [[5, 7, 1, 3], [4, 6, 1, 1], [1, 3, 5, 7], [1, 1, 4, 6]] +//! to build the 4t x 4t matrix used for the external (full) rounds). + +//! Long term we will use more optimised internal and external linear layers. +use alloc::vec::Vec; + +use p3_field::{Algebra, InjectiveMonomial}; +use p3_poseidon2::{ + ExternalLayer, ExternalLayerConstants, ExternalLayerConstructor, HLMDSMat4, InternalLayer, + InternalLayerConstructor, MDSMat4, Poseidon2, add_rc_and_sbox_generic, + external_initial_permute_state, external_terminal_permute_state, internal_permute_state, + matmul_internal, +}; + +use crate::Goldilocks; + +/// Degree of the chosen permutation polynomial for Goldilocks, used as the Poseidon2 S-Box. +/// +/// As p - 1 = 2^32 * 3 * 5 * 17 * ... the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 7. +const GOLDILOCKS_S_BOX_DEGREE: u64 = 7; + +/// An implementation of the Poseidon2 hash function for the Goldilocks field. +/// +/// It acts on arrays of the form `[Goldilocks; WIDTH]`. +/// Currently the internal layers are unoptimized. These could be sped up in a similar way to +/// how it was done for Monty31 fields. +pub type Poseidon2Goldilocks = Poseidon2< + Goldilocks, + Poseidon2ExternalLayerGoldilocks, + Poseidon2InternalLayerGoldilocks, + WIDTH, + GOLDILOCKS_S_BOX_DEGREE, +>; + +/// A recreating of the Poseidon2 implementation by Horizen Labs for the Goldilocks field. +/// +/// It acts on arrays of the form `[Goldilocks; WIDTH]` +/// The original implementation can be found here: https://github.com/HorizenLabs/poseidon2. +/// This implementation is slightly slower than `Poseidon2Goldilocks` as is uses a slower matrix +/// for the external rounds. +pub type Poseidon2GoldilocksHL = Poseidon2< + Goldilocks, + Poseidon2ExternalLayerGoldilocksHL, + Poseidon2InternalLayerGoldilocks, + WIDTH, + GOLDILOCKS_S_BOX_DEGREE, +>; + +pub const MATRIX_DIAG_8_GOLDILOCKS: [Goldilocks; 8] = Goldilocks::new_array([ + 0xa98811a1fed4e3a5, + 0x1cc48b54f377e2a0, + 0xe40cd4f6c5609a26, + 0x11de79ebca97a4a3, + 0x9177c73d8b7e929c, + 0x2a6fe8085797e791, + 0x3de6e93329f8d5ad, + 0x3f7af9125da962fe, +]); + +pub const MATRIX_DIAG_12_GOLDILOCKS: [Goldilocks; 12] = Goldilocks::new_array([ + 0xc3b6c08e23ba9300, + 0xd84b5de94a324fb6, + 0x0d0c371c5b35b84f, + 0x7964f570e7188037, + 0x5daf18bbd996604b, + 0x6743bc47b9595257, + 0x5528b9362c59bb70, + 0xac45e25b7127b68b, + 0xa2077d7dfbb606b5, + 0xf3faac6faee378ae, + 0x0c6388b51545e883, + 0xd27dbb6944917b60, +]); + +pub const MATRIX_DIAG_16_GOLDILOCKS: [Goldilocks; 16] = Goldilocks::new_array([ + 0xde9b91a467d6afc0, + 0xc5f16b9c76a9be17, + 0x0ab0fef2d540ac55, + 0x3001d27009d05773, + 0xed23b1f906d3d9eb, + 0x5ce73743cba97054, + 0x1c3bab944af4ba24, + 0x2faa105854dbafae, + 0x53ffb3ae6d421a10, + 0xbcda9df8884ba396, + 0xfc1273e4a31807bb, + 0xc77952573d5142c0, + 0x56683339a819b85e, + 0x328fcbd8f0ddc8eb, + 0xb5101e303fce9cb7, + 0x774487b8c40089bb, +]); + +pub const MATRIX_DIAG_20_GOLDILOCKS: [Goldilocks; 20] = Goldilocks::new_array([ + 0x95c381fda3b1fa57, + 0xf36fe9eb1288f42c, + 0x89f5dcdfef277944, + 0x106f22eadeb3e2d2, + 0x684e31a2530e5111, + 0x27435c5d89fd148e, + 0x3ebed31c414dbf17, + 0xfd45b0b2d294e3cc, + 0x48c904473a7f6dbf, + 0xe0d1b67809295b4d, + 0xddd1941e9d199dcb, + 0x8cfe534eeb742219, + 0xa6e5261d9e3b8524, + 0x6897ee5ed0f82c1b, + 0x0e7dcd0739ee5f78, + 0x493253f3d0d32363, + 0xbb2737f5845f05c0, + 0xa187e810b06ad903, + 0xb635b995936c4918, + 0x0b3694a940bd2394, +]); + +/// The internal layers of the Poseidon2 permutation. +#[derive(Debug, Clone, Default)] +pub struct Poseidon2InternalLayerGoldilocks { + internal_constants: Vec, +} + +impl InternalLayerConstructor for Poseidon2InternalLayerGoldilocks { + fn new_from_constants(internal_constants: Vec) -> Self { + Self { internal_constants } + } +} + +impl + InjectiveMonomial> + InternalLayer for Poseidon2InternalLayerGoldilocks +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [A; 8]) { + internal_permute_state( + state, + |x| matmul_internal(x, MATRIX_DIAG_8_GOLDILOCKS), + &self.internal_constants, + ) + } +} + +impl + InjectiveMonomial> + InternalLayer for Poseidon2InternalLayerGoldilocks +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [A; 12]) { + internal_permute_state( + state, + |x| matmul_internal(x, MATRIX_DIAG_12_GOLDILOCKS), + &self.internal_constants, + ) + } +} + +impl + InjectiveMonomial> + InternalLayer for Poseidon2InternalLayerGoldilocks +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [A; 16]) { + internal_permute_state( + state, + |x| matmul_internal(x, MATRIX_DIAG_16_GOLDILOCKS), + &self.internal_constants, + ) + } +} + +impl + InjectiveMonomial> + InternalLayer for Poseidon2InternalLayerGoldilocks +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [A; 20]) { + internal_permute_state( + state, + |x| matmul_internal(x, MATRIX_DIAG_20_GOLDILOCKS), + &self.internal_constants, + ) + } +} + +/// The external layers of the Poseidon2 permutation. +#[derive(Clone)] +pub struct Poseidon2ExternalLayerGoldilocks { + pub(crate) external_constants: ExternalLayerConstants, +} + +impl ExternalLayerConstructor + for Poseidon2ExternalLayerGoldilocks +{ + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + Self { external_constants } + } +} + +impl + InjectiveMonomial, const WIDTH: usize> + ExternalLayer for Poseidon2ExternalLayerGoldilocks +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [A; WIDTH]) { + external_initial_permute_state( + state, + self.external_constants.get_initial_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [A; WIDTH]) { + external_terminal_permute_state( + state, + self.external_constants.get_terminal_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } +} + +/// The external layers of the Poseidon2 permutation used by Horizen Labs. +#[derive(Clone)] +pub struct Poseidon2ExternalLayerGoldilocksHL { + pub(crate) external_constants: ExternalLayerConstants, +} + +impl ExternalLayerConstructor + for Poseidon2ExternalLayerGoldilocksHL +{ + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + Self { external_constants } + } +} + +impl + InjectiveMonomial, const WIDTH: usize> + ExternalLayer for Poseidon2ExternalLayerGoldilocksHL +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [A; WIDTH]) { + external_initial_permute_state( + state, + self.external_constants.get_initial_constants(), + add_rc_and_sbox_generic, + &HLMDSMat4, + ); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [A; WIDTH]) { + external_terminal_permute_state( + state, + self.external_constants.get_terminal_constants(), + add_rc_and_sbox_generic, + &HLMDSMat4, + ); + } +} + +pub const HL_GOLDILOCKS_8_EXTERNAL_ROUND_CONSTANTS: [[[u64; 8]; 4]; 2] = [ + [ + [ + 0xdd5743e7f2a5a5d9, + 0xcb3a864e58ada44b, + 0xffa2449ed32f8cdc, + 0x42025f65d6bd13ee, + 0x7889175e25506323, + 0x34b98bb03d24b737, + 0xbdcc535ecc4faa2a, + 0x5b20ad869fc0d033, + ], + [ + 0xf1dda5b9259dfcb4, + 0x27515210be112d59, + 0x4227d1718c766c3f, + 0x26d333161a5bd794, + 0x49b938957bf4b026, + 0x4a56b5938b213669, + 0x1120426b48c8353d, + 0x6b323c3f10a56cad, + ], + [ + 0xce57d6245ddca6b2, + 0xb1fc8d402bba1eb1, + 0xb5c5096ca959bd04, + 0x6db55cd306d31f7f, + 0xc49d293a81cb9641, + 0x1ce55a4fe979719f, + 0xa92e60a9d178a4d1, + 0x002cc64973bcfd8c, + ], + [ + 0xcea721cce82fb11b, + 0xe5b55eb8098ece81, + 0x4e30525c6f1ddd66, + 0x43c6702827070987, + 0xaca68430a7b5762a, + 0x3674238634df9c93, + 0x88cee1c825e33433, + 0xde99ae8d74b57176, + ], + ], + [ + [ + 0x014ef1197d341346, + 0x9725e20825d07394, + 0xfdb25aef2c5bae3b, + 0xbe5402dc598c971e, + 0x93a5711f04cdca3d, + 0xc45a9a5b2f8fb97b, + 0xfe8946a924933545, + 0x2af997a27369091c, + ], + [ + 0xaa62c88e0b294011, + 0x058eb9d810ce9f74, + 0xb3cb23eced349ae4, + 0xa3648177a77b4a84, + 0x43153d905992d95d, + 0xf4e2a97cda44aa4b, + 0x5baa2702b908682f, + 0x082923bdf4f750d1, + ], + [ + 0x98ae09a325893803, + 0xf8a6475077968838, + 0xceb0735bf00b2c5f, + 0x0a1a5d953888e072, + 0x2fcb190489f94475, + 0xb5be06270dec69fc, + 0x739cb934b09acf8b, + 0x537750b75ec7f25b, + ], + [ + 0xe9dd318bae1f3961, + 0xf7462137299efe1a, + 0xb1f6b8eee9adb940, + 0xbdebcc8a809dfe6b, + 0x40fc1f791b178113, + 0x3ac1c3362d014864, + 0x9a016184bdb8aeba, + 0x95f2394459fbc25e, + ], + ], +]; +pub const HL_GOLDILOCKS_8_INTERNAL_ROUND_CONSTANTS: [u64; 22] = [ + 0x488897d85ff51f56, + 0x1140737ccb162218, + 0xa7eeb9215866ed35, + 0x9bd2976fee49fcc9, + 0xc0c8f0de580a3fcc, + 0x4fb2dae6ee8fc793, + 0x343a89f35f37395b, + 0x223b525a77ca72c8, + 0x56ccb62574aaa918, + 0xc4d507d8027af9ed, + 0xa080673cf0b7e95c, + 0xf0184884eb70dcf8, + 0x044f10b0cb3d5c69, + 0xe9e3f7993938f186, + 0x1b761c80e772f459, + 0x606cec607a1b5fac, + 0x14a0c2e1d45f03cd, + 0x4eace8855398574f, + 0xf905ca7103eff3e6, + 0xf8c8f8d20862c059, + 0xb524fe8bdd678e5a, + 0xfbb7865901a1ec41, +]; + +#[cfg(test)] +mod tests { + use core::array; + + use p3_field::PrimeCharacteristicRing; + use p3_poseidon2::Poseidon2; + use p3_symmetric::Permutation; + + use super::*; + + type F = Goldilocks; + + // A function which recreates the poseidon2 implementation in + // https://github.com/HorizenLabs/poseidon2 + fn hl_poseidon2_goldilocks_width_8(input: &mut [F; 8]) { + const WIDTH: usize = 8; + + // Our Poseidon2 implementation. + let poseidon2: Poseidon2GoldilocksHL = Poseidon2::new( + ExternalLayerConstants::::new_from_saved_array( + HL_GOLDILOCKS_8_EXTERNAL_ROUND_CONSTANTS, + Goldilocks::new_array, + ), + Goldilocks::new_array(HL_GOLDILOCKS_8_INTERNAL_ROUND_CONSTANTS).to_vec(), + ); + + poseidon2.permute_mut(input); + } + + /// Test on the constant 0 input. + #[test] + fn test_poseidon2_width_8_zeros() { + let mut input: [F; 8] = [Goldilocks::ZERO; 8]; + + let expected: [F; 8] = Goldilocks::new_array([ + 4214787979728720400, + 12324939279576102560, + 10353596058419792404, + 15456793487362310586, + 10065219879212154722, + 16227496357546636742, + 2959271128466640042, + 14285409611125725709, + ]); + hl_poseidon2_goldilocks_width_8(&mut input); + assert_eq!(input, expected); + } + + /// Test on the input 0..16. + #[test] + fn test_poseidon2_width_8_range() { + let mut input: [F; 8] = array::from_fn(|i| F::from_u64(i as u64)); + + let expected: [F; 8] = Goldilocks::new_array([ + 14266028122062624699, + 5353147180106052723, + 15203350112844181434, + 17630919042639565165, + 16601551015858213987, + 10184091939013874068, + 16774100645754596496, + 12047415603622314780, + ]); + hl_poseidon2_goldilocks_width_8(&mut input); + assert_eq!(input, expected); + } + + /// Test on a roughly random input. + /// This random input is generated by the following sage code: + /// set_random_seed(2468) + /// vector([ZZ.random_element(2**31) for t in range(16)]) + #[test] + fn test_poseidon2_width_8_random() { + let mut input: [F; 8] = Goldilocks::new_array([ + 5116996373749832116, + 8931548647907683339, + 17132360229780760684, + 11280040044015983889, + 11957737519043010992, + 15695650327991256125, + 17604752143022812942, + 543194415197607509, + ]); + + let expected: [F; 8] = Goldilocks::new_array([ + 1831346684315917658, + 13497752062035433374, + 12149460647271516589, + 15656333994315312197, + 4671534937670455565, + 3140092508031220630, + 4251208148861706881, + 6973971209430822232, + ]); + + hl_poseidon2_goldilocks_width_8(&mut input); + assert_eq!(input, expected); + } +} diff --git a/CoqOfRust/plonky3/goldilocks/src/poseidon2.v b/CoqOfRust/plonky3/goldilocks/src/poseidon2.v new file mode 100644 index 000000000..3c58a6bba --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/poseidon2.v @@ -0,0 +1,2095 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module poseidon2. + Definition value_GOLDILOCKS_S_BOX_DEGREE + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U64 7 |))). + + Global Instance Instance_IsConstant_value_GOLDILOCKS_S_BOX_DEGREE : + M.IsFunction.C + "p3_goldilocks::poseidon2::GOLDILOCKS_S_BOX_DEGREE" + value_GOLDILOCKS_S_BOX_DEGREE. + Admitted. + Global Typeclasses Opaque value_GOLDILOCKS_S_BOX_DEGREE. + + Axiom Poseidon2Goldilocks : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_goldilocks::poseidon2::Poseidon2Goldilocks") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ + WIDTH; + M.unevaluated_const + (mk_str (| "p3_goldilocks_poseidon2_Poseidon2Goldilocks_discriminant" |)) + ] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.apply + (Ty.path "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocks") + [ WIDTH ] + []; + Ty.path "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks" + ]). + + Axiom Poseidon2GoldilocksHL : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_goldilocks::poseidon2::Poseidon2GoldilocksHL") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ + WIDTH; + M.unevaluated_const + (mk_str (| "p3_goldilocks_poseidon2_Poseidon2GoldilocksHL_discriminant" |)) + ] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.apply + (Ty.path "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocksHL") + [ WIDTH ] + []; + Ty.path "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks" + ]). + + Definition value_MATRIX_DIAG_8_GOLDILOCKS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new_array", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U64 12216033376705242021; + Value.Integer IntegerKind.U64 2072934925475504800; + Value.Integer IntegerKind.U64 16432743296706583078; + Value.Integer IntegerKind.U64 1287600597097751715; + Value.Integer IntegerKind.U64 10482065724875379356; + Value.Integer IntegerKind.U64 3057917794534811537; + Value.Integer IntegerKind.U64 4460508886913832365; + Value.Integer IntegerKind.U64 4574242228824269566 + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_MATRIX_DIAG_8_GOLDILOCKS : + M.IsFunction.C + "p3_goldilocks::poseidon2::MATRIX_DIAG_8_GOLDILOCKS" + value_MATRIX_DIAG_8_GOLDILOCKS. + Admitted. + Global Typeclasses Opaque value_MATRIX_DIAG_8_GOLDILOCKS. + + Definition value_MATRIX_DIAG_12_GOLDILOCKS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new_array", + [ Value.Integer IntegerKind.Usize 12 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U64 14102670999874605824; + Value.Integer IntegerKind.U64 15585654191999307702; + Value.Integer IntegerKind.U64 940187017142450255; + Value.Integer IntegerKind.U64 8747386241522630711; + Value.Integer IntegerKind.U64 6750641561540124747; + Value.Integer IntegerKind.U64 7440998025584530007; + Value.Integer IntegerKind.U64 6136358134615751536; + Value.Integer IntegerKind.U64 12413576830284969611; + Value.Integer IntegerKind.U64 11675438539028694709; + Value.Integer IntegerKind.U64 17580553691069642926; + Value.Integer IntegerKind.U64 892707462476851331; + Value.Integer IntegerKind.U64 15167485180850043744 + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_MATRIX_DIAG_12_GOLDILOCKS : + M.IsFunction.C + "p3_goldilocks::poseidon2::MATRIX_DIAG_12_GOLDILOCKS" + value_MATRIX_DIAG_12_GOLDILOCKS. + Admitted. + Global Typeclasses Opaque value_MATRIX_DIAG_12_GOLDILOCKS. + + Definition value_MATRIX_DIAG_16_GOLDILOCKS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new_array", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U64 16040574633112940480; + Value.Integer IntegerKind.U64 14263299814608977431; + Value.Integer IntegerKind.U64 770395855193680981; + Value.Integer IntegerKind.U64 3459277367440070515; + Value.Integer IntegerKind.U64 17087697094293314027; + Value.Integer IntegerKind.U64 6694380135428747348; + Value.Integer IntegerKind.U64 2034408310088972836; + Value.Integer IntegerKind.U64 3434575637390274478; + Value.Integer IntegerKind.U64 6052753985947965968; + Value.Integer IntegerKind.U64 13608362914817483670; + Value.Integer IntegerKind.U64 18163707672964630459; + Value.Integer IntegerKind.U64 14373610220374016704; + Value.Integer IntegerKind.U64 6226282807566121054; + Value.Integer IntegerKind.U64 3643354756180461803; + Value.Integer IntegerKind.U64 13046961313070095543; + Value.Integer IntegerKind.U64 8594143216561850811 + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_MATRIX_DIAG_16_GOLDILOCKS : + M.IsFunction.C + "p3_goldilocks::poseidon2::MATRIX_DIAG_16_GOLDILOCKS" + value_MATRIX_DIAG_16_GOLDILOCKS. + Admitted. + Global Typeclasses Opaque value_MATRIX_DIAG_16_GOLDILOCKS. + + Definition value_MATRIX_DIAG_20_GOLDILOCKS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_associated_function (| + Ty.path "p3_goldilocks::goldilocks::Goldilocks", + "new_array", + [ Value.Integer IntegerKind.Usize 20 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U64 10791612058482899543; + Value.Integer IntegerKind.U64 17541496269468922924; + Value.Integer IntegerKind.U64 9941094606838397252; + Value.Integer IntegerKind.U64 1184203619175752402; + Value.Integer IntegerKind.U64 7515999401375846673; + Value.Integer IntegerKind.U64 2829206547735581838; + Value.Integer IntegerKind.U64 4521283194234715927; + Value.Integer IntegerKind.U64 18250187347072443340; + Value.Integer IntegerKind.U64 5244727945020272063; + Value.Integer IntegerKind.U64 16199929961294420813; + Value.Integer IntegerKind.U64 15983719411720232395; + Value.Integer IntegerKind.U64 10159649407817228825; + Value.Integer IntegerKind.U64 12026060288613385508; + Value.Integer IntegerKind.U64 7536754592428076059; + Value.Integer IntegerKind.U64 1044216119540211576; + Value.Integer IntegerKind.U64 5274370420249928547; + Value.Integer IntegerKind.U64 13485809136811574720; + Value.Integer IntegerKind.U64 11639526920339249411; + Value.Integer IntegerKind.U64 13129604340743162136; + Value.Integer IntegerKind.U64 807996637816103828 + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_MATRIX_DIAG_20_GOLDILOCKS : + M.IsFunction.C + "p3_goldilocks::poseidon2::MATRIX_DIAG_20_GOLDILOCKS" + value_MATRIX_DIAG_20_GOLDILOCKS. + Admitted. + Global Typeclasses Opaque value_MATRIX_DIAG_20_GOLDILOCKS. + + (* StructRecord + { + name := "Poseidon2InternalLayerGoldilocks"; + const_params := []; + ty_params := []; + fields := + [ + ("internal_constants", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; Ty.path "alloc::alloc::Global" ]) + ]; + } *) + + Module Impl_core_fmt_Debug_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Poseidon2InternalLayerGoldilocks" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "internal_constants" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks", + "internal_constants" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + + Module Impl_core_clone_Clone_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks" + [ + ("internal_constants", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks", + "internal_constants" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + + Module Impl_core_default_Default_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks" + [ + ("internal_constants", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + + Module Impl_p3_poseidon2_internal_InternalLayerConstructor_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + Definition Self : Ty.t := Ty.path "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks". + + (* + fn new_from_constants(internal_constants: Vec) -> Self { + Self { internal_constants } + } + *) + Definition new_from_constants (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ internal_constants ] => + ltac:(M.monadic + (let internal_constants := M.alloc (| internal_constants |) in + Value.StructRecord + "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks" + [ ("internal_constants", M.read (| internal_constants |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayerConstructor" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + Self + (* Instance *) [ ("new_from_constants", InstanceField.Method new_from_constants) ]. + End Impl_p3_poseidon2_internal_InternalLayerConstructor_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + + Module Impl_p3_poseidon2_internal_InternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_Usize_8_expr_A_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + Definition Self (A : Ty.t) : Ty.t := + Ty.path "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks". + + (* + fn permute_state(&self, state: &mut [A; 8]) { + internal_permute_state( + state, + |x| matmul_internal(x, MATRIX_DIAG_8_GOLDILOCKS), + &self.internal_constants, + ) + } + *) + Definition permute_state (A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self A in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::internal_permute_state", + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.U64 7 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + (* ClosureFnPointer(Safe) *) + M.pointer_coercion + (M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ A ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::matmul_internal", + [ Value.Integer IntegerKind.Usize 8 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| + get_constant (| + "p3_goldilocks::poseidon2::MATRIX_DIAG_8_GOLDILOCKS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end))); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks", + "internal_constants" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (A : Ty.t), + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayer" + (* Trait polymorphic consts *) + [ + Value.Integer IntegerKind.Usize 8; + M.unevaluated_const (mk_str (| "p3_goldilocks_poseidon2_discriminant" |)) + ] + (* Trait polymorphic types *) [ A ] + (Self A) + (* Instance *) [ ("permute_state", InstanceField.Method (permute_state A)) ]. + End Impl_p3_poseidon2_internal_InternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_Usize_8_expr_A_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + + Module Impl_p3_poseidon2_internal_InternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_Usize_12_expr_A_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + Definition Self (A : Ty.t) : Ty.t := + Ty.path "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks". + + (* + fn permute_state(&self, state: &mut [A; 12]) { + internal_permute_state( + state, + |x| matmul_internal(x, MATRIX_DIAG_12_GOLDILOCKS), + &self.internal_constants, + ) + } + *) + Definition permute_state (A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self A in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::internal_permute_state", + [ Value.Integer IntegerKind.Usize 12; Value.Integer IntegerKind.U64 7 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + (* ClosureFnPointer(Safe) *) + M.pointer_coercion + (M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ A ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::matmul_internal", + [ Value.Integer IntegerKind.Usize 12 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| + get_constant (| + "p3_goldilocks::poseidon2::MATRIX_DIAG_12_GOLDILOCKS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end))); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks", + "internal_constants" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (A : Ty.t), + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayer" + (* Trait polymorphic consts *) + [ + Value.Integer IntegerKind.Usize 12; + M.unevaluated_const (mk_str (| "p3_goldilocks_poseidon2_discriminant" |)) + ] + (* Trait polymorphic types *) [ A ] + (Self A) + (* Instance *) [ ("permute_state", InstanceField.Method (permute_state A)) ]. + End Impl_p3_poseidon2_internal_InternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_Usize_12_expr_A_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + + Module Impl_p3_poseidon2_internal_InternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_Usize_16_expr_A_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + Definition Self (A : Ty.t) : Ty.t := + Ty.path "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks". + + (* + fn permute_state(&self, state: &mut [A; 16]) { + internal_permute_state( + state, + |x| matmul_internal(x, MATRIX_DIAG_16_GOLDILOCKS), + &self.internal_constants, + ) + } + *) + Definition permute_state (A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self A in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::internal_permute_state", + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.U64 7 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + (* ClosureFnPointer(Safe) *) + M.pointer_coercion + (M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ A ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::matmul_internal", + [ Value.Integer IntegerKind.Usize 16 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| + get_constant (| + "p3_goldilocks::poseidon2::MATRIX_DIAG_16_GOLDILOCKS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end))); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks", + "internal_constants" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (A : Ty.t), + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayer" + (* Trait polymorphic consts *) + [ + Value.Integer IntegerKind.Usize 16; + M.unevaluated_const (mk_str (| "p3_goldilocks_poseidon2_discriminant" |)) + ] + (* Trait polymorphic types *) [ A ] + (Self A) + (* Instance *) [ ("permute_state", InstanceField.Method (permute_state A)) ]. + End Impl_p3_poseidon2_internal_InternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_Usize_16_expr_A_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + + Module Impl_p3_poseidon2_internal_InternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_Usize_20_expr_A_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + Definition Self (A : Ty.t) : Ty.t := + Ty.path "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks". + + (* + fn permute_state(&self, state: &mut [A; 20]) { + internal_permute_state( + state, + |x| matmul_internal(x, MATRIX_DIAG_20_GOLDILOCKS), + &self.internal_constants, + ) + } + *) + Definition permute_state (A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self A in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::internal_permute_state", + [ Value.Integer IntegerKind.Usize 20; Value.Integer IntegerKind.U64 7 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + (* ClosureFnPointer(Safe) *) + M.pointer_coercion + (M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ A ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::matmul_internal", + [ Value.Integer IntegerKind.Usize 20 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| + get_constant (| + "p3_goldilocks::poseidon2::MATRIX_DIAG_20_GOLDILOCKS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end))); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2InternalLayerGoldilocks", + "internal_constants" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (A : Ty.t), + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayer" + (* Trait polymorphic consts *) + [ + Value.Integer IntegerKind.Usize 20; + M.unevaluated_const (mk_str (| "p3_goldilocks_poseidon2_discriminant" |)) + ] + (* Trait polymorphic types *) [ A ] + (Self A) + (* Instance *) [ ("permute_state", InstanceField.Method (permute_state A)) ]. + End Impl_p3_poseidon2_internal_InternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_Usize_20_expr_A_for_p3_goldilocks_poseidon2_Poseidon2InternalLayerGoldilocks. + + (* StructRecord + { + name := "Poseidon2ExternalLayerGoldilocks"; + const_params := [ "WIDTH" ]; + ty_params := []; + fields := + [ + ("external_constants", + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]) + ]; + } *) + + Module Impl_core_clone_Clone_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocks_WIDTH. + Definition Self (WIDTH : Value.t) : Ty.t := + Ty.apply (Ty.path "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocks") [ WIDTH ] []. + + (* Clone *) + Definition clone (WIDTH : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocks" + [ + ("external_constants", + M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocks", + "external_constants" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH)) ]. + End Impl_core_clone_Clone_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocks_WIDTH. + + Module Impl_p3_poseidon2_external_ExternalLayerConstructor_WIDTH_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocks_WIDTH. + Definition Self (WIDTH : Value.t) : Ty.t := + Ty.apply (Ty.path "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocks") [ WIDTH ] []. + + (* + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + Self { external_constants } + } + *) + Definition new_from_constants + (WIDTH : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ external_constants ] => + ltac:(M.monadic + (let external_constants := M.alloc (| external_constants |) in + Value.StructRecord + "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocks" + [ ("external_constants", M.read (| external_constants |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t), + M.IsTraitInstance + "p3_poseidon2::external::ExternalLayerConstructor" + (* Trait polymorphic consts *) [ WIDTH ] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + (Self WIDTH) + (* Instance *) [ ("new_from_constants", InstanceField.Method (new_from_constants WIDTH)) ]. + End Impl_p3_poseidon2_external_ExternalLayerConstructor_WIDTH_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocks_WIDTH. + + Module Impl_p3_poseidon2_external_ExternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_WIDTH_expr_A_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocks_WIDTH. + Definition Self (WIDTH : Value.t) (A : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocks") [ WIDTH ] []. + + (* + fn permute_state_initial(&self, state: &mut [A; WIDTH]) { + external_initial_permute_state( + state, + self.external_constants.get_initial_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + *) + Definition permute_state_initial + (WIDTH : Value.t) + (A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH A in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_initial_permute_state", + [ WIDTH ], + [ + A; + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "p3_poseidon2::external::MDSMat4" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "get_initial_constants", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocks", + "external_constants" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ Value.Integer IntegerKind.U64 7 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::MDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_state_terminal(&self, state: &mut [A; WIDTH]) { + external_terminal_permute_state( + state, + self.external_constants.get_terminal_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + *) + Definition permute_state_terminal + (WIDTH : Value.t) + (A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH A in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_terminal_permute_state", + [ WIDTH ], + [ + A; + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "p3_poseidon2::external::MDSMat4" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "get_terminal_constants", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocks", + "external_constants" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ Value.Integer IntegerKind.U64 7 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::MDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (A : Ty.t), + M.IsTraitInstance + "p3_poseidon2::external::ExternalLayer" + (* Trait polymorphic consts *) + [ WIDTH; M.unevaluated_const (mk_str (| "p3_goldilocks_poseidon2_discriminant" |)) ] + (* Trait polymorphic types *) [ A ] + (Self WIDTH A) + (* Instance *) + [ + ("permute_state_initial", InstanceField.Method (permute_state_initial WIDTH A)); + ("permute_state_terminal", InstanceField.Method (permute_state_terminal WIDTH A)) + ]. + End Impl_p3_poseidon2_external_ExternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_WIDTH_expr_A_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocks_WIDTH. + + (* StructRecord + { + name := "Poseidon2ExternalLayerGoldilocksHL"; + const_params := [ "WIDTH" ]; + ty_params := []; + fields := + [ + ("external_constants", + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]) + ]; + } *) + + Module Impl_core_clone_Clone_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocksHL_WIDTH. + Definition Self (WIDTH : Value.t) : Ty.t := + Ty.apply + (Ty.path "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocksHL") + [ WIDTH ] + []. + + (* Clone *) + Definition clone (WIDTH : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocksHL" + [ + ("external_constants", + M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocksHL", + "external_constants" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH)) ]. + End Impl_core_clone_Clone_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocksHL_WIDTH. + + Module Impl_p3_poseidon2_external_ExternalLayerConstructor_WIDTH_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocksHL_WIDTH. + Definition Self (WIDTH : Value.t) : Ty.t := + Ty.apply + (Ty.path "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocksHL") + [ WIDTH ] + []. + + (* + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + Self { external_constants } + } + *) + Definition new_from_constants + (WIDTH : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ external_constants ] => + ltac:(M.monadic + (let external_constants := M.alloc (| external_constants |) in + Value.StructRecord + "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocksHL" + [ ("external_constants", M.read (| external_constants |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t), + M.IsTraitInstance + "p3_poseidon2::external::ExternalLayerConstructor" + (* Trait polymorphic consts *) [ WIDTH ] + (* Trait polymorphic types *) [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + (Self WIDTH) + (* Instance *) [ ("new_from_constants", InstanceField.Method (new_from_constants WIDTH)) ]. + End Impl_p3_poseidon2_external_ExternalLayerConstructor_WIDTH_p3_goldilocks_goldilocks_Goldilocks_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocksHL_WIDTH. + + Module Impl_p3_poseidon2_external_ExternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_WIDTH_expr_A_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocksHL_WIDTH. + Definition Self (WIDTH : Value.t) (A : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocksHL") + [ WIDTH ] + []. + + (* + fn permute_state_initial(&self, state: &mut [A; WIDTH]) { + external_initial_permute_state( + state, + self.external_constants.get_initial_constants(), + add_rc_and_sbox_generic, + &HLMDSMat4, + ); + } + *) + Definition permute_state_initial + (WIDTH : Value.t) + (A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH A in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_initial_permute_state", + [ WIDTH ], + [ + A; + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "p3_poseidon2::external::HLMDSMat4" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "get_initial_constants", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocksHL", + "external_constants" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ Value.Integer IntegerKind.U64 7 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::HLMDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_state_terminal(&self, state: &mut [A; WIDTH]) { + external_terminal_permute_state( + state, + self.external_constants.get_terminal_constants(), + add_rc_and_sbox_generic, + &HLMDSMat4, + ); + } + *) + Definition permute_state_terminal + (WIDTH : Value.t) + (A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH A in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_terminal_permute_state", + [ WIDTH ], + [ + A; + Ty.path "p3_goldilocks::goldilocks::Goldilocks"; + Ty.path "p3_poseidon2::external::HLMDSMat4" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks" ], + "get_terminal_constants", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_goldilocks::poseidon2::Poseidon2ExternalLayerGoldilocksHL", + "external_constants" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ Value.Integer IntegerKind.U64 7 ], + [ Ty.path "p3_goldilocks::goldilocks::Goldilocks"; A ] + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::HLMDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (A : Ty.t), + M.IsTraitInstance + "p3_poseidon2::external::ExternalLayer" + (* Trait polymorphic consts *) + [ WIDTH; M.unevaluated_const (mk_str (| "p3_goldilocks_poseidon2_discriminant" |)) ] + (* Trait polymorphic types *) [ A ] + (Self WIDTH A) + (* Instance *) + [ + ("permute_state_initial", InstanceField.Method (permute_state_initial WIDTH A)); + ("permute_state_terminal", InstanceField.Method (permute_state_terminal WIDTH A)) + ]. + End Impl_p3_poseidon2_external_ExternalLayer_where_p3_field_field_Algebra_A_p3_goldilocks_goldilocks_Goldilocks_where_p3_field_field_InjectiveMonomial_A_WIDTH_expr_A_for_p3_goldilocks_poseidon2_Poseidon2ExternalLayerGoldilocksHL_WIDTH. + + Definition value_HL_GOLDILOCKS_8_EXTERNAL_ROUND_CONSTANTS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Array + [ + Value.Array + [ + Value.Integer IntegerKind.U64 15949291268843349465; + Value.Integer IntegerKind.U64 14644164809401934923; + Value.Integer IntegerKind.U64 18420360874837380316; + Value.Integer IntegerKind.U64 4756469047455716334; + Value.Integer IntegerKind.U64 8685499049481102115; + Value.Integer IntegerKind.U64 3799221349720045367; + Value.Integer IntegerKind.U64 13676397835037157930; + Value.Integer IntegerKind.U64 6566439050423619635 + ]; + Value.Array + [ + Value.Integer IntegerKind.U64 17428268347612331188; + Value.Integer IntegerKind.U64 2833135872454503769; + Value.Integer IntegerKind.U64 4767009016213040191; + Value.Integer IntegerKind.U64 2797635963551733652; + Value.Integer IntegerKind.U64 5312339450141126694; + Value.Integer IntegerKind.U64 5356668452102813289; + Value.Integer IntegerKind.U64 1234059326449530173; + Value.Integer IntegerKind.U64 7724302552453704877 + ]; + Value.Array + [ + Value.Integer IntegerKind.U64 14868588146468890290; + Value.Integer IntegerKind.U64 12825281145595371185; + Value.Integer IntegerKind.U64 13097885453579304196; + Value.Integer IntegerKind.U64 7905326782341128063; + Value.Integer IntegerKind.U64 14167525334039893569; + Value.Integer IntegerKind.U64 2082169701994688927; + Value.Integer IntegerKind.U64 12190787523818595537; + Value.Integer IntegerKind.U64 12602917751946636 + ]; + Value.Array + [ + Value.Integer IntegerKind.U64 14890907856876319003; + Value.Integer IntegerKind.U64 16552240149997473409; + Value.Integer IntegerKind.U64 5634093690795187558; + Value.Integer IntegerKind.U64 4883714163685656967; + Value.Integer IntegerKind.U64 12440776365164557866; + Value.Integer IntegerKind.U64 3923800234666204307; + Value.Integer IntegerKind.U64 9858064884105950259; + Value.Integer IntegerKind.U64 16040043470428402038 + ] + ]; + Value.Array + [ + Value.Array + [ + Value.Integer IntegerKind.U64 94277733998400326; + Value.Integer IntegerKind.U64 10891359798487446420; + Value.Integer IntegerKind.U64 18280773820738154043; + Value.Integer IntegerKind.U64 13714589910668449566; + Value.Integer IntegerKind.U64 10639034072771185213; + Value.Integer IntegerKind.U64 14148790895768484219; + Value.Integer IntegerKind.U64 18341268649720100165; + Value.Integer IntegerKind.U64 3096672942770686236 + ]; + Value.Array + [ + Value.Integer IntegerKind.U64 12277596046563557393; + Value.Integer IntegerKind.U64 400461754528604020; + Value.Integer IntegerKind.U64 12955488253560265444; + Value.Integer IntegerKind.U64 11773677676764285572; + Value.Integer IntegerKind.U64 4833837465239476573; + Value.Integer IntegerKind.U64 17645852643693996619; + Value.Integer IntegerKind.U64 6605134696140007471; + Value.Integer IntegerKind.U64 588040525114200273 + ]; + Value.Array + [ + Value.Integer IntegerKind.U64 11001741536026769411; + Value.Integer IntegerKind.U64 17917086578469406776; + Value.Integer IntegerKind.U64 14893530806420712543; + Value.Integer IntegerKind.U64 727997185253761138; + Value.Integer IntegerKind.U64 3443873847340254325; + Value.Integer IntegerKind.U64 13095911531247069692; + Value.Integer IntegerKind.U64 8330737046680948619; + Value.Integer IntegerKind.U64 6014364575875986011 + ]; + Value.Array + [ + Value.Integer IntegerKind.U64 16851679856681761121; + Value.Integer IntegerKind.U64 17817965496543149594; + Value.Integer IntegerKind.U64 12823640325246269760; + Value.Integer IntegerKind.U64 13685256787930775147; + Value.Integer IntegerKind.U64 4682652317564502291; + Value.Integer IntegerKind.U64 4233879762155685988; + Value.Integer IntegerKind.U64 11097258179564187322; + Value.Integer IntegerKind.U64 10804761421745472094 + ] + ] + ] + |))). + + Global Instance Instance_IsConstant_value_HL_GOLDILOCKS_8_EXTERNAL_ROUND_CONSTANTS : + M.IsFunction.C + "p3_goldilocks::poseidon2::HL_GOLDILOCKS_8_EXTERNAL_ROUND_CONSTANTS" + value_HL_GOLDILOCKS_8_EXTERNAL_ROUND_CONSTANTS. + Admitted. + Global Typeclasses Opaque value_HL_GOLDILOCKS_8_EXTERNAL_ROUND_CONSTANTS. + + Definition value_HL_GOLDILOCKS_8_INTERNAL_ROUND_CONSTANTS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U64 5226594323142090582; + Value.Integer IntegerKind.U64 1243120476974621208; + Value.Integer IntegerKind.U64 12100812801659301173; + Value.Integer IntegerKind.U64 11228203327983058121; + Value.Integer IntegerKind.U64 13891617888374767564; + Value.Integer IntegerKind.U64 5742893160230537107; + Value.Integer IntegerKind.U64 3763472116988983643; + Value.Integer IntegerKind.U64 2466655769425769160; + Value.Integer IntegerKind.U64 6254574254498162968; + Value.Integer IntegerKind.U64 14183251225809189357; + Value.Integer IntegerKind.U64 11565357354521717084; + Value.Integer IntegerKind.U64 17300657704266685688; + Value.Integer IntegerKind.U64 310485250821938281; + Value.Integer IntegerKind.U64 16853586468012618118; + Value.Integer IntegerKind.U64 1978800426240373849; + Value.Integer IntegerKind.U64 6948188224235462572; + Value.Integer IntegerKind.U64 1486402152218690509; + Value.Integer IntegerKind.U64 5669161690283398991; + Value.Integer IntegerKind.U64 17943970877073781734; + Value.Integer IntegerKind.U64 17926851897715769433; + Value.Integer IntegerKind.U64 13052837496695000666; + Value.Integer IntegerKind.U64 18138113741095562305 + ] + |))). + + Global Instance Instance_IsConstant_value_HL_GOLDILOCKS_8_INTERNAL_ROUND_CONSTANTS : + M.IsFunction.C + "p3_goldilocks::poseidon2::HL_GOLDILOCKS_8_INTERNAL_ROUND_CONSTANTS" + value_HL_GOLDILOCKS_8_INTERNAL_ROUND_CONSTANTS. + Admitted. + Global Typeclasses Opaque value_HL_GOLDILOCKS_8_INTERNAL_ROUND_CONSTANTS. +End poseidon2. diff --git a/CoqOfRust/plonky3/goldilocks/src/x86_64_avx2/mds.rs b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx2/mds.rs new file mode 100644 index 000000000..eef8e64e7 --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx2/mds.rs @@ -0,0 +1,155 @@ +use p3_mds::MdsPermutation; +use p3_mds::util::apply_circulant; +use p3_symmetric::Permutation; + +use crate::x86_64_avx2::packing::PackedGoldilocksAVX2; +use crate::{ + MATRIX_CIRC_MDS_8_SML_ROW, MATRIX_CIRC_MDS_12_SML_ROW, MATRIX_CIRC_MDS_16_SML_ROW, + MATRIX_CIRC_MDS_24_GOLDILOCKS, MdsMatrixGoldilocks, +}; +const fn convert_array(arr: [i64; N]) -> [u64; N] { + let mut result: [u64; N] = [0; N]; + let mut i = 0; + while i < N { + result[i] = arr[i] as u64; + i += 1; + } + result +} + +impl Permutation<[PackedGoldilocksAVX2; 8]> for MdsMatrixGoldilocks { + fn permute(&self, input: [PackedGoldilocksAVX2; 8]) -> [PackedGoldilocksAVX2; 8] { + const MATRIX_CIRC_MDS_8_SML_ROW_U64: [u64; 8] = convert_array(MATRIX_CIRC_MDS_8_SML_ROW); + apply_circulant(&MATRIX_CIRC_MDS_8_SML_ROW_U64, input) + } + + fn permute_mut(&self, input: &mut [PackedGoldilocksAVX2; 8]) { + *input = self.permute(*input); + } +} + +impl MdsPermutation for MdsMatrixGoldilocks {} + +impl Permutation<[PackedGoldilocksAVX2; 12]> for MdsMatrixGoldilocks { + fn permute(&self, input: [PackedGoldilocksAVX2; 12]) -> [PackedGoldilocksAVX2; 12] { + const MATRIX_CIRC_MDS_12_SML_ROW_U64: [u64; 12] = convert_array(MATRIX_CIRC_MDS_12_SML_ROW); + apply_circulant(&MATRIX_CIRC_MDS_12_SML_ROW_U64, input) + } + + fn permute_mut(&self, input: &mut [PackedGoldilocksAVX2; 12]) { + *input = self.permute(*input); + } +} + +impl MdsPermutation for MdsMatrixGoldilocks {} + +impl Permutation<[PackedGoldilocksAVX2; 16]> for MdsMatrixGoldilocks { + fn permute(&self, input: [PackedGoldilocksAVX2; 16]) -> [PackedGoldilocksAVX2; 16] { + const MATRIX_CIRC_MDS_16_SML_ROW_U64: [u64; 16] = convert_array(MATRIX_CIRC_MDS_16_SML_ROW); + apply_circulant(&MATRIX_CIRC_MDS_16_SML_ROW_U64, input) + } + + fn permute_mut(&self, input: &mut [PackedGoldilocksAVX2; 16]) { + *input = self.permute(*input); + } +} + +impl MdsPermutation for MdsMatrixGoldilocks {} + +impl Permutation<[PackedGoldilocksAVX2; 24]> for MdsMatrixGoldilocks { + fn permute(&self, input: [PackedGoldilocksAVX2; 24]) -> [PackedGoldilocksAVX2; 24] { + apply_circulant(&MATRIX_CIRC_MDS_24_GOLDILOCKS, input) + } + + fn permute_mut(&self, input: &mut [PackedGoldilocksAVX2; 24]) { + *input = self.permute(*input); + } +} + +impl MdsPermutation for MdsMatrixGoldilocks {} + +#[cfg(test)] +mod tests { + use p3_poseidon::Poseidon; + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use crate::{Goldilocks, MdsMatrixGoldilocks, PackedGoldilocksAVX2}; + + #[test] + fn test_avx2_poseidon_width_8() { + let mut rng = SmallRng::seed_from_u64(1); + type F = Goldilocks; + type Perm = Poseidon; + let poseidon = Perm::new_from_rng(4, 22, MdsMatrixGoldilocks, &mut rng); + + let input: [F; 8] = rng.random(); + + let mut expected = input; + poseidon.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + assert_eq!(avx2_output, expected); + } + + #[test] + fn test_avx2_poseidon_width_12() { + let mut rng = SmallRng::seed_from_u64(1); + type F = Goldilocks; + type Perm = Poseidon; + let poseidon = Perm::new_from_rng(4, 22, MdsMatrixGoldilocks, &mut rng); + + let input: [F; 12] = rng.random(); + + let mut expected = input; + poseidon.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + assert_eq!(avx2_output, expected); + } + + #[test] + fn test_avx2_poseidon_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + type F = Goldilocks; + type Perm = Poseidon; + let poseidon = Perm::new_from_rng(4, 22, MdsMatrixGoldilocks, &mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + assert_eq!(avx2_output, expected); + } + + #[test] + fn test_avx2_poseidon_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + type F = Goldilocks; + type Perm = Poseidon; + let poseidon = Perm::new_from_rng(4, 22, MdsMatrixGoldilocks, &mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + assert_eq!(avx2_output, expected); + } +} diff --git a/CoqOfRust/plonky3/goldilocks/src/x86_64_avx2/mod.rs b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx2/mod.rs new file mode 100644 index 000000000..09300a20f --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx2/mod.rs @@ -0,0 +1,3 @@ +mod mds; +mod packing; +pub use packing::*; diff --git a/CoqOfRust/plonky3/goldilocks/src/x86_64_avx2/packing.rs b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx2/packing.rs new file mode 100644 index 000000000..5123aa31e --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx2/packing.rs @@ -0,0 +1,618 @@ +use alloc::vec::Vec; +use core::arch::x86_64::*; +use core::fmt; +use core::fmt::{Debug, Formatter}; +use core::iter::{Product, Sum}; +use core::mem::transmute; +use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; + +use p3_field::exponentiation::exp_10540996611094048183; +use p3_field::{ + Algebra, Field, InjectiveMonomial, PackedField, PackedFieldPow2, PackedValue, + PermutationMonomial, PrimeCharacteristicRing, PrimeField64, +}; +use p3_util::reconstitute_from_base; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; + +use crate::Goldilocks; + +const WIDTH: usize = 4; + +/// AVX2 Goldilocks Field +/// +/// Ideally `PackedGoldilocksAVX2` would wrap `__m256i`. Unfortunately, `__m256i` has an alignment of +/// 32B, which would preclude us from casting `[Goldilocks; 4]` (alignment 8B) to +/// `PackedGoldilocksAVX2`. We need to ensure that `PackedGoldilocksAVX2` has the same alignment as +/// `Goldilocks`. Thus we wrap `[Goldilocks; 4]` and use the `new` and `get` methods to +/// convert to and from `__m256i`. +#[derive(Copy, Clone, PartialEq, Eq)] +#[repr(transparent)] +pub struct PackedGoldilocksAVX2(pub [Goldilocks; WIDTH]); + +impl PackedGoldilocksAVX2 { + #[inline] + fn new(x: __m256i) -> Self { + unsafe { transmute(x) } + } + #[inline] + fn get(&self) -> __m256i { + unsafe { transmute(*self) } + } +} + +impl Add for PackedGoldilocksAVX2 { + type Output = Self; + #[inline] + fn add(self, rhs: Self) -> Self { + Self::new(unsafe { add(self.get(), rhs.get()) }) + } +} +impl Add for PackedGoldilocksAVX2 { + type Output = Self; + #[inline] + fn add(self, rhs: Goldilocks) -> Self { + self + Self::from(rhs) + } +} +impl Add for Goldilocks { + type Output = PackedGoldilocksAVX2; + #[inline] + fn add(self, rhs: Self::Output) -> Self::Output { + Self::Output::from(self) + rhs + } +} +impl AddAssign for PackedGoldilocksAVX2 { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} +impl AddAssign for PackedGoldilocksAVX2 { + #[inline] + fn add_assign(&mut self, rhs: Goldilocks) { + *self = *self + rhs; + } +} + +impl Debug for PackedGoldilocksAVX2 { + #[inline] + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "({:?})", self.get()) + } +} + +impl Default for PackedGoldilocksAVX2 { + #[inline] + fn default() -> Self { + Self::ZERO + } +} + +impl Div for PackedGoldilocksAVX2 { + type Output = Self; + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: Goldilocks) -> Self { + self * rhs.inverse() + } +} +impl DivAssign for PackedGoldilocksAVX2 { + #[allow(clippy::suspicious_op_assign_impl)] + #[inline] + fn div_assign(&mut self, rhs: Goldilocks) { + *self *= rhs.inverse(); + } +} + +impl From for PackedGoldilocksAVX2 { + fn from(x: Goldilocks) -> Self { + Self([x; WIDTH]) + } +} + +impl Mul for PackedGoldilocksAVX2 { + type Output = Self; + #[inline] + fn mul(self, rhs: Self) -> Self { + Self::new(unsafe { mul(self.get(), rhs.get()) }) + } +} +impl Mul for PackedGoldilocksAVX2 { + type Output = Self; + #[inline] + fn mul(self, rhs: Goldilocks) -> Self { + self * Self::from(rhs) + } +} +impl Mul for Goldilocks { + type Output = PackedGoldilocksAVX2; + #[inline] + fn mul(self, rhs: PackedGoldilocksAVX2) -> Self::Output { + Self::Output::from(self) * rhs + } +} +impl MulAssign for PackedGoldilocksAVX2 { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} +impl MulAssign for PackedGoldilocksAVX2 { + #[inline] + fn mul_assign(&mut self, rhs: Goldilocks) { + *self = *self * rhs; + } +} + +impl Neg for PackedGoldilocksAVX2 { + type Output = Self; + #[inline] + fn neg(self) -> Self { + Self::new(unsafe { neg(self.get()) }) + } +} + +impl Product for PackedGoldilocksAVX2 { + #[inline] + fn product>(iter: I) -> Self { + iter.reduce(|x, y| x * y).unwrap_or(Self::ONE) + } +} + +impl PrimeCharacteristicRing for PackedGoldilocksAVX2 { + type PrimeSubfield = Goldilocks; + + const ZERO: Self = Self([Goldilocks::ZERO; WIDTH]); + const ONE: Self = Self([Goldilocks::ONE; WIDTH]); + const TWO: Self = Self([Goldilocks::TWO; WIDTH]); + const NEG_ONE: Self = Self([Goldilocks::NEG_ONE; WIDTH]); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f.into() + } + + #[inline] + fn square(&self) -> Self { + Self::new(unsafe { square(self.get()) }) + } + + #[inline] + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(Goldilocks::zero_vec(len * WIDTH)) } + } +} + +// Degree of the smallest permutation polynomial for Goldilocks. +// +// As p - 1 = 2^32 * 3 * 5 * 17 * ... the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 7. +impl InjectiveMonomial<7> for PackedGoldilocksAVX2 {} + +impl PermutationMonomial<7> for PackedGoldilocksAVX2 { + /// In the field `Goldilocks`, `a^{1/7}` is equal to a^{10540996611094048183}. + /// + /// This follows from the calculation `7*10540996611094048183 = 4*(2^64 - 2**32) + 1 = 1 mod (p - 1)`. + fn injective_exp_root_n(&self) -> Self { + exp_10540996611094048183(*self) + } +} + +impl Algebra for PackedGoldilocksAVX2 {} + +unsafe impl PackedValue for PackedGoldilocksAVX2 { + type Value = Goldilocks; + + const WIDTH: usize = WIDTH; + + #[inline] + fn from_slice(slice: &[Goldilocks]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { &*slice.as_ptr().cast() } + } + #[inline] + fn from_slice_mut(slice: &mut [Goldilocks]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { &mut *slice.as_mut_ptr().cast() } + } + #[inline] + fn as_slice(&self) -> &[Goldilocks] { + &self.0[..] + } + #[inline] + fn as_slice_mut(&mut self) -> &mut [Goldilocks] { + &mut self.0[..] + } + + /// Similar to `core:array::from_fn`. + #[inline] + fn from_fn Goldilocks>(f: F) -> Self { + let vals_arr: [_; WIDTH] = core::array::from_fn(f); + Self(vals_arr) + } +} + +unsafe impl PackedField for PackedGoldilocksAVX2 { + type Scalar = Goldilocks; +} + +unsafe impl PackedFieldPow2 for PackedGoldilocksAVX2 { + #[inline] + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { + let (v0, v1) = (self.get(), other.get()); + let (res0, res1) = match block_len { + 1 => unsafe { interleave1(v0, v1) }, + 2 => unsafe { interleave2(v0, v1) }, + 4 => (v0, v1), + _ => panic!("unsupported block_len"), + }; + (Self::new(res0), Self::new(res1)) + } +} + +impl Sub for PackedGoldilocksAVX2 { + type Output = Self; + #[inline] + fn sub(self, rhs: Self) -> Self { + Self::new(unsafe { sub(self.get(), rhs.get()) }) + } +} +impl Sub for PackedGoldilocksAVX2 { + type Output = Self; + #[inline] + fn sub(self, rhs: Goldilocks) -> Self { + self - Self::from(rhs) + } +} +impl Sub for Goldilocks { + type Output = PackedGoldilocksAVX2; + #[inline] + fn sub(self, rhs: PackedGoldilocksAVX2) -> Self::Output { + Self::Output::from(self) - rhs + } +} +impl SubAssign for PackedGoldilocksAVX2 { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} +impl SubAssign for PackedGoldilocksAVX2 { + #[inline] + fn sub_assign(&mut self, rhs: Goldilocks) { + *self = *self - rhs; + } +} + +impl Sum for PackedGoldilocksAVX2 { + #[inline] + fn sum>(iter: I) -> Self { + iter.reduce(|x, y| x + y).unwrap_or(Self::ZERO) + } +} + +impl Distribution for StandardUniform { + #[inline] + fn sample(&self, rng: &mut R) -> PackedGoldilocksAVX2 { + PackedGoldilocksAVX2(rng.random()) + } +} + +// Resources: +// 1. Intel Intrinsics Guide for explanation of each intrinsic: +// https://software.intel.com/sites/landingpage/IntrinsicsGuide/ +// 2. uops.info lists micro-ops for each instruction: https://uops.info/table.html +// 3. Intel optimization manual for introduction to x86 vector extensions and best practices: +// https://software.intel.com/content/www/us/en/develop/download/intel-64-and-ia-32-architectures-optimization-reference-manual.html + +// Preliminary knowledge: +// 1. Vector code usually avoids branching. Instead of branches, we can do input selection with +// _mm256_blendv_epi8 or similar instruction. If all we're doing is conditionally zeroing a +// vector element then _mm256_and_si256 or _mm256_andnot_si256 may be used and are cheaper. +// +// 2. AVX does not support addition with carry but 128-bit (2-word) addition can be easily +// emulated. The method recognizes that for a + b overflowed iff (a + b) < a: +// i. res_lo = a_lo + b_lo +// ii. carry_mask = res_lo < a_lo +// iii. res_hi = a_hi + b_hi - carry_mask +// Notice that carry_mask is subtracted, not added. This is because AVX comparison instructions +// return -1 (all bits 1) for true and 0 for false. +// +// 3. AVX does not have unsigned 64-bit comparisons. Those can be emulated with signed comparisons +// by recognizing that a __m256i { + unsafe { _mm256_xor_si256(x, SIGN_BIT) } +} + +/// Convert to canonical representation. +/// The argument is assumed to be shifted by 1 << 63 (i.e. x_s = x + 1<<63, where x is the field +/// value). The returned value is similarly shifted by 1 << 63 (i.e. we return y_s = y + (1<<63), +/// where 0 <= y < FIELD_ORDER). +#[inline] +unsafe fn canonicalize_s(x_s: __m256i) -> __m256i { + unsafe { + // If x >= FIELD_ORDER then corresponding mask bits are all 0; otherwise all 1. + let mask = _mm256_cmpgt_epi64(SHIFTED_FIELD_ORDER, x_s); + // wrapback_amt is -FIELD_ORDER if mask is 0; otherwise 0. + let wrapback_amt = _mm256_andnot_si256(mask, EPSILON); + _mm256_add_epi64(x_s, wrapback_amt) + } +} + +/// Addition u64 + u64 -> u64. Assumes that x + y < 2^64 + FIELD_ORDER. The second argument is +/// pre-shifted by 1 << 63. The result is similarly shifted. +#[inline] +unsafe fn add_no_double_overflow_64_64s_s(x: __m256i, y_s: __m256i) -> __m256i { + unsafe { + let res_wrapped_s = _mm256_add_epi64(x, y_s); + let mask = _mm256_cmpgt_epi64(y_s, res_wrapped_s); // -1 if overflowed else 0. + let wrapback_amt = _mm256_srli_epi64::<32>(mask); // -FIELD_ORDER if overflowed else 0. + _mm256_add_epi64(res_wrapped_s, wrapback_amt) + } +} + +#[inline] +unsafe fn add(x: __m256i, y: __m256i) -> __m256i { + unsafe { + let y_s = shift(y); + let res_s = add_no_double_overflow_64_64s_s(x, canonicalize_s(y_s)); + shift(res_s) + } +} + +#[inline] +unsafe fn sub(x: __m256i, y: __m256i) -> __m256i { + unsafe { + let mut y_s = shift(y); + y_s = canonicalize_s(y_s); + let x_s = shift(x); + let mask = _mm256_cmpgt_epi64(y_s, x_s); // -1 if sub will underflow (y > x) else 0. + let wrapback_amt = _mm256_srli_epi64::<32>(mask); // -FIELD_ORDER if underflow else 0. + let res_wrapped = _mm256_sub_epi64(x_s, y_s); + _mm256_sub_epi64(res_wrapped, wrapback_amt) + } +} + +#[inline] +unsafe fn neg(y: __m256i) -> __m256i { + unsafe { + let y_s = shift(y); + _mm256_sub_epi64(SHIFTED_FIELD_ORDER, canonicalize_s(y_s)) + } +} + +/// Full 64-bit by 64-bit multiplication. This emulated multiplication is 1.33x slower than the +/// scalar instruction, but may be worth it if we want our data to live in vector registers. +#[inline] +unsafe fn mul64_64(x: __m256i, y: __m256i) -> (__m256i, __m256i) { + unsafe { + // We want to move the high 32 bits to the low position. The multiplication instruction ignores + // the high 32 bits, so it's ok to just duplicate it into the low position. This duplication can + // be done on port 5; bitshifts run on ports 0 and 1, competing with multiplication. + // This instruction is only provided for 32-bit floats, not integers. Idk why Intel makes the + // distinction; the casts are free and it guarantees that the exact bit pattern is preserved. + // Using a swizzle instruction of the wrong domain (float vs int) does not increase latency + // since Haswell. + let x_hi = _mm256_castps_si256(_mm256_movehdup_ps(_mm256_castsi256_ps(x))); + let y_hi = _mm256_castps_si256(_mm256_movehdup_ps(_mm256_castsi256_ps(y))); + + // All four pairwise multiplications + let mul_ll = _mm256_mul_epu32(x, y); + let mul_lh = _mm256_mul_epu32(x, y_hi); + let mul_hl = _mm256_mul_epu32(x_hi, y); + let mul_hh = _mm256_mul_epu32(x_hi, y_hi); + + // Bignum addition + // Extract high 32 bits of mul_ll and add to mul_hl. This cannot overflow. + let mul_ll_hi = _mm256_srli_epi64::<32>(mul_ll); + let t0 = _mm256_add_epi64(mul_hl, mul_ll_hi); + // Extract low 32 bits of t0 and add to mul_lh. Again, this cannot overflow. + // Also, extract high 32 bits of t0 and add to mul_hh. + let t0_lo = _mm256_and_si256(t0, EPSILON); + let t0_hi = _mm256_srli_epi64::<32>(t0); + let t1 = _mm256_add_epi64(mul_lh, t0_lo); + let t2 = _mm256_add_epi64(mul_hh, t0_hi); + // Lastly, extract the high 32 bits of t1 and add to t2. + let t1_hi = _mm256_srli_epi64::<32>(t1); + let res_hi = _mm256_add_epi64(t2, t1_hi); + + // Form res_lo by combining the low half of mul_ll with the low half of t1 (shifted into high + // position). + let t1_lo = _mm256_castps_si256(_mm256_moveldup_ps(_mm256_castsi256_ps(t1))); + let res_lo = _mm256_blend_epi32::<0xaa>(mul_ll, t1_lo); + + (res_hi, res_lo) + } +} + +/// Full 64-bit squaring. This routine is 1.2x faster than the scalar instruction. +#[inline] +unsafe fn square64(x: __m256i) -> (__m256i, __m256i) { + unsafe { + // Get high 32 bits of x. See comment in mul64_64_s. + let x_hi = _mm256_castps_si256(_mm256_movehdup_ps(_mm256_castsi256_ps(x))); + + // All pairwise multiplications. + let mul_ll = _mm256_mul_epu32(x, x); + let mul_lh = _mm256_mul_epu32(x, x_hi); + let mul_hh = _mm256_mul_epu32(x_hi, x_hi); + + // Bignum addition, but mul_lh is shifted by 33 bits (not 32). + let mul_ll_hi = _mm256_srli_epi64::<33>(mul_ll); + let t0 = _mm256_add_epi64(mul_lh, mul_ll_hi); + let t0_hi = _mm256_srli_epi64::<31>(t0); + let res_hi = _mm256_add_epi64(mul_hh, t0_hi); + + // Form low result by adding the mul_ll and the low 31 bits of mul_lh (shifted to the high + // position). + let mul_lh_lo = _mm256_slli_epi64::<33>(mul_lh); + let res_lo = _mm256_add_epi64(mul_ll, mul_lh_lo); + + (res_hi, res_lo) + } +} + +/// Goldilocks addition of a "small" number. `x_s` is pre-shifted by 2**63. `y` is assumed to be <= +/// `0xffffffff00000000`. The result is shifted by 2**63. +#[inline] +unsafe fn add_small_64s_64_s(x_s: __m256i, y: __m256i) -> __m256i { + unsafe { + let res_wrapped_s = _mm256_add_epi64(x_s, y); + // 32-bit compare is faster than 64-bit. It's safe as long as x > res_wrapped iff x >> 32 > + // res_wrapped >> 32. The case of x >> 32 > res_wrapped >> 32 is trivial and so is <. The case + // where x >> 32 = res_wrapped >> 32 remains. If x >> 32 = res_wrapped >> 32, then y >> 32 = + // 0xffffffff and the addition of the low 32 bits generated a carry. This can never occur if y + // <= 0xffffffff00000000: if y >> 32 = 0xffffffff, then no carry can occur. + let mask = _mm256_cmpgt_epi32(x_s, res_wrapped_s); // -1 if overflowed else 0. + // The mask contains 0xffffffff in the high 32 bits if wraparound occurred and 0 otherwise. + let wrapback_amt = _mm256_srli_epi64::<32>(mask); // -FIELD_ORDER if overflowed else 0. + _mm256_add_epi64(res_wrapped_s, wrapback_amt) + } +} + +/// Goldilocks subtraction of a "small" number. `x_s` is pre-shifted by 2**63. `y` is assumed to be +/// <= `0xffffffff00000000`. The result is shifted by 2**63. +#[inline] +unsafe fn sub_small_64s_64_s(x_s: __m256i, y: __m256i) -> __m256i { + unsafe { + let res_wrapped_s = _mm256_sub_epi64(x_s, y); + // 32-bit compare is faster than 64-bit. It's safe as long as res_wrapped > x iff res_wrapped >> + // 32 > x >> 32. The case of res_wrapped >> 32 > x >> 32 is trivial and so is <. The case where + // res_wrapped >> 32 = x >> 32 remains. If res_wrapped >> 32 = x >> 32, then y >> 32 = + // 0xffffffff and the subtraction of the low 32 bits generated a borrow. This can never occur if + // y <= 0xffffffff00000000: if y >> 32 = 0xffffffff, then no borrow can occur. + let mask = _mm256_cmpgt_epi32(res_wrapped_s, x_s); // -1 if underflowed else 0. + // The mask contains 0xffffffff in the high 32 bits if wraparound occurred and 0 otherwise. + let wrapback_amt = _mm256_srli_epi64::<32>(mask); // -FIELD_ORDER if underflowed else 0. + _mm256_sub_epi64(res_wrapped_s, wrapback_amt) + } +} + +#[inline] +unsafe fn reduce128(x: (__m256i, __m256i)) -> __m256i { + unsafe { + let (hi0, lo0) = x; + let lo0_s = shift(lo0); + let hi_hi0 = _mm256_srli_epi64::<32>(hi0); + let lo1_s = sub_small_64s_64_s(lo0_s, hi_hi0); + let t1 = _mm256_mul_epu32(hi0, EPSILON); + let lo2_s = add_small_64s_64_s(lo1_s, t1); + shift(lo2_s) + } +} + +/// Multiply two integers modulo FIELD_ORDER. +#[inline] +unsafe fn mul(x: __m256i, y: __m256i) -> __m256i { + unsafe { reduce128(mul64_64(x, y)) } +} + +/// Square an integer modulo FIELD_ORDER. +#[inline] +unsafe fn square(x: __m256i) -> __m256i { + unsafe { reduce128(square64(x)) } +} + +#[inline] +unsafe fn interleave1(x: __m256i, y: __m256i) -> (__m256i, __m256i) { + unsafe { + let a = _mm256_unpacklo_epi64(x, y); + let b = _mm256_unpackhi_epi64(x, y); + (a, b) + } +} + +#[inline] +unsafe fn interleave2(x: __m256i, y: __m256i) -> (__m256i, __m256i) { + unsafe { + let y_lo = _mm256_castsi256_si128(y); // This has 0 cost. + + // 1 places y_lo in the high half of x; 0 would place it in the lower half. + let a = _mm256_inserti128_si256::<1>(x, y_lo); + // NB: _mm256_permute2x128_si256 could be used here as well but _mm256_inserti128_si256 has + // lower latency on Zen 3 processors. + + // Each nibble of the constant has the following semantics: + // 0 => src1[low 128 bits] + // 1 => src1[high 128 bits] + // 2 => src2[low 128 bits] + // 3 => src2[high 128 bits] + // The low (resp. high) nibble chooses the low (resp. high) 128 bits of the result. + let b = _mm256_permute2x128_si256::<0x31>(x, y); + + (a, b) + } +} + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::{Goldilocks, PackedGoldilocksAVX2, WIDTH}; + + const SPECIAL_VALS: [Goldilocks; WIDTH] = Goldilocks::new_array([ + 0xFFFF_FFFF_0000_0000, + 0xFFFF_FFFF_FFFF_FFFF, + 0x0000_0000_0000_0001, + 0xFFFF_FFFF_0000_0001, + ]); + + const ZEROS: PackedGoldilocksAVX2 = PackedGoldilocksAVX2(Goldilocks::new_array([ + 0x0000_0000_0000_0000, + 0xFFFF_FFFF_0000_0001, + 0x0000_0000_0000_0000, + 0xFFFF_FFFF_0000_0001, + ])); + + const ONES: PackedGoldilocksAVX2 = PackedGoldilocksAVX2(Goldilocks::new_array([ + 0x0000_0000_0000_0001, + 0xFFFF_FFFF_0000_0002, + 0x0000_0000_0000_0001, + 0xFFFF_FFFF_0000_0002, + ])); + + test_packed_field!( + crate::PackedGoldilocksAVX2, + &[super::ZEROS], + &[super::ONES], + crate::PackedGoldilocksAVX2(super::SPECIAL_VALS) + ); +} diff --git a/CoqOfRust/plonky3/goldilocks/src/x86_64_avx512/mds.rs b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx512/mds.rs new file mode 100644 index 000000000..230cfd87c --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx512/mds.rs @@ -0,0 +1,155 @@ +use p3_mds::MdsPermutation; +use p3_mds::util::apply_circulant; +use p3_symmetric::Permutation; + +use crate::x86_64_avx512::packing::PackedGoldilocksAVX512; +use crate::{ + MATRIX_CIRC_MDS_8_SML_ROW, MATRIX_CIRC_MDS_12_SML_ROW, MATRIX_CIRC_MDS_16_SML_ROW, + MATRIX_CIRC_MDS_24_GOLDILOCKS, MdsMatrixGoldilocks, +}; +const fn convert_array(arr: [i64; N]) -> [u64; N] { + let mut result: [u64; N] = [0; N]; + let mut i = 0; + while i < N { + result[i] = arr[i] as u64; + i += 1; + } + result +} + +impl Permutation<[PackedGoldilocksAVX512; 8]> for MdsMatrixGoldilocks { + fn permute(&self, input: [PackedGoldilocksAVX512; 8]) -> [PackedGoldilocksAVX512; 8] { + const MATRIX_CIRC_MDS_8_SML_ROW_U64: [u64; 8] = convert_array(MATRIX_CIRC_MDS_8_SML_ROW); + apply_circulant(&MATRIX_CIRC_MDS_8_SML_ROW_U64, input) + } + + fn permute_mut(&self, input: &mut [PackedGoldilocksAVX512; 8]) { + *input = self.permute(*input); + } +} + +impl MdsPermutation for MdsMatrixGoldilocks {} + +impl Permutation<[PackedGoldilocksAVX512; 12]> for MdsMatrixGoldilocks { + fn permute(&self, input: [PackedGoldilocksAVX512; 12]) -> [PackedGoldilocksAVX512; 12] { + const MATRIX_CIRC_MDS_12_SML_ROW_U64: [u64; 12] = convert_array(MATRIX_CIRC_MDS_12_SML_ROW); + apply_circulant(&MATRIX_CIRC_MDS_12_SML_ROW_U64, input) + } + + fn permute_mut(&self, input: &mut [PackedGoldilocksAVX512; 12]) { + *input = self.permute(*input); + } +} + +impl MdsPermutation for MdsMatrixGoldilocks {} + +impl Permutation<[PackedGoldilocksAVX512; 16]> for MdsMatrixGoldilocks { + fn permute(&self, input: [PackedGoldilocksAVX512; 16]) -> [PackedGoldilocksAVX512; 16] { + const MATRIX_CIRC_MDS_16_SML_ROW_U64: [u64; 16] = convert_array(MATRIX_CIRC_MDS_16_SML_ROW); + apply_circulant(&MATRIX_CIRC_MDS_16_SML_ROW_U64, input) + } + + fn permute_mut(&self, input: &mut [PackedGoldilocksAVX512; 16]) { + *input = self.permute(*input); + } +} + +impl MdsPermutation for MdsMatrixGoldilocks {} + +impl Permutation<[PackedGoldilocksAVX512; 24]> for MdsMatrixGoldilocks { + fn permute(&self, input: [PackedGoldilocksAVX512; 24]) -> [PackedGoldilocksAVX512; 24] { + apply_circulant(&MATRIX_CIRC_MDS_24_GOLDILOCKS, input) + } + + fn permute_mut(&self, input: &mut [PackedGoldilocksAVX512; 24]) { + *input = self.permute(*input); + } +} + +impl MdsPermutation for MdsMatrixGoldilocks {} + +#[cfg(test)] +mod tests { + use p3_poseidon::Poseidon; + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use crate::{Goldilocks, MdsMatrixGoldilocks, PackedGoldilocksAVX512}; + + #[test] + fn test_avx512_poseidon_width_8() { + let mut rng = SmallRng::seed_from_u64(1); + type F = Goldilocks; + type Perm = Poseidon; + let poseidon = Perm::new_from_rng(4, 22, MdsMatrixGoldilocks, &mut rng); + + let input: [F; 8] = rng.random(); + + let mut expected = input; + poseidon.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + assert_eq!(avx2_output, expected); + } + + #[test] + fn test_avx512_poseidon_width_12() { + let mut rng = SmallRng::seed_from_u64(1); + type F = Goldilocks; + type Perm = Poseidon; + let poseidon = Perm::new_from_rng(4, 22, MdsMatrixGoldilocks, &mut rng); + + let input: [F; 12] = rng.random(); + + let mut expected = input; + poseidon.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + assert_eq!(avx2_output, expected); + } + + #[test] + fn test_avx512_poseidon_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + type F = Goldilocks; + type Perm = Poseidon; + let poseidon = Perm::new_from_rng(4, 22, MdsMatrixGoldilocks, &mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + assert_eq!(avx2_output, expected); + } + + #[test] + fn test_avx512_poseidon_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + type F = Goldilocks; + type Perm = Poseidon; + let poseidon = Perm::new_from_rng(4, 22, MdsMatrixGoldilocks, &mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + assert_eq!(avx2_output, expected); + } +} diff --git a/CoqOfRust/plonky3/goldilocks/src/x86_64_avx512/mod.rs b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx512/mod.rs new file mode 100644 index 000000000..09300a20f --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx512/mod.rs @@ -0,0 +1,3 @@ +mod mds; +mod packing; +pub use packing::*; diff --git a/CoqOfRust/plonky3/goldilocks/src/x86_64_avx512/packing.rs b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx512/packing.rs new file mode 100644 index 000000000..2d8f7eb59 --- /dev/null +++ b/CoqOfRust/plonky3/goldilocks/src/x86_64_avx512/packing.rs @@ -0,0 +1,521 @@ +use alloc::vec::Vec; +use core::arch::x86_64::*; +use core::fmt; +use core::fmt::{Debug, Formatter}; +use core::iter::{Product, Sum}; +use core::mem::transmute; +use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; + +use p3_field::exponentiation::exp_10540996611094048183; +use p3_field::{ + Algebra, Field, InjectiveMonomial, PackedField, PackedFieldPow2, PackedValue, + PermutationMonomial, PrimeCharacteristicRing, PrimeField64, +}; +use p3_util::reconstitute_from_base; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; + +use crate::Goldilocks; + +const WIDTH: usize = 8; +/// AVX512 Goldilocks Field +/// +/// Ideally `PackedGoldilocksAVX512` would wrap `__m512i`. Unfortunately, `__m512i` has an alignment +/// of 64B, which would preclude us from casting `[Goldilocks; 8]` (alignment 8B) to +/// `PackedGoldilocksAVX512`. We need to ensure that `PackedGoldilocksAVX512` has the same alignment as +/// `Goldilocks`. Thus we wrap `[Goldilocks; 8]` and use the `new` and `get` methods to +/// convert to and from `__m512i`. +#[derive(Copy, Clone, PartialEq, Eq)] +#[repr(transparent)] +pub struct PackedGoldilocksAVX512(pub [Goldilocks; WIDTH]); + +impl PackedGoldilocksAVX512 { + #[inline] + fn new(x: __m512i) -> Self { + unsafe { transmute(x) } + } + #[inline] + fn get(&self) -> __m512i { + unsafe { transmute(*self) } + } +} + +impl Add for PackedGoldilocksAVX512 { + type Output = Self; + #[inline] + fn add(self, rhs: Self) -> Self { + Self::new(unsafe { add(self.get(), rhs.get()) }) + } +} +impl Add for PackedGoldilocksAVX512 { + type Output = Self; + #[inline] + fn add(self, rhs: Goldilocks) -> Self { + self + Self::from(rhs) + } +} +impl Add for Goldilocks { + type Output = PackedGoldilocksAVX512; + #[inline] + fn add(self, rhs: Self::Output) -> Self::Output { + Self::Output::from(self) + rhs + } +} +impl AddAssign for PackedGoldilocksAVX512 { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} +impl AddAssign for PackedGoldilocksAVX512 { + #[inline] + fn add_assign(&mut self, rhs: Goldilocks) { + *self = *self + rhs; + } +} + +impl Debug for PackedGoldilocksAVX512 { + #[inline] + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "({:?})", self.get()) + } +} + +impl Default for PackedGoldilocksAVX512 { + #[inline] + fn default() -> Self { + Self::ZERO + } +} + +impl Div for PackedGoldilocksAVX512 { + type Output = Self; + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: Goldilocks) -> Self { + self * rhs.inverse() + } +} +impl DivAssign for PackedGoldilocksAVX512 { + #[allow(clippy::suspicious_op_assign_impl)] + #[inline] + fn div_assign(&mut self, rhs: Goldilocks) { + *self *= rhs.inverse(); + } +} + +impl From for PackedGoldilocksAVX512 { + fn from(x: Goldilocks) -> Self { + Self([x; WIDTH]) + } +} + +impl Mul for PackedGoldilocksAVX512 { + type Output = Self; + #[inline] + fn mul(self, rhs: Self) -> Self { + Self::new(unsafe { mul(self.get(), rhs.get()) }) + } +} +impl Mul for PackedGoldilocksAVX512 { + type Output = Self; + #[inline] + fn mul(self, rhs: Goldilocks) -> Self { + self * Self::from(rhs) + } +} +impl Mul for Goldilocks { + type Output = PackedGoldilocksAVX512; + #[inline] + fn mul(self, rhs: PackedGoldilocksAVX512) -> Self::Output { + Self::Output::from(self) * rhs + } +} +impl MulAssign for PackedGoldilocksAVX512 { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} +impl MulAssign for PackedGoldilocksAVX512 { + #[inline] + fn mul_assign(&mut self, rhs: Goldilocks) { + *self = *self * rhs; + } +} + +impl Neg for PackedGoldilocksAVX512 { + type Output = Self; + #[inline] + fn neg(self) -> Self { + Self::new(unsafe { neg(self.get()) }) + } +} + +impl Product for PackedGoldilocksAVX512 { + #[inline] + fn product>(iter: I) -> Self { + iter.reduce(|x, y| x * y).unwrap_or(Self::ONE) + } +} + +impl PrimeCharacteristicRing for PackedGoldilocksAVX512 { + type PrimeSubfield = Goldilocks; + + const ZERO: Self = Self([Goldilocks::ZERO; WIDTH]); + const ONE: Self = Self([Goldilocks::ONE; WIDTH]); + const TWO: Self = Self([Goldilocks::TWO; WIDTH]); + const NEG_ONE: Self = Self([Goldilocks::NEG_ONE; WIDTH]); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f.into() + } + + #[inline] + fn square(&self) -> Self { + Self::new(unsafe { square(self.get()) }) + } + + #[inline] + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(Goldilocks::zero_vec(len * WIDTH)) } + } +} + +impl Algebra for PackedGoldilocksAVX512 {} + +// Degree of the smallest permutation polynomial for Goldilocks. +// +// As p - 1 = 2^32 * 3 * 5 * 17 * ... the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 7. +impl InjectiveMonomial<7> for PackedGoldilocksAVX512 {} + +impl PermutationMonomial<7> for PackedGoldilocksAVX512 { + /// In the field `Goldilocks`, `a^{1/7}` is equal to a^{10540996611094048183}. + /// + /// This follows from the calculation `7*10540996611094048183 = 4*(2^64 - 2**32) + 1 = 1 mod (p - 1)`. + fn injective_exp_root_n(&self) -> Self { + exp_10540996611094048183(*self) + } +} + +unsafe impl PackedValue for PackedGoldilocksAVX512 { + type Value = Goldilocks; + + const WIDTH: usize = WIDTH; + + #[inline] + fn from_slice(slice: &[Goldilocks]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { &*slice.as_ptr().cast() } + } + #[inline] + fn from_slice_mut(slice: &mut [Goldilocks]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { &mut *slice.as_mut_ptr().cast() } + } + #[inline] + fn as_slice(&self) -> &[Goldilocks] { + &self.0[..] + } + #[inline] + fn as_slice_mut(&mut self) -> &mut [Goldilocks] { + &mut self.0[..] + } + + /// Similar to `core:array::from_fn`. + #[inline] + fn from_fn Goldilocks>(f: F) -> Self { + let vals_arr: [_; WIDTH] = core::array::from_fn(f); + Self(vals_arr) + } +} + +unsafe impl PackedField for PackedGoldilocksAVX512 { + type Scalar = Goldilocks; +} + +unsafe impl PackedFieldPow2 for PackedGoldilocksAVX512 { + #[inline] + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { + let (v0, v1) = (self.get(), other.get()); + let (res0, res1) = match block_len { + 1 => unsafe { interleave1(v0, v1) }, + 2 => unsafe { interleave2(v0, v1) }, + 4 => unsafe { interleave4(v0, v1) }, + 8 => (v0, v1), + _ => panic!("unsupported block_len"), + }; + (Self::new(res0), Self::new(res1)) + } +} + +impl Sub for PackedGoldilocksAVX512 { + type Output = Self; + #[inline] + fn sub(self, rhs: Self) -> Self { + Self::new(unsafe { sub(self.get(), rhs.get()) }) + } +} +impl Sub for PackedGoldilocksAVX512 { + type Output = Self; + #[inline] + fn sub(self, rhs: Goldilocks) -> Self { + self - Self::from(rhs) + } +} +impl Sub for Goldilocks { + type Output = PackedGoldilocksAVX512; + #[inline] + fn sub(self, rhs: PackedGoldilocksAVX512) -> Self::Output { + Self::Output::from(self) - rhs + } +} +impl SubAssign for PackedGoldilocksAVX512 { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} +impl SubAssign for PackedGoldilocksAVX512 { + #[inline] + fn sub_assign(&mut self, rhs: Goldilocks) { + *self = *self - rhs; + } +} + +impl Sum for PackedGoldilocksAVX512 { + #[inline] + fn sum>(iter: I) -> Self { + iter.reduce(|x, y| x + y).unwrap_or(Self::ZERO) + } +} + +impl Distribution for StandardUniform { + #[inline] + fn sample(&self, rng: &mut R) -> PackedGoldilocksAVX512 { + PackedGoldilocksAVX512(rng.random()) + } +} + +const FIELD_ORDER: __m512i = unsafe { transmute([Goldilocks::ORDER_U64; WIDTH]) }; +const EPSILON: __m512i = unsafe { transmute([Goldilocks::ORDER_U64.wrapping_neg(); WIDTH]) }; + +#[inline] +unsafe fn canonicalize(x: __m512i) -> __m512i { + unsafe { + let mask = _mm512_cmpge_epu64_mask(x, FIELD_ORDER); + _mm512_mask_sub_epi64(x, mask, x, FIELD_ORDER) + } +} + +#[inline] +unsafe fn add_no_double_overflow_64_64(x: __m512i, y: __m512i) -> __m512i { + unsafe { + let res_wrapped = _mm512_add_epi64(x, y); + let mask = _mm512_cmplt_epu64_mask(res_wrapped, y); // mask set if add overflowed + _mm512_mask_sub_epi64(res_wrapped, mask, res_wrapped, FIELD_ORDER) + } +} + +#[inline] +unsafe fn sub_no_double_overflow_64_64(x: __m512i, y: __m512i) -> __m512i { + unsafe { + let mask = _mm512_cmplt_epu64_mask(x, y); // mask set if sub will underflow (x < y) + let res_wrapped = _mm512_sub_epi64(x, y); + _mm512_mask_add_epi64(res_wrapped, mask, res_wrapped, FIELD_ORDER) + } +} + +#[inline] +unsafe fn add(x: __m512i, y: __m512i) -> __m512i { + unsafe { add_no_double_overflow_64_64(x, canonicalize(y)) } +} + +#[inline] +unsafe fn sub(x: __m512i, y: __m512i) -> __m512i { + unsafe { sub_no_double_overflow_64_64(x, canonicalize(y)) } +} + +#[inline] +unsafe fn neg(y: __m512i) -> __m512i { + unsafe { _mm512_sub_epi64(FIELD_ORDER, canonicalize(y)) } +} + +#[allow(clippy::useless_transmute)] +const LO_32_BITS_MASK: __mmask16 = unsafe { transmute(0b0101010101010101u16) }; + +#[inline] +unsafe fn mul64_64(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + unsafe { + // We want to move the high 32 bits to the low position. The multiplication instruction ignores + // the high 32 bits, so it's ok to just duplicate it into the low position. This duplication can + // be done on port 5; bitshifts run on port 0, competing with multiplication. + // This instruction is only provided for 32-bit floats, not integers. Idk why Intel makes the + // distinction; the casts are free and it guarantees that the exact bit pattern is preserved. + // Using a swizzle instruction of the wrong domain (float vs int) does not increase latency + // since Haswell. + let x_hi = _mm512_castps_si512(_mm512_movehdup_ps(_mm512_castsi512_ps(x))); + let y_hi = _mm512_castps_si512(_mm512_movehdup_ps(_mm512_castsi512_ps(y))); + + // All four pairwise multiplications + let mul_ll = _mm512_mul_epu32(x, y); + let mul_lh = _mm512_mul_epu32(x, y_hi); + let mul_hl = _mm512_mul_epu32(x_hi, y); + let mul_hh = _mm512_mul_epu32(x_hi, y_hi); + + // Bignum addition + // Extract high 32 bits of mul_ll and add to mul_hl. This cannot overflow. + let mul_ll_hi = _mm512_srli_epi64::<32>(mul_ll); + let t0 = _mm512_add_epi64(mul_hl, mul_ll_hi); + // Extract low 32 bits of t0 and add to mul_lh. Again, this cannot overflow. + // Also, extract high 32 bits of t0 and add to mul_hh. + let t0_lo = _mm512_and_si512(t0, EPSILON); + let t0_hi = _mm512_srli_epi64::<32>(t0); + let t1 = _mm512_add_epi64(mul_lh, t0_lo); + let t2 = _mm512_add_epi64(mul_hh, t0_hi); + // Lastly, extract the high 32 bits of t1 and add to t2. + let t1_hi = _mm512_srli_epi64::<32>(t1); + let res_hi = _mm512_add_epi64(t2, t1_hi); + + // Form res_lo by combining the low half of mul_ll with the low half of t1 (shifted into high + // position). + let t1_lo = _mm512_castps_si512(_mm512_moveldup_ps(_mm512_castsi512_ps(t1))); + let res_lo = _mm512_mask_blend_epi32(LO_32_BITS_MASK, t1_lo, mul_ll); + + (res_hi, res_lo) + } +} + +#[inline] +unsafe fn square64(x: __m512i) -> (__m512i, __m512i) { + unsafe { + // Get high 32 bits of x. See comment in mul64_64_s. + let x_hi = _mm512_castps_si512(_mm512_movehdup_ps(_mm512_castsi512_ps(x))); + + // All pairwise multiplications. + let mul_ll = _mm512_mul_epu32(x, x); + let mul_lh = _mm512_mul_epu32(x, x_hi); + let mul_hh = _mm512_mul_epu32(x_hi, x_hi); + + // Bignum addition, but mul_lh is shifted by 33 bits (not 32). + let mul_ll_hi = _mm512_srli_epi64::<33>(mul_ll); + let t0 = _mm512_add_epi64(mul_lh, mul_ll_hi); + let t0_hi = _mm512_srli_epi64::<31>(t0); + let res_hi = _mm512_add_epi64(mul_hh, t0_hi); + + // Form low result by adding the mul_ll and the low 31 bits of mul_lh (shifted to the high + // position). + let mul_lh_lo = _mm512_slli_epi64::<33>(mul_lh); + let res_lo = _mm512_add_epi64(mul_ll, mul_lh_lo); + + (res_hi, res_lo) + } +} + +#[inline] +unsafe fn reduce128(x: (__m512i, __m512i)) -> __m512i { + unsafe { + let (hi0, lo0) = x; + let hi_hi0 = _mm512_srli_epi64::<32>(hi0); + let lo1 = sub_no_double_overflow_64_64(lo0, hi_hi0); + let t1 = _mm512_mul_epu32(hi0, EPSILON); + add_no_double_overflow_64_64(lo1, t1) + } +} + +#[inline] +unsafe fn mul(x: __m512i, y: __m512i) -> __m512i { + unsafe { reduce128(mul64_64(x, y)) } +} + +#[inline] +unsafe fn square(x: __m512i) -> __m512i { + unsafe { reduce128(square64(x)) } +} + +#[inline] +unsafe fn interleave1(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + unsafe { + let a = _mm512_unpacklo_epi64(x, y); + let b = _mm512_unpackhi_epi64(x, y); + (a, b) + } +} + +const INTERLEAVE2_IDX_A: __m512i = unsafe { + transmute([ + 0o00u64, 0o01u64, 0o10u64, 0o11u64, 0o04u64, 0o05u64, 0o14u64, 0o15u64, + ]) +}; +const INTERLEAVE2_IDX_B: __m512i = unsafe { + transmute([ + 0o02u64, 0o03u64, 0o12u64, 0o13u64, 0o06u64, 0o07u64, 0o16u64, 0o17u64, + ]) +}; + +#[inline] +unsafe fn interleave2(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + unsafe { + let a = _mm512_permutex2var_epi64(x, INTERLEAVE2_IDX_A, y); + let b = _mm512_permutex2var_epi64(x, INTERLEAVE2_IDX_B, y); + (a, b) + } +} + +#[inline] +unsafe fn interleave4(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + unsafe { + let a = _mm512_shuffle_i64x2::<0x44>(x, y); + let b = _mm512_shuffle_i64x2::<0xee>(x, y); + (a, b) + } +} + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::{Goldilocks, PackedGoldilocksAVX512, WIDTH}; + + const SPECIAL_VALS: [Goldilocks; WIDTH] = Goldilocks::new_array([ + 0xFFFF_FFFF_0000_0001, + 0xFFFF_FFFF_0000_0000, + 0xFFFF_FFFE_FFFF_FFFF, + 0xFFFF_FFFF_FFFF_FFFF, + 0x0000_0000_0000_0000, + 0x0000_0000_0000_0001, + 0x0000_0000_0000_0002, + 0x0FFF_FFFF_F000_0000, + ]); + + const ZEROS: PackedGoldilocksAVX512 = PackedGoldilocksAVX512(Goldilocks::new_array([ + 0x0000_0000_0000_0000, + 0xFFFF_FFFF_0000_0001, + 0x0000_0000_0000_0000, + 0xFFFF_FFFF_0000_0001, + 0x0000_0000_0000_0000, + 0xFFFF_FFFF_0000_0001, + 0x0000_0000_0000_0000, + 0xFFFF_FFFF_0000_0001, + ])); + + const ONES: PackedGoldilocksAVX512 = PackedGoldilocksAVX512(Goldilocks::new_array([ + 0x0000_0000_0000_0001, + 0xFFFF_FFFF_0000_0002, + 0x0000_0000_0000_0001, + 0xFFFF_FFFF_0000_0002, + 0x0000_0000_0000_0001, + 0xFFFF_FFFF_0000_0002, + 0x0000_0000_0000_0001, + 0xFFFF_FFFF_0000_0002, + ])); + + test_packed_field!( + crate::PackedGoldilocksAVX512, + &[super::ZEROS], + &[super::ONES], + crate::PackedGoldilocksAVX512(super::SPECIAL_VALS) + ); +} diff --git a/CoqOfRust/plonky3/interpolation/src/lib.rs b/CoqOfRust/plonky3/interpolation/src/lib.rs new file mode 100644 index 000000000..0416d9aea --- /dev/null +++ b/CoqOfRust/plonky3/interpolation/src/lib.rs @@ -0,0 +1,135 @@ +//! Tools for Lagrange interpolation. + +#![no_std] + +extern crate alloc; + +use alloc::vec::Vec; + +use p3_field::{ + ExtensionField, TwoAdicField, batch_multiplicative_inverse, scale_vec, + two_adic_coset_vanishing_polynomial, +}; +use p3_matrix::Matrix; +use p3_maybe_rayon::prelude::*; +use p3_util::log2_strict_usize; + +/// Given evaluations of a batch of polynomials over the canonical power-of-two subgroup, evaluate +/// the polynomials at `point`. +/// +/// This assumes the point is not in the subgroup, otherwise the behavior is undefined. +pub fn interpolate_subgroup(subgroup_evals: &Mat, point: EF) -> Vec +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + Mat: Matrix, +{ + interpolate_coset(subgroup_evals, F::ONE, point, None) +} + +/// Given evaluations of a batch of polynomials over the given coset of the canonical power-of-two +/// subgroup, evaluate the polynomials at `point`. +/// +/// This assumes the point is not in the coset, otherwise the behavior is undefined. +/// If available, reuse denominator diffs that is `1 / (x_i-z)` to avoid batch inversion. +pub fn interpolate_coset( + coset_evals: &Mat, + shift: F, + point: EF, + diff_invs: Option<&[EF]>, +) -> Vec +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + Mat: Matrix, +{ + // Slight variation of this approach: https://hackmd.io/@vbuterin/barycentric_evaluation + + let height = coset_evals.height(); + let log_height = log2_strict_usize(height); + + let g = F::two_adic_generator(log_height).powers().take(height); + let col_scale: Vec<_> = if let Some(diff_invs) = diff_invs { + g.zip(diff_invs) + .map(|(sg, &diff_inv)| diff_inv * sg) + .collect() + } else { + let subgroup = g.collect::>(); + let diffs: Vec = subgroup + .par_iter() + .map(|&subgroup_i| point - subgroup_i * shift) + .collect(); + let diff_invs = batch_multiplicative_inverse(&diffs); + subgroup + .par_iter() + .zip(diff_invs) + .map(|(&sg, diff_inv)| diff_inv * sg) + .collect() + }; + let sum = coset_evals.columnwise_dot_product(&col_scale); + + let vanishing_polynomial = + two_adic_coset_vanishing_polynomial::(log_height, shift.into(), point); + + // In principle, height could be bigger than the characteristic of F. + let denominator = shift + .exp_u64(height as u64 - 1) + .mul_2exp_u64(log_height as u64); + scale_vec(vanishing_polynomial * denominator.inverse(), sum) +} + +#[cfg(test)] +mod tests { + use alloc::vec; + use alloc::vec::Vec; + + use p3_baby_bear::BabyBear; + use p3_field::{Field, PrimeCharacteristicRing, batch_multiplicative_inverse}; + use p3_matrix::dense::RowMajorMatrix; + use p3_util::log2_strict_usize; + + use crate::{interpolate_coset, interpolate_subgroup}; + + #[test] + fn test_interpolate_subgroup() { + // x^2 + 2 x + 3 + type F = BabyBear; + let evals = [ + 6, 886605102, 1443543107, 708307799, 2, 556938009, 569722818, 1874680944, + ] + .map(F::from_u32); + let evals_mat = RowMajorMatrix::new(evals.to_vec(), 1); + let point = F::from_u16(100); + let result = interpolate_subgroup(&evals_mat, point); + assert_eq!(result, vec![F::from_u16(10203)]); + } + + #[test] + fn test_interpolate_coset() { + // x^2 + 2 x + 3 + type F = BabyBear; + let shift = F::GENERATOR; + let evals = [ + 1026, 129027310, 457985035, 994890337, 902, 1988942953, 1555278970, 913671254, + ] + .map(F::from_u32); + let evals_mat = RowMajorMatrix::new(evals.to_vec(), 1); + let point = F::from_u16(100); + let result = interpolate_coset(&evals_mat, shift, point, None); + assert_eq!(result, vec![F::from_u16(10203)]); + + use p3_field::TwoAdicField; + let n = evals.len(); + let k = log2_strict_usize(n); + + let denom: Vec<_> = F::two_adic_generator(k) + .shifted_powers(shift) + .take(n) + .map(|w| point - w) + .collect(); + + let denom = batch_multiplicative_inverse(&denom); + let result = interpolate_coset(&evals_mat, shift, point, Some(&denom)); + assert_eq!(result, vec![F::from_u16(10203)]); + } +} diff --git a/CoqOfRust/plonky3/interpolation/src/lib.v b/CoqOfRust/plonky3/interpolation/src/lib.v new file mode 100644 index 000000000..184dc51aa --- /dev/null +++ b/CoqOfRust/plonky3/interpolation/src/lib.v @@ -0,0 +1,912 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +(* +pub fn interpolate_subgroup(subgroup_evals: &Mat, point: EF) -> Vec +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + Mat: Matrix, +{ + interpolate_coset(subgroup_evals, F::ONE, point, None) +} +*) +Definition interpolate_subgroup (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF; Mat ], [ subgroup_evals; point ] => + ltac:(M.monadic + (let subgroup_evals := M.alloc (| subgroup_evals |) in + let point := M.alloc (| point |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| "p3_interpolation::interpolate_coset", [], [ F; EF; Mat ] |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| subgroup_evals |) |) |); + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) |); + M.read (| point |); + Value.StructTuple "core::option::Option::None" [] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_interpolate_subgroup : + M.IsFunction.C "p3_interpolation::interpolate_subgroup" interpolate_subgroup. +Admitted. +Global Typeclasses Opaque interpolate_subgroup. + +(* +pub fn interpolate_coset( + coset_evals: &Mat, + shift: F, + point: EF, + diff_invs: Option<&[EF]>, +) -> Vec +where + F: TwoAdicField, + EF: ExtensionField + TwoAdicField, + Mat: Matrix, +{ + // Slight variation of this approach: https://hackmd.io/@vbuterin/barycentric_evaluation + + let height = coset_evals.height(); + let log_height = log2_strict_usize(height); + + let g = F::two_adic_generator(log_height).powers().take(height); + let col_scale: Vec<_> = if let Some(diff_invs) = diff_invs { + g.zip(diff_invs) + .map(|(sg, &diff_inv)| diff_inv * sg) + .collect() + } else { + let subgroup = g.collect::>(); + let diffs: Vec = subgroup + .par_iter() + .map(|&subgroup_i| point - subgroup_i * shift) + .collect(); + let diff_invs = batch_multiplicative_inverse(&diffs); + subgroup + .par_iter() + .zip(diff_invs) + .map(|(&sg, diff_inv)| diff_inv * sg) + .collect() + }; + let sum = coset_evals.columnwise_dot_product(&col_scale); + + let vanishing_polynomial = + two_adic_coset_vanishing_polynomial::(log_height, shift.into(), point); + + // In principle, height could be bigger than the characteristic of F. + let denominator = shift + .exp_u64(height as u64 - 1) + .mul_2exp_u64(log_height as u64); + scale_vec(vanishing_polynomial * denominator.inverse(), sum) +} +*) +Definition interpolate_coset (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; EF; Mat ], [ coset_evals; shift; point; diff_invs ] => + ltac:(M.monadic + (let coset_evals := M.alloc (| coset_evals |) in + let shift := M.alloc (| shift |) in + let point := M.alloc (| point |) in + let diff_invs := M.alloc (| diff_invs |) in + M.read (| + let~ height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| "p3_matrix::Matrix", Mat, [], [ F ], "height", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| coset_evals |) |) |) ] + |) + |) in + let~ log_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| height |) ] + |) + |) in + let~ g : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_height |) ] + |) + |) + |) + ] + |); + M.read (| height |) + ] + |) + |) in + let~ col_scale : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := diff_invs in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let diff_invs := M.copy (| γ0_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ]; + Ty.function + [ Ty.tuple [ Ty.tuple [ F; Ty.apply (Ty.path "&") [] [ EF ] ] ] ] + EF + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ]; + Ty.function + [ Ty.tuple [ Ty.tuple [ F; Ty.apply (Ty.path "&") [] [ EF ] ] ] ] + EF + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ], + [], + [], + "map", + [], + [ + EF; + Ty.function + [ Ty.tuple [ Ty.tuple [ F; Ty.apply (Ty.path "&") [] [ EF ] ] ] ] + EF + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ EF ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] ] + ] + |), + [ M.read (| g |); M.read (| diff_invs |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ F; Ty.apply (Ty.path "&") [] [ EF ] ] + ] + ] + EF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let sg := M.copy (| γ0_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let diff_inv := M.copy (| γ0_1 |) in + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| diff_inv |); M.read (| sg |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ subgroup : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ M.read (| g |) ] + |) + |) in + let~ diffs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] EF + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] EF + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "map", + [], + [ + EF; + Ty.function [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] EF + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelRefIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "par_iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, subgroup |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ] ] ] + EF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let subgroup_i := M.copy (| γ |) in + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Sub", + EF, + [], + [ F ], + "sub", + [], + [] + |), + [ + M.read (| point |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| subgroup_i |); + M.read (| shift |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ diff_invs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_field::batch_inverse::batch_multiplicative_inverse", + [], + [ EF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ EF ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, diffs |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ]; EF ] ] ] + EF + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ]; EF ] ] ] + EF + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "map", + [], + [ + EF; + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ]; EF ] ] ] + EF + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelRefIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "par_iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, subgroup |) ] + |); + M.read (| diff_invs |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ F ]; EF ] + ] + ] + EF + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let sg := M.copy (| γ0_0 |) in + let diff_inv := M.copy (| γ0_1 |) in + M.call_closure (| + EF, + M.get_trait_method (| + "core::ops::arith::Mul", + EF, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| diff_inv |); M.read (| sg |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |))) + ] + |) + |) in + let~ sum : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_matrix::Matrix", + Mat, + [], + [ F ], + "columnwise_dot_product", + [], + [ EF ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| coset_evals |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ EF ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ EF; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, col_scale |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ vanishing_polynomial : Ty.apply (Ty.path "*") [] [ EF ] := + M.alloc (| + M.call_closure (| + EF, + M.get_function (| + "p3_field::helpers::two_adic_coset_vanishing_polynomial", + [], + [ EF ] + |), + [ + M.read (| log_height |); + M.call_closure (| + EF, + M.get_trait_method (| "core::convert::Into", F, [], [ EF ], "into", [], [] |), + [ M.read (| shift |) ] + |); + M.read (| point |) + ] + |) + |) in + let~ denominator : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "mul_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, shift |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.cast (Ty.path "u64") (M.read (| height |)); + Value.Integer IntegerKind.U64 1 + ] + |) + ] + |) + |) + |); + M.cast (Ty.path "u64") (M.read (| log_height |)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ EF; Ty.path "alloc::alloc::Global" ], + M.get_function (| "p3_field::helpers::scale_vec", [], [ EF ] |), + [ + M.call_closure (| + EF, + M.get_trait_method (| "core::ops::arith::Mul", EF, [], [ F ], "mul", [], [] |), + [ + M.read (| vanishing_polynomial |); + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, denominator |) ] + |) + ] + |); + M.read (| sum |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_interpolate_coset : + M.IsFunction.C "p3_interpolation::interpolate_coset" interpolate_coset. +Admitted. +Global Typeclasses Opaque interpolate_coset. diff --git a/CoqOfRust/plonky3/keccak-air/src/air.rs b/CoqOfRust/plonky3/keccak-air/src/air.rs new file mode 100644 index 000000000..93f4b237d --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/air.rs @@ -0,0 +1,208 @@ +use alloc::vec::Vec; +use core::array; +use core::borrow::Borrow; + +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{PrimeCharacteristicRing, PrimeField64}; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use rand::rngs::SmallRng; +use rand::{Rng, SeedableRng}; + +use crate::columns::{KeccakCols, NUM_KECCAK_COLS}; +use crate::constants::rc_value_bit; +use crate::round_flags::eval_round_flags; +use crate::{BITS_PER_LIMB, NUM_ROUNDS, U64_LIMBS, generate_trace_rows}; + +/// Assumes the field size is at least 16 bits. +#[derive(Debug)] +pub struct KeccakAir {} + +impl KeccakAir { + pub fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix { + let mut rng = SmallRng::seed_from_u64(1); + let inputs = (0..num_hashes).map(|_| rng.random()).collect::>(); + generate_trace_rows(inputs, extra_capacity_bits) + } +} + +impl BaseAir for KeccakAir { + fn width(&self) -> usize { + NUM_KECCAK_COLS + } +} + +impl Air for KeccakAir { + #[inline] + fn eval(&self, builder: &mut AB) { + eval_round_flags(builder); + + let main = builder.main(); + let (local, next) = (main.row_slice(0), main.row_slice(1)); + let local: &KeccakCols = (*local).borrow(); + let next: &KeccakCols = (*next).borrow(); + + let first_step = local.step_flags[0]; + let final_step = local.step_flags[NUM_ROUNDS - 1]; + let not_final_step = AB::Expr::ONE - final_step; + + // If this is the first step, the input A must match the preimage. + for y in 0..5 { + for x in 0..5 { + builder + .when(first_step) + .assert_zeros::(array::from_fn(|limb| { + local.preimage[y][x][limb] - local.a[y][x][limb] + })); + } + } + + // If this is not the final step, the local and next preimages must match. + for y in 0..5 { + for x in 0..5 { + builder + .when(not_final_step.clone()) + .when_transition() + .assert_zeros::(array::from_fn(|limb| { + local.preimage[y][x][limb] - next.preimage[y][x][limb] + })); + } + } + + // The export flag must be 0 or 1. + builder.assert_bool(local.export); + + // If this is not the final step, the export flag must be off. + builder + .when(not_final_step.clone()) + .assert_zero(local.export); + + // C'[x, z] = xor(C[x, z], C[x - 1, z], C[x + 1, z - 1]). + // Note that if all entries of C are boolean, the arithmetic generalization + // xor3 function only outputs 0, 1 and so this check also ensures that all + // entries of C'[x, z] are boolean. + for x in 0..5 { + builder.assert_bools(local.c[x]); + builder.assert_zeros::<64, _>(array::from_fn(|z| { + let xor = local.c[x][z].into().xor3( + &local.c[(x + 4) % 5][z].into(), + &local.c[(x + 1) % 5][(z + 63) % 64].into(), + ); + local.c_prime[x][z] - xor + })); + } + + // Check that the input limbs are consistent with A' and D. + // A[x, y, z] = xor(A'[x, y, z], D[x, y, z]) + // = xor(A'[x, y, z], C[x - 1, z], C[x + 1, z - 1]) + // = xor(A'[x, y, z], C[x, z], C'[x, z]). + // The last step is valid based on the identity we checked above. + // It isn't required, but makes this check a bit cleaner. + // We also check that all entries of A' are bools. + // This has the side effect of also range checking the limbs of A. + for y in 0..5 { + for x in 0..5 { + let get_bit = |z| { + Into::::into(local.a_prime[y][x][z]).xor3( + &Into::::into(local.c[x][z]), + &Into::::into(local.c_prime[x][z]), + ) + }; + + // Check that all entries of A'[y][x] are boolean. + builder.assert_bools(local.a_prime[y][x]); + + builder.assert_zeros::(array::from_fn(|limb| { + let computed_limb = (limb * BITS_PER_LIMB..(limb + 1) * BITS_PER_LIMB) + .rev() + .fold(AB::Expr::ZERO, |acc, z| { + // Check to ensure all entries of A' are bools. + acc.double() + get_bit(z) + }); + computed_limb - local.a[y][x][limb] + })); + } + } + + // xor_{i=0}^4 A'[x, i, z] = C'[x, z], so for each x, z, + // diff * (diff - 2) * (diff - 4) = 0, where + // diff = sum_{i=0}^4 A'[x, i, z] - C'[x, z] + for x in 0..5 { + let four = AB::Expr::TWO.double(); + builder.assert_zeros::<64, _>(array::from_fn(|z| { + let sum: AB::Expr = (0..5).map(|y| local.a_prime[y][x][z].into()).sum(); + let diff = sum - local.c_prime[x][z]; + diff.clone() * (diff.clone() - AB::Expr::TWO) * (diff - four.clone()) + })); + } + + // A''[x, y] = xor(B[x, y], andn(B[x + 1, y], B[x + 2, y])). + // As B is a rotation of A', all entries must be bools and so + // this check also range checks A''. + for y in 0..5 { + for x in 0..5 { + let get_bit = |z| { + let andn = local + .b((x + 1) % 5, y, z) + .into() + .andn(&local.b((x + 2) % 5, y, z).into()); + andn.xor(&local.b(x, y, z).into()) + }; + builder.assert_zeros::(array::from_fn(|limb| { + let computed_limb = (limb * BITS_PER_LIMB..(limb + 1) * BITS_PER_LIMB) + .rev() + .fold(AB::Expr::ZERO, |acc, z| acc.double() + get_bit(z)); + computed_limb - local.a_prime_prime[y][x][limb] + })); + } + } + + // A'''[0, 0] = A''[0, 0] XOR RC + // Check to ensure the bits of A''[0, 0] are boolean. + builder.assert_bools(local.a_prime_prime_0_0_bits); + builder.assert_zeros::(array::from_fn(|limb| { + let computed_a_prime_prime_0_0_limb = (limb * BITS_PER_LIMB + ..(limb + 1) * BITS_PER_LIMB) + .rev() + .fold(AB::Expr::ZERO, |acc, z| { + acc.double() + local.a_prime_prime_0_0_bits[z] + }); + computed_a_prime_prime_0_0_limb - local.a_prime_prime[0][0][limb] + })); + + let get_xored_bit = |i| { + let mut rc_bit_i = AB::Expr::ZERO; + for r in 0..NUM_ROUNDS { + let this_round = local.step_flags[r]; + let this_round_constant = AB::Expr::from_bool(rc_value_bit(r, i) != 0); + rc_bit_i += this_round * this_round_constant; + } + + rc_bit_i.xor(&local.a_prime_prime_0_0_bits[i].into()) + }; + + builder.assert_zeros::(array::from_fn(|limb| { + let computed_a_prime_prime_prime_0_0_limb = (limb * BITS_PER_LIMB + ..(limb + 1) * BITS_PER_LIMB) + .rev() + .fold(AB::Expr::ZERO, |acc, z| acc.double() + get_xored_bit(z)); + computed_a_prime_prime_prime_0_0_limb - local.a_prime_prime_prime_0_0_limbs[limb] + })); + + // Enforce that this round's output equals the next round's input. + for x in 0..5 { + for y in 0..5 { + builder + .when_transition() + .when(not_final_step.clone()) + .assert_zeros::(array::from_fn(|limb| { + local.a_prime_prime_prime(y, x, limb) - next.a[y][x][limb] + })); + } + } + } +} diff --git a/CoqOfRust/plonky3/keccak-air/src/air.v b/CoqOfRust/plonky3/keccak-air/src/air.v new file mode 100644 index 000000000..54ac849eb --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/air.v @@ -0,0 +1,7462 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module air. + (* StructTuple + { + name := "KeccakAir"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_fmt_Debug_for_p3_keccak_air_air_KeccakAir. + Definition Self : Ty.t := Ty.path "p3_keccak_air::air::KeccakAir". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "KeccakAir" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_keccak_air_air_KeccakAir. + + Module Impl_p3_keccak_air_air_KeccakAir. + Definition Self : Ty.t := Ty.path "p3_keccak_air::air::KeccakAir". + + (* + pub fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix { + let mut rng = SmallRng::seed_from_u64(1); + let inputs = (0..num_hashes).map(|_| rng.random()).collect::>(); + generate_trace_rows(inputs, extra_capacity_bits) + } + *) + Definition generate_trace_rows (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ self; num_hashes; extra_capacity_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_hashes := M.alloc (| num_hashes |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ inputs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| num_hashes |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_function (| "p3_keccak_air::generation::generate_trace_rows", [], [ F ] |), + [ M.read (| inputs |); M.read (| extra_capacity_bits |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_generate_trace_rows : + M.IsAssociatedFunction.C Self "generate_trace_rows" generate_trace_rows. + Admitted. + Global Typeclasses Opaque generate_trace_rows. + End Impl_p3_keccak_air_air_KeccakAir. + + Module Impl_p3_air_air_BaseAir_F_for_p3_keccak_air_air_KeccakAir. + Definition Self (F : Ty.t) : Ty.t := Ty.path "p3_keccak_air::air::KeccakAir". + + (* + fn width(&self) -> usize { + NUM_KECCAK_COLS + } + *) + Definition width (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + get_constant (| "p3_keccak_air::columns::NUM_KECCAK_COLS", Ty.path "usize" |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_air::air::BaseAir" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) [ ("width", InstanceField.Method (width F)) ]. + End Impl_p3_air_air_BaseAir_F_for_p3_keccak_air_air_KeccakAir. + + Module Impl_p3_air_air_Air_where_p3_air_air_AirBuilder_AB_AB_for_p3_keccak_air_air_KeccakAir. + Definition Self (AB : Ty.t) : Ty.t := Ty.path "p3_keccak_air::air::KeccakAir". + + (* + fn eval(&self, builder: &mut AB) { + eval_round_flags(builder); + + let main = builder.main(); + let (local, next) = (main.row_slice(0), main.row_slice(1)); + let local: &KeccakCols = ( *local).borrow(); + let next: &KeccakCols = ( *next).borrow(); + + let first_step = local.step_flags[0]; + let final_step = local.step_flags[NUM_ROUNDS - 1]; + let not_final_step = AB::Expr::ONE - final_step; + + // If this is the first step, the input A must match the preimage. + for y in 0..5 { + for x in 0..5 { + builder + .when(first_step) + .assert_zeros::(array::from_fn(|limb| { + local.preimage[y][x][limb] - local.a[y][x][limb] + })); + } + } + + // If this is not the final step, the local and next preimages must match. + for y in 0..5 { + for x in 0..5 { + builder + .when(not_final_step.clone()) + .when_transition() + .assert_zeros::(array::from_fn(|limb| { + local.preimage[y][x][limb] - next.preimage[y][x][limb] + })); + } + } + + // The export flag must be 0 or 1. + builder.assert_bool(local.export); + + // If this is not the final step, the export flag must be off. + builder + .when(not_final_step.clone()) + .assert_zero(local.export); + + // C'[x, z] = xor(C[x, z], C[x - 1, z], C[x + 1, z - 1]). + // Note that if all entries of C are boolean, the arithmetic generalization + // xor3 function only outputs 0, 1 and so this check also ensures that all + // entries of C'[x, z] are boolean. + for x in 0..5 { + builder.assert_bools(local.c[x]); + builder.assert_zeros::<64, _>(array::from_fn(|z| { + let xor = local.c[x][z].into().xor3( + &local.c[(x + 4) % 5][z].into(), + &local.c[(x + 1) % 5][(z + 63) % 64].into(), + ); + local.c_prime[x][z] - xor + })); + } + + // Check that the input limbs are consistent with A' and D. + // A[x, y, z] = xor(A'[x, y, z], D[x, y, z]) + // = xor(A'[x, y, z], C[x - 1, z], C[x + 1, z - 1]) + // = xor(A'[x, y, z], C[x, z], C'[x, z]). + // The last step is valid based on the identity we checked above. + // It isn't required, but makes this check a bit cleaner. + // We also check that all entries of A' are bools. + // This has the side effect of also range checking the limbs of A. + for y in 0..5 { + for x in 0..5 { + let get_bit = |z| { + Into::::into(local.a_prime[y][x][z]).xor3( + &Into::::into(local.c[x][z]), + &Into::::into(local.c_prime[x][z]), + ) + }; + + // Check that all entries of A'[y][x] are boolean. + builder.assert_bools(local.a_prime[y][x]); + + builder.assert_zeros::(array::from_fn(|limb| { + let computed_limb = (limb * BITS_PER_LIMB..(limb + 1) * BITS_PER_LIMB) + .rev() + .fold(AB::Expr::ZERO, |acc, z| { + // Check to ensure all entries of A' are bools. + acc.double() + get_bit(z) + }); + computed_limb - local.a[y][x][limb] + })); + } + } + + // xor_{i=0}^4 A'[x, i, z] = C'[x, z], so for each x, z, + // diff * (diff - 2) * (diff - 4) = 0, where + // diff = sum_{i=0}^4 A'[x, i, z] - C'[x, z] + for x in 0..5 { + let four = AB::Expr::TWO.double(); + builder.assert_zeros::<64, _>(array::from_fn(|z| { + let sum: AB::Expr = (0..5).map(|y| local.a_prime[y][x][z].into()).sum(); + let diff = sum - local.c_prime[x][z]; + diff.clone() * (diff.clone() - AB::Expr::TWO) * (diff - four.clone()) + })); + } + + // A''[x, y] = xor(B[x, y], andn(B[x + 1, y], B[x + 2, y])). + // As B is a rotation of A', all entries must be bools and so + // this check also range checks A''. + for y in 0..5 { + for x in 0..5 { + let get_bit = |z| { + let andn = local + .b((x + 1) % 5, y, z) + .into() + .andn(&local.b((x + 2) % 5, y, z).into()); + andn.xor(&local.b(x, y, z).into()) + }; + builder.assert_zeros::(array::from_fn(|limb| { + let computed_limb = (limb * BITS_PER_LIMB..(limb + 1) * BITS_PER_LIMB) + .rev() + .fold(AB::Expr::ZERO, |acc, z| acc.double() + get_bit(z)); + computed_limb - local.a_prime_prime[y][x][limb] + })); + } + } + + // A'''[0, 0] = A''[0, 0] XOR RC + // Check to ensure the bits of A''[0, 0] are boolean. + builder.assert_bools(local.a_prime_prime_0_0_bits); + builder.assert_zeros::(array::from_fn(|limb| { + let computed_a_prime_prime_0_0_limb = (limb * BITS_PER_LIMB + ..(limb + 1) * BITS_PER_LIMB) + .rev() + .fold(AB::Expr::ZERO, |acc, z| { + acc.double() + local.a_prime_prime_0_0_bits[z] + }); + computed_a_prime_prime_0_0_limb - local.a_prime_prime[0][0][limb] + })); + + let get_xored_bit = |i| { + let mut rc_bit_i = AB::Expr::ZERO; + for r in 0..NUM_ROUNDS { + let this_round = local.step_flags[r]; + let this_round_constant = AB::Expr::from_bool(rc_value_bit(r, i) != 0); + rc_bit_i += this_round * this_round_constant; + } + + rc_bit_i.xor(&local.a_prime_prime_0_0_bits[i].into()) + }; + + builder.assert_zeros::(array::from_fn(|limb| { + let computed_a_prime_prime_prime_0_0_limb = (limb * BITS_PER_LIMB + ..(limb + 1) * BITS_PER_LIMB) + .rev() + .fold(AB::Expr::ZERO, |acc, z| acc.double() + get_xored_bit(z)); + computed_a_prime_prime_prime_0_0_limb - local.a_prime_prime_prime_0_0_limbs[limb] + })); + + // Enforce that this round's output equals the next round's input. + for x in 0..5 { + for y in 0..5 { + builder + .when_transition() + .when(not_final_step.clone()) + .assert_zeros::(array::from_fn(|limb| { + local.a_prime_prime_prime(y, x, limb) - next.a[y][x][limb] + })); + } + } + } + *) + Definition eval (AB : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self AB in + match ε, τ, α with + | [], [], [ self; builder ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let builder := M.alloc (| builder |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_keccak_air::round_flags::eval_round_flags", [], [ AB ] |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |) ] + |) + |) in + let~ main : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + M.get_trait_method (| "p3_air::air::AirBuilder", AB, [], [], "main", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| builder |) |) |) ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "row_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, main |); Value.Integer IntegerKind.Usize 0 ] + |); + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "row_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, main |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let local := M.copy (| γ0_0 |) in + let next := M.copy (| γ0_1 |) in + let~ local : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ], + [], + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "M") + "{{synthetic}}'2", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, local |) ] + |) + |) + |) + ] + |) + |) + |) + |) in + let~ next : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ], + [], + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "M") + "{{synthetic}}'2", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, next |) ] + |) + |) + |) + ] + |) + |) + |) + |) in + let~ first_step : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] := + M.copy (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_keccak_air::columns::KeccakCols", + "step_flags" + |), + Value.Integer IntegerKind.Usize 0 + |) + |) in + let~ final_step : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] := + M.copy (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_keccak_air::columns::KeccakCols", + "step_flags" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_keccak_air::NUM_ROUNDS", Ty.path "usize" |) + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) in + let~ not_final_step : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "sub", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + |) + |); + M.read (| final_step |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let y := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 0); + ("end_", + Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ AB ], + [], + [], + "assert_zeros", + [ + Value.Integer + IntegerKind.Usize + 4 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ AB ], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "when", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + builder + |) + |) + |); + M.read (| + first_step + |) + ] + |) + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + M.get_function (| + "core::array::from_fn", + [ + Value.Integer + IntegerKind.Usize + 4 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + limb := + M.copy (| + γ + |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "preimage" + |), + M.read (| + y + |) + |), + M.read (| + x + |) + |), + M.read (| + limb + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "a" + |), + M.read (| + y + |) + |), + M.read (| + x + |) + |), + M.read (| + limb + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let y := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 0); + ("end_", + Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ AB ] + ], + [], + [], + "assert_zeros", + [ + Value.Integer + IntegerKind.Usize + 4 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ AB ] + ], + M.get_trait_method (| + "p3_air::air::AirBuilder", + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ AB ], + [], + [], + "when_transition", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ AB + ], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "when", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + builder + |) + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + not_final_step + |) + ] + |) + ] + |) + |) + |) + ] + |) + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + M.get_function (| + "core::array::from_fn", + [ + Value.Integer + IntegerKind.Usize + 4 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + limb := + M.copy (| + γ + |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "preimage" + |), + M.read (| + y + |) + |), + M.read (| + x + |) + |), + M.read (| + limb + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + next + |) + |), + "p3_keccak_air::columns::KeccakCols", + "preimage" + |), + M.read (| + y + |) + |), + M.read (| + x + |) + |), + M.read (| + limb + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_bool", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_keccak_air::columns::KeccakCols", + "export" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + Ty.apply (Ty.path "p3_air::air::FilteredAirBuilder") [] [ AB ], + [], + [], + "assert_zero", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_air::air::FilteredAirBuilder") [] [ AB ], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "when", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, not_final_step |) ] + |) + ] + |) + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_keccak_air::columns::KeccakCols", + "export" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_bools", + [ Value.Integer IntegerKind.Usize 64 ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_keccak_air::columns::KeccakCols", + "c" + |), + M.read (| x |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_zeros", + [ Value.Integer IntegerKind.Usize 64 ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 64 ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.path "usize" ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let z := + M.copy (| γ |) in + M.read (| + let~ xor : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "xor3", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "c" + |), + M.read (| + x + |) + |), + M.read (| + z + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "c" + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + x + |); + Value.Integer + IntegerKind.Usize + 4 + ] + |); + Value.Integer + IntegerKind.Usize + 5 + ] + |) + |), + M.read (| + z + |) + |) + |) + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "c" + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + x + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + Value.Integer + IntegerKind.Usize + 5 + ] + |) + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + z + |); + Value.Integer + IntegerKind.Usize + 63 + ] + |); + Value.Integer + IntegerKind.Usize + 64 + ] + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "c_prime" + |), + M.read (| + x + |) + |), + M.read (| + z + |) + |) + |); + M.read (| xor |) + ] + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let y := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 0); + ("end_", + Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ get_bit : + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] := + M.alloc (| + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + z := + M.copy (| + γ + |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "xor3", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "a_prime" + |), + M.read (| + y + |) + |), + M.read (| + x + |) + |), + M.read (| + z + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "c" + |), + M.read (| + x + |) + |), + M.read (| + z + |) + |) + |) + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "c_prime" + |), + M.read (| + x + |) + |), + M.read (| + z + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_bools", + [ + Value.Integer + IntegerKind.Usize + 64 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + builder + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "a_prime" + |), + M.read (| y |) + |), + M.read (| x |) + |) + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_zeros", + [ + Value.Integer + IntegerKind.Usize + 4 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + builder + |) + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + M.get_function (| + "core::array::from_fn", + [ + Value.Integer + IntegerKind.Usize + 4 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + limb := + M.copy (| + γ + |) in + M.read (| + let~ + computed_limb : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ] + ], + [], + [], + "fold", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + M.read (| + limb + |); + M.read (| + get_constant (| + "p3_keccak_air::BITS_PER_LIMB", + Ty.path + "usize" + |) + |) + ] + |)); + ("end_", + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + limb + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + M.read (| + get_constant (| + "p3_keccak_air::BITS_PER_LIMB", + Ty.path + "usize" + |) + |) + ] + |)) + ] + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + |) + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0; + α1 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + acc := + M.copy (| + γ + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α1 + |), + [ + fun + γ => + ltac:(M.monadic + (let + z := + M.copy (| + γ + |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + acc + |) + ] + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"), + [], + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_bit + |); + Value.Tuple + [ + M.read (| + z + |) + ] + ] + |) + ] + |))) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "sub", + [], + [] + |), + [ + M.read (| + computed_limb + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "a" + |), + M.read (| + y + |) + |), + M.read (| + x + |) + |), + M.read (| + limb + |) + |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ four : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::TWO", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_zeros", + [ Value.Integer IntegerKind.Usize 64 ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 64 ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.path "usize" ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let z := + M.copy (| γ |) in + M.read (| + let~ sum : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + [], + [], + "sum", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "map", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", + Value.Integer + IntegerKind.Usize + 5) + ]; + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + y := + M.copy (| + γ + |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "a_prime" + |), + M.read (| + y + |) + |), + M.read (| + x + |) + |), + M.read (| + z + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ diff : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "sub", + [], + [] + |), + [ + M.read (| + sum + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "c_prime" + |), + M.read (| + x + |) + |), + M.read (| + z + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + diff + |) + ] + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "sub", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + diff + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::TWO", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "sub", + [], + [] + |), + [ + M.read (| + diff + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + four + |) + ] + |) + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let y := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 0); + ("end_", + Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ get_bit : + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] := + M.alloc (| + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + z := + M.copy (| + γ + |) in + M.read (| + let~ + andn : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "andn", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_keccak_air::columns::KeccakCols") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "b", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + local + |) + |) + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + x + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + Value.Integer + IntegerKind.Usize + 5 + ] + |); + M.read (| + y + |); + M.read (| + z + |) + ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_keccak_air::columns::KeccakCols") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "b", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + local + |) + |) + |); + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + x + |); + Value.Integer + IntegerKind.Usize + 2 + ] + |); + Value.Integer + IntegerKind.Usize + 5 + ] + |); + M.read (| + y + |); + M.read (| + z + |) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + andn + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_keccak_air::columns::KeccakCols") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "b", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + local + |) + |) + |); + M.read (| + x + |); + M.read (| + y + |); + M.read (| + z + |) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_zeros", + [ + Value.Integer + IntegerKind.Usize + 4 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + builder + |) + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + M.get_function (| + "core::array::from_fn", + [ + Value.Integer + IntegerKind.Usize + 4 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + limb := + M.copy (| + γ + |) in + M.read (| + let~ + computed_limb : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ] + ], + [], + [], + "fold", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + M.read (| + limb + |); + M.read (| + get_constant (| + "p3_keccak_air::BITS_PER_LIMB", + Ty.path + "usize" + |) + |) + ] + |)); + ("end_", + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + limb + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + M.read (| + get_constant (| + "p3_keccak_air::BITS_PER_LIMB", + Ty.path + "usize" + |) + |) + ] + |)) + ] + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + |) + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0; + α1 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + acc := + M.copy (| + γ + |) in + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α1 + |), + [ + fun + γ => + ltac:(M.monadic + (let + z := + M.copy (| + γ + |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + acc + |) + ] + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"), + [], + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_bit + |); + Value.Tuple + [ + M.read (| + z + |) + ] + ] + |) + ] + |))) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "sub", + [], + [] + |), + [ + M.read (| + computed_limb + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime" + |), + M.read (| + y + |) + |), + M.read (| + x + |) + |), + M.read (| + limb + |) + |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_bools", + [ Value.Integer IntegerKind.Usize 64 ], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime_0_0_bits" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_zeros", + [ Value.Integer IntegerKind.Usize 4 ], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let limb := M.copy (| γ |) in + M.read (| + let~ computed_a_prime_prime_0_0_limb : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + [], + [], + "fold", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| limb |); + M.read (| + get_constant (| + "p3_keccak_air::BITS_PER_LIMB", + Ty.path "usize" + |) + |) + ] + |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| limb |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + M.read (| + get_constant (| + "p3_keccak_air::BITS_PER_LIMB", + Ty.path "usize" + |) + |) + ] + |)) + ] + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := + M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let z := + M.copy (| + γ + |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + acc + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + local + |) + |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime_0_0_bits" + |), + M.read (| + z + |) + |) + |) + ] + |))) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "sub", + [], + [] + |), + [ + M.read (| + computed_a_prime_prime_0_0_limb + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| local |) + |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime" + |), + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| limb |) + |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ get_xored_bit : + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr") + ] := + M.alloc (| + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + let~ rc_bit_i : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.copy (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 0); + ("end_", + M.read (| + get_constant (| + "p3_keccak_air::NUM_ROUNDS", + Ty.path "usize" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let r := M.copy (| γ0_0 |) in + let~ this_round : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] := + M.copy (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| local |) + |), + "p3_keccak_air::columns::KeccakCols", + "step_flags" + |), + M.read (| r |) + |) + |) in + let~ this_round_constant : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "from_bool", + [], + [] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.call_closure (| + Ty.path "u8", + M.get_function (| + "p3_keccak_air::constants::rc_value_bit", + [], + [] + |), + [ + M.read (| + r + |); + M.read (| i |) + ] + |); + Value.Integer + IntegerKind.U8 + 0 + ] + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + rc_bit_i + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "mul", + [], + [] + |), + [ + M.read (| + this_round + |); + M.read (| + this_round_constant + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "xor", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, rc_bit_i |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| local |) + |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime_0_0_bits" + |), + M.read (| i |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_zeros", + [ Value.Integer IntegerKind.Usize 4 ], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let limb := M.copy (| γ |) in + M.read (| + let~ computed_a_prime_prime_prime_0_0_limb : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + [], + [], + "fold", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| limb |); + M.read (| + get_constant (| + "p3_keccak_air::BITS_PER_LIMB", + Ty.path "usize" + |) + |) + ] + |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| limb |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + M.read (| + get_constant (| + "p3_keccak_air::BITS_PER_LIMB", + Ty.path "usize" + |) + |) + ] + |)) + ] + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := + M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let z := + M.copy (| + γ + |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + acc + |) + ] + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"), + [], + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_xored_bit + |); + Value.Tuple + [ + M.read (| + z + |) + ] + ] + |) + ] + |))) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "sub", + [], + [] + |), + [ + M.read (| + computed_a_prime_prime_prime_0_0_limb + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime_prime_0_0_limbs" + |), + M.read (| limb |) + |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer IntegerKind.Usize 0); + ("end_", + Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let y := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ AB ] + ], + [], + [], + "assert_zeros", + [ + Value.Integer + IntegerKind.Usize + 4 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ AB ] + ], + M.get_trait_method (| + "p3_air::air::AirBuilder", + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ AB ], + [], + [], + "when", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_air::air::FilteredAirBuilder") + [] + [ AB ], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "when_transition", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + builder + |) + |) + |) + ] + |) + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + not_final_step + |) + ] + |) + ] + |) + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + M.get_function (| + "core::array::from_fn", + [ + Value.Integer + IntegerKind.Usize + 4 + ], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + limb := + M.copy (| + γ + |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "sub", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_keccak_air::columns::KeccakCols") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "a_prime_prime_prime", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + local + |) + |) + |); + M.read (| + y + |); + M.read (| + x + |); + M.read (| + limb + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + next + |) + |), + "p3_keccak_air::columns::KeccakCols", + "a" + |), + M.read (| + y + |) + |), + M.read (| + x + |) + |), + M.read (| + limb + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (AB : Ty.t), + M.IsTraitInstance + "p3_air::air::Air" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ AB ] + (Self AB) + (* Instance *) [ ("eval", InstanceField.Method (eval AB)) ]. + End Impl_p3_air_air_Air_where_p3_air_air_AirBuilder_AB_AB_for_p3_keccak_air_air_KeccakAir. +End air. diff --git a/CoqOfRust/plonky3/keccak-air/src/columns.rs b/CoqOfRust/plonky3/keccak-air/src/columns.rs new file mode 100644 index 000000000..5ae52ce08 --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/columns.rs @@ -0,0 +1,148 @@ +use core::borrow::{Borrow, BorrowMut}; +use core::mem::{size_of, transmute}; + +use p3_util::indices_arr; + +use crate::constants::R; +use crate::{NUM_ROUNDS, RATE_LIMBS, U64_LIMBS}; + +/// Note: The ordering of each array is based on the input mapping. As the spec says, +/// +/// > The mapping between the bits of s and those of a is `s[w(5y + x) + z] = a[x][y][z]`. +/// +/// Thus, for example, `a_prime` is stored in `y, x, z` order. This departs from the more common +/// convention of `x, y, z` order, but it has the benefit that input lists map to AIR columns in a +/// nicer way. +#[derive(Debug)] +#[repr(C)] +pub struct KeccakCols { + /// The `i`th value is set to 1 if we are in the `i`th round, otherwise 0. + pub step_flags: [T; NUM_ROUNDS], + + /// A register which indicates if a row should be exported, i.e. included in a multiset equality + /// argument. Should be 1 only for certain rows which are final steps, i.e. with + /// `step_flags[23] = 1`. + pub export: T, + + /// Permutation inputs, stored in y-major order. + pub preimage: [[[T; U64_LIMBS]; 5]; 5], + + pub a: [[[T; U64_LIMBS]; 5]; 5], + + /// ```ignore + /// C[x] = xor(A[x, 0], A[x, 1], A[x, 2], A[x, 3], A[x, 4]) + /// ``` + pub c: [[T; 64]; 5], + + /// ```ignore + /// C'[x, z] = xor(C[x, z], C[x - 1, z], C[x + 1, z - 1]) + /// ``` + pub c_prime: [[T; 64]; 5], + + // Note: D is inlined, not stored in the witness. + /// ```ignore + /// A'[x, y] = xor(A[x, y], D[x]) + /// = xor(A[x, y], C[x - 1], ROT(C[x + 1], 1)) + /// ``` + pub a_prime: [[[T; 64]; 5]; 5], + + /// ```ignore + /// A''[x, y] = xor(B[x, y], andn(B[x + 1, y], B[x + 2, y])). + /// ``` + pub a_prime_prime: [[[T; U64_LIMBS]; 5]; 5], + + /// The bits of `A''[0, 0]`. + pub a_prime_prime_0_0_bits: [T; 64], + + /// ```ignore + /// A'''[0, 0, z] = A''[0, 0, z] ^ RC[k, z] + /// ``` + pub a_prime_prime_prime_0_0_limbs: [T; U64_LIMBS], +} + +impl KeccakCols { + pub fn b(&self, x: usize, y: usize, z: usize) -> T { + debug_assert!(x < 5); + debug_assert!(y < 5); + debug_assert!(z < 64); + + // B is just a rotation of A', so these are aliases for A' registers. + // From the spec, + // B[y, (2x + 3y) % 5] = ROT(A'[x, y], r[x, y]) + // So, + // B[x, y] = f((x + 3y) % 5, x) + // where f(a, b) = ROT(A'[a, b], r[a, b]) + let a = (x + 3 * y) % 5; + let b = x; + let rot = R[a][b] as usize; + self.a_prime[b][a][(z + 64 - rot) % 64] + } + + pub fn a_prime_prime_prime(&self, y: usize, x: usize, limb: usize) -> T { + debug_assert!(y < 5); + debug_assert!(x < 5); + debug_assert!(limb < U64_LIMBS); + + if y == 0 && x == 0 { + self.a_prime_prime_prime_0_0_limbs[limb] + } else { + self.a_prime_prime[y][x][limb] + } + } +} + +pub fn input_limb(i: usize) -> usize { + debug_assert!(i < RATE_LIMBS); + + let i_u64 = i / U64_LIMBS; + let limb_index = i % U64_LIMBS; + + // The 5x5 state is treated as y-major, as per the Keccak spec. + let y = i_u64 / 5; + let x = i_u64 % 5; + + KECCAK_COL_MAP.preimage[y][x][limb_index] +} + +pub fn output_limb(i: usize) -> usize { + debug_assert!(i < RATE_LIMBS); + + let i_u64 = i / U64_LIMBS; + let limb_index = i % U64_LIMBS; + + // The 5x5 state is treated as y-major, as per the Keccak spec. + let y = i_u64 / 5; + let x = i_u64 % 5; + + KECCAK_COL_MAP.a_prime_prime_prime(y, x, limb_index) +} + +pub const NUM_KECCAK_COLS: usize = size_of::>(); +pub(crate) const KECCAK_COL_MAP: KeccakCols = make_col_map(); + +const fn make_col_map() -> KeccakCols { + let indices_arr = indices_arr::(); + unsafe { transmute::<[usize; NUM_KECCAK_COLS], KeccakCols>(indices_arr) } +} + +impl Borrow> for [T] { + fn borrow(&self) -> &KeccakCols { + debug_assert_eq!(self.len(), NUM_KECCAK_COLS); + let (prefix, shorts, suffix) = unsafe { self.align_to::>() }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &shorts[0] + } +} + +impl BorrowMut> for [T] { + fn borrow_mut(&mut self) -> &mut KeccakCols { + debug_assert_eq!(self.len(), NUM_KECCAK_COLS); + let (prefix, shorts, suffix) = unsafe { self.align_to_mut::>() }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &mut shorts[0] + } +} diff --git a/CoqOfRust/plonky3/keccak-air/src/columns.v b/CoqOfRust/plonky3/keccak-air/src/columns.v new file mode 100644 index 000000000..d8c8d5aaa --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/columns.v @@ -0,0 +1,2434 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module columns. + (* StructRecord + { + name := "KeccakCols"; + const_params := []; + ty_params := [ "T" ]; + fields := + [ + ("step_flags", + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_keccak_air_columns_KeccakCols_step_flags_discriminant" |)) + ] + [ T ]); + ("export", T); + ("preimage", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_keccak_air_columns_KeccakCols_preimage_discriminant" |)) + ] + [ T ] + ] + ]); + ("a", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| "p3_keccak_air_columns_KeccakCols_a_discriminant" |)) + ] + [ T ] + ] + ]); + ("c", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ T ] ]); + ("c_prime", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ T ] ]); + ("a_prime", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ T ] ] + ]); + ("a_prime_prime", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| + "p3_keccak_air_columns_KeccakCols_a_prime_prime_discriminant" + |)) + ] + [ T ] + ] + ]); + ("a_prime_prime_0_0_bits", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ T ]); + ("a_prime_prime_prime_0_0_limbs", + Ty.apply + (Ty.path "array") + [ + M.unevaluated_const + (mk_str (| + "p3_keccak_air_columns_KeccakCols_a_prime_prime_prime_0_0_limbs_discriminant" + |)) + ] + [ T ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_T_for_p3_keccak_air_columns_KeccakCols_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ T ]. + + (* Debug *) + Definition fmt (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + let~ names : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 10 ] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "step_flags" |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "export" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "preimage" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "a" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "c" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "c_prime" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "a_prime" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "a_prime_prime" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "a_prime_prime_0_0_bits" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "a_prime_prime_prime_0_0_limbs" |) |) + |) + ] + |) + |) + |) + |) + |) in + let~ values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.dyn [ ("core::fmt::Debug::Trait", []) ] ] + ] + ] + ] := + M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "step_flags" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "export" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "preimage" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "a" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "c" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "c_prime" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime_0_0_bits" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime_prime_0_0_limbs" + |) + |) + |) + |) + |) + |)) + ] + |) + |) + |) + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_fields_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "KeccakCols" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| names |) |) |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| values |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("fmt", InstanceField.Method (fmt T)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_T_for_p3_keccak_air_columns_KeccakCols_T. + + Module Impl_p3_keccak_air_columns_KeccakCols_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ T ]. + + (* + pub fn b(&self, x: usize, y: usize, z: usize) -> T { + debug_assert!(x < 5); + debug_assert!(y < 5); + debug_assert!(z < 64); + + // B is just a rotation of A', so these are aliases for A' registers. + // From the spec, + // B[y, (2x + 3y) % 5] = ROT(A'[x, y], r[x, y]) + // So, + // B[x, y] = f((x + 3y) % 5, x) + // where f(a, b) = ROT(A'[a, b], r[a, b]) + let a = (x + 3 * y) % 5; + let b = x; + let rot = R[a][b] as usize; + self.a_prime[b][a][(z + 64 - rot) % 64] + } + *) + Definition b (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self; x; y; z ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + let z := M.alloc (| z |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| x |); Value.Integer IntegerKind.Usize 5 ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: x < 5" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| y |); Value.Integer IntegerKind.Usize 5 ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: y < 5" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| z |); Value.Integer IntegerKind.Usize 64 ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: z < 64" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ a : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| x |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 3; M.read (| y |) ] + |) + ] + |); + Value.Integer IntegerKind.Usize 5 + ] + |) + |) in + let~ b : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := M.copy (| x |) in + let~ rot : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.cast + (Ty.path "usize") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_keccak_air::constants::R", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u8" ] + ] + |), + M.read (| a |) + |), + M.read (| b |) + |) + |)) + |) in + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime" + |), + M.read (| b |) + |), + M.read (| a |) + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| z |); Value.Integer IntegerKind.Usize 64 ] + |); + M.read (| rot |) + ] + |); + Value.Integer IntegerKind.Usize 64 + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_b : + forall (T : Ty.t), + M.IsAssociatedFunction.C (Self T) "b" (b T). + Admitted. + Global Typeclasses Opaque b. + + (* + pub fn a_prime_prime_prime(&self, y: usize, x: usize, limb: usize) -> T { + debug_assert!(y < 5); + debug_assert!(x < 5); + debug_assert!(limb < U64_LIMBS); + + if y == 0 && x == 0 { + self.a_prime_prime_prime_0_0_limbs[limb] + } else { + self.a_prime_prime[y][x][limb] + } + } + *) + Definition a_prime_prime_prime + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self; y; x; limb ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let y := M.alloc (| y |) in + let x := M.alloc (| x |) in + let limb := M.alloc (| limb |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| y |); Value.Integer IntegerKind.Usize 5 ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: y < 5" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| x |); Value.Integer IntegerKind.Usize 5 ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: x < 5" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| limb |); + M.read (| + get_constant (| + "p3_keccak_air::U64_LIMBS", + Ty.path "usize" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: limb < U64_LIMBS" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ T ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| y |); Value.Integer IntegerKind.Usize 0 ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| x |); Value.Integer IntegerKind.Usize 0 ] + |))) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime_prime_0_0_limbs" + |), + M.read (| limb |) + |))); + fun γ => + ltac:(M.monadic + (M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime" + |), + M.read (| y |) + |), + M.read (| x |) + |), + M.read (| limb |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_a_prime_prime_prime : + forall (T : Ty.t), + M.IsAssociatedFunction.C (Self T) "a_prime_prime_prime" (a_prime_prime_prime T). + Admitted. + Global Typeclasses Opaque a_prime_prime_prime. + End Impl_p3_keccak_air_columns_KeccakCols_T. + + (* + pub fn input_limb(i: usize) -> usize { + debug_assert!(i < RATE_LIMBS); + + let i_u64 = i / U64_LIMBS; + let limb_index = i % U64_LIMBS; + + // The 5x5 state is treated as y-major, as per the Keccak spec. + let y = i_u64 / 5; + let x = i_u64 % 5; + + KECCAK_COL_MAP.preimage[y][x][limb_index] + } + *) + Definition input_limb (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ i ] => + ltac:(M.monadic + (let i := M.alloc (| i |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| i |); + M.read (| + get_constant (| + "p3_keccak_air::RATE_LIMBS", + Ty.path "usize" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: i < RATE_LIMBS" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ i_u64 : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.read (| i |); + M.read (| get_constant (| "p3_keccak_air::U64_LIMBS", Ty.path "usize" |) |) + ] + |) + |) in + let~ limb_index : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.read (| i |); + M.read (| get_constant (| "p3_keccak_air::U64_LIMBS", Ty.path "usize" |) |) + ] + |) + |) in + let~ y : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| i_u64 |); Value.Integer IntegerKind.Usize 5 ] + |) + |) in + let~ x : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| i_u64 |); Value.Integer IntegerKind.Usize 5 ] + |) + |) in + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + get_constant (| + "p3_keccak_air::columns::KECCAK_COL_MAP", + Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ Ty.path "usize" ] + |), + "p3_keccak_air::columns::KeccakCols", + "preimage" + |), + M.read (| y |) + |), + M.read (| x |) + |), + M.read (| limb_index |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_input_limb : + M.IsFunction.C "p3_keccak_air::columns::input_limb" input_limb. + Admitted. + Global Typeclasses Opaque input_limb. + + (* + pub fn output_limb(i: usize) -> usize { + debug_assert!(i < RATE_LIMBS); + + let i_u64 = i / U64_LIMBS; + let limb_index = i % U64_LIMBS; + + // The 5x5 state is treated as y-major, as per the Keccak spec. + let y = i_u64 / 5; + let x = i_u64 % 5; + + KECCAK_COL_MAP.a_prime_prime_prime(y, x, limb_index) + } + *) + Definition output_limb (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ i ] => + ltac:(M.monadic + (let i := M.alloc (| i |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| i |); + M.read (| + get_constant (| + "p3_keccak_air::RATE_LIMBS", + Ty.path "usize" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: i < RATE_LIMBS" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ i_u64 : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.read (| i |); + M.read (| get_constant (| "p3_keccak_air::U64_LIMBS", Ty.path "usize" |) |) + ] + |) + |) in + let~ limb_index : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.read (| i |); + M.read (| get_constant (| "p3_keccak_air::U64_LIMBS", Ty.path "usize" |) |) + ] + |) + |) in + let~ y : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| i_u64 |); Value.Integer IntegerKind.Usize 5 ] + |) + |) in + let~ x : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| i_u64 |); Value.Integer IntegerKind.Usize 5 ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ Ty.path "usize" ], + "a_prime_prime_prime", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_keccak_air::columns::KECCAK_COL_MAP", + Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ Ty.path "usize" ] + |) + |); + M.read (| y |); + M.read (| x |); + M.read (| limb_index |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_output_limb : + M.IsFunction.C "p3_keccak_air::columns::output_limb" output_limb. + Admitted. + Global Typeclasses Opaque output_limb. + + Definition value_NUM_KECCAK_COLS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ Ty.path "u8" ] ] + |), + [] + |) + |))). + + Global Instance Instance_IsConstant_value_NUM_KECCAK_COLS : + M.IsFunction.C "p3_keccak_air::columns::NUM_KECCAK_COLS" value_NUM_KECCAK_COLS. + Admitted. + Global Typeclasses Opaque value_NUM_KECCAK_COLS. + + Definition value_KECCAK_COL_MAP (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ Ty.path "usize" ], + M.get_function (| "p3_keccak_air::columns::make_col_map", [], [] |), + [] + |) + |))). + + Global Instance Instance_IsConstant_value_KECCAK_COL_MAP : + M.IsFunction.C "p3_keccak_air::columns::KECCAK_COL_MAP" value_KECCAK_COL_MAP. + Admitted. + Global Typeclasses Opaque value_KECCAK_COL_MAP. + + (* + const fn make_col_map() -> KeccakCols { + let indices_arr = indices_arr::(); + unsafe { transmute::<[usize; NUM_KECCAK_COLS], KeccakCols>(indices_arr) } + } + *) + Definition make_col_map (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.read (| + let~ indices_arr : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2633 ] + [ Ty.path "usize" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2633 ] + [ Ty.path "usize" ], + M.get_function (| + "p3_util::indices_arr", + [ Value.Integer IntegerKind.Usize 2633 ], + [] + |), + [] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ Ty.path "usize" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2633 ] + [ Ty.path "usize" ]; + Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ Ty.path "usize" ] + ] + |), + [ M.read (| indices_arr |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_make_col_map : + M.IsFunction.C "p3_keccak_air::columns::make_col_map" make_col_map. + Admitted. + Global Typeclasses Opaque make_col_map. + + Module Impl_core_borrow_Borrow_p3_keccak_air_columns_KeccakCols_T_for_slice_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ T ]. + + (* + fn borrow(&self) -> &KeccakCols { + debug_assert_eq!(self.len(), NUM_KECCAK_COLS); + let (prefix, shorts, suffix) = unsafe { self.align_to::>() }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &shorts[0] + } + *) + Definition borrow (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_keccak_air::columns::NUM_KECCAK_COLS", + Ty.path "usize" + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ T ] ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ T ] ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "align_to", + [], + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ T ] ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let shorts := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ T ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shorts |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 1 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| shorts |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ T ] ] + (Self T) + (* Instance *) [ ("borrow", InstanceField.Method (borrow T)) ]. + End Impl_core_borrow_Borrow_p3_keccak_air_columns_KeccakCols_T_for_slice_T. + + Module Impl_core_borrow_BorrowMut_p3_keccak_air_columns_KeccakCols_T_for_slice_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ T ]. + + (* + fn borrow_mut(&mut self) -> &mut KeccakCols { + debug_assert_eq!(self.len(), NUM_KECCAK_COLS); + let (prefix, shorts, suffix) = unsafe { self.align_to_mut::>() }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &mut shorts[0] + } + *) + Definition borrow_mut (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_keccak_air::columns::NUM_KECCAK_COLS", + Ty.path "usize" + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ T ] ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ T ] ] + ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "align_to_mut", + [], + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ T ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let shorts := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_keccak_air::columns::KeccakCols") + [] + [ T ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shorts |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 1 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| shorts |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + |))) + ] + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ T ] ] + (Self T) + (* Instance *) [ ("borrow_mut", InstanceField.Method (borrow_mut T)) ]. + End Impl_core_borrow_BorrowMut_p3_keccak_air_columns_KeccakCols_T_for_slice_T. +End columns. diff --git a/CoqOfRust/plonky3/keccak-air/src/constants.rs b/CoqOfRust/plonky3/keccak-air/src/constants.rs new file mode 100644 index 000000000..056e0c57a --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/constants.rs @@ -0,0 +1,161 @@ +pub(crate) const R: [[u8; 5]; 5] = [ + [0, 36, 3, 41, 18], + [1, 44, 10, 45, 2], + [62, 6, 43, 15, 61], + [28, 55, 25, 21, 56], + [27, 20, 39, 8, 14], +]; + +pub const RC: [u64; 24] = [ + 0x0000000000000001, + 0x0000000000008082, + 0x800000000000808A, + 0x8000000080008000, + 0x000000000000808B, + 0x0000000080000001, + 0x8000000080008081, + 0x8000000000008009, + 0x000000000000008A, + 0x0000000000000088, + 0x0000000080008009, + 0x000000008000000A, + 0x000000008000808B, + 0x800000000000008B, + 0x8000000000008089, + 0x8000000000008003, + 0x8000000000008002, + 0x8000000000000080, + 0x000000000000800A, + 0x800000008000000A, + 0x8000000080008081, + 0x8000000000008080, + 0x0000000080000001, + 0x8000000080008008, +]; + +const RC_BITS: [[u8; 64]; 24] = [ + [ + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], + [ + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ], + [ + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, + ], +]; + +pub(crate) const fn rc_value_bit(round: usize, bit_index: usize) -> u8 { + RC_BITS[round][bit_index] +} diff --git a/CoqOfRust/plonky3/keccak-air/src/constants.v b/CoqOfRust/plonky3/keccak-air/src/constants.v new file mode 100644 index 000000000..d9463afe0 --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/constants.v @@ -0,0 +1,1754 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module constants. + Definition value_R (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 36; + Value.Integer IntegerKind.U8 3; + Value.Integer IntegerKind.U8 41; + Value.Integer IntegerKind.U8 18 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 44; + Value.Integer IntegerKind.U8 10; + Value.Integer IntegerKind.U8 45; + Value.Integer IntegerKind.U8 2 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 62; + Value.Integer IntegerKind.U8 6; + Value.Integer IntegerKind.U8 43; + Value.Integer IntegerKind.U8 15; + Value.Integer IntegerKind.U8 61 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 28; + Value.Integer IntegerKind.U8 55; + Value.Integer IntegerKind.U8 25; + Value.Integer IntegerKind.U8 21; + Value.Integer IntegerKind.U8 56 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 27; + Value.Integer IntegerKind.U8 20; + Value.Integer IntegerKind.U8 39; + Value.Integer IntegerKind.U8 8; + Value.Integer IntegerKind.U8 14 + ] + ] + |))). + + Global Instance Instance_IsConstant_value_R : + M.IsFunction.C "p3_keccak_air::constants::R" value_R. + Admitted. + Global Typeclasses Opaque value_R. + + Definition value_RC (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U64 1; + Value.Integer IntegerKind.U64 32898; + Value.Integer IntegerKind.U64 9223372036854808714; + Value.Integer IntegerKind.U64 9223372039002292224; + Value.Integer IntegerKind.U64 32907; + Value.Integer IntegerKind.U64 2147483649; + Value.Integer IntegerKind.U64 9223372039002292353; + Value.Integer IntegerKind.U64 9223372036854808585; + Value.Integer IntegerKind.U64 138; + Value.Integer IntegerKind.U64 136; + Value.Integer IntegerKind.U64 2147516425; + Value.Integer IntegerKind.U64 2147483658; + Value.Integer IntegerKind.U64 2147516555; + Value.Integer IntegerKind.U64 9223372036854775947; + Value.Integer IntegerKind.U64 9223372036854808713; + Value.Integer IntegerKind.U64 9223372036854808579; + Value.Integer IntegerKind.U64 9223372036854808578; + Value.Integer IntegerKind.U64 9223372036854775936; + Value.Integer IntegerKind.U64 32778; + Value.Integer IntegerKind.U64 9223372039002259466; + Value.Integer IntegerKind.U64 9223372039002292353; + Value.Integer IntegerKind.U64 9223372036854808704; + Value.Integer IntegerKind.U64 2147483649; + Value.Integer IntegerKind.U64 9223372039002292232 + ] + |))). + + Global Instance Instance_IsConstant_value_RC : + M.IsFunction.C "p3_keccak_air::constants::RC" value_RC. + Admitted. + Global Typeclasses Opaque value_RC. + + Definition value_RC_BITS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1 + ] + ] + |))). + + Global Instance Instance_IsConstant_value_RC_BITS : + M.IsFunction.C "p3_keccak_air::constants::RC_BITS" value_RC_BITS. + Admitted. + Global Typeclasses Opaque value_RC_BITS. + + (* + pub(crate) const fn rc_value_bit(round: usize, bit_index: usize) -> u8 { + RC_BITS[round][bit_index] + } + *) + Definition rc_value_bit (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ round; bit_index ] => + ltac:(M.monadic + (let round := M.alloc (| round |) in + let bit_index := M.alloc (| bit_index |) in + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_keccak_air::constants::RC_BITS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "u8" ] + ] + |), + M.read (| round |) + |), + M.read (| bit_index |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_rc_value_bit : + M.IsFunction.C "p3_keccak_air::constants::rc_value_bit" rc_value_bit. + Admitted. + Global Typeclasses Opaque rc_value_bit. +End constants. diff --git a/CoqOfRust/plonky3/keccak-air/src/generation.rs b/CoqOfRust/plonky3/keccak-air/src/generation.rs new file mode 100644 index 000000000..d05de9387 --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/generation.rs @@ -0,0 +1,137 @@ +use alloc::vec::Vec; +use core::array; +use core::mem::transmute; + +use p3_air::utils::{u64_to_16_bit_limbs, u64_to_bits_le}; +use p3_field::PrimeField64; +use p3_matrix::dense::RowMajorMatrix; +use p3_maybe_rayon::iter::repeat_n; +use p3_maybe_rayon::prelude::*; +use tracing::instrument; + +use crate::columns::{KeccakCols, NUM_KECCAK_COLS}; +use crate::{NUM_ROUNDS, R, RC, U64_LIMBS}; + +// TODO: Take generic iterable +#[instrument(name = "generate Keccak trace", skip_all)] +pub fn generate_trace_rows( + inputs: Vec<[u64; 25]>, + extra_capacity_bits: usize, +) -> RowMajorMatrix { + let num_rows = (inputs.len() * NUM_ROUNDS).next_power_of_two(); + let trace_length = num_rows * NUM_KECCAK_COLS; + + // We allocate extra_capacity_bits now as this will be needed by the dft. + let mut long_trace = F::zero_vec(trace_length << extra_capacity_bits); + long_trace.truncate(trace_length); + + let mut trace = RowMajorMatrix::new(long_trace, NUM_KECCAK_COLS); + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::>() }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(rows.len(), num_rows); + + let num_padding_inputs = num_rows.div_ceil(NUM_ROUNDS) - inputs.len(); + let padded_inputs = inputs + .into_par_iter() + .chain(repeat_n([0; 25], num_padding_inputs)); + + rows.par_chunks_mut(NUM_ROUNDS) + .zip(padded_inputs) + .for_each(|(row, input)| { + generate_trace_rows_for_perm(row, input); + }); + + trace +} + +/// `rows` will normally consist of 24 rows, with an exception for the final row. +fn generate_trace_rows_for_perm(rows: &mut [KeccakCols], input: [u64; 25]) { + let mut current_state: [[u64; 5]; 5] = unsafe { transmute(input) }; + + let initial_state: [[[F; 4]; 5]; 5] = + array::from_fn(|y| array::from_fn(|x| u64_to_16_bit_limbs(current_state[x][y]))); + + // Populate the round input for the first round. + rows[0].a = initial_state; + rows[0].preimage = initial_state; + + generate_trace_row_for_round(&mut rows[0], 0, &mut current_state); + + for round in 1..rows.len() { + rows[round].preimage = initial_state; + + // Copy previous row's output to next row's input. + for y in 0..5 { + for x in 0..5 { + for limb in 0..U64_LIMBS { + rows[round].a[y][x][limb] = rows[round - 1].a_prime_prime_prime(y, x, limb); + } + } + } + + generate_trace_row_for_round(&mut rows[round], round, &mut current_state); + } +} + +fn generate_trace_row_for_round( + row: &mut KeccakCols, + round: usize, + current_state: &mut [[u64; 5]; 5], +) { + row.step_flags[round] = F::ONE; + + // Populate C[x] = xor(A[x, 0], A[x, 1], A[x, 2], A[x, 3], A[x, 4]). + let state_c: [u64; 5] = current_state.map(|row| row.iter().fold(0, |acc, y| acc ^ y)); + for (x, elem) in state_c.iter().enumerate() { + row.c[x] = u64_to_bits_le(*elem); + } + + // Populate C'[x, z] = xor(C[x, z], C[x - 1, z], C[x + 1, z - 1]). + let state_c_prime: [u64; 5] = + array::from_fn(|x| state_c[x] ^ state_c[(x + 4) % 5] ^ state_c[(x + 1) % 5].rotate_left(1)); + for (x, elem) in state_c_prime.iter().enumerate() { + row.c_prime[x] = u64_to_bits_le(*elem); + } + + // Populate A'. To avoid shifting indices, we rewrite + // A'[x, y, z] = xor(A[x, y, z], C[x - 1, z], C[x + 1, z - 1]) + // as + // A'[x, y, z] = xor(A[x, y, z], C[x, z], C'[x, z]). + *current_state = + array::from_fn(|i| array::from_fn(|j| current_state[i][j] ^ state_c[i] ^ state_c_prime[i])); + for (x, x_row) in current_state.iter().enumerate() { + for (y, elem) in x_row.iter().enumerate() { + row.a_prime[y][x] = u64_to_bits_le(*elem); + } + } + + // Rotate the current state to get the B array. + *current_state = array::from_fn(|i| { + array::from_fn(|j| { + let new_i = (i + 3 * j) % 5; + let new_j = i; + current_state[new_i][new_j].rotate_left(R[new_i][new_j] as u32) + }) + }); + + // Populate A''. + // A''[x, y] = xor(B[x, y], andn(B[x + 1, y], B[x + 2, y])). + *current_state = array::from_fn(|i| { + array::from_fn(|j| { + current_state[i][j] ^ ((!current_state[(i + 1) % 5][j]) & current_state[(i + 2) % 5][j]) + }) + }); + for (x, x_row) in current_state.iter().enumerate() { + for (y, elem) in x_row.iter().enumerate() { + row.a_prime_prime[y][x] = u64_to_16_bit_limbs(*elem); + } + } + + row.a_prime_prime_0_0_bits = u64_to_bits_le(current_state[0][0]); + + // A''[0, 0] is additionally xor'd with RC. + current_state[0][0] ^= RC[round]; + + row.a_prime_prime_prime_0_0_limbs = u64_to_16_bit_limbs(current_state[0][0]); +} diff --git a/CoqOfRust/plonky3/keccak-air/src/generation.v b/CoqOfRust/plonky3/keccak-air/src/generation.v new file mode 100644 index 000000000..dd01a9fba --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/generation.v @@ -0,0 +1,4751 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module generation. + (* #[instrument(name = "generate Keccak trace", skip_all)] *) + Definition generate_trace_rows (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ inputs; extra_capacity_bits ] => + ltac:(M.monadic + (let inputs := M.alloc (| inputs |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.catch_return + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_keccak_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_keccak_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_keccak_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_keccak_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ num_rows : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "next_power_of_two", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inputs |) ] + |); + M.read (| + get_constant (| "p3_keccak_air::NUM_ROUNDS", Ty.path "usize" |) + |) + ] + |) + ] + |) + |) in + let~ trace_length : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| num_rows |); + M.read (| + get_constant (| + "p3_keccak_air::columns::NUM_KECCAK_COLS", + Ty.path "usize" + |) + |) + ] + |) + |) in + let~ long_trace : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "zero_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ M.read (| trace_length |); M.read (| extra_capacity_bits |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "truncate", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, long_trace |); M.read (| trace_length |) ] + |) + |) in + let~ trace : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ + M.read (| long_trace |); + M.read (| + get_constant (| + "p3_keccak_air::columns::NUM_KECCAK_COLS", + Ty.path "usize" + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ F ] ] + ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "align_to_mut", + [], + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ F ] ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + trace, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let rows := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Alignment should match" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Alignment should match" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ F ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| rows |) |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, num_rows |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ num_padding_inputs : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "div_ceil", [], [] |), + [ + M.read (| num_rows |); + M.read (| + get_constant (| "p3_keccak_air::NUM_ROUNDS", Ty.path "usize" |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inputs |) ] + |) + ] + |) + |) in + let~ padded_inputs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_par_iter", + [], + [] + |), + [ M.read (| inputs |) ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ], + M.get_function (| + "core::iter::sources::repeat_n::repeat_n", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] + |), + [ + repeat (| + Value.Integer IntegerKind.U64 0, + Value.Integer IntegerKind.Usize 25 + |); + M.read (| num_padding_inputs |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ F ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ F ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ F ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksMut") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ F ] + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ F ] + ], + [], + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ F ] + ], + "par_chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| rows |) |) + |); + M.read (| + get_constant (| + "p3_keccak_air::NUM_ROUNDS", + Ty.path "usize" + |) + |) + ] + |); + M.read (| padded_inputs |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_keccak_air::columns::KeccakCols") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let row := M.copy (| γ0_0 |) in + let input := M.copy (| γ0_1 |) in + M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_keccak_air::generation::generate_trace_rows_for_perm", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| row |) |) + |); + M.read (| input |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + trace)) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_trace_rows : + M.IsFunction.C "p3_keccak_air::generation::generate_trace_rows" generate_trace_rows. + Admitted. + Global Typeclasses Opaque generate_trace_rows. + + (* + fn generate_trace_rows_for_perm(rows: &mut [KeccakCols], input: [u64; 25]) { + let mut current_state: [[u64; 5]; 5] = unsafe { transmute(input) }; + + let initial_state: [[[F; 4]; 5]; 5] = + array::from_fn(|y| array::from_fn(|x| u64_to_16_bit_limbs(current_state[x][y]))); + + // Populate the round input for the first round. + rows[0].a = initial_state; + rows[0].preimage = initial_state; + + generate_trace_row_for_round(&mut rows[0], 0, &mut current_state); + + for round in 1..rows.len() { + rows[round].preimage = initial_state; + + // Copy previous row's output to next row's input. + for y in 0..5 { + for x in 0..5 { + for limb in 0..U64_LIMBS { + rows[round].a[y][x][limb] = rows[round - 1].a_prime_prime_prime(y, x, limb); + } + } + } + + generate_trace_row_for_round(&mut rows[round], round, &mut current_state); + } + } + *) + Definition generate_trace_rows_for_perm + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ rows; input ] => + ltac:(M.monadic + (let rows := M.alloc (| rows |) in + let input := M.alloc (| input |) in + M.read (| + let~ current_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ] + |), + [ M.read (| input |) ] + |) + |) in + let~ initial_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ F ] ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ F ] ] + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 5 ], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ F ] ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ F ] ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let y := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ] + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 5 ], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ F ], + M.get_function (| + "p3_air::utils::u64_to_16_bit_limbs", + [], + [ F ] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + current_state, + M.read (| x |) + |), + M.read (| y |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| rows |) |), + Value.Integer IntegerKind.Usize 0 + |), + "p3_keccak_air::columns::KeccakCols", + "a" + |), + M.read (| initial_state |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| rows |) |), + Value.Integer IntegerKind.Usize 0 + |), + "p3_keccak_air::columns::KeccakCols", + "preimage" + |), + M.read (| initial_state |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_keccak_air::generation::generate_trace_row_for_round", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| rows |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |); + Value.Integer IntegerKind.Usize 0; + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, current_state |) |) + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 1); + ("end_", + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_keccak_air::columns::KeccakCols") [] [ F ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| rows |) |) |) ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let round := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| rows |) |), + M.read (| round |) + |), + "p3_keccak_air::columns::KeccakCols", + "preimage" + |), + M.read (| initial_state |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let y := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", + Value.Integer + IntegerKind.Usize + 5) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := + M.copy (| + γ0_0 + |) in + M.use + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", + M.read (| + get_constant (| + "p3_keccak_air::U64_LIMBS", + Ty.path + "usize" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let + iter := + M.copy (| + γ + |) in + M.loop (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + ltac:(M.monadic + (let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "usize" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun + γ => + ltac:(M.monadic + (let + _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.break (||) + |) + |) + |))); + fun + γ => + ltac:(M.monadic + (let + γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let + limb := + M.copy (| + γ0_0 + |) in + let~ + _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + rows + |) + |), + M.read (| + round + |) + |), + "p3_keccak_air::columns::KeccakCols", + "a" + |), + M.read (| + y + |) + |), + M.read (| + x + |) + |), + M.read (| + limb + |) + |), + M.call_closure (| + F, + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_keccak_air::columns::KeccakCols") + [] + [ + F + ], + "a_prime_prime_prime", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + rows + |) + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.sub, + [ + M.read (| + round + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + |) + |); + M.read (| + y + |); + M.read (| + x + |); + M.read (| + limb + |) + ] + |) + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) in + M.alloc (| + Value.Tuple + [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| + Value.Tuple [] + |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_keccak_air::generation::generate_trace_row_for_round", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| rows |) |), + M.read (| round |) + |) + |) + |) + |); + M.read (| round |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, current_state |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_trace_rows_for_perm : + M.IsFunction.C + "p3_keccak_air::generation::generate_trace_rows_for_perm" + generate_trace_rows_for_perm. + Admitted. + Global Typeclasses Opaque generate_trace_rows_for_perm. + + (* + fn generate_trace_row_for_round( + row: &mut KeccakCols, + round: usize, + current_state: &mut [[u64; 5]; 5], + ) { + row.step_flags[round] = F::ONE; + + // Populate C[x] = xor(A[x, 0], A[x, 1], A[x, 2], A[x, 3], A[x, 4]). + let state_c: [u64; 5] = current_state.map(|row| row.iter().fold(0, |acc, y| acc ^ y)); + for (x, elem) in state_c.iter().enumerate() { + row.c[x] = u64_to_bits_le( *elem); + } + + // Populate C'[x, z] = xor(C[x, z], C[x - 1, z], C[x + 1, z - 1]). + let state_c_prime: [u64; 5] = + array::from_fn(|x| state_c[x] ^ state_c[(x + 4) % 5] ^ state_c[(x + 1) % 5].rotate_left(1)); + for (x, elem) in state_c_prime.iter().enumerate() { + row.c_prime[x] = u64_to_bits_le( *elem); + } + + // Populate A'. To avoid shifting indices, we rewrite + // A'[x, y, z] = xor(A[x, y, z], C[x - 1, z], C[x + 1, z - 1]) + // as + // A'[x, y, z] = xor(A[x, y, z], C[x, z], C'[x, z]). + *current_state = + array::from_fn(|i| array::from_fn(|j| current_state[i][j] ^ state_c[i] ^ state_c_prime[i])); + for (x, x_row) in current_state.iter().enumerate() { + for (y, elem) in x_row.iter().enumerate() { + row.a_prime[y][x] = u64_to_bits_le( *elem); + } + } + + // Rotate the current state to get the B array. + *current_state = array::from_fn(|i| { + array::from_fn(|j| { + let new_i = (i + 3 * j) % 5; + let new_j = i; + current_state[new_i][new_j].rotate_left(R[new_i][new_j] as u32) + }) + }); + + // Populate A''. + // A''[x, y] = xor(B[x, y], andn(B[x + 1, y], B[x + 2, y])). + *current_state = array::from_fn(|i| { + array::from_fn(|j| { + current_state[i][j] ^ ((!current_state[(i + 1) % 5][j]) & current_state[(i + 2) % 5][j]) + }) + }); + for (x, x_row) in current_state.iter().enumerate() { + for (y, elem) in x_row.iter().enumerate() { + row.a_prime_prime[y][x] = u64_to_16_bit_limbs( *elem); + } + } + + row.a_prime_prime_0_0_bits = u64_to_bits_le(current_state[0][0]); + + // A''[0, 0] is additionally xor'd with RC. + current_state[0][0] ^= RC[round]; + + row.a_prime_prime_prime_0_0_limbs = u64_to_16_bit_limbs(current_state[0][0]); + } + *) + Definition generate_trace_row_for_round + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ row; round; current_state ] => + ltac:(M.monadic + (let row := M.alloc (| row |) in + let round := M.alloc (| round |) in + let current_state := M.alloc (| current_state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_keccak_air::columns::KeccakCols", + "step_flags" + |), + M.read (| round |) + |), + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) |) + |) + |) in + let~ state_c : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 5 ] [ Ty.path "u64" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 5 ] [ Ty.path "u64" ], + M.get_associated_function (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + "map", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ] + (Ty.path "u64"); + Ty.path "u64" + ] + |), + [ + M.read (| M.deref (| M.read (| current_state |) |) |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let row := M.copy (| γ |) in + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ], + [], + [], + "fold", + [], + [ + Ty.path "u64"; + Ty.function + [ + Ty.tuple + [ + Ty.path "u64"; + Ty.apply (Ty.path "&") [] [ Ty.path "u64" ] + ] + ] + (Ty.path "u64") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u64" ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, row |)) + ] + |); + Value.Integer IntegerKind.U64 0; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "u64"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u64" ] + ] + ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "u64"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u64" ] + ] + ] + (Ty.path "u64") + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := M.copy (| γ |) in + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::ops::bit::BitXor", + Ty.path "u64", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u64" ] + ], + "bitxor", + [], + [] + |), + [ + M.read (| acc |); + M.read (| y |) + ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u64" ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, state_c |)) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ Ty.path "u64" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let x := M.copy (| γ1_0 |) in + let elem := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_keccak_air::columns::KeccakCols", + "c" + |), + M.read (| x |) + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ F ], + M.get_function (| + "p3_air::utils::u64_to_bits_le", + [], + [ F ] + |), + [ M.read (| M.deref (| M.read (| elem |) |) |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ state_c_prime : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 5 ] [ Ty.path "u64" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 5 ] [ Ty.path "u64" ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 5 ], + [ Ty.path "u64"; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.path "u64") ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.path "u64") ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_xor, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_xor, + [ + M.read (| + M.SubPointer.get_array_field (| + state_c, + M.read (| x |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + state_c, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| x |); + Value.Integer IntegerKind.Usize 4 + ] + |); + Value.Integer IntegerKind.Usize 5 + ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| + Ty.path "u64", + "rotate_left", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + state_c, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| x |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 5 + ] + |) + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u64" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u64" ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, state_c_prime |)) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ Ty.path "u64" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let x := M.copy (| γ1_0 |) in + let elem := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_keccak_air::columns::KeccakCols", + "c_prime" + |), + M.read (| x |) + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ F ], + M.get_function (| + "p3_air::utils::u64_to_bits_le", + [], + [ F ] + |), + [ M.read (| M.deref (| M.read (| elem |) |) |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| current_state |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 5 ], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 5 ], + [ + Ty.path "u64"; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u64") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_xor, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_xor, + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + current_state + |) + |), + M.read (| i |) + |), + M.read (| j |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + state_c, + M.read (| i |) + |) + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + state_c_prime, + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| current_state |) |) + |)) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let x := M.copy (| γ1_0 |) in + let x_row := M.copy (| γ1_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u64" ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x_row |) |) + |)) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u64" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "u64" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let y := M.copy (| γ1_0 |) in + let elem := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| row |) + |), + "p3_keccak_air::columns::KeccakCols", + "a_prime" + |), + M.read (| y |) + |), + M.read (| x |) + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 64 + ] + [ F ], + M.get_function (| + "p3_air::utils::u64_to_bits_le", + [], + [ F ] + |), + [ + M.read (| + M.deref (| + M.read (| elem |) + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| current_state |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 5 ], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 5 ], + [ + Ty.path "u64"; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u64") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.read (| + let~ new_i : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer + IntegerKind.Usize + 3; + M.read (| j |) + ] + |) + ] + |); + Value.Integer + IntegerKind.Usize + 5 + ] + |) + |) in + let~ new_j : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.copy (| i |) in + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| + Ty.path "u64", + "rotate_left", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + current_state + |) + |), + M.read (| new_i |) + |), + M.read (| new_j |) + |) + |); + M.cast + (Ty.path "u32") + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_keccak_air::constants::R", + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 5 + ] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 5 + ] + [ Ty.path "u8" ] + ] + |), + M.read (| new_i |) + |), + M.read (| new_j |) + |) + |)) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| current_state |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 5 ], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 5 ], + [ + Ty.path "u64"; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u64") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_xor, + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| current_state |) + |), + M.read (| i |) + |), + M.read (| j |) + |) + |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_and, + [ + UnOp.not (| + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + current_state + |) + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + Value.Integer + IntegerKind.Usize + 5 + ] + |) + |), + M.read (| j |) + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + current_state + |) + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer + IntegerKind.Usize + 2 + ] + |); + Value.Integer + IntegerKind.Usize + 5 + ] + |) + |), + M.read (| j |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| current_state |) |) + |)) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "u64" ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let x := M.copy (| γ1_0 |) in + let x_row := M.copy (| γ1_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u64" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u64" ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x_row |) |) + |)) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u64" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "u64" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let y := M.copy (| γ1_0 |) in + let elem := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| row |) + |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime" + |), + M.read (| y |) + |), + M.read (| x |) + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ F ], + M.get_function (| + "p3_air::utils::u64_to_16_bit_limbs", + [], + [ F ] + |), + [ + M.read (| + M.deref (| + M.read (| elem |) + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime_0_0_bits" + |), + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 64 ] [ F ], + M.get_function (| "p3_air::utils::u64_to_bits_le", [], [ F ] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| current_state |) |), + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| current_state |) |), + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 0 + |) in + M.write (| + β, + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_xor, + [ + M.read (| β |); + M.read (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_keccak_air::constants::RC", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u64" ] + |), + M.read (| round |) + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| row |) |), + "p3_keccak_air::columns::KeccakCols", + "a_prime_prime_prime_0_0_limbs" + |), + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ F ], + M.get_function (| "p3_air::utils::u64_to_16_bit_limbs", [], [ F ] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| current_state |) |), + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_trace_row_for_round : + M.IsFunction.C + "p3_keccak_air::generation::generate_trace_row_for_round" + generate_trace_row_for_round. + Admitted. + Global Typeclasses Opaque generate_trace_row_for_round. +End generation. diff --git a/CoqOfRust/plonky3/keccak-air/src/lib.rs b/CoqOfRust/plonky3/keccak-air/src/lib.rs new file mode 100644 index 000000000..1ccfdd081 --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/lib.rs @@ -0,0 +1,22 @@ +//! An AIR for the Keccak-f permutation. Assumes the field size is between 2^16 and 2^32. + +#![no_std] + +extern crate alloc; + +mod air; +mod columns; +mod constants; +mod generation; +mod round_flags; + +pub use air::*; +pub use columns::*; +pub use constants::*; +pub use generation::*; + +pub const NUM_ROUNDS: usize = 24; +const BITS_PER_LIMB: usize = 16; +pub const U64_LIMBS: usize = 64 / BITS_PER_LIMB; +const RATE_BITS: usize = 1088; +const RATE_LIMBS: usize = RATE_BITS / BITS_PER_LIMB; diff --git a/CoqOfRust/plonky3/keccak-air/src/lib.v b/CoqOfRust/plonky3/keccak-air/src/lib.v new file mode 100644 index 000000000..d88d9e72c --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/lib.v @@ -0,0 +1,62 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Definition value_NUM_ROUNDS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 24 |))). + +Global Instance Instance_IsConstant_value_NUM_ROUNDS : + M.IsFunction.C "p3_keccak_air::NUM_ROUNDS" value_NUM_ROUNDS. +Admitted. +Global Typeclasses Opaque value_NUM_ROUNDS. + +Definition value_BITS_PER_LIMB (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 16 |))). + +Global Instance Instance_IsConstant_value_BITS_PER_LIMB : + M.IsFunction.C "p3_keccak_air::BITS_PER_LIMB" value_BITS_PER_LIMB. +Admitted. +Global Typeclasses Opaque value_BITS_PER_LIMB. + +Definition value_U64_LIMBS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + Value.Integer IntegerKind.Usize 64; + M.read (| get_constant (| "p3_keccak_air::BITS_PER_LIMB", Ty.path "usize" |) |) + ] + |) + |))). + +Global Instance Instance_IsConstant_value_U64_LIMBS : + M.IsFunction.C "p3_keccak_air::U64_LIMBS" value_U64_LIMBS. +Admitted. +Global Typeclasses Opaque value_U64_LIMBS. + +Definition value_RATE_BITS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 1088 |))). + +Global Instance Instance_IsConstant_value_RATE_BITS : + M.IsFunction.C "p3_keccak_air::RATE_BITS" value_RATE_BITS. +Admitted. +Global Typeclasses Opaque value_RATE_BITS. + +Definition value_RATE_LIMBS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.read (| get_constant (| "p3_keccak_air::RATE_BITS", Ty.path "usize" |) |); + M.read (| get_constant (| "p3_keccak_air::BITS_PER_LIMB", Ty.path "usize" |) |) + ] + |) + |))). + +Global Instance Instance_IsConstant_value_RATE_LIMBS : + M.IsFunction.C "p3_keccak_air::RATE_LIMBS" value_RATE_LIMBS. +Admitted. +Global Typeclasses Opaque value_RATE_LIMBS. diff --git a/CoqOfRust/plonky3/keccak-air/src/round_flags.rs b/CoqOfRust/plonky3/keccak-air/src/round_flags.rs new file mode 100644 index 000000000..58bbe01e4 --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/round_flags.rs @@ -0,0 +1,30 @@ +use core::array; +use core::borrow::Borrow; + +use p3_air::AirBuilder; +use p3_matrix::Matrix; + +use crate::NUM_ROUNDS; +use crate::columns::KeccakCols; + +const NUM_ROUNDS_MIN_1: usize = NUM_ROUNDS - 1; + +#[inline] +pub(crate) fn eval_round_flags(builder: &mut AB) { + let main = builder.main(); + let (local, next) = (main.row_slice(0), main.row_slice(1)); + let local: &KeccakCols = (*local).borrow(); + let next: &KeccakCols = (*next).borrow(); + + // Initially, the first step flag should be 1 while the others should be 0. + builder.when_first_row().assert_one(local.step_flags[0]); + builder + .when_first_row() + .assert_zeros::(local.step_flags[1..].try_into().unwrap()); + + builder + .when_transition() + .assert_zeros::(array::from_fn(|i| { + local.step_flags[i] - next.step_flags[(i + 1) % NUM_ROUNDS] + })); +} diff --git a/CoqOfRust/plonky3/keccak-air/src/round_flags.v b/CoqOfRust/plonky3/keccak-air/src/round_flags.v new file mode 100644 index 000000000..57746216d --- /dev/null +++ b/CoqOfRust/plonky3/keccak-air/src/round_flags.v @@ -0,0 +1,724 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module round_flags. + Definition value_NUM_ROUNDS_MIN_1 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| get_constant (| "p3_keccak_air::NUM_ROUNDS", Ty.path "usize" |) |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |))). + + Global Instance Instance_IsConstant_value_NUM_ROUNDS_MIN_1 : + M.IsFunction.C "p3_keccak_air::round_flags::NUM_ROUNDS_MIN_1" value_NUM_ROUNDS_MIN_1. + Admitted. + Global Typeclasses Opaque value_NUM_ROUNDS_MIN_1. + + (* + pub(crate) fn eval_round_flags(builder: &mut AB) { + let main = builder.main(); + let (local, next) = (main.row_slice(0), main.row_slice(1)); + let local: &KeccakCols = ( *local).borrow(); + let next: &KeccakCols = ( *next).borrow(); + + // Initially, the first step flag should be 1 while the others should be 0. + builder.when_first_row().assert_one(local.step_flags[0]); + builder + .when_first_row() + .assert_zeros::(local.step_flags[1..].try_into().unwrap()); + + builder + .when_transition() + .assert_zeros::(array::from_fn(|i| { + local.step_flags[i] - next.step_flags[(i + 1) % NUM_ROUNDS] + })); + } + *) + Definition eval_round_flags (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ AB ], [ builder ] => + ltac:(M.monadic + (let builder := M.alloc (| builder |) in + M.read (| + let~ main : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + M.get_trait_method (| "p3_air::air::AirBuilder", AB, [], [], "main", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| builder |) |) |) ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "row_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, main |); Value.Integer IntegerKind.Usize 0 ] + |); + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "row_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, main |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let local := M.copy (| γ0_0 |) in + let next := M.copy (| γ0_1 |) in + let~ local : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "M") + "{{synthetic}}'2", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, local |) ] + |) + |) + |) + ] + |) + |) + |) + |) in + let~ next : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [ + Ty.apply + (Ty.path "p3_keccak_air::columns::KeccakCols") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "M") + "{{synthetic}}'2", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, next |) ] + |) + |) + |) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + Ty.apply (Ty.path "p3_air::air::FilteredAirBuilder") [] [ AB ], + [], + [], + "assert_one", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_air::air::FilteredAirBuilder") [] [ AB ], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "when_first_row", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |) + ] + |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_keccak_air::columns::KeccakCols", + "step_flags" + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + Ty.apply (Ty.path "p3_air::air::FilteredAirBuilder") [] [ AB ], + [], + [], + "assert_zeros", + [ Value.Integer IntegerKind.Usize 23 ], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_air::air::FilteredAirBuilder") [] [ AB ], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "when_first_row", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |) + ] + |) + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 23 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 23 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 23 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 23 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_keccak_air::columns::KeccakCols", + "step_flags" + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + Ty.apply (Ty.path "p3_air::air::FilteredAirBuilder") [] [ AB ], + [], + [], + "assert_zeros", + [ Value.Integer IntegerKind.Usize 24 ], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_air::air::FilteredAirBuilder") [] [ AB ], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "when_transition", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |) + ] + |) + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 24 ], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_keccak_air::columns::KeccakCols", + "step_flags" + |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| next |) |), + "p3_keccak_air::columns::KeccakCols", + "step_flags" + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |); + M.read (| + get_constant (| + "p3_keccak_air::NUM_ROUNDS", + Ty.path "usize" + |) + |) + ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_eval_round_flags : + M.IsFunction.C "p3_keccak_air::round_flags::eval_round_flags" eval_round_flags. + Admitted. + Global Typeclasses Opaque eval_round_flags. +End round_flags. diff --git a/CoqOfRust/plonky3/keccak/src/avx2.rs b/CoqOfRust/plonky3/keccak/src/avx2.rs new file mode 100644 index 000000000..0627e023b --- /dev/null +++ b/CoqOfRust/plonky3/keccak/src/avx2.rs @@ -0,0 +1,471 @@ +use core::arch::x86_64::{ + __m256i, _mm256_add_epi64, _mm256_andnot_si256, _mm256_or_si256, _mm256_shuffle_epi8, + _mm256_slli_epi64, _mm256_srli_epi64, _mm256_xor_si256, +}; +use core::mem::transmute; + +use p3_symmetric::{CryptographicPermutation, Permutation}; + +use crate::KeccakF; + +pub const VECTOR_LEN: usize = 4; + +const RC: [__m256i; 24] = unsafe { + transmute([ + [1u64; 4], + [0x8082u64; 4], + [0x800000000000808au64; 4], + [0x8000000080008000u64; 4], + [0x808bu64; 4], + [0x80000001u64; 4], + [0x8000000080008081u64; 4], + [0x8000000000008009u64; 4], + [0x8au64; 4], + [0x88u64; 4], + [0x80008009u64; 4], + [0x8000000au64; 4], + [0x8000808bu64; 4], + [0x800000000000008bu64; 4], + [0x8000000000008089u64; 4], + [0x8000000000008003u64; 4], + [0x8000000000008002u64; 4], + [0x8000000000000080u64; 4], + [0x800au64; 4], + [0x800000008000000au64; 4], + [0x8000000080008081u64; 4], + [0x8000000000008080u64; 4], + [0x80000001u64; 4], + [0x8000000080008008u64; 4], + ]) +}; + +#[inline(always)] +fn form_matrix(buf: [__m256i; 25]) -> [[__m256i; 5]; 5] { + unsafe { transmute(buf) } +} + +#[inline(always)] +fn flatten(mat: [[__m256i; 5]; 5]) -> [__m256i; 25] { + unsafe { transmute(mat) } +} + +#[inline(always)] +fn rol_1(a: __m256i) -> __m256i { + unsafe { + let shl = _mm256_add_epi64(a, a); + let shr = _mm256_srli_epi64::<63>(a); + _mm256_or_si256(shl, shr) + } +} + +const ROL_8_CTRL: __m256i = unsafe { + transmute::<[u8; 32], _>([ + 0o07, 0o00, 0o01, 0o02, 0o03, 0o04, 0o05, 0o06, 0o17, 0o10, 0o11, 0o12, 0o13, 0o14, 0o15, + 0o16, 0o07, 0o00, 0o01, 0o02, 0o03, 0o04, 0o05, 0o06, 0o17, 0o10, 0o11, 0o12, 0o13, 0o14, + 0o15, 0o16, + ]) +}; + +#[inline(always)] +fn rol_8(a: __m256i) -> __m256i { + unsafe { _mm256_shuffle_epi8(a, ROL_8_CTRL) } +} + +const ROL_56_CTRL: __m256i = unsafe { + transmute::<[u8; 32], _>([ + 0o01, 0o02, 0o03, 0o04, 0o05, 0o06, 0o07, 0o00, 0o11, 0o12, 0o13, 0o14, 0o15, 0o16, 0o17, + 0o10, 0o01, 0o02, 0o03, 0o04, 0o05, 0o06, 0o07, 0o00, 0o11, 0o12, 0o13, 0o14, 0o15, 0o16, + 0o17, 0o10, + ]) +}; + +#[inline(always)] +fn rol_56(a: __m256i) -> __m256i { + unsafe { _mm256_shuffle_epi8(a, ROL_56_CTRL) } +} + +#[inline(always)] +fn rol(a: __m256i) -> __m256i { + unsafe { + let shl = _mm256_slli_epi64::(a); + let shr = _mm256_srli_epi64::(a); + _mm256_or_si256(shl, shr) + } +} + +#[inline(always)] +fn get_theta_parities(state: [[__m256i; 5]; 5]) -> [__m256i; 5] { + unsafe { + let mut par0 = _mm256_xor_si256(state[0][0], state[1][0]); + let mut par1 = _mm256_xor_si256(state[0][1], state[1][1]); + let mut par2 = _mm256_xor_si256(state[0][2], state[1][2]); + let mut par3 = _mm256_xor_si256(state[0][3], state[1][3]); + let mut par4 = _mm256_xor_si256(state[0][4], state[1][4]); + + par0 = _mm256_xor_si256(par0, state[2][0]); + par1 = _mm256_xor_si256(par1, state[2][1]); + par2 = _mm256_xor_si256(par2, state[2][2]); + par3 = _mm256_xor_si256(par3, state[2][3]); + par4 = _mm256_xor_si256(par4, state[2][4]); + + par0 = _mm256_xor_si256(par0, state[3][0]); + par1 = _mm256_xor_si256(par1, state[3][1]); + par2 = _mm256_xor_si256(par2, state[3][2]); + par3 = _mm256_xor_si256(par3, state[3][3]); + par4 = _mm256_xor_si256(par4, state[3][4]); + + par0 = _mm256_xor_si256(par0, state[4][0]); + par1 = _mm256_xor_si256(par1, state[4][1]); + par2 = _mm256_xor_si256(par2, state[4][2]); + par3 = _mm256_xor_si256(par3, state[4][3]); + par4 = _mm256_xor_si256(par4, state[4][4]); + + [ + _mm256_xor_si256(par4, rol_1(par1)), + _mm256_xor_si256(par0, rol_1(par2)), + _mm256_xor_si256(par1, rol_1(par3)), + _mm256_xor_si256(par2, rol_1(par4)), + _mm256_xor_si256(par3, rol_1(par0)), + ] + } +} + +#[inline(always)] +fn theta(state: [[__m256i; 5]; 5]) -> [[__m256i; 5]; 5] { + let theta_parities = get_theta_parities(state); + + unsafe { + [ + [ + _mm256_xor_si256(state[0][0], theta_parities[0]), + _mm256_xor_si256(state[0][1], theta_parities[1]), + _mm256_xor_si256(state[0][2], theta_parities[2]), + _mm256_xor_si256(state[0][3], theta_parities[3]), + _mm256_xor_si256(state[0][4], theta_parities[4]), + ], + [ + _mm256_xor_si256(state[1][0], theta_parities[0]), + _mm256_xor_si256(state[1][1], theta_parities[1]), + _mm256_xor_si256(state[1][2], theta_parities[2]), + _mm256_xor_si256(state[1][3], theta_parities[3]), + _mm256_xor_si256(state[1][4], theta_parities[4]), + ], + [ + _mm256_xor_si256(state[2][0], theta_parities[0]), + _mm256_xor_si256(state[2][1], theta_parities[1]), + _mm256_xor_si256(state[2][2], theta_parities[2]), + _mm256_xor_si256(state[2][3], theta_parities[3]), + _mm256_xor_si256(state[2][4], theta_parities[4]), + ], + [ + _mm256_xor_si256(state[3][0], theta_parities[0]), + _mm256_xor_si256(state[3][1], theta_parities[1]), + _mm256_xor_si256(state[3][2], theta_parities[2]), + _mm256_xor_si256(state[3][3], theta_parities[3]), + _mm256_xor_si256(state[3][4], theta_parities[4]), + ], + [ + _mm256_xor_si256(state[4][0], theta_parities[0]), + _mm256_xor_si256(state[4][1], theta_parities[1]), + _mm256_xor_si256(state[4][2], theta_parities[2]), + _mm256_xor_si256(state[4][3], theta_parities[3]), + _mm256_xor_si256(state[4][4], theta_parities[4]), + ], + ] + } +} + +#[inline(always)] +fn rho(state: [[__m256i; 5]; 5]) -> [[__m256i; 5]; 5] { + [ + [ + state[0][0], + rol_1(state[0][1]), + rol::<62, { 64 - 62 }>(state[0][2]), + rol::<28, { 64 - 28 }>(state[0][3]), + rol::<27, { 64 - 27 }>(state[0][4]), + ], + [ + rol::<36, { 64 - 36 }>(state[1][0]), + rol::<44, { 64 - 44 }>(state[1][1]), + rol::<6, { 64 - 6 }>(state[1][2]), + rol::<55, { 64 - 55 }>(state[1][3]), + rol::<20, { 64 - 20 }>(state[1][4]), + ], + [ + rol::<3, { 64 - 3 }>(state[2][0]), + rol::<10, { 64 - 10 }>(state[2][1]), + rol::<43, { 64 - 43 }>(state[2][2]), + rol::<25, { 64 - 25 }>(state[2][3]), + rol::<39, { 64 - 39 }>(state[2][4]), + ], + [ + rol::<41, { 64 - 41 }>(state[3][0]), + rol::<45, { 64 - 45 }>(state[3][1]), + rol::<15, { 64 - 15 }>(state[3][2]), + rol::<21, { 64 - 21 }>(state[3][3]), + rol_8(state[3][4]), + ], + [ + rol::<18, { 64 - 18 }>(state[4][0]), + rol::<2, { 64 - 2 }>(state[4][1]), + rol::<61, { 64 - 61 }>(state[4][2]), + rol_56(state[4][3]), + rol::<14, { 64 - 14 }>(state[4][4]), + ], + ] +} + +#[inline(always)] +fn pi(state: [[__m256i; 5]; 5]) -> [[__m256i; 5]; 5] { + [ + [ + state[0][0], + state[1][1], + state[2][2], + state[3][3], + state[4][4], + ], + [ + state[0][3], + state[1][4], + state[2][0], + state[3][1], + state[4][2], + ], + [ + state[0][1], + state[1][2], + state[2][3], + state[3][4], + state[4][0], + ], + [ + state[0][4], + state[1][0], + state[2][1], + state[3][2], + state[4][3], + ], + [ + state[0][2], + state[1][3], + state[2][4], + state[3][0], + state[4][1], + ], + ] +} + +#[inline(always)] +fn chi_row(row: [__m256i; 5]) -> [__m256i; 5] { + unsafe { + [ + _mm256_xor_si256(row[0], _mm256_andnot_si256(row[1], row[2])), + _mm256_xor_si256(row[1], _mm256_andnot_si256(row[2], row[3])), + _mm256_xor_si256(row[2], _mm256_andnot_si256(row[3], row[4])), + _mm256_xor_si256(row[3], _mm256_andnot_si256(row[4], row[0])), + _mm256_xor_si256(row[4], _mm256_andnot_si256(row[0], row[1])), + ] + } +} + +#[inline(always)] +fn chi(state: [[__m256i; 5]; 5]) -> [[__m256i; 5]; 5] { + [ + chi_row(state[0]), + chi_row(state[1]), + chi_row(state[2]), + chi_row(state[3]), + chi_row(state[4]), + ] +} + +#[inline(always)] +fn iota(i: usize, state: [[__m256i; 5]; 5]) -> [[__m256i; 5]; 5] { + let mut res = state; + unsafe { + res[0][0] = _mm256_xor_si256(state[0][0], RC[i]); + } + res +} + +#[inline(always)] +fn round(i: usize, state: [__m256i; 25]) -> [__m256i; 25] { + let mut state = form_matrix(state); + state = theta(state); + state = rho(state); + state = pi(state); + state = chi(state); + state = iota(i, state); + flatten(state) +} + +fn keccak_perm(buf: &mut [[u64; VECTOR_LEN]; 25]) { + let mut state: [__m256i; 25] = unsafe { transmute(*buf) }; + for i in 0..24 { + state = round(i, state); + } + *buf = unsafe { transmute::<[__m256i; 25], [[u64; VECTOR_LEN]; 25]>(state) }; +} + +impl Permutation<[[u64; VECTOR_LEN]; 25]> for KeccakF { + fn permute_mut(&self, state: &mut [[u64; VECTOR_LEN]; 25]) { + keccak_perm(state); + } +} + +impl CryptographicPermutation<[[u64; VECTOR_LEN]; 25]> for KeccakF {} + +#[cfg(test)] +mod tests { + use tiny_keccak::keccakf; + + use super::*; + + const STATES: [[u64; 25]; 4] = [ + [ + 0xc22c4c11dbedc46a, + 0x317f74268c4f5cd0, + 0x838719da5aa295b6, + 0x9e9b17211985a3ba, + 0x92927b963ce29d69, + 0xf9a7169e38cc7216, + 0x639a594d6fbfe341, + 0x2335ebd8d15777bd, + 0x44e1abc0d022823b, + 0xb3657f9d16b36c13, + 0x26d9217c32b3010a, + 0x6e73d6e9c7e5bcc8, + 0x400aa469d130a391, + 0x1aa7c8a2cb97188a, + 0xdc3084a09bd0a6e3, + 0xbcfe3b656841baea, + 0x325f41887c840166, + 0x844656e313674bfe, + 0xd63de8bad19d156c, + 0x49ef0ac0ab52e147, + 0x8b92ee811c654ca9, + 0x42a9310fedf09bda, + 0x182dbdac03a5358e, + 0x3b4692ce58af8cb5, + 0x534da610f01b8fb3, + ], + [ + 0x1c322ff4aea07d26, + 0xbd67bde061c97612, + 0x517565bd02ab410a, + 0xb251273ddc12a725, + 0x24f0979fe4f4fedc, + 0xc32d063a64f0bf03, + 0xd33c6709a7b103d2, + 0xaf33a8224b5c8828, + 0x6544ca066e997f1c, + 0xd53ad41e39f06d68, + 0x67695f6fb71d77d9, + 0xd6378cf19ee510f2, + 0x49472ea57abcbd08, + 0xcf3739df1eefbbb4, + 0x0fac1bf30e8ef101, + 0x7ff04c9b90de0f27, + 0xf3d63ec0e64cb2ab, + 0x76388c05f377d4bd, + 0x7886dd8f5b14ef5b, + 0xb036d289ba24a513, + 0x011e8fd6be65a408, + 0x695e2d20848eec67, + 0x31f9e80c5f45f8ee, + 0xcdf873daf7a5fdeb, + 0xfe98ff5bf28d560a, + ], + [ + 0xed7423c3e4cda469, + 0x8bbbe52577993e33, + 0x93182a78487f96db, + 0x3c5209456d78dc73, + 0x8b66bde37b967146, + 0x226ae6e2148314fc, + 0x302aed4f30cd2db9, + 0x621a7c7751302084, + 0x4054874254bc66cc, + 0xb513327739d3c109, + 0x0ae03189599dd81a, + 0x457e6f324e512ed9, + 0x3870ea63c7367728, + 0xb08c7c0e401d2623, + 0xa1316890c9bb3ac1, + 0x0a313e02f34f6c7e, + 0x7c1325754df4dbf5, + 0x287e3d88240bedd2, + 0xc7c0f3c5058290bb, + 0x39471c62d065a4d1, + 0x050d8ecb5c7911bf, + 0x7a6cd7ca757186a7, + 0xed14a51934a17895, + 0x8a75418d7ffb98dd, + 0x8096f8d803188d57, + ], + [ + 0x118d693606b316cd, + 0xc2614f04c0dfca91, + 0x5eb3da95450a214f, + 0x193eb69a8198e724, + 0xc24dea1c58e5fa6d, + 0xcf8630adb771d47c, + 0xe612253b23ade1df, + 0x281b2b53f2d5fe61, + 0x9a3f8fb149d7c419, + 0x7ac1eeffbd426464, + 0xb1bdb03caa7b20a3, + 0x4e38a03b709d47d1, + 0x35cafd22e9a91879, + 0x26c9ae757c5b9f80, + 0x9113b092720d90db, + 0xeb504ed5104a0a09, + 0x1405c220c45ee2b1, + 0x8055d2c37b02472b, + 0x545eeff9734b4b99, + 0x79eb67721385dff8, + 0x4133f750b0446360, + 0x7167e6c1fd8ff59b, + 0x576436ac7d46936e, + 0x8db22fbb547d0826, + 0xa855d775d64f0110, + ], + ]; + + #[allow(clippy::needless_range_loop)] + fn our_res() -> [[u64; 25]; 4] { + let mut packed_result = [[0; 4]; 25]; + for (i, packed_res) in packed_result.iter_mut().enumerate() { + *packed_res = [STATES[0][i], STATES[1][i], STATES[2][i], STATES[3][i]]; + } + + keccak_perm(&mut packed_result); + + let mut result = [[0; 25]; 4]; + for (i, packed_res) in packed_result.iter_mut().enumerate() { + result[0][i] = packed_res[0]; + result[1][i] = packed_res[1]; + result[2][i] = packed_res[2]; + result[3][i] = packed_res[3]; + } + result + } + + fn tiny_keccak_res() -> [[u64; 25]; 4] { + let mut result = STATES; + keccakf(&mut result[0]); + keccakf(&mut result[1]); + keccakf(&mut result[2]); + keccakf(&mut result[3]); + result + } + + #[test] + fn test_vs_tiny_keccak() { + let expected = tiny_keccak_res(); + let computed = our_res(); + assert_eq!(expected, computed); + } +} diff --git a/CoqOfRust/plonky3/keccak/src/avx512.rs b/CoqOfRust/plonky3/keccak/src/avx512.rs new file mode 100644 index 000000000..44bd251a4 --- /dev/null +++ b/CoqOfRust/plonky3/keccak/src/avx512.rs @@ -0,0 +1,643 @@ +use core::arch::x86_64::{ + __m512i, _mm512_rol_epi64, _mm512_set1_epi64, _mm512_ternarylogic_epi64, _mm512_xor_epi64, +}; +use core::mem::transmute; + +use p3_symmetric::{CryptographicPermutation, Permutation}; + +use crate::KeccakF; + +pub const VECTOR_LEN: usize = 8; + +const RC: [u64; 24] = [ + 1u64, + 0x8082u64, + 0x800000000000808au64, + 0x8000000080008000u64, + 0x808bu64, + 0x80000001u64, + 0x8000000080008081u64, + 0x8000000000008009u64, + 0x8au64, + 0x88u64, + 0x80008009u64, + 0x8000000au64, + 0x8000808bu64, + 0x800000000000008bu64, + 0x8000000000008089u64, + 0x8000000000008003u64, + 0x8000000000008002u64, + 0x8000000000000080u64, + 0x800au64, + 0x800000008000000au64, + 0x8000000080008081u64, + 0x8000000000008080u64, + 0x80000001u64, + 0x8000000080008008u64, +]; + +#[inline(always)] +fn form_matrix(buf: [__m512i; 25]) -> [[__m512i; 5]; 5] { + unsafe { transmute(buf) } +} + +#[inline(always)] +fn flatten(mat: [[__m512i; 5]; 5]) -> [__m512i; 25] { + unsafe { transmute(mat) } +} + +#[inline(always)] +fn get_theta_parities(state: [[__m512i; 5]; 5]) -> [(__m512i, __m512i); 5] { + unsafe { + let mut par0 = + _mm512_ternarylogic_epi64::<0b10010110>(state[0][0], state[1][0], state[2][0]); + let mut par1 = + _mm512_ternarylogic_epi64::<0b10010110>(state[0][1], state[1][1], state[2][1]); + let mut par2 = + _mm512_ternarylogic_epi64::<0b10010110>(state[0][2], state[1][2], state[2][2]); + let mut par3 = + _mm512_ternarylogic_epi64::<0b10010110>(state[0][3], state[1][3], state[2][3]); + let mut par4 = + _mm512_ternarylogic_epi64::<0b10010110>(state[0][4], state[1][4], state[2][4]); + + par0 = _mm512_ternarylogic_epi64::<0b10010110>(par0, state[3][0], state[4][0]); + par1 = _mm512_ternarylogic_epi64::<0b10010110>(par1, state[3][1], state[4][1]); + par2 = _mm512_ternarylogic_epi64::<0b10010110>(par2, state[3][2], state[4][2]); + par3 = _mm512_ternarylogic_epi64::<0b10010110>(par3, state[3][3], state[4][3]); + par4 = _mm512_ternarylogic_epi64::<0b10010110>(par4, state[3][4], state[4][4]); + + [ + (par4, _mm512_rol_epi64::<1>(par1)), + (par0, _mm512_rol_epi64::<1>(par2)), + (par1, _mm512_rol_epi64::<1>(par3)), + (par2, _mm512_rol_epi64::<1>(par4)), + (par3, _mm512_rol_epi64::<1>(par0)), + ] + } +} + +#[inline(always)] +fn theta(state: [[__m512i; 5]; 5]) -> [[__m512i; 5]; 5] { + let theta_parities = get_theta_parities(state); + + unsafe { + [ + [ + _mm512_ternarylogic_epi64::<0b10010110>( + state[0][0], + theta_parities[0].0, + theta_parities[0].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[0][1], + theta_parities[1].0, + theta_parities[1].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[0][2], + theta_parities[2].0, + theta_parities[2].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[0][3], + theta_parities[3].0, + theta_parities[3].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[0][4], + theta_parities[4].0, + theta_parities[4].1, + ), + ], + [ + _mm512_ternarylogic_epi64::<0b10010110>( + state[1][0], + theta_parities[0].0, + theta_parities[0].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[1][1], + theta_parities[1].0, + theta_parities[1].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[1][2], + theta_parities[2].0, + theta_parities[2].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[1][3], + theta_parities[3].0, + theta_parities[3].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[1][4], + theta_parities[4].0, + theta_parities[4].1, + ), + ], + [ + _mm512_ternarylogic_epi64::<0b10010110>( + state[2][0], + theta_parities[0].0, + theta_parities[0].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[2][1], + theta_parities[1].0, + theta_parities[1].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[2][2], + theta_parities[2].0, + theta_parities[2].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[2][3], + theta_parities[3].0, + theta_parities[3].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[2][4], + theta_parities[4].0, + theta_parities[4].1, + ), + ], + [ + _mm512_ternarylogic_epi64::<0b10010110>( + state[3][0], + theta_parities[0].0, + theta_parities[0].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[3][1], + theta_parities[1].0, + theta_parities[1].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[3][2], + theta_parities[2].0, + theta_parities[2].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[3][3], + theta_parities[3].0, + theta_parities[3].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[3][4], + theta_parities[4].0, + theta_parities[4].1, + ), + ], + [ + _mm512_ternarylogic_epi64::<0b10010110>( + state[4][0], + theta_parities[0].0, + theta_parities[0].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[4][1], + theta_parities[1].0, + theta_parities[1].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[4][2], + theta_parities[2].0, + theta_parities[2].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[4][3], + theta_parities[3].0, + theta_parities[3].1, + ), + _mm512_ternarylogic_epi64::<0b10010110>( + state[4][4], + theta_parities[4].0, + theta_parities[4].1, + ), + ], + ] + } +} + +#[inline(always)] +fn rho(state: [[__m512i; 5]; 5]) -> [[__m512i; 5]; 5] { + unsafe { + [ + [ + state[0][0], + _mm512_rol_epi64::<1>(state[0][1]), + _mm512_rol_epi64::<62>(state[0][2]), + _mm512_rol_epi64::<28>(state[0][3]), + _mm512_rol_epi64::<27>(state[0][4]), + ], + [ + _mm512_rol_epi64::<36>(state[1][0]), + _mm512_rol_epi64::<44>(state[1][1]), + _mm512_rol_epi64::<6>(state[1][2]), + _mm512_rol_epi64::<55>(state[1][3]), + _mm512_rol_epi64::<20>(state[1][4]), + ], + [ + _mm512_rol_epi64::<3>(state[2][0]), + _mm512_rol_epi64::<10>(state[2][1]), + _mm512_rol_epi64::<43>(state[2][2]), + _mm512_rol_epi64::<25>(state[2][3]), + _mm512_rol_epi64::<39>(state[2][4]), + ], + [ + _mm512_rol_epi64::<41>(state[3][0]), + _mm512_rol_epi64::<45>(state[3][1]), + _mm512_rol_epi64::<15>(state[3][2]), + _mm512_rol_epi64::<21>(state[3][3]), + _mm512_rol_epi64::<8>(state[3][4]), + ], + [ + _mm512_rol_epi64::<18>(state[4][0]), + _mm512_rol_epi64::<2>(state[4][1]), + _mm512_rol_epi64::<61>(state[4][2]), + _mm512_rol_epi64::<56>(state[4][3]), + _mm512_rol_epi64::<14>(state[4][4]), + ], + ] + } +} + +#[inline(always)] +fn pi(state: [[__m512i; 5]; 5]) -> [[__m512i; 5]; 5] { + [ + [ + state[0][0], + state[1][1], + state[2][2], + state[3][3], + state[4][4], + ], + [ + state[0][3], + state[1][4], + state[2][0], + state[3][1], + state[4][2], + ], + [ + state[0][1], + state[1][2], + state[2][3], + state[3][4], + state[4][0], + ], + [ + state[0][4], + state[1][0], + state[2][1], + state[3][2], + state[4][3], + ], + [ + state[0][2], + state[1][3], + state[2][4], + state[3][0], + state[4][1], + ], + ] +} + +#[inline(always)] +fn chi_row(row: [__m512i; 5]) -> [__m512i; 5] { + unsafe { + [ + _mm512_ternarylogic_epi64::<0b11010010>(row[0], row[1], row[2]), + _mm512_ternarylogic_epi64::<0b11010010>(row[1], row[2], row[3]), + _mm512_ternarylogic_epi64::<0b11010010>(row[2], row[3], row[4]), + _mm512_ternarylogic_epi64::<0b11010010>(row[3], row[4], row[0]), + _mm512_ternarylogic_epi64::<0b11010010>(row[4], row[0], row[1]), + ] + } +} + +#[inline(always)] +fn chi(state: [[__m512i; 5]; 5]) -> [[__m512i; 5]; 5] { + [ + chi_row(state[0]), + chi_row(state[1]), + chi_row(state[2]), + chi_row(state[3]), + chi_row(state[4]), + ] +} + +#[inline(always)] +fn iota(i: usize, state: [[__m512i; 5]; 5]) -> [[__m512i; 5]; 5] { + let mut res = state; + unsafe { + res[0][0] = _mm512_xor_epi64(state[0][0], _mm512_set1_epi64(RC[i] as i64)); + } + res +} +#[inline(always)] +fn round(i: usize, state: [__m512i; 25]) -> [__m512i; 25] { + let mut state = form_matrix(state); + state = theta(state); + state = rho(state); + state = pi(state); + state = chi(state); + state = iota(i, state); + flatten(state) +} + +fn keccak_perm(buf: &mut [[u64; VECTOR_LEN]; 25]) { + let mut state: [__m512i; 25] = unsafe { transmute(*buf) }; + for i in 0..24 { + state = round(i, state); + } + *buf = unsafe { transmute::<[__m512i; 25], [[u64; VECTOR_LEN]; 25]>(state) }; +} + +impl Permutation<[[u64; VECTOR_LEN]; 25]> for KeccakF { + fn permute_mut(&self, state: &mut [[u64; VECTOR_LEN]; 25]) { + keccak_perm(state); + } +} + +impl CryptographicPermutation<[[u64; VECTOR_LEN]; 25]> for KeccakF {} + +#[cfg(test)] +mod tests { + use tiny_keccak::keccakf; + + use super::*; + + const STATES: [[u64; 25]; 8] = [ + [ + 0xc22c4c11dbedc46a, + 0x317f74268c4f5cd0, + 0x838719da5aa295b6, + 0x9e9b17211985a3ba, + 0x92927b963ce29d69, + 0xf9a7169e38cc7216, + 0x639a594d6fbfe341, + 0x2335ebd8d15777bd, + 0x44e1abc0d022823b, + 0xb3657f9d16b36c13, + 0x26d9217c32b3010a, + 0x6e73d6e9c7e5bcc8, + 0x400aa469d130a391, + 0x1aa7c8a2cb97188a, + 0xdc3084a09bd0a6e3, + 0xbcfe3b656841baea, + 0x325f41887c840166, + 0x844656e313674bfe, + 0xd63de8bad19d156c, + 0x49ef0ac0ab52e147, + 0x8b92ee811c654ca9, + 0x42a9310fedf09bda, + 0x182dbdac03a5358e, + 0x3b4692ce58af8cb5, + 0x534da610f01b8fb3, + ], + [ + 0x1c322ff4aea07d26, + 0xbd67bde061c97612, + 0x517565bd02ab410a, + 0xb251273ddc12a725, + 0x24f0979fe4f4fedc, + 0xc32d063a64f0bf03, + 0xd33c6709a7b103d2, + 0xaf33a8224b5c8828, + 0x6544ca066e997f1c, + 0xd53ad41e39f06d68, + 0x67695f6fb71d77d9, + 0xd6378cf19ee510f2, + 0x49472ea57abcbd08, + 0xcf3739df1eefbbb4, + 0x0fac1bf30e8ef101, + 0x7ff04c9b90de0f27, + 0xf3d63ec0e64cb2ab, + 0x76388c05f377d4bd, + 0x7886dd8f5b14ef5b, + 0xb036d289ba24a513, + 0x011e8fd6be65a408, + 0x695e2d20848eec67, + 0x31f9e80c5f45f8ee, + 0xcdf873daf7a5fdeb, + 0xfe98ff5bf28d560a, + ], + [ + 0xed7423c3e4cda469, + 0x8bbbe52577993e33, + 0x93182a78487f96db, + 0x3c5209456d78dc73, + 0x8b66bde37b967146, + 0x226ae6e2148314fc, + 0x302aed4f30cd2db9, + 0x621a7c7751302084, + 0x4054874254bc66cc, + 0xb513327739d3c109, + 0x0ae03189599dd81a, + 0x457e6f324e512ed9, + 0x3870ea63c7367728, + 0xb08c7c0e401d2623, + 0xa1316890c9bb3ac1, + 0x0a313e02f34f6c7e, + 0x7c1325754df4dbf5, + 0x287e3d88240bedd2, + 0xc7c0f3c5058290bb, + 0x39471c62d065a4d1, + 0x050d8ecb5c7911bf, + 0x7a6cd7ca757186a7, + 0xed14a51934a17895, + 0x8a75418d7ffb98dd, + 0x8096f8d803188d57, + ], + [ + 0x118d693606b316cd, + 0xc2614f04c0dfca91, + 0x5eb3da95450a214f, + 0x193eb69a8198e724, + 0xc24dea1c58e5fa6d, + 0xcf8630adb771d47c, + 0xe612253b23ade1df, + 0x281b2b53f2d5fe61, + 0x9a3f8fb149d7c419, + 0x7ac1eeffbd426464, + 0xb1bdb03caa7b20a3, + 0x4e38a03b709d47d1, + 0x35cafd22e9a91879, + 0x26c9ae757c5b9f80, + 0x9113b092720d90db, + 0xeb504ed5104a0a09, + 0x1405c220c45ee2b1, + 0x8055d2c37b02472b, + 0x545eeff9734b4b99, + 0x79eb67721385dff8, + 0x4133f750b0446360, + 0x7167e6c1fd8ff59b, + 0x576436ac7d46936e, + 0x8db22fbb547d0826, + 0xa855d775d64f0110, + ], + [ + 0x3a7a076a7653164a, + 0x831ec41826c9f433, + 0xe741ec156d6cc2e8, + 0x9d22d9b4c52d1fcd, + 0x29378130bb66801f, + 0x7cb8ed48278ca775, + 0xda6eb5186ea6d93a, + 0xcb1af159fddb7de9, + 0x36fcc875105933ec, + 0x769bcf74dfc5633e, + 0x007493ff65d57f29, + 0xf25df62693770de4, + 0xa19106354a107435, + 0x3e22d2a729a5cfc0, + 0x1b668ba97bb34bda, + 0x3431c9e512de7508, + 0xaef52c95d26bee5c, + 0xd469b70970274fac, + 0xacb862720dc53c99, + 0x5611b0fac5ee9c0e, + 0xbd0c97dc9334b4d1, + 0x60f5b3e10a84d18b, + 0xcdc7ce6afa7bb654, + 0xf9718de3fbd9912e, + 0x52cf33b8bc689764, + ], + [ + 0x05bb9ba0620488de, + 0x255c733bef224059, + 0x836115d2296389ba, + 0x0ab2167d49cb289f, + 0x1e945f1edf1ae30f, + 0x36af6f7dd549671a, + 0xb916e7817d618a31, + 0xacc5e1bc38255a26, + 0x6e30e1996f6ff60d, + 0x444d39f393a03988, + 0x9be737f450a656d1, + 0x54908135176000bb, + 0x22dfe68128bbbd2a, + 0x4538a20e8a41722f, + 0x9300dad7d26702ac, + 0x1ca0e4154cb8fa3c, + 0xe79bd6461d454f8c, + 0x97623f4622fc67f1, + 0xdd34f7723269bec4, + 0x095027718c687fe2, + 0x765164adaf88f509, + 0x10398b41075c534f, + 0xe4f0b2a3dc53fa47, + 0x47d683e87df22978, + 0x977202dbb006d455, + ], + [ + 0x6de734e9ca9ddca9, + 0x7cc622c3598980d0, + 0x8c70c4f776592af9, + 0x144bf613df515cce, + 0xed86fd2c951c694d, + 0x0a611f64e6cc71c3, + 0xae4f84322fc5998a, + 0xb816fc65939ab4a8, + 0xa577b843b0abd02e, + 0x2160c58bb6db9141, + 0xc265e1147f5acd16, + 0x2e92b214f27e458c, + 0xa3a3ebcd6499c3cf, + 0x7bc8a5d387a5ad1f, + 0xf76dea4bb3417c7a, + 0x6f4363ceac81fb57, + 0x32b5083239511ab5, + 0x9a0d5ab2ce107ca6, + 0x096a14d0969929c3, + 0x584c7db06dff5e95, + 0x8c65e65adf7b69bc, + 0x022d0d01ad78864c, + 0x446e102a8d2bcc57, + 0x2320241b97aadd47, + 0x1f13645237109652, + ], + [ + 0xe3149e204e6a7aa5, + 0x23897bedb6c59de2, + 0x03f0745c35262f50, + 0x8dcf451d452046ed, + 0xfb287468366762a1, + 0x78985371e9efbf92, + 0x6666bed6730a6dec, + 0xe8558e22c8470063, + 0x21ef2a4bc19dee21, + 0x1ee3471999a6b9d2, + 0x4bf213b0fa5d9543, + 0x58eb13d92e3e3ee0, + 0xe846d822d8c8465f, + 0x8d1651f1bbb16da3, + 0x22ee8e86032c05f9, + 0xcef6a50f4ffb4858, + 0xfcbbb4a9a09bd82a, + 0xa40a08af13eff462, + 0x10dc2712bd87257e, + 0xe62affc17fc01ee6, + 0xecc888362afd5d4c, + 0x8caf7e13b4c630bc, + 0xa6cec6299e0ec6fb, + 0xb876c1f8dd351df4, + 0x9e8edc1e068c2f1c, + ], + ]; + + #[allow(clippy::needless_range_loop)] + fn our_res() -> [[u64; 25]; 8] { + let mut packed_result = [[0; 8]; 25]; + for (i, packed_res) in packed_result.iter_mut().enumerate() { + *packed_res = [ + STATES[0][i], + STATES[1][i], + STATES[2][i], + STATES[3][i], + STATES[4][i], + STATES[5][i], + STATES[6][i], + STATES[7][i], + ]; + } + + keccak_perm(&mut packed_result); + + let mut result = [[0; 25]; 8]; + for (i, packed_res) in packed_result.iter_mut().enumerate() { + result[0][i] = packed_res[0]; + result[1][i] = packed_res[1]; + result[2][i] = packed_res[2]; + result[3][i] = packed_res[3]; + result[4][i] = packed_res[4]; + result[5][i] = packed_res[5]; + result[6][i] = packed_res[6]; + result[7][i] = packed_res[7]; + } + result + } + + fn tiny_keccak_res() -> [[u64; 25]; 8] { + let mut result = STATES; + keccakf(&mut result[0]); + keccakf(&mut result[1]); + keccakf(&mut result[2]); + keccakf(&mut result[3]); + keccakf(&mut result[4]); + keccakf(&mut result[5]); + keccakf(&mut result[6]); + keccakf(&mut result[7]); + result + } + + #[test] + fn test_vs_tiny_keccak() { + let expected = tiny_keccak_res(); + let computed = our_res(); + assert_eq!(expected, computed); + } +} diff --git a/CoqOfRust/plonky3/keccak/src/fallback.rs b/CoqOfRust/plonky3/keccak/src/fallback.rs new file mode 100644 index 000000000..70ac32b42 --- /dev/null +++ b/CoqOfRust/plonky3/keccak/src/fallback.rs @@ -0,0 +1,19 @@ +//! This module should be included only when none of the more target-specific implementations are +//! available. It fills in a few things based on a pure Rust implementation of Keccak. + +use core::mem::transmute; + +use p3_symmetric::{CryptographicPermutation, Permutation}; + +use crate::KeccakF; + +pub const VECTOR_LEN: usize = 1; + +impl Permutation<[[u64; VECTOR_LEN]; 25]> for KeccakF { + fn permute_mut(&self, input: &mut [[u64; VECTOR_LEN]; 25]) { + let input: &mut [u64; 25] = unsafe { transmute(input) }; + self.permute_mut(input); + } +} + +impl CryptographicPermutation<[[u64; VECTOR_LEN]; 25]> for KeccakF {} diff --git a/CoqOfRust/plonky3/keccak/src/lib.rs b/CoqOfRust/plonky3/keccak/src/lib.rs new file mode 100644 index 000000000..d07394d4f --- /dev/null +++ b/CoqOfRust/plonky3/keccak/src/lib.rs @@ -0,0 +1,144 @@ +//! The Keccak-f permutation, and hash functions built from it. + +#![no_std] +#![cfg_attr( + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), + feature(stdarch_x86_avx512) +)] + +use p3_symmetric::{CryptographicHasher, CryptographicPermutation, Permutation}; +use tiny_keccak::{Hasher, Keccak, keccakf}; + +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +pub mod avx512; +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +pub use avx512::*; + +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +pub mod avx2; +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +pub use avx2::*; + +#[cfg(all(target_arch = "x86_64", not(target_feature = "avx2")))] +pub mod sse2; +#[cfg(all(target_arch = "x86_64", not(target_feature = "avx2")))] +pub use sse2::*; + +#[cfg(all( + target_arch = "aarch64", + target_feature = "neon", + target_feature = "sha3" +))] +pub mod neon; +#[cfg(all( + target_arch = "aarch64", + target_feature = "neon", + target_feature = "sha3" +))] +pub use neon::*; + +#[cfg(not(any( + all( + target_arch = "aarch64", + target_feature = "neon", + target_feature = "sha3", + ), + target_arch = "x86_64", +)))] +mod fallback; +#[cfg(not(any( + all( + target_arch = "aarch64", + target_feature = "neon", + target_feature = "sha3", + ), + target_arch = "x86_64", +)))] +pub use fallback::*; + +/// The Keccak-f permutation. +#[derive(Copy, Clone, Debug)] +pub struct KeccakF; + +impl Permutation<[u64; 25]> for KeccakF { + fn permute_mut(&self, input: &mut [u64; 25]) { + keccakf(input); + } +} + +impl CryptographicPermutation<[u64; 25]> for KeccakF {} + +impl Permutation<[u8; 200]> for KeccakF { + fn permute(&self, input_u8s: [u8; 200]) -> [u8; 200] { + let mut state_u64s: [u64; 25] = core::array::from_fn(|i| { + u64::from_le_bytes(input_u8s[i * 8..][..8].try_into().unwrap()) + }); + + keccakf(&mut state_u64s); + + core::array::from_fn(|i| { + let u64_limb = state_u64s[i / 8]; + u64_limb.to_le_bytes()[i % 8] + }) + } + + fn permute_mut(&self, input: &mut [u8; 200]) { + *input = self.permute(*input); + } +} + +impl CryptographicPermutation<[u8; 200]> for KeccakF {} + +/// The `Keccak` hash functions defined in +/// [Keccak SHA3 submission](https://keccak.team/files/Keccak-submission-3.pdf). +#[derive(Copy, Clone, Debug)] +pub struct Keccak256Hash; + +impl CryptographicHasher for Keccak256Hash { + fn hash_iter(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + const BUFLEN: usize = 512; // Tweakable parameter; determined by experiment + let mut hasher = Keccak::v256(); + p3_util::apply_to_chunks::(input, |buf| hasher.update(buf)); + + let mut output = [0u8; 32]; + hasher.finalize(&mut output); + output + } + + fn hash_iter_slices<'a, I>(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + let mut hasher = Keccak::v256(); + for chunk in input { + hasher.update(chunk); + } + + let mut output = [0u8; 32]; + hasher.finalize(&mut output); + output + } +} diff --git a/CoqOfRust/plonky3/keccak/src/lib.v b/CoqOfRust/plonky3/keccak/src/lib.v new file mode 100644 index 000000000..c1bdb8a97 --- /dev/null +++ b/CoqOfRust/plonky3/keccak/src/lib.v @@ -0,0 +1,939 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +(* StructTuple + { + name := "KeccakF"; + const_params := []; + ty_params := []; + fields := []; + } *) + +Module Impl_core_marker_Copy_for_p3_keccak_KeccakF. + Definition Self : Ty.t := Ty.path "p3_keccak::KeccakF". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. +End Impl_core_marker_Copy_for_p3_keccak_KeccakF. + +Module Impl_core_clone_Clone_for_p3_keccak_KeccakF. + Definition Self : Ty.t := Ty.path "p3_keccak::KeccakF". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. +End Impl_core_clone_Clone_for_p3_keccak_KeccakF. + +Module Impl_core_fmt_Debug_for_p3_keccak_KeccakF. + Definition Self : Ty.t := Ty.path "p3_keccak::KeccakF". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "KeccakF" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. +End Impl_core_fmt_Debug_for_p3_keccak_KeccakF. + +Module Impl_p3_symmetric_permutation_Permutation_array_Usize_25_u64_for_p3_keccak_KeccakF. + Definition Self : Ty.t := Ty.path "p3_keccak::KeccakF". + + (* + fn permute_mut(&self, input: &mut [u64; 25]) { + keccakf(input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "tiny_keccak::keccakf::keccakf", [], [] |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 25 ] [ Ty.path "u64" ] ] + Self + (* Instance *) [ ("permute_mut", InstanceField.Method permute_mut) ]. +End Impl_p3_symmetric_permutation_Permutation_array_Usize_25_u64_for_p3_keccak_KeccakF. + +Module Impl_p3_symmetric_permutation_CryptographicPermutation_array_Usize_25_u64_for_p3_keccak_KeccakF. + Definition Self : Ty.t := Ty.path "p3_keccak::KeccakF". + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::CryptographicPermutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 25 ] [ Ty.path "u64" ] ] + Self + (* Instance *) []. +End Impl_p3_symmetric_permutation_CryptographicPermutation_array_Usize_25_u64_for_p3_keccak_KeccakF. + +Module Impl_p3_symmetric_permutation_Permutation_array_Usize_200_u8_for_p3_keccak_KeccakF. + Definition Self : Ty.t := Ty.path "p3_keccak::KeccakF". + + (* + fn permute(&self, input_u8s: [u8; 200]) -> [u8; 200] { + let mut state_u64s: [u64; 25] = core::array::from_fn(|i| { + u64::from_le_bytes(input_u8s[i * 8..][..8].try_into().unwrap()) + }); + + keccakf(&mut state_u64s); + + core::array::from_fn(|i| { + let u64_limb = state_u64s[i / 8]; + u64_limb.to_le_bytes()[i % 8] + }) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input_u8s ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input_u8s := M.alloc (| input_u8s |) in + M.read (| + let~ state_u64s : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "u64" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 25 ] [ Ty.path "u64" ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 25 ], + [ Ty.path "u64"; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.path "u64") ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.path "u64") ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| + Ty.path "u64", + "from_le_bytes", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] + ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 200 + ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + input_u8s + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| i |); + Value.Integer + IntegerKind.Usize + 8 + ] + |)) + ] + ] + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + Value.Integer IntegerKind.Usize 8) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "tiny_keccak::keccakf::keccakf", [], [] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state_u64s |) |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 200 ] [ Ty.path "u8" ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 200 ], + [ Ty.path "u8"; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.path "u8") ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.path "u8") ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + let~ u64_limb : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.copy (| + M.SubPointer.get_array_field (| + state_u64s, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| i |); Value.Integer IntegerKind.Usize 8 ] + |) + |) + |) in + M.SubPointer.get_array_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "u64", + "to_le_bytes", + [], + [] + |), + [ M.read (| u64_limb |) ] + |) + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| i |); Value.Integer IntegerKind.Usize 8 ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [u8; 200]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 200 ] + [ Ty.path "u8" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_keccak::KeccakF", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 200 ] + [ Ty.path "u8" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 200 ] [ Ty.path "u8" ] ] + Self + (* Instance *) + [ ("permute", InstanceField.Method permute); ("permute_mut", InstanceField.Method permute_mut) + ]. +End Impl_p3_symmetric_permutation_Permutation_array_Usize_200_u8_for_p3_keccak_KeccakF. + +Module Impl_p3_symmetric_permutation_CryptographicPermutation_array_Usize_200_u8_for_p3_keccak_KeccakF. + Definition Self : Ty.t := Ty.path "p3_keccak::KeccakF". + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::CryptographicPermutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 200 ] [ Ty.path "u8" ] ] + Self + (* Instance *) []. +End Impl_p3_symmetric_permutation_CryptographicPermutation_array_Usize_200_u8_for_p3_keccak_KeccakF. + +(* StructTuple + { + name := "Keccak256Hash"; + const_params := []; + ty_params := []; + fields := []; + } *) + +Module Impl_core_marker_Copy_for_p3_keccak_Keccak256Hash. + Definition Self : Ty.t := Ty.path "p3_keccak::Keccak256Hash". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. +End Impl_core_marker_Copy_for_p3_keccak_Keccak256Hash. + +Module Impl_core_clone_Clone_for_p3_keccak_Keccak256Hash. + Definition Self : Ty.t := Ty.path "p3_keccak::Keccak256Hash". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. +End Impl_core_clone_Clone_for_p3_keccak_Keccak256Hash. + +Module Impl_core_fmt_Debug_for_p3_keccak_Keccak256Hash. + Definition Self : Ty.t := Ty.path "p3_keccak::Keccak256Hash". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Keccak256Hash" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. +End Impl_core_fmt_Debug_for_p3_keccak_Keccak256Hash. + +Module Impl_p3_symmetric_hasher_CryptographicHasher_u8_array_Usize_32_u8_for_p3_keccak_Keccak256Hash. + Definition Self : Ty.t := Ty.path "p3_keccak::Keccak256Hash". + + (* + fn hash_iter(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + const BUFLEN: usize = 512; // Tweakable parameter; determined by experiment + let mut hasher = Keccak::v256(); + p3_util::apply_to_chunks::(input, |buf| hasher.update(buf)); + + let mut output = [0u8; 32]; + hasher.finalize(&mut output); + output + } + *) + Definition hash_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ hasher : Ty.apply (Ty.path "*") [] [ Ty.path "tiny_keccak::keccak::Keccak" ] := + M.alloc (| + M.call_closure (| + Ty.path "tiny_keccak::keccak::Keccak", + M.get_associated_function (| + Ty.path "tiny_keccak::keccak::Keccak", + "v256", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::apply_to_chunks", + [ Value.Integer IntegerKind.Usize 512 ], + [ + I; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let buf := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "tiny_keccak::Hasher", + Ty.path "tiny_keccak::keccak::Keccak", + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, hasher |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| buf |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ output : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ] := + M.alloc (| + repeat (| Value.Integer IntegerKind.U8 0, Value.Integer IntegerKind.Usize 32 |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "tiny_keccak::Hasher", + Ty.path "tiny_keccak::keccak::Keccak", + [], + [], + "finalize", + [], + [] + |), + [ + M.read (| hasher |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, output |) |) + |)) + ] + |) + |) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn hash_iter_slices<'a, I>(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + let mut hasher = Keccak::v256(); + for chunk in input { + hasher.update(chunk); + } + + let mut output = [0u8; 32]; + hasher.finalize(&mut output); + output + } + *) + Definition hash_iter_slices (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ hasher : Ty.apply (Ty.path "*") [] [ Ty.path "tiny_keccak::keccak::Keccak" ] := + M.alloc (| + M.call_closure (| + Ty.path "tiny_keccak::keccak::Keccak", + M.get_associated_function (| + Ty.path "tiny_keccak::keccak::Keccak", + "v256", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let chunk := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "tiny_keccak::Hasher", + Ty.path "tiny_keccak::keccak::Keccak", + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, hasher |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| chunk |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ output : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ] := + M.alloc (| + repeat (| Value.Integer IntegerKind.U8 0, Value.Integer IntegerKind.Usize 32 |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "tiny_keccak::Hasher", + Ty.path "tiny_keccak::keccak::Keccak", + [], + [], + "finalize", + [], + [] + |), + [ + M.read (| hasher |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, output |) |) + |)) + ] + |) + |) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::hasher::CryptographicHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.path "u8"; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ] + Self + (* Instance *) + [ + ("hash_iter", InstanceField.Method hash_iter); + ("hash_iter_slices", InstanceField.Method hash_iter_slices) + ]. +End Impl_p3_symmetric_hasher_CryptographicHasher_u8_array_Usize_32_u8_for_p3_keccak_Keccak256Hash. diff --git a/CoqOfRust/plonky3/keccak/src/neon.rs b/CoqOfRust/plonky3/keccak/src/neon.rs new file mode 100644 index 000000000..bcc660517 --- /dev/null +++ b/CoqOfRust/plonky3/keccak/src/neon.rs @@ -0,0 +1,312 @@ +use core::arch::aarch64::{uint64x2_t, vbcaxq_u64, veor3q_u64, veorq_u64, vrax1q_u64, vxarq_u64}; +use core::mem::transmute; + +use p3_symmetric::{CryptographicPermutation, Permutation}; + +use crate::KeccakF; + +pub const VECTOR_LEN: usize = 2; + +const RC: [uint64x2_t; 24] = unsafe { + transmute([ + [1u64; 2], + [0x8082u64; 2], + [0x800000000000808au64; 2], + [0x8000000080008000u64; 2], + [0x808bu64; 2], + [0x80000001u64; 2], + [0x8000000080008081u64; 2], + [0x8000000000008009u64; 2], + [0x8au64; 2], + [0x88u64; 2], + [0x80008009u64; 2], + [0x8000000au64; 2], + [0x8000808bu64; 2], + [0x800000000000008bu64; 2], + [0x8000000000008089u64; 2], + [0x8000000000008003u64; 2], + [0x8000000000008002u64; 2], + [0x8000000000000080u64; 2], + [0x800au64; 2], + [0x800000008000000au64; 2], + [0x8000000080008081u64; 2], + [0x8000000000008080u64; 2], + [0x80000001u64; 2], + [0x8000000080008008u64; 2], + ]) +}; + +#[inline(always)] +fn form_matrix(buf: [uint64x2_t; 25]) -> [[uint64x2_t; 5]; 5] { + unsafe { transmute(buf) } +} + +#[inline(always)] +fn flatten(mat: [[uint64x2_t; 5]; 5]) -> [uint64x2_t; 25] { + unsafe { transmute(mat) } +} + +#[inline(always)] +fn get_theta_parities(state: [[uint64x2_t; 5]; 5]) -> [uint64x2_t; 5] { + unsafe { + let mut par0 = veor3q_u64(state[0][0], state[1][0], state[2][0]); + let mut par1 = veor3q_u64(state[0][1], state[1][1], state[2][1]); + let mut par2 = veor3q_u64(state[0][2], state[1][2], state[2][2]); + let mut par3 = veor3q_u64(state[0][3], state[1][3], state[2][3]); + let mut par4 = veor3q_u64(state[0][4], state[1][4], state[2][4]); + + par0 = veor3q_u64(par0, state[3][0], state[4][0]); + par1 = veor3q_u64(par1, state[3][1], state[4][1]); + par2 = veor3q_u64(par2, state[3][2], state[4][2]); + par3 = veor3q_u64(par3, state[3][3], state[4][3]); + par4 = veor3q_u64(par4, state[3][4], state[4][4]); + + [ + vrax1q_u64(par4, par1), + vrax1q_u64(par0, par2), + vrax1q_u64(par1, par3), + vrax1q_u64(par2, par4), + vrax1q_u64(par3, par0), + ] + } +} + +#[inline(always)] +fn theta_rho(state: [[uint64x2_t; 5]; 5]) -> [[uint64x2_t; 5]; 5] { + let theta_parities = get_theta_parities(state); + + unsafe { + [ + [ + veorq_u64(state[0][0], theta_parities[0]), + vxarq_u64::<63>(state[0][1], theta_parities[1]), + vxarq_u64::<2>(state[0][2], theta_parities[2]), + vxarq_u64::<36>(state[0][3], theta_parities[3]), + vxarq_u64::<37>(state[0][4], theta_parities[4]), + ], + [ + vxarq_u64::<28>(state[1][0], theta_parities[0]), + vxarq_u64::<20>(state[1][1], theta_parities[1]), + vxarq_u64::<58>(state[1][2], theta_parities[2]), + vxarq_u64::<9>(state[1][3], theta_parities[3]), + vxarq_u64::<44>(state[1][4], theta_parities[4]), + ], + [ + vxarq_u64::<61>(state[2][0], theta_parities[0]), + vxarq_u64::<54>(state[2][1], theta_parities[1]), + vxarq_u64::<21>(state[2][2], theta_parities[2]), + vxarq_u64::<39>(state[2][3], theta_parities[3]), + vxarq_u64::<25>(state[2][4], theta_parities[4]), + ], + [ + vxarq_u64::<23>(state[3][0], theta_parities[0]), + vxarq_u64::<19>(state[3][1], theta_parities[1]), + vxarq_u64::<49>(state[3][2], theta_parities[2]), + vxarq_u64::<43>(state[3][3], theta_parities[3]), + vxarq_u64::<56>(state[3][4], theta_parities[4]), + ], + [ + vxarq_u64::<46>(state[4][0], theta_parities[0]), + vxarq_u64::<62>(state[4][1], theta_parities[1]), + vxarq_u64::<3>(state[4][2], theta_parities[2]), + vxarq_u64::<8>(state[4][3], theta_parities[3]), + vxarq_u64::<50>(state[4][4], theta_parities[4]), + ], + ] + } +} + +#[inline(always)] +const fn pi(state: [[uint64x2_t; 5]; 5]) -> [[uint64x2_t; 5]; 5] { + [ + [ + state[0][0], + state[1][1], + state[2][2], + state[3][3], + state[4][4], + ], + [ + state[0][3], + state[1][4], + state[2][0], + state[3][1], + state[4][2], + ], + [ + state[0][1], + state[1][2], + state[2][3], + state[3][4], + state[4][0], + ], + [ + state[0][4], + state[1][0], + state[2][1], + state[3][2], + state[4][3], + ], + [ + state[0][2], + state[1][3], + state[2][4], + state[3][0], + state[4][1], + ], + ] +} + +#[inline(always)] +fn chi_row(row: [uint64x2_t; 5]) -> [uint64x2_t; 5] { + unsafe { + [ + vbcaxq_u64(row[0], row[2], row[1]), + vbcaxq_u64(row[1], row[3], row[2]), + vbcaxq_u64(row[2], row[4], row[3]), + vbcaxq_u64(row[3], row[0], row[4]), + vbcaxq_u64(row[4], row[1], row[0]), + ] + } +} + +#[inline(always)] +fn chi(state: [[uint64x2_t; 5]; 5]) -> [[uint64x2_t; 5]; 5] { + [ + chi_row(state[0]), + chi_row(state[1]), + chi_row(state[2]), + chi_row(state[3]), + chi_row(state[4]), + ] +} + +#[inline(always)] +fn iota(i: usize, state: [[uint64x2_t; 5]; 5]) -> [[uint64x2_t; 5]; 5] { + let mut res = state; + unsafe { + res[0][0] = veorq_u64(state[0][0], RC[i]); + } + res +} + +#[inline(always)] +fn round(i: usize, state: [uint64x2_t; 25]) -> [uint64x2_t; 25] { + let mut state = form_matrix(state); + state = theta_rho(state); + state = pi(state); + state = chi(state); + state = iota(i, state); + flatten(state) +} + +fn keccak_perm(buf: &mut [[u64; VECTOR_LEN]; 25]) { + let mut state: [uint64x2_t; 25] = unsafe { transmute(*buf) }; + for i in 0..24 { + state = round(i, state); + } + *buf = unsafe { transmute::<[uint64x2_t; 25], [[u64; VECTOR_LEN]; 25]>(state) }; +} + +impl Permutation<[[u64; VECTOR_LEN]; 25]> for KeccakF { + fn permute_mut(&self, state: &mut [[u64; VECTOR_LEN]; 25]) { + keccak_perm(state); + } +} + +impl CryptographicPermutation<[[u64; VECTOR_LEN]; 25]> for KeccakF {} + +#[cfg(test)] +mod tests { + use tiny_keccak::keccakf; + + use super::*; + + const STATES: [[u64; 25]; 2] = [ + [ + 0xc22c4c11dbedc46a, + 0x317f74268c4f5cd0, + 0x838719da5aa295b6, + 0x9e9b17211985a3ba, + 0x92927b963ce29d69, + 0xf9a7169e38cc7216, + 0x639a594d6fbfe341, + 0x2335ebd8d15777bd, + 0x44e1abc0d022823b, + 0xb3657f9d16b36c13, + 0x26d9217c32b3010a, + 0x6e73d6e9c7e5bcc8, + 0x400aa469d130a391, + 0x1aa7c8a2cb97188a, + 0xdc3084a09bd0a6e3, + 0xbcfe3b656841baea, + 0x325f41887c840166, + 0x844656e313674bfe, + 0xd63de8bad19d156c, + 0x49ef0ac0ab52e147, + 0x8b92ee811c654ca9, + 0x42a9310fedf09bda, + 0x182dbdac03a5358e, + 0x3b4692ce58af8cb5, + 0x534da610f01b8fb3, + ], + [ + 0x1c322ff4aea07d26, + 0xbd67bde061c97612, + 0x517565bd02ab410a, + 0xb251273ddc12a725, + 0x24f0979fe4f4fedc, + 0xc32d063a64f0bf03, + 0xd33c6709a7b103d2, + 0xaf33a8224b5c8828, + 0x6544ca066e997f1c, + 0xd53ad41e39f06d68, + 0x67695f6fb71d77d9, + 0xd6378cf19ee510f2, + 0x49472ea57abcbd08, + 0xcf3739df1eefbbb4, + 0x0fac1bf30e8ef101, + 0x7ff04c9b90de0f27, + 0xf3d63ec0e64cb2ab, + 0x76388c05f377d4bd, + 0x7886dd8f5b14ef5b, + 0xb036d289ba24a513, + 0x011e8fd6be65a408, + 0x695e2d20848eec67, + 0x31f9e80c5f45f8ee, + 0xcdf873daf7a5fdeb, + 0xfe98ff5bf28d560a, + ], + ]; + + #[allow(clippy::needless_range_loop)] + fn our_res() -> [[u64; 25]; 2] { + let mut packed_result = [[0; 2]; 25]; + for i in 0..25 { + packed_result[i] = [STATES[0][i], STATES[1][i]]; + } + + keccak_perm(&mut packed_result); + + let mut result = [[0; 25]; 2]; + for i in 0..25 { + result[0][i] = packed_result[i][0]; + result[1][i] = packed_result[i][1]; + } + result + } + + fn tiny_keccak_res() -> [[u64; 25]; 2] { + let mut result = STATES; + keccakf(&mut result[0]); + keccakf(&mut result[1]); + result + } + + #[test] + fn test_vs_tiny_keccak() { + let expected = tiny_keccak_res(); + let computed = our_res(); + assert_eq!(expected, computed); + } +} diff --git a/CoqOfRust/plonky3/keccak/src/sse2.rs b/CoqOfRust/plonky3/keccak/src/sse2.rs new file mode 100644 index 000000000..49f949c5e --- /dev/null +++ b/CoqOfRust/plonky3/keccak/src/sse2.rs @@ -0,0 +1,425 @@ +use core::arch::x86_64::{ + __m128i, _mm_add_epi64, _mm_andnot_si128, _mm_or_si128, _mm_slli_epi64, _mm_srli_epi64, + _mm_xor_si128, +}; +use core::mem::transmute; + +use p3_symmetric::{CryptographicPermutation, Permutation}; + +use crate::KeccakF; + +pub const VECTOR_LEN: usize = 2; + +const RC: [__m128i; 24] = unsafe { + transmute([ + [1u64; 2], + [0x8082u64; 2], + [0x800000000000808au64; 2], + [0x8000000080008000u64; 2], + [0x808bu64; 2], + [0x80000001u64; 2], + [0x8000000080008081u64; 2], + [0x8000000000008009u64; 2], + [0x8au64; 2], + [0x88u64; 2], + [0x80008009u64; 2], + [0x8000000au64; 2], + [0x8000808bu64; 2], + [0x800000000000008bu64; 2], + [0x8000000000008089u64; 2], + [0x8000000000008003u64; 2], + [0x8000000000008002u64; 2], + [0x8000000000000080u64; 2], + [0x800au64; 2], + [0x800000008000000au64; 2], + [0x8000000080008081u64; 2], + [0x8000000000008080u64; 2], + [0x80000001u64; 2], + [0x8000000080008008u64; 2], + ]) +}; + +#[inline(always)] +fn form_matrix(buf: [__m128i; 25]) -> [[__m128i; 5]; 5] { + unsafe { transmute(buf) } +} + +#[inline(always)] +fn flatten(mat: [[__m128i; 5]; 5]) -> [__m128i; 25] { + unsafe { transmute(mat) } +} + +#[inline(always)] +fn rol_1(a: __m128i) -> __m128i { + unsafe { + let shl = _mm_add_epi64(a, a); + let shr = _mm_srli_epi64::<63>(a); + _mm_or_si128(shl, shr) + } +} + +#[cfg(target_feature = "ssse3")] +#[inline(always)] +fn rol_8(a: __m128i) -> __m128i { + use core::arch::x86_64::_mm_shuffle_epi8; + const ROL_8_CTRL: __m128i = unsafe { + transmute::<[u8; 16], _>([ + 0o07, 0o00, 0o01, 0o02, 0o03, 0o04, 0o05, 0o06, 0o17, 0o10, 0o11, 0o12, 0o13, 0o14, + 0o15, 0o16, + ]) + }; + unsafe { _mm_shuffle_epi8(a, ROL_8_CTRL) } +} + +#[cfg(not(target_feature = "ssse3"))] +#[inline(always)] +fn rol_8(a: __m128i) -> __m128i { + rol::<8, { 64 - 8 }>(a) +} + +#[cfg(target_feature = "ssse3")] +#[inline(always)] +fn rol_56(a: __m128i) -> __m128i { + use core::arch::x86_64::_mm_shuffle_epi8; + const ROL_56_CTRL: __m128i = unsafe { + transmute::<[u8; 16], _>([ + 0o01, 0o02, 0o03, 0o04, 0o05, 0o06, 0o07, 0o00, 0o11, 0o12, 0o13, 0o14, 0o15, 0o16, + 0o17, 0o10, + ]) + }; + unsafe { _mm_shuffle_epi8(a, ROL_56_CTRL) } +} + +#[cfg(not(target_feature = "ssse3"))] +#[inline(always)] +fn rol_56(a: __m128i) -> __m128i { + rol::<56, { 64 - 56 }>(a) +} + +#[inline(always)] +fn rol(a: __m128i) -> __m128i { + unsafe { + let shl = _mm_slli_epi64::(a); + let shr = _mm_srli_epi64::(a); + _mm_or_si128(shl, shr) + } +} + +#[inline(always)] +fn get_theta_parities(state: [[__m128i; 5]; 5]) -> [__m128i; 5] { + unsafe { + let mut par0 = _mm_xor_si128(state[0][0], state[1][0]); + let mut par1 = _mm_xor_si128(state[0][1], state[1][1]); + let mut par2 = _mm_xor_si128(state[0][2], state[1][2]); + let mut par3 = _mm_xor_si128(state[0][3], state[1][3]); + let mut par4 = _mm_xor_si128(state[0][4], state[1][4]); + + par0 = _mm_xor_si128(par0, state[2][0]); + par1 = _mm_xor_si128(par1, state[2][1]); + par2 = _mm_xor_si128(par2, state[2][2]); + par3 = _mm_xor_si128(par3, state[2][3]); + par4 = _mm_xor_si128(par4, state[2][4]); + + par0 = _mm_xor_si128(par0, state[3][0]); + par1 = _mm_xor_si128(par1, state[3][1]); + par2 = _mm_xor_si128(par2, state[3][2]); + par3 = _mm_xor_si128(par3, state[3][3]); + par4 = _mm_xor_si128(par4, state[3][4]); + + par0 = _mm_xor_si128(par0, state[4][0]); + par1 = _mm_xor_si128(par1, state[4][1]); + par2 = _mm_xor_si128(par2, state[4][2]); + par3 = _mm_xor_si128(par3, state[4][3]); + par4 = _mm_xor_si128(par4, state[4][4]); + + [ + _mm_xor_si128(par4, rol_1(par1)), + _mm_xor_si128(par0, rol_1(par2)), + _mm_xor_si128(par1, rol_1(par3)), + _mm_xor_si128(par2, rol_1(par4)), + _mm_xor_si128(par3, rol_1(par0)), + ] + } +} + +#[inline(always)] +fn theta(state: [[__m128i; 5]; 5]) -> [[__m128i; 5]; 5] { + let theta_parities = get_theta_parities(state); + + unsafe { + [ + [ + _mm_xor_si128(state[0][0], theta_parities[0]), + _mm_xor_si128(state[0][1], theta_parities[1]), + _mm_xor_si128(state[0][2], theta_parities[2]), + _mm_xor_si128(state[0][3], theta_parities[3]), + _mm_xor_si128(state[0][4], theta_parities[4]), + ], + [ + _mm_xor_si128(state[1][0], theta_parities[0]), + _mm_xor_si128(state[1][1], theta_parities[1]), + _mm_xor_si128(state[1][2], theta_parities[2]), + _mm_xor_si128(state[1][3], theta_parities[3]), + _mm_xor_si128(state[1][4], theta_parities[4]), + ], + [ + _mm_xor_si128(state[2][0], theta_parities[0]), + _mm_xor_si128(state[2][1], theta_parities[1]), + _mm_xor_si128(state[2][2], theta_parities[2]), + _mm_xor_si128(state[2][3], theta_parities[3]), + _mm_xor_si128(state[2][4], theta_parities[4]), + ], + [ + _mm_xor_si128(state[3][0], theta_parities[0]), + _mm_xor_si128(state[3][1], theta_parities[1]), + _mm_xor_si128(state[3][2], theta_parities[2]), + _mm_xor_si128(state[3][3], theta_parities[3]), + _mm_xor_si128(state[3][4], theta_parities[4]), + ], + [ + _mm_xor_si128(state[4][0], theta_parities[0]), + _mm_xor_si128(state[4][1], theta_parities[1]), + _mm_xor_si128(state[4][2], theta_parities[2]), + _mm_xor_si128(state[4][3], theta_parities[3]), + _mm_xor_si128(state[4][4], theta_parities[4]), + ], + ] + } +} + +#[inline(always)] +fn rho(state: [[__m128i; 5]; 5]) -> [[__m128i; 5]; 5] { + [ + [ + state[0][0], + rol_1(state[0][1]), + rol::<62, { 64 - 62 }>(state[0][2]), + rol::<28, { 64 - 28 }>(state[0][3]), + rol::<27, { 64 - 27 }>(state[0][4]), + ], + [ + rol::<36, { 64 - 36 }>(state[1][0]), + rol::<44, { 64 - 44 }>(state[1][1]), + rol::<6, { 64 - 6 }>(state[1][2]), + rol::<55, { 64 - 55 }>(state[1][3]), + rol::<20, { 64 - 20 }>(state[1][4]), + ], + [ + rol::<3, { 64 - 3 }>(state[2][0]), + rol::<10, { 64 - 10 }>(state[2][1]), + rol::<43, { 64 - 43 }>(state[2][2]), + rol::<25, { 64 - 25 }>(state[2][3]), + rol::<39, { 64 - 39 }>(state[2][4]), + ], + [ + rol::<41, { 64 - 41 }>(state[3][0]), + rol::<45, { 64 - 45 }>(state[3][1]), + rol::<15, { 64 - 15 }>(state[3][2]), + rol::<21, { 64 - 21 }>(state[3][3]), + rol_8(state[3][4]), + ], + [ + rol::<18, { 64 - 18 }>(state[4][0]), + rol::<2, { 64 - 2 }>(state[4][1]), + rol::<61, { 64 - 61 }>(state[4][2]), + rol_56(state[4][3]), + rol::<14, { 64 - 14 }>(state[4][4]), + ], + ] +} + +#[inline(always)] +fn pi(state: [[__m128i; 5]; 5]) -> [[__m128i; 5]; 5] { + [ + [ + state[0][0], + state[1][1], + state[2][2], + state[3][3], + state[4][4], + ], + [ + state[0][3], + state[1][4], + state[2][0], + state[3][1], + state[4][2], + ], + [ + state[0][1], + state[1][2], + state[2][3], + state[3][4], + state[4][0], + ], + [ + state[0][4], + state[1][0], + state[2][1], + state[3][2], + state[4][3], + ], + [ + state[0][2], + state[1][3], + state[2][4], + state[3][0], + state[4][1], + ], + ] +} + +#[inline(always)] +fn chi_row(row: [__m128i; 5]) -> [__m128i; 5] { + unsafe { + [ + _mm_xor_si128(row[0], _mm_andnot_si128(row[1], row[2])), + _mm_xor_si128(row[1], _mm_andnot_si128(row[2], row[3])), + _mm_xor_si128(row[2], _mm_andnot_si128(row[3], row[4])), + _mm_xor_si128(row[3], _mm_andnot_si128(row[4], row[0])), + _mm_xor_si128(row[4], _mm_andnot_si128(row[0], row[1])), + ] + } +} + +#[inline(always)] +fn chi(state: [[__m128i; 5]; 5]) -> [[__m128i; 5]; 5] { + [ + chi_row(state[0]), + chi_row(state[1]), + chi_row(state[2]), + chi_row(state[3]), + chi_row(state[4]), + ] +} + +#[inline(always)] +fn iota(i: usize, state: [[__m128i; 5]; 5]) -> [[__m128i; 5]; 5] { + let mut res = state; + unsafe { + res[0][0] = _mm_xor_si128(state[0][0], RC[i]); + } + res +} + +#[inline(always)] +fn round(i: usize, state: [__m128i; 25]) -> [__m128i; 25] { + let mut state = form_matrix(state); + state = theta(state); + state = rho(state); + state = pi(state); + state = chi(state); + state = iota(i, state); + flatten(state) +} + +fn keccak_perm(buf: &mut [[u64; VECTOR_LEN]; 25]) { + let mut state: [__m128i; 25] = unsafe { transmute(*buf) }; + for i in 0..24 { + state = round(i, state); + } + *buf = unsafe { transmute::<[__m128i; 25], [[u64; VECTOR_LEN]; 25]>(state) }; +} + +impl Permutation<[[u64; VECTOR_LEN]; 25]> for KeccakF { + fn permute_mut(&self, state: &mut [[u64; VECTOR_LEN]; 25]) { + keccak_perm(state); + } +} + +impl CryptographicPermutation<[[u64; VECTOR_LEN]; 25]> for KeccakF {} + +#[cfg(test)] +mod tests { + use tiny_keccak::keccakf; + + use super::*; + + const STATES: [[u64; 25]; 2] = [ + [ + 0xc22c4c11dbedc46a, + 0x317f74268c4f5cd0, + 0x838719da5aa295b6, + 0x9e9b17211985a3ba, + 0x92927b963ce29d69, + 0xf9a7169e38cc7216, + 0x639a594d6fbfe341, + 0x2335ebd8d15777bd, + 0x44e1abc0d022823b, + 0xb3657f9d16b36c13, + 0x26d9217c32b3010a, + 0x6e73d6e9c7e5bcc8, + 0x400aa469d130a391, + 0x1aa7c8a2cb97188a, + 0xdc3084a09bd0a6e3, + 0xbcfe3b656841baea, + 0x325f41887c840166, + 0x844656e313674bfe, + 0xd63de8bad19d156c, + 0x49ef0ac0ab52e147, + 0x8b92ee811c654ca9, + 0x42a9310fedf09bda, + 0x182dbdac03a5358e, + 0x3b4692ce58af8cb5, + 0x534da610f01b8fb3, + ], + [ + 0x1c322ff4aea07d26, + 0xbd67bde061c97612, + 0x517565bd02ab410a, + 0xb251273ddc12a725, + 0x24f0979fe4f4fedc, + 0xc32d063a64f0bf03, + 0xd33c6709a7b103d2, + 0xaf33a8224b5c8828, + 0x6544ca066e997f1c, + 0xd53ad41e39f06d68, + 0x67695f6fb71d77d9, + 0xd6378cf19ee510f2, + 0x49472ea57abcbd08, + 0xcf3739df1eefbbb4, + 0x0fac1bf30e8ef101, + 0x7ff04c9b90de0f27, + 0xf3d63ec0e64cb2ab, + 0x76388c05f377d4bd, + 0x7886dd8f5b14ef5b, + 0xb036d289ba24a513, + 0x011e8fd6be65a408, + 0x695e2d20848eec67, + 0x31f9e80c5f45f8ee, + 0xcdf873daf7a5fdeb, + 0xfe98ff5bf28d560a, + ], + ]; + + #[allow(clippy::needless_range_loop)] + fn our_res() -> [[u64; 25]; 2] { + let mut packed_result = [[0; 2]; 25]; + for i in 0..25 { + packed_result[i] = [STATES[0][i], STATES[1][i]]; + } + + keccak_perm(&mut packed_result); + + let mut result = [[0; 25]; 2]; + for i in 0..25 { + result[0][i] = packed_result[i][0]; + result[1][i] = packed_result[i][1]; + } + result + } + + fn tiny_keccak_res() -> [[u64; 25]; 2] { + let mut result = STATES; + keccakf(&mut result[0]); + keccakf(&mut result[1]); + result + } + + #[test] + fn test_vs_tiny_keccak() { + let expected = tiny_keccak_res(); + let computed = our_res(); + assert_eq!(expected, computed); + } +} diff --git a/CoqOfRust/plonky3/keccak/src/sse2.v b/CoqOfRust/plonky3/keccak/src/sse2.v new file mode 100644 index 000000000..065bb2b36 --- /dev/null +++ b/CoqOfRust/plonky3/keccak/src/sse2.v @@ -0,0 +1,2891 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module sse2. + Definition value_VECTOR_LEN (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 2 |))). + + Global Instance Instance_IsConstant_value_VECTOR_LEN : + M.IsFunction.C "p3_keccak::sse2::VECTOR_LEN" value_VECTOR_LEN. + Admitted. + Global Typeclasses Opaque value_VECTOR_LEN. + + Definition value_RC (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ Ty.path "u64" ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ] + |), + [ + Value.Array + [ + repeat (| Value.Integer IntegerKind.U64 1, Value.Integer IntegerKind.Usize 2 |); + repeat (| Value.Integer IntegerKind.U64 32898, Value.Integer IntegerKind.Usize 2 |); + repeat (| + Value.Integer IntegerKind.U64 9223372036854808714, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372039002292224, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| Value.Integer IntegerKind.U64 32907, Value.Integer IntegerKind.Usize 2 |); + repeat (| + Value.Integer IntegerKind.U64 2147483649, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372039002292353, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372036854808585, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| Value.Integer IntegerKind.U64 138, Value.Integer IntegerKind.Usize 2 |); + repeat (| Value.Integer IntegerKind.U64 136, Value.Integer IntegerKind.Usize 2 |); + repeat (| + Value.Integer IntegerKind.U64 2147516425, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 2147483658, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 2147516555, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372036854775947, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372036854808713, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372036854808579, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372036854808578, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372036854775936, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| Value.Integer IntegerKind.U64 32778, Value.Integer IntegerKind.Usize 2 |); + repeat (| + Value.Integer IntegerKind.U64 9223372039002259466, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372039002292353, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372036854808704, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 2147483649, + Value.Integer IntegerKind.Usize 2 + |); + repeat (| + Value.Integer IntegerKind.U64 9223372039002292232, + Value.Integer IntegerKind.Usize 2 + |) + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_RC : M.IsFunction.C "p3_keccak::sse2::RC" value_RC. + Admitted. + Global Typeclasses Opaque value_RC. + + (* + fn form_matrix(buf: [__m128i; 25]) -> [[__m128i; 5]; 5] { + unsafe { transmute(buf) } + } + *) + Definition form_matrix (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ buf ] => + ltac:(M.monadic + (let buf := M.alloc (| buf |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "core::core_arch::x86::__m128i" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ] + ] + |), + [ M.read (| buf |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_form_matrix : + M.IsFunction.C "p3_keccak::sse2::form_matrix" form_matrix. + Admitted. + Global Typeclasses Opaque form_matrix. + + (* + fn flatten(mat: [[__m128i; 5]; 5]) -> [__m128i; 25] { + unsafe { transmute(mat) } + } + *) + Definition flatten (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ mat ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ] + |), + [ M.read (| mat |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_flatten : M.IsFunction.C "p3_keccak::sse2::flatten" flatten. + Admitted. + Global Typeclasses Opaque flatten. + + (* + fn rol_1(a: __m128i) -> __m128i { + unsafe { + let shl = _mm_add_epi64(a, a); + let shr = _mm_srli_epi64::<63>(a); + _mm_or_si128(shl, shr) + } + } + *) + Definition rol_1 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.read (| + let~ shl : Ty.apply (Ty.path "*") [] [ Ty.path "core::core_arch::x86::__m128i" ] := + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_add_epi64", [], [] |), + [ M.read (| a |); M.read (| a |) ] + |) + |) in + let~ shr : Ty.apply (Ty.path "*") [] [ Ty.path "core::core_arch::x86::__m128i" ] := + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "core::core_arch::x86::sse2::_mm_srli_epi64", + [ Value.Integer IntegerKind.I32 63 ], + [] + |), + [ M.read (| a |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_or_si128", [], [] |), + [ M.read (| shl |); M.read (| shr |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_rol_1 : M.IsFunction.C "p3_keccak::sse2::rol_1" rol_1. + Admitted. + Global Typeclasses Opaque rol_1. + + (* + fn rol_8(a: __m128i) -> __m128i { + rol::<8, { 64 - 8 }>(a) + } + *) + Definition rol_8 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 8; Value.Integer IntegerKind.I32 56 ], + [] + |), + [ M.read (| a |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_rol_8 : M.IsFunction.C "p3_keccak::sse2::rol_8" rol_8. + Admitted. + Global Typeclasses Opaque rol_8. + + (* + fn rol_56(a: __m128i) -> __m128i { + rol::<56, { 64 - 56 }>(a) + } + *) + Definition rol_56 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 56; Value.Integer IntegerKind.I32 8 ], + [] + |), + [ M.read (| a |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_rol_56 : M.IsFunction.C "p3_keccak::sse2::rol_56" rol_56. + Admitted. + Global Typeclasses Opaque rol_56. + + (* + fn rol(a: __m128i) -> __m128i { + unsafe { + let shl = _mm_slli_epi64::(a); + let shr = _mm_srli_epi64::(a); + _mm_or_si128(shl, shr) + } + } + *) + Definition rol (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ SHL_AMT; SHR_AMT ], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.read (| + let~ shl : Ty.apply (Ty.path "*") [] [ Ty.path "core::core_arch::x86::__m128i" ] := + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_slli_epi64", [ SHL_AMT ], [] |), + [ M.read (| a |) ] + |) + |) in + let~ shr : Ty.apply (Ty.path "*") [] [ Ty.path "core::core_arch::x86::__m128i" ] := + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_srli_epi64", [ SHR_AMT ], [] |), + [ M.read (| a |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_or_si128", [], [] |), + [ M.read (| shl |); M.read (| shr |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_rol : M.IsFunction.C "p3_keccak::sse2::rol" rol. + Admitted. + Global Typeclasses Opaque rol. + + (* + fn get_theta_parities(state: [[__m128i; 5]; 5]) -> [__m128i; 5] { + unsafe { + let mut par0 = _mm_xor_si128(state[0][0], state[1][0]); + let mut par1 = _mm_xor_si128(state[0][1], state[1][1]); + let mut par2 = _mm_xor_si128(state[0][2], state[1][2]); + let mut par3 = _mm_xor_si128(state[0][3], state[1][3]); + let mut par4 = _mm_xor_si128(state[0][4], state[1][4]); + + par0 = _mm_xor_si128(par0, state[2][0]); + par1 = _mm_xor_si128(par1, state[2][1]); + par2 = _mm_xor_si128(par2, state[2][2]); + par3 = _mm_xor_si128(par3, state[2][3]); + par4 = _mm_xor_si128(par4, state[2][4]); + + par0 = _mm_xor_si128(par0, state[3][0]); + par1 = _mm_xor_si128(par1, state[3][1]); + par2 = _mm_xor_si128(par2, state[3][2]); + par3 = _mm_xor_si128(par3, state[3][3]); + par4 = _mm_xor_si128(par4, state[3][4]); + + par0 = _mm_xor_si128(par0, state[4][0]); + par1 = _mm_xor_si128(par1, state[4][1]); + par2 = _mm_xor_si128(par2, state[4][2]); + par3 = _mm_xor_si128(par3, state[4][3]); + par4 = _mm_xor_si128(par4, state[4][4]); + + [ + _mm_xor_si128(par4, rol_1(par1)), + _mm_xor_si128(par0, rol_1(par2)), + _mm_xor_si128(par1, rol_1(par3)), + _mm_xor_si128(par2, rol_1(par4)), + _mm_xor_si128(par3, rol_1(par0)), + ] + } + } + *) + Definition get_theta_parities (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ par0 : Ty.apply (Ty.path "*") [] [ Ty.path "core::core_arch::x86::__m128i" ] := + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ par1 : Ty.apply (Ty.path "*") [] [ Ty.path "core::core_arch::x86::__m128i" ] := + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ par2 : Ty.apply (Ty.path "*") [] [ Ty.path "core::core_arch::x86::__m128i" ] := + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |) in + let~ par3 : Ty.apply (Ty.path "*") [] [ Ty.path "core::core_arch::x86::__m128i" ] := + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + |) in + let~ par4 : Ty.apply (Ty.path "*") [] [ Ty.path "core::core_arch::x86::__m128i" ] := + M.alloc (| + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par0, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par0 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par1, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par1 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par2, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par2 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par3, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par3 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par4, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par4 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par0, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par0 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par1, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par1 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par2, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par2 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par3, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par3 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par4, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par4 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par0, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par0 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par1, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par1 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par2, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par2 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par3, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par3 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + par4, + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par4 |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + |) + |) in + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par4 |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "p3_keccak::sse2::rol_1", [], [] |), + [ M.read (| par1 |) ] + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par0 |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "p3_keccak::sse2::rol_1", [], [] |), + [ M.read (| par2 |) ] + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par1 |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "p3_keccak::sse2::rol_1", [], [] |), + [ M.read (| par3 |) ] + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par2 |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "p3_keccak::sse2::rol_1", [], [] |), + [ M.read (| par4 |) ] + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| par3 |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "p3_keccak::sse2::rol_1", [], [] |), + [ M.read (| par0 |) ] + |) + ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_get_theta_parities : + M.IsFunction.C "p3_keccak::sse2::get_theta_parities" get_theta_parities. + Admitted. + Global Typeclasses Opaque get_theta_parities. + + (* + fn theta(state: [[__m128i; 5]; 5]) -> [[__m128i; 5]; 5] { + let theta_parities = get_theta_parities(state); + + unsafe { + [ + [ + _mm_xor_si128(state[0][0], theta_parities[0]), + _mm_xor_si128(state[0][1], theta_parities[1]), + _mm_xor_si128(state[0][2], theta_parities[2]), + _mm_xor_si128(state[0][3], theta_parities[3]), + _mm_xor_si128(state[0][4], theta_parities[4]), + ], + [ + _mm_xor_si128(state[1][0], theta_parities[0]), + _mm_xor_si128(state[1][1], theta_parities[1]), + _mm_xor_si128(state[1][2], theta_parities[2]), + _mm_xor_si128(state[1][3], theta_parities[3]), + _mm_xor_si128(state[1][4], theta_parities[4]), + ], + [ + _mm_xor_si128(state[2][0], theta_parities[0]), + _mm_xor_si128(state[2][1], theta_parities[1]), + _mm_xor_si128(state[2][2], theta_parities[2]), + _mm_xor_si128(state[2][3], theta_parities[3]), + _mm_xor_si128(state[2][4], theta_parities[4]), + ], + [ + _mm_xor_si128(state[3][0], theta_parities[0]), + _mm_xor_si128(state[3][1], theta_parities[1]), + _mm_xor_si128(state[3][2], theta_parities[2]), + _mm_xor_si128(state[3][3], theta_parities[3]), + _mm_xor_si128(state[3][4], theta_parities[4]), + ], + [ + _mm_xor_si128(state[4][0], theta_parities[0]), + _mm_xor_si128(state[4][1], theta_parities[1]), + _mm_xor_si128(state[4][2], theta_parities[2]), + _mm_xor_si128(state[4][3], theta_parities[3]), + _mm_xor_si128(state[4][4], theta_parities[4]), + ], + ] + } + } + *) + Definition theta (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ theta_parities : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| "p3_keccak::sse2::get_theta_parities", [], [] |), + [ M.read (| state |) ] + |) + |) in + M.alloc (| + Value.Array + [ + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ]; + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 1 + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 1 + |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 1 + |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 1 + |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 1 + |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ]; + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 2 + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 2 + |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 2 + |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 2 + |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 2 + |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ]; + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 3 + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 3 + |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 3 + |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 3 + |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 3 + |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ]; + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 4 + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 4 + |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 4 + |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 4 + |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 4 + |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + theta_parities, + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ] + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_theta : M.IsFunction.C "p3_keccak::sse2::theta" theta. + Admitted. + Global Typeclasses Opaque theta. + + (* + fn rho(state: [[__m128i; 5]; 5]) -> [[__m128i; 5]; 5] { + [ + [ + state[0][0], + rol_1(state[0][1]), + rol::<62, { 64 - 62 }>(state[0][2]), + rol::<28, { 64 - 28 }>(state[0][3]), + rol::<27, { 64 - 27 }>(state[0][4]), + ], + [ + rol::<36, { 64 - 36 }>(state[1][0]), + rol::<44, { 64 - 44 }>(state[1][1]), + rol::<6, { 64 - 6 }>(state[1][2]), + rol::<55, { 64 - 55 }>(state[1][3]), + rol::<20, { 64 - 20 }>(state[1][4]), + ], + [ + rol::<3, { 64 - 3 }>(state[2][0]), + rol::<10, { 64 - 10 }>(state[2][1]), + rol::<43, { 64 - 43 }>(state[2][2]), + rol::<25, { 64 - 25 }>(state[2][3]), + rol::<39, { 64 - 39 }>(state[2][4]), + ], + [ + rol::<41, { 64 - 41 }>(state[3][0]), + rol::<45, { 64 - 45 }>(state[3][1]), + rol::<15, { 64 - 15 }>(state[3][2]), + rol::<21, { 64 - 21 }>(state[3][3]), + rol_8(state[3][4]), + ], + [ + rol::<18, { 64 - 18 }>(state[4][0]), + rol::<2, { 64 - 2 }>(state[4][1]), + rol::<61, { 64 - 61 }>(state[4][2]), + rol_56(state[4][3]), + rol::<14, { 64 - 14 }>(state[4][4]), + ], + ] + } + *) + Definition rho (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + Value.Array + [ + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "p3_keccak::sse2::rol_1", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 62; Value.Integer IntegerKind.I32 2 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 28; Value.Integer IntegerKind.I32 36 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 27; Value.Integer IntegerKind.I32 37 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ]; + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 36; Value.Integer IntegerKind.I32 28 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 44; Value.Integer IntegerKind.I32 20 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 6; Value.Integer IntegerKind.I32 58 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 55; Value.Integer IntegerKind.I32 9 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 20; Value.Integer IntegerKind.I32 44 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ]; + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 3; Value.Integer IntegerKind.I32 61 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 10; Value.Integer IntegerKind.I32 54 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 43; Value.Integer IntegerKind.I32 21 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 25; Value.Integer IntegerKind.I32 39 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 39; Value.Integer IntegerKind.I32 25 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ]; + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 41; Value.Integer IntegerKind.I32 23 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 45; Value.Integer IntegerKind.I32 19 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 15; Value.Integer IntegerKind.I32 49 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 21; Value.Integer IntegerKind.I32 43 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "p3_keccak::sse2::rol_8", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ]; + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 18; Value.Integer IntegerKind.I32 46 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 2; Value.Integer IntegerKind.I32 62 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 61; Value.Integer IntegerKind.I32 3 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "p3_keccak::sse2::rol_56", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| + "p3_keccak::sse2::rol", + [ Value.Integer IntegerKind.I32 14; Value.Integer IntegerKind.I32 50 ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_rho : M.IsFunction.C "p3_keccak::sse2::rho" rho. + Admitted. + Global Typeclasses Opaque rho. + + (* + fn pi(state: [[__m128i; 5]; 5]) -> [[__m128i; 5]; 5] { + [ + [ + state[0][0], + state[1][1], + state[2][2], + state[3][3], + state[4][4], + ], + [ + state[0][3], + state[1][4], + state[2][0], + state[3][1], + state[4][2], + ], + [ + state[0][1], + state[1][2], + state[2][3], + state[3][4], + state[4][0], + ], + [ + state[0][4], + state[1][0], + state[2][1], + state[3][2], + state[4][3], + ], + [ + state[0][2], + state[1][3], + state[2][4], + state[3][0], + state[4][1], + ], + ] + } + *) + Definition pi (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + Value.Array + [ + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ]; + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ]; + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ]; + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ]; + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |), + Value.Integer IntegerKind.Usize 4 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_pi : M.IsFunction.C "p3_keccak::sse2::pi" pi. + Admitted. + Global Typeclasses Opaque pi. + + (* + fn chi_row(row: [__m128i; 5]) -> [__m128i; 5] { + unsafe { + [ + _mm_xor_si128(row[0], _mm_andnot_si128(row[1], row[2])), + _mm_xor_si128(row[1], _mm_andnot_si128(row[2], row[3])), + _mm_xor_si128(row[2], _mm_andnot_si128(row[3], row[4])), + _mm_xor_si128(row[3], _mm_andnot_si128(row[4], row[0])), + _mm_xor_si128(row[4], _mm_andnot_si128(row[0], row[1])), + ] + } + } + *) + Definition chi_row (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ row ] => + ltac:(M.monadic + (let row := M.alloc (| row |) in + Value.Array + [ + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 0 |) + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_andnot_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 1 |) + |); + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 2 |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 1 |) + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_andnot_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 2 |) + |); + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 3 |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 2 |) + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_andnot_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 3 |) + |); + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 4 |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 3 |) + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_andnot_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 4 |) + |); + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 0 |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 4 |) + |); + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_andnot_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 0 |) + |); + M.read (| + M.SubPointer.get_array_field (| row, Value.Integer IntegerKind.Usize 1 |) + |) + ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_chi_row : M.IsFunction.C "p3_keccak::sse2::chi_row" chi_row. + Admitted. + Global Typeclasses Opaque chi_row. + + (* + fn chi(state: [[__m128i; 5]; 5]) -> [[__m128i; 5]; 5] { + [ + chi_row(state[0]), + chi_row(state[1]), + chi_row(state[2]), + chi_row(state[3]), + chi_row(state[4]), + ] + } + *) + Definition chi (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + Value.Array + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| "p3_keccak::sse2::chi_row", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 0 |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| "p3_keccak::sse2::chi_row", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 1 |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| "p3_keccak::sse2::chi_row", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 2 |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| "p3_keccak::sse2::chi_row", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 3 |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| "p3_keccak::sse2::chi_row", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| state, Value.Integer IntegerKind.Usize 4 |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_chi : M.IsFunction.C "p3_keccak::sse2::chi" chi. + Admitted. + Global Typeclasses Opaque chi. + + (* + fn iota(i: usize, state: [[__m128i; 5]; 5]) -> [[__m128i; 5]; 5] { + let mut res = state; + unsafe { + res[0][0] = _mm_xor_si128(state[0][0], RC[i]); + } + res + } + *) + Definition iota (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ i; state ] => + ltac:(M.monadic + (let i := M.alloc (| i |) in + let state := M.alloc (| state |) in + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ] + ] := + M.copy (| state |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| res, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + Ty.path "core::core_arch::x86::__m128i", + M.get_function (| "core::core_arch::x86::sse2::_mm_xor_si128", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + state, + Value.Integer IntegerKind.Usize 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + get_constant (| + "p3_keccak::sse2::RC", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + |), + M.read (| i |) + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) in + res + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_iota : M.IsFunction.C "p3_keccak::sse2::iota" iota. + Admitted. + Global Typeclasses Opaque iota. + + (* + fn round(i: usize, state: [__m128i; 25]) -> [__m128i; 25] { + let mut state = form_matrix(state); + state = theta(state); + state = rho(state); + state = pi(state); + state = chi(state); + state = iota(i, state); + flatten(state) + } + *) + Definition round (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ i; state ] => + ltac:(M.monadic + (let i := M.alloc (| i |) in + let state := M.alloc (| state |) in + M.read (| + let~ state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ], + M.get_function (| "p3_keccak::sse2::form_matrix", [], [] |), + [ M.read (| state |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + state, + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ], + M.get_function (| "p3_keccak::sse2::theta", [], [] |), + [ M.read (| state |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + state, + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ], + M.get_function (| "p3_keccak::sse2::rho", [], [] |), + [ M.read (| state |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + state, + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ], + M.get_function (| "p3_keccak::sse2::pi", [], [] |), + [ M.read (| state |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + state, + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ], + M.get_function (| "p3_keccak::sse2::chi", [], [] |), + [ M.read (| state |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + state, + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 5 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ], + M.get_function (| "p3_keccak::sse2::iota", [], [] |), + [ M.read (| i |); M.read (| state |) ] + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| "p3_keccak::sse2::flatten", [], [] |), + [ M.read (| state |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_round : M.IsFunction.C "p3_keccak::sse2::round" round. + Admitted. + Global Typeclasses Opaque round. + + (* + fn keccak_perm(buf: &mut [[u64; VECTOR_LEN]; 25]) { + let mut state: [__m128i; 25] = unsafe { transmute( *buf) }; + for i in 0..24 { + state = round(i, state); + } + *buf = unsafe { transmute::<[__m128i; 25], [[u64; VECTOR_LEN]; 25]>(state) }; + } + *) + Definition keccak_perm (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ buf ] => + ltac:(M.monadic + (let buf := M.alloc (| buf |) in + M.read (| + let~ state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ] + ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "core::core_arch::x86::__m128i" ] + ] + |), + [ M.read (| M.deref (| M.read (| buf |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 24) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + state, + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "core::core_arch::x86::__m128i" ], + M.get_function (| "p3_keccak::sse2::round", [], [] |), + [ M.read (| i |); M.read (| state |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| buf |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ Ty.path "core::core_arch::x86::__m128i" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ] + ] + ] + |), + [ M.read (| state |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_keccak_perm : + M.IsFunction.C "p3_keccak::sse2::keccak_perm" keccak_perm. + Admitted. + Global Typeclasses Opaque keccak_perm. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_25_array_expr_u64_for_p3_keccak_KeccakF. + Definition Self : Ty.t := Ty.path "p3_keccak::KeccakF". + + (* + fn permute_mut(&self, state: &mut [[u64; VECTOR_LEN]; 25]) { + keccak_perm(state); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_keccak::sse2::keccak_perm", [], [] |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ + Ty.apply + (Ty.path "array") + [ M.unevaluated_const (mk_str (| "p3_keccak_sse2_discriminant" |)) ] + [ Ty.path "u64" ] + ] + ] + Self + (* Instance *) [ ("permute_mut", InstanceField.Method permute_mut) ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_25_array_expr_u64_for_p3_keccak_KeccakF. + + Module Impl_p3_symmetric_permutation_CryptographicPermutation_array_Usize_25_array_expr_u64_for_p3_keccak_KeccakF. + Definition Self : Ty.t := Ty.path "p3_keccak::KeccakF". + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::CryptographicPermutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ + Ty.apply + (Ty.path "array") + [ M.unevaluated_const (mk_str (| "p3_keccak_sse2_discriminant" |)) ] + [ Ty.path "u64" ] + ] + ] + Self + (* Instance *) []. + End Impl_p3_symmetric_permutation_CryptographicPermutation_array_Usize_25_array_expr_u64_for_p3_keccak_KeccakF. +End sse2. diff --git a/CoqOfRust/plonky3/koala-bear/src/aarch64_neon/mod.rs b/CoqOfRust/plonky3/koala-bear/src/aarch64_neon/mod.rs new file mode 100644 index 000000000..d47a7ccc5 --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/aarch64_neon/mod.rs @@ -0,0 +1,4 @@ +mod packing; +mod poseidon2; + +pub use packing::*; diff --git a/CoqOfRust/plonky3/koala-bear/src/aarch64_neon/packing.rs b/CoqOfRust/plonky3/koala-bear/src/aarch64_neon/packing.rs new file mode 100644 index 000000000..96be44847 --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/aarch64_neon/packing.rs @@ -0,0 +1,34 @@ +use core::arch::aarch64::{int32x4_t, uint32x4_t}; +use core::mem::transmute; + +use p3_monty_31::{MontyParametersNeon, PackedMontyField31Neon}; + +use crate::KoalaBearParameters; + +const WIDTH: usize = 4; + +impl MontyParametersNeon for KoalaBearParameters { + const PACKED_P: uint32x4_t = unsafe { transmute::<[u32; WIDTH], _>([0x7f000001; WIDTH]) }; + // This MU is the same 0x88000001 as elsewhere, just interpreted as an `i32`. + const PACKED_MU: int32x4_t = unsafe { transmute::<[i32; WIDTH], _>([-0x7effffff; WIDTH]) }; +} + +pub type PackedKoalaBearNeon = PackedMontyField31Neon; + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::WIDTH; + use crate::KoalaBear; + + const SPECIAL_VALS: [KoalaBear; WIDTH] = + KoalaBear::new_array([0x00000000, 0x00000001, 0x00000002, 0x7f000000]); + + test_packed_field!( + crate::PackedKoalaBearNeon, + &[crate::PackedKoalaBearNeon::ZERO], + &[crate::PackedKoalaBearNeon::ONE], + p3_monty_31::PackedMontyField31Neon::(super::SPECIAL_VALS) + ); +} diff --git a/CoqOfRust/plonky3/koala-bear/src/aarch64_neon/poseidon2.rs b/CoqOfRust/plonky3/koala-bear/src/aarch64_neon/poseidon2.rs new file mode 100644 index 000000000..d4a71d51d --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/aarch64_neon/poseidon2.rs @@ -0,0 +1,59 @@ +//! Eventually this will hold a vectorized Neon implementation of Poseidon2 for PackedKoalaBearNeon +//! Currently this is essentially a placeholder to allow compilation and testing on Neon devices. +//! +//! Converting the AVX2/AVX512 code across to Neon is on the TODO list. + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use crate::{KoalaBear, PackedKoalaBearNeon, Poseidon2KoalaBear}; + + type F = KoalaBear; + type Perm16 = Poseidon2KoalaBear<16>; + type Perm24 = Poseidon2KoalaBear<24>; + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_neon_poseidon2_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm16::new_from_rng_128(&mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut neon_input = input.map(Into::::into); + poseidon2.permute_mut(&mut neon_input); + + let neon_output = neon_input.map(|x| x.0[0]); + + assert_eq!(neon_output, expected); + } + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_neon_poseidon2_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm24::new_from_rng_128(&mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut neon_input = input.map(Into::::into); + poseidon2.permute_mut(&mut neon_input); + + let neon_output = neon_input.map(|x| x.0[0]); + + assert_eq!(neon_output, expected); + } +} diff --git a/CoqOfRust/plonky3/koala-bear/src/extension.rs b/CoqOfRust/plonky3/koala-bear/src/extension.rs new file mode 100644 index 000000000..023ff4773 --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/extension.rs @@ -0,0 +1,55 @@ +#[cfg(test)] +mod test_quartic_extension { + use alloc::format; + + use num_bigint::BigUint; + use p3_field::extension::BinomialExtensionField; + use p3_field::{BasedVectorSpace, PrimeCharacteristicRing}; + use p3_field_testing::{test_field, test_two_adic_extension_field}; + + use crate::KoalaBear; + + type F = KoalaBear; + type EF = BinomialExtensionField; + + // MontyField31's have no redundant representations. + const ZEROS: [EF; 1] = [EF::ZERO]; + const ONES: [EF; 1] = [EF::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P^4 - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 7] { + [ + (BigUint::from(2u8), 26), + (BigUint::from(3u8), 1), + (BigUint::from(5u8), 1), + (BigUint::from(127u8), 1), + (BigUint::from(283u16), 1), + (BigUint::from(1254833u32), 1), + (BigUint::from(453990990362758349u64), 1), + ] + } + + test_field!( + super::EF, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + test_two_adic_extension_field!(super::F, super::EF); + + #[test] + fn display() { + assert_eq!(format!("{}", EF::ZERO), "0"); + assert_eq!(format!("{}", EF::ONE), "1"); + assert_eq!(format!("{}", EF::TWO), "2"); + + assert_eq!( + format!( + "{}", + EF::from_basis_coefficients_slice(&[F::TWO, F::ONE, F::ZERO, F::TWO]).unwrap() + ), + "2 + X + 2 X^3" + ); + } +} diff --git a/CoqOfRust/plonky3/koala-bear/src/koala_bear.rs b/CoqOfRust/plonky3/koala-bear/src/koala_bear.rs new file mode 100644 index 000000000..31cb22967 --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/koala_bear.rs @@ -0,0 +1,217 @@ +use p3_field::exponentiation::exp_1420470955; +use p3_field::{Field, PrimeCharacteristicRing}; +use p3_monty_31::{ + BarrettParameters, BinomialExtensionData, FieldParameters, MontyField31, MontyParameters, + PackedMontyParameters, RelativelyPrimePower, TwoAdicData, +}; + +/// The prime field `2^31 - 2^24 + 1`, a.k.a. the Koala Bear field. +pub type KoalaBear = MontyField31; + +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialEq)] +pub struct KoalaBearParameters; + +impl MontyParameters for KoalaBearParameters { + /// The KoalaBear prime: 2^31 - 2^24 + 1 + /// This is a 31-bit prime with the highest possible two adicity if we additionally demand that + /// the cube map (x -> x^3) is an automorphism of the multiplicative group. + /// It's not unique, as there is one other option with equal 2 adicity: 2^30 + 2^27 + 2^24 + 1. + /// There is also one 29-bit prime with higher two adicity which might be appropriate for some applications: 2^29 - 2^26 + 1. + const PRIME: u32 = 0x7f000001; + + const MONTY_BITS: u32 = 32; + const MONTY_MU: u32 = 0x81000001; +} + +impl PackedMontyParameters for KoalaBearParameters {} + +impl BarrettParameters for KoalaBearParameters {} + +impl FieldParameters for KoalaBearParameters { + const MONTY_GEN: KoalaBear = KoalaBear::new(3); + + fn try_inverse(p1: F) -> Option { + if p1.is_zero() { + return None; + } + + // From Fermat's little theorem, in a prime field `F_p`, the inverse of `a` is `a^(p-2)`. + // Here p-2 = 2130706431 = 1111110111111111111111111111111_2 + // Uses 29 Squares + 7 Multiplications => 36 Operations total. + + let p10 = p1.square(); + let p11 = p10 * p1; + let p1100 = p11.exp_power_of_2(2); + let p1111 = p1100 * p11; + let p110000 = p1100.exp_power_of_2(2); + let p111111 = p110000 * p1111; + let p1111110000 = p111111.exp_power_of_2(4); + let p1111111111 = p1111110000 * p1111; + let p11111101111 = p1111111111 * p1111110000; + let p111111011110000000000 = p11111101111.exp_power_of_2(10); + let p111111011111111111111 = p111111011110000000000 * p1111111111; + let p1111110111111111111110000000000 = p111111011111111111111.exp_power_of_2(10); + let p1111110111111111111111111111111 = p1111110111111111111110000000000 * p1111111111; + + Some(p1111110111111111111111111111111) + } +} + +impl RelativelyPrimePower<3> for KoalaBearParameters { + /// In the field `KoalaBear`, `a^{1/3}` is equal to a^{1420470955}. + /// + /// This follows from the calculation `3 * 1420470955 = 2*(2^31 - 2^24) + 1 = 1 mod (p - 1)`. + fn exp_root_d(val: R) -> R { + exp_1420470955(val) + } +} + +impl TwoAdicData for KoalaBearParameters { + const TWO_ADICITY: usize = 24; + + type ArrayLike = &'static [KoalaBear]; + + const TWO_ADIC_GENERATORS: Self::ArrayLike = &KoalaBear::new_array([ + 0x1, 0x7f000000, 0x7e010002, 0x6832fe4a, 0x8dbd69c, 0xa28f031, 0x5c4a5b99, 0x29b75a80, + 0x17668b8a, 0x27ad539b, 0x334d48c7, 0x7744959c, 0x768fc6fa, 0x303964b2, 0x3e687d4d, + 0x45a60e61, 0x6e2f4d7a, 0x163bd499, 0x6c4a8a45, 0x143ef899, 0x514ddcad, 0x484ef19b, + 0x205d63c3, 0x68e7dd49, 0x6ac49f88, + ]); + + const ROOTS_8: Self::ArrayLike = + &KoalaBear::new_array([0x1, 0x6832fe4a, 0x7e010002, 0x174e3650]); + const INV_ROOTS_8: Self::ArrayLike = + &KoalaBear::new_array([0x1, 0x67b1c9b1, 0xfeffff, 0x16cd01b7]); + + const ROOTS_16: Self::ArrayLike = &KoalaBear::new_array([ + 0x1, 0x8dbd69c, 0x6832fe4a, 0x27ae21e2, 0x7e010002, 0x3a89a025, 0x174e3650, 0x27dfce22, + ]); + const INV_ROOTS_16: Self::ArrayLike = &KoalaBear::new_array([ + 0x1, 0x572031df, 0x67b1c9b1, 0x44765fdc, 0xfeffff, 0x5751de1f, 0x16cd01b7, 0x76242965, + ]); +} + +impl BinomialExtensionData<4> for KoalaBearParameters { + const W: KoalaBear = KoalaBear::new(3); + const DTH_ROOT: KoalaBear = KoalaBear::new(2113994754); + const EXT_GENERATOR: [KoalaBear; 4] = KoalaBear::new_array([2, 1, 0, 0]); + const EXT_TWO_ADICITY: usize = 26; + + type ArrayLike = [[KoalaBear; 4]; 2]; + + const TWO_ADIC_EXTENSION_GENERATORS: Self::ArrayLike = + KoalaBear::new_2d_array([[0, 0, 1759267465, 0], [0, 0, 0, 777715144]]); +} + +#[cfg(test)] +mod tests { + use num_bigint::BigUint; + use p3_field::extension::BinomialExtensionField; + use p3_field::{InjectiveMonomial, PermutationMonomial, PrimeField64, TwoAdicField}; + use p3_field_testing::{ + test_field, test_field_dft, test_prime_field, test_prime_field_32, test_prime_field_64, + test_two_adic_field, + }; + + use super::*; + + type F = KoalaBear; + type EF = BinomialExtensionField; + + #[test] + fn test_koala_bear_two_adicity_generators() { + let base = KoalaBear::from_u32(0x6ac49f88); + for bits in 0..=KoalaBear::TWO_ADICITY { + assert_eq!( + KoalaBear::two_adic_generator(bits), + base.exp_power_of_2(KoalaBear::TWO_ADICITY - bits) + ); + } + } + + #[test] + fn test_koala_bear() { + let f = F::from_u32(100); + assert_eq!(f.as_canonical_u64(), 100); + + let f_1 = F::ONE; + let f_2 = F::TWO; + let f_p_minus_1 = F::NEG_ONE; + let f_p_minus_2 = F::NEG_ONE + F::NEG_ONE; + let m1 = F::from_u32(0x34167c58); + let m2 = F::from_u32(0x61f3207b); + let expected_prod = F::from_u32(0x54b46b81); + assert_eq!(m1 * m2, expected_prod); + + assert_eq!(m1.injective_exp_n().injective_exp_root_n(), m1); + assert_eq!(m2.injective_exp_n().injective_exp_root_n(), m2); + assert_eq!(f_2.injective_exp_n().injective_exp_root_n(), f_2); + + let f_serialized = serde_json::to_string(&f).unwrap(); + let f_deserialized: F = serde_json::from_str(&f_serialized).unwrap(); + assert_eq!(f, f_deserialized); + + let f_1_serialized = serde_json::to_string(&f_1).unwrap(); + let f_1_deserialized: F = serde_json::from_str(&f_1_serialized).unwrap(); + let f_1_serialized_again = serde_json::to_string(&f_1_deserialized).unwrap(); + let f_1_deserialized_again: F = serde_json::from_str(&f_1_serialized_again).unwrap(); + assert_eq!(f_1, f_1_deserialized); + assert_eq!(f_1, f_1_deserialized_again); + + let f_2_serialized = serde_json::to_string(&f_2).unwrap(); + let f_2_deserialized: F = serde_json::from_str(&f_2_serialized).unwrap(); + assert_eq!(f_2, f_2_deserialized); + + let f_p_minus_1_serialized = serde_json::to_string(&f_p_minus_1).unwrap(); + let f_p_minus_1_deserialized: F = serde_json::from_str(&f_p_minus_1_serialized).unwrap(); + assert_eq!(f_p_minus_1, f_p_minus_1_deserialized); + + let f_p_minus_2_serialized = serde_json::to_string(&f_p_minus_2).unwrap(); + let f_p_minus_2_deserialized: F = serde_json::from_str(&f_p_minus_2_serialized).unwrap(); + assert_eq!(f_p_minus_2, f_p_minus_2_deserialized); + + let m1_serialized = serde_json::to_string(&m1).unwrap(); + let m1_deserialized: F = serde_json::from_str(&m1_serialized).unwrap(); + assert_eq!(m1, m1_deserialized); + + let m2_serialized = serde_json::to_string(&m2).unwrap(); + let m2_deserialized: F = serde_json::from_str(&m2_serialized).unwrap(); + assert_eq!(m2, m2_deserialized); + } + + // MontyField31's have no redundant representations. + const ZEROS: [KoalaBear; 1] = [KoalaBear::ZERO]; + const ONES: [KoalaBear; 1] = [KoalaBear::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 2] { + [(BigUint::from(2u8), 24), (BigUint::from(127u8), 1)] + } + + test_field!( + crate::KoalaBear, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + test_two_adic_field!(crate::KoalaBear); + + test_field_dft!(radix2dit, crate::KoalaBear, super::EF, p3_dft::Radix2Dit<_>); + test_field_dft!(bowers, crate::KoalaBear, super::EF, p3_dft::Radix2Bowers); + test_field_dft!( + parallel, + crate::KoalaBear, + super::EF, + p3_dft::Radix2DitParallel:: + ); + test_field_dft!( + recur_dft, + crate::KoalaBear, + super::EF, + p3_monty_31::dft::RecursiveDft<_> + ); + test_prime_field!(crate::KoalaBear); + test_prime_field_64!(crate::KoalaBear); + test_prime_field_32!(crate::KoalaBear); +} diff --git a/CoqOfRust/plonky3/koala-bear/src/koala_bear.v b/CoqOfRust/plonky3/koala-bear/src/koala_bear.v new file mode 100644 index 000000000..f31c96d79 --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/koala_bear.v @@ -0,0 +1,1123 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module koala_bear. + Axiom KoalaBear : + (Ty.path "p3_koala_bear::koala_bear::KoalaBear") = + (Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ]). + + (* StructTuple + { + name := "KoalaBearParameters"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_marker_Copy_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_core_clone_Clone_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_core_default_Default_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic (Value.StructTuple "p3_koala_bear::koala_bear::KoalaBearParameters" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_core_fmt_Debug_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "KoalaBearParameters" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_core_cmp_Eq_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_core_hash_Hash_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + Value.Tuple [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_core_marker_StructuralPartialEq_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_core_cmp_PartialEq_p3_koala_bear_koala_bear_KoalaBearParameters_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + Value.Bool true)) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_p3_koala_bear_koala_bear_KoalaBearParameters_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_p3_monty_31_data_traits_MontyParameters_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* const PRIME: u32 = 0x7f000001; *) + (* Ty.path "u32" *) + Definition value_PRIME (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U32 2130706433 |))). + + (* const MONTY_BITS: u32 = 32; *) + (* Ty.path "u32" *) + Definition value_MONTY_BITS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U32 32 |))). + + (* const MONTY_MU: u32 = 0x81000001; *) + (* Ty.path "u32" *) + Definition value_MONTY_MU (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U32 2164260865 |))). + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::MontyParameters" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_PRIME", InstanceField.Method value_PRIME); + ("value_MONTY_BITS", InstanceField.Method value_MONTY_BITS); + ("value_MONTY_MU", InstanceField.Method value_MONTY_MU) + ]. + End Impl_p3_monty_31_data_traits_MontyParameters_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_p3_monty_31_data_traits_PackedMontyParameters_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::PackedMontyParameters" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_monty_31_data_traits_PackedMontyParameters_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_p3_monty_31_data_traits_BarrettParameters_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::BarrettParameters" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_monty_31_data_traits_BarrettParameters_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_p3_monty_31_data_traits_FieldParameters_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* const MONTY_GEN: KoalaBear = KoalaBear::new(3); *) + (* Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] *) + Definition value_MONTY_GEN (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 3 ] + |) + |))). + + (* + fn try_inverse(p1: F) -> Option { + if p1.is_zero() { + return None; + } + + // From Fermat's little theorem, in a prime field `F_p`, the inverse of `a` is `a^(p-2)`. + // Here p-2 = 2130706431 = 1111110111111111111111111111111_2 + // Uses 29 Squares + 7 Multiplications => 36 Operations total. + + let p10 = p1.square(); + let p11 = p10 * p1; + let p1100 = p11.exp_power_of_2(2); + let p1111 = p1100 * p11; + let p110000 = p1100.exp_power_of_2(2); + let p111111 = p110000 * p1111; + let p1111110000 = p111111.exp_power_of_2(4); + let p1111111111 = p1111110000 * p1111; + let p11111101111 = p1111111111 * p1111110000; + let p111111011110000000000 = p11111101111.exp_power_of_2(10); + let p111111011111111111111 = p111111011110000000000 * p1111111111; + let p1111110111111111111110000000000 = p111111011111111111111.exp_power_of_2(10); + let p1111110111111111111111111111111 = p1111110111111111111110000000000 * p1111111111; + + Some(p1111110111111111111111111111111) + } + *) + Definition try_inverse (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ p1 ] => + ltac:(M.monadic + (let p1 := M.alloc (| p1 |) in + M.catch_return (Ty.apply (Ty.path "core::option::Option") [] [ F ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1 |) ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| Value.StructTuple "core::option::Option::None" [] |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ p10 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1 |) ] + |) + |) in + let~ p11 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p10 |); M.read (| p1 |) ] + |) + |) in + let~ p1100 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p11 |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ p1111 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p1100 |); M.read (| p11 |) ] + |) + |) in + let~ p110000 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1100 |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ p111111 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p110000 |); M.read (| p1111 |) ] + |) + |) in + let~ p1111110000 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p111111 |); Value.Integer IntegerKind.Usize 4 + ] + |) + |) in + let~ p1111111111 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p1111110000 |); M.read (| p1111 |) ] + |) + |) in + let~ p11111101111 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p1111111111 |); M.read (| p1111110000 |) ] + |) + |) in + let~ p111111011110000000000 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p11111101111 |); + Value.Integer IntegerKind.Usize 10 + ] + |) + |) in + let~ p111111011111111111111 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p111111011110000000000 |); M.read (| p1111111111 |) ] + |) + |) in + let~ p1111110111111111111110000000000 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p111111011111111111111 |); + Value.Integer IntegerKind.Usize 10 + ] + |) + |) in + let~ p1111110111111111111111111111111 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::ops::arith::Mul", F, [], [ F ], "mul", [], [] |), + [ M.read (| p1111110111111111111110000000000 |); M.read (| p1111111111 |) ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.read (| p1111110111111111111111111111111 |) ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::FieldParameters" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_MONTY_GEN", InstanceField.Method value_MONTY_GEN); + ("try_inverse", InstanceField.Method try_inverse) + ]. + End Impl_p3_monty_31_data_traits_FieldParameters_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_p3_monty_31_data_traits_RelativelyPrimePower_U64_3_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* + fn exp_root_d(val: R) -> R { + exp_1420470955(val) + } + *) + Definition exp_root_d (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ val ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + M.call_closure (| + R, + M.get_function (| "p3_field::exponentiation::exp_1420470955", [], [ R ] |), + [ M.read (| val |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::RelativelyPrimePower" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.U64 3 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("exp_root_d", InstanceField.Method exp_root_d) ]. + End Impl_p3_monty_31_data_traits_RelativelyPrimePower_U64_3_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_p3_monty_31_data_traits_TwoAdicData_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* const TWO_ADICITY: usize = 24; *) + (* Ty.path "usize" *) + Definition value_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 24 |))). + + (* type ArrayLike = &'static [KoalaBear]; *) + Definition _ArrayLike : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ]. + + (* + const TWO_ADIC_GENERATORS: Self::ArrayLike = &KoalaBear::new_array([ + 0x1, 0x7f000000, 0x7e010002, 0x6832fe4a, 0x8dbd69c, 0xa28f031, 0x5c4a5b99, 0x29b75a80, + 0x17668b8a, 0x27ad539b, 0x334d48c7, 0x7744959c, 0x768fc6fa, 0x303964b2, 0x3e687d4d, + 0x45a60e61, 0x6e2f4d7a, 0x163bd499, 0x6c4a8a45, 0x143ef899, 0x514ddcad, 0x484ef19b, + 0x205d63c3, 0x68e7dd49, 0x6ac49f88, + ]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + (Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters") + "ArrayLike" *) + Definition value_TWO_ADIC_GENERATORS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 25 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 25 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 2130706432; + Value.Integer IntegerKind.U32 2113994754; + Value.Integer IntegerKind.U32 1748172362; + Value.Integer IntegerKind.U32 148625052; + Value.Integer IntegerKind.U32 170455089; + Value.Integer IntegerKind.U32 1548376985; + Value.Integer IntegerKind.U32 699882112; + Value.Integer IntegerKind.U32 392596362; + Value.Integer IntegerKind.U32 665670555; + Value.Integer IntegerKind.U32 860702919; + Value.Integer IntegerKind.U32 2000983452; + Value.Integer IntegerKind.U32 1989134074; + Value.Integer IntegerKind.U32 809067698; + Value.Integer IntegerKind.U32 1047035213; + Value.Integer IntegerKind.U32 1168510561; + Value.Integer IntegerKind.U32 1848593786; + Value.Integer IntegerKind.U32 373019801; + Value.Integer IntegerKind.U32 1816824389; + Value.Integer IntegerKind.U32 339671193; + Value.Integer IntegerKind.U32 1364057261; + Value.Integer IntegerKind.U32 1213133211; + Value.Integer IntegerKind.U32 542991299; + Value.Integer IntegerKind.U32 1760025929; + Value.Integer IntegerKind.U32 1791270792 + ] + ] + |) + |) + |) + |) + |)) + |))). + + (* + const ROOTS_8: Self::ArrayLike = + &KoalaBear::new_array([0x1, 0x6832fe4a, 0x7e010002, 0x174e3650]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + (Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters") + "ArrayLike" *) + Definition value_ROOTS_8 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 1748172362; + Value.Integer IntegerKind.U32 2113994754; + Value.Integer IntegerKind.U32 391001680 + ] + ] + |) + |) + |) + |) + |)) + |))). + + (* + const INV_ROOTS_8: Self::ArrayLike = + &KoalaBear::new_array([0x1, 0x67b1c9b1, 0xfeffff, 0x16cd01b7]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + (Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters") + "ArrayLike" *) + Definition value_INV_ROOTS_8 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 1739704753; + Value.Integer IntegerKind.U32 16711679; + Value.Integer IntegerKind.U32 382534071 + ] + ] + |) + |) + |) + |) + |)) + |))). + + (* + const ROOTS_16: Self::ArrayLike = &KoalaBear::new_array([ + 0x1, 0x8dbd69c, 0x6832fe4a, 0x27ae21e2, 0x7e010002, 0x3a89a025, 0x174e3650, 0x27dfce22, + ]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + (Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters") + "ArrayLike" *) + Definition value_ROOTS_16 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 148625052; + Value.Integer IntegerKind.U32 1748172362; + Value.Integer IntegerKind.U32 665723362; + Value.Integer IntegerKind.U32 2113994754; + Value.Integer IntegerKind.U32 982097957; + Value.Integer IntegerKind.U32 391001680; + Value.Integer IntegerKind.U32 668978722 + ] + ] + |) + |) + |) + |) + |)) + |))). + + (* + const INV_ROOTS_16: Self::ArrayLike = &KoalaBear::new_array([ + 0x1, 0x572031df, 0x67b1c9b1, 0x44765fdc, 0xfeffff, 0x5751de1f, 0x16cd01b7, 0x76242965, + ]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + (Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters") + "ArrayLike" *) + Definition value_INV_ROOTS_16 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 1461727711; + Value.Integer IntegerKind.U32 1739704753; + Value.Integer IntegerKind.U32 1148608476; + Value.Integer IntegerKind.U32 16711679; + Value.Integer IntegerKind.U32 1464983071; + Value.Integer IntegerKind.U32 382534071; + Value.Integer IntegerKind.U32 1982081381 + ] + ] + |) + |) + |) + |) + |)) + |))). + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::TwoAdicData" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_TWO_ADICITY", InstanceField.Method value_TWO_ADICITY); + ("ArrayLike", InstanceField.Ty _ArrayLike); + ("value_TWO_ADIC_GENERATORS", InstanceField.Method value_TWO_ADIC_GENERATORS); + ("value_ROOTS_8", InstanceField.Method value_ROOTS_8); + ("value_INV_ROOTS_8", InstanceField.Method value_INV_ROOTS_8); + ("value_ROOTS_16", InstanceField.Method value_ROOTS_16); + ("value_INV_ROOTS_16", InstanceField.Method value_INV_ROOTS_16) + ]. + End Impl_p3_monty_31_data_traits_TwoAdicData_for_p3_koala_bear_koala_bear_KoalaBearParameters. + + Module Impl_p3_monty_31_data_traits_BinomialExtensionData_Usize_4_for_p3_koala_bear_koala_bear_KoalaBearParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters". + + (* const W: KoalaBear = KoalaBear::new(3); *) + (* Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] *) + Definition value_W (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 3 ] + |) + |))). + + (* const DTH_ROOT: KoalaBear = KoalaBear::new(2113994754); *) + (* Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] *) + Definition value_DTH_ROOT (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 2113994754 ] + |) + |))). + + (* const EXT_GENERATOR: [KoalaBear; 4] = KoalaBear::new_array([2, 1, 0, 0]); *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] *) + Definition value_EXT_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U32 2; + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 0 + ] + ] + |) + |))). + + (* const EXT_TWO_ADICITY: usize = 26; *) + (* Ty.path "usize" *) + Definition value_EXT_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 26 |))). + + (* type ArrayLike = [[KoalaBear; 4]; 2]; *) + Definition _ArrayLike : Ty.t := + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ]. + + (* + const TWO_ADIC_EXTENSION_GENERATORS: Self::ArrayLike = + KoalaBear::new_2d_array([[0, 0, 1759267465, 0], [0, 0, 0, 777715144]]); + *) + (* Ty.associated_in_trait + "p3_monty_31::data_traits::BinomialExtensionData" + [ Value.Integer IntegerKind.Usize 4 ] + [] + (Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters") + "ArrayLike" *) + Definition value_TWO_ADIC_EXTENSION_GENERATORS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new_2d_array", + [ Value.Integer IntegerKind.Usize 4; Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + Value.Array + [ + Value.Array + [ + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 1759267465; + Value.Integer IntegerKind.U32 0 + ]; + Value.Array + [ + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 0; + Value.Integer IntegerKind.U32 777715144 + ] + ] + ] + |) + |))). + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::data_traits::BinomialExtensionData" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 4 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_W", InstanceField.Method value_W); + ("value_DTH_ROOT", InstanceField.Method value_DTH_ROOT); + ("value_EXT_GENERATOR", InstanceField.Method value_EXT_GENERATOR); + ("value_EXT_TWO_ADICITY", InstanceField.Method value_EXT_TWO_ADICITY); + ("ArrayLike", InstanceField.Ty _ArrayLike); + ("value_TWO_ADIC_EXTENSION_GENERATORS", + InstanceField.Method value_TWO_ADIC_EXTENSION_GENERATORS) + ]. + End Impl_p3_monty_31_data_traits_BinomialExtensionData_Usize_4_for_p3_koala_bear_koala_bear_KoalaBearParameters. +End koala_bear. diff --git a/CoqOfRust/plonky3/koala-bear/src/lib.rs b/CoqOfRust/plonky3/koala-bear/src/lib.rs new file mode 100644 index 000000000..dec83fc11 --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/lib.rs @@ -0,0 +1,49 @@ +#![no_std] +#![cfg_attr( + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), + feature(stdarch_x86_avx512) +)] + +extern crate alloc; + +mod extension; +mod koala_bear; +mod poseidon2; + +pub use koala_bear::*; +pub use poseidon2::*; + +#[cfg(all(target_arch = "aarch64", target_feature = "neon"))] +mod aarch64_neon; +#[cfg(all(target_arch = "aarch64", target_feature = "neon"))] +pub use aarch64_neon::*; + +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +mod x86_64_avx2; +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +pub use x86_64_avx2::*; + +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +mod x86_64_avx512; +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +pub use x86_64_avx512::*; diff --git a/CoqOfRust/plonky3/koala-bear/src/poseidon2.rs b/CoqOfRust/plonky3/koala-bear/src/poseidon2.rs new file mode 100644 index 000000000..54772b23d --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/poseidon2.rs @@ -0,0 +1,355 @@ +//! Implementation of Poseidon2, see: https://eprint.iacr.org/2023/323 +//! +//! For the diffusion matrix, 1 + Diag(V), we perform a search to find an optimized +//! vector V composed of elements with efficient multiplication algorithms in AVX2/AVX512/NEON. +//! +//! This leads to using small values (e.g. 1, 2, 3, 4) where multiplication is implemented using addition +//! and inverse powers of 2 where it is possible to avoid monty reductions. +//! Additionally, for technical reasons, having the first entry be -2 is useful. +//! +//! Optimized Diagonal for KoalaBear16: +//! [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/8, 1/2^24, -1/2^8, -1/8, -1/16, -1/2^24] +//! Optimized Diagonal for KoalaBear24: +//! [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/32, 1/64, 1/2^24, -1/2^8, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^9, -1/2^24] +//! See poseidon2\src\diffusion.rs for information on how to double check these matrices in Sage. + +use p3_field::{Algebra, Field, PrimeCharacteristicRing, PrimeField32}; +use p3_monty_31::{ + GenericPoseidon2LinearLayersMonty31, InternalLayerBaseParameters, InternalLayerParameters, + MontyField31, Poseidon2ExternalLayerMonty31, Poseidon2InternalLayerMonty31, +}; +use p3_poseidon2::Poseidon2; + +use crate::{KoalaBear, KoalaBearParameters}; + +pub type Poseidon2InternalLayerKoalaBear = + Poseidon2InternalLayerMonty31; + +pub type Poseidon2ExternalLayerKoalaBear = + Poseidon2ExternalLayerMonty31; + +/// Degree of the chosen permutation polynomial for KoalaBear, used as the Poseidon2 S-Box. +/// +/// As p - 1 = 127 * 2^{24} we have a lot of choice in degree D satisfying gcd(p - 1, D) = 1. +/// Experimentation suggests that the optimal choice is the smallest available one, namely 3. +const KOALABEAR_S_BOX_DEGREE: u64 = 3; + +/// An implementation of the Poseidon2 hash function specialised to run on the current architecture. +/// +/// It acts on arrays of the form either `[KoalaBear::Packing; WIDTH]` or `[KoalaBear; WIDTH]`. For speed purposes, +/// wherever possible, input arrays should of the form `[KoalaBear::Packing; WIDTH]`. +pub type Poseidon2KoalaBear = Poseidon2< + KoalaBear, + Poseidon2ExternalLayerKoalaBear, + Poseidon2InternalLayerKoalaBear, + WIDTH, + KOALABEAR_S_BOX_DEGREE, +>; + +/// An implementation of the matrix multiplications in the internal and external layers of Poseidon2. +/// +/// This can act on `[A; WIDTH]` for any ring implementing `Algebra`. +/// If you have either `[KoalaBear::Packing; WIDTH]` or `[KoalaBear; WIDTH]` it will be much faster +/// to use `Poseidon2KoalaBear` instead of building a Poseidon2 permutation using this. +pub type GenericPoseidon2LinearLayersKoalaBear = + GenericPoseidon2LinearLayersMonty31; + +// In order to use KoalaBear::new_array we need to convert our vector to a vector of u32's. +// To do this we make use of the fact that KoalaBear::ORDER_U32 - 1 = 127 * 2^24 so for 0 <= n <= 24: +// -1/2^n = (KoalaBear::ORDER_U32 - 1) >> n +// 1/2^n = -(-1/2^n) = KoalaBear::ORDER_U32 - ((KoalaBear::ORDER_U32 - 1) >> n) + +/// The vector [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/8, 1/2^24, -1/2^8, -1/8, -1/16, -1/2^24] +/// saved as an array of KoalaBear elements. +const INTERNAL_DIAG_MONTY_16: [KoalaBear; 16] = KoalaBear::new_array([ + KoalaBear::ORDER_U32 - 2, + 1, + 2, + (KoalaBear::ORDER_U32 + 1) >> 1, + 3, + 4, + (KoalaBear::ORDER_U32 - 1) >> 1, + KoalaBear::ORDER_U32 - 3, + KoalaBear::ORDER_U32 - 4, + KoalaBear::ORDER_U32 - ((KoalaBear::ORDER_U32 - 1) >> 8), + KoalaBear::ORDER_U32 - ((KoalaBear::ORDER_U32 - 1) >> 3), + KoalaBear::ORDER_U32 - 127, + (KoalaBear::ORDER_U32 - 1) >> 8, + (KoalaBear::ORDER_U32 - 1) >> 3, + (KoalaBear::ORDER_U32 - 1) >> 4, + 127, +]); + +/// The vector [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/32, 1/64, 1/2^24, -1/2^8, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^9, -1/2^24] +/// saved as an array of KoalaBear elements. +const INTERNAL_DIAG_MONTY_24: [KoalaBear; 24] = KoalaBear::new_array([ + KoalaBear::ORDER_U32 - 2, + 1, + 2, + (KoalaBear::ORDER_U32 + 1) >> 1, + 3, + 4, + (KoalaBear::ORDER_U32 - 1) >> 1, + KoalaBear::ORDER_U32 - 3, + KoalaBear::ORDER_U32 - 4, + KoalaBear::ORDER_U32 - ((KoalaBear::ORDER_U32 - 1) >> 8), + KoalaBear::ORDER_U32 - ((KoalaBear::ORDER_U32 - 1) >> 2), + KoalaBear::ORDER_U32 - ((KoalaBear::ORDER_U32 - 1) >> 3), + KoalaBear::ORDER_U32 - ((KoalaBear::ORDER_U32 - 1) >> 4), + KoalaBear::ORDER_U32 - ((KoalaBear::ORDER_U32 - 1) >> 5), + KoalaBear::ORDER_U32 - ((KoalaBear::ORDER_U32 - 1) >> 6), + KoalaBear::ORDER_U32 - 127, + (KoalaBear::ORDER_U32 - 1) >> 8, + (KoalaBear::ORDER_U32 - 1) >> 3, + (KoalaBear::ORDER_U32 - 1) >> 4, + (KoalaBear::ORDER_U32 - 1) >> 5, + (KoalaBear::ORDER_U32 - 1) >> 6, + (KoalaBear::ORDER_U32 - 1) >> 7, + (KoalaBear::ORDER_U32 - 1) >> 9, + 127, +]); + +/// Contains data needed to define the internal layers of the Poseidon2 permutation. +#[derive(Debug, Clone, Default)] +pub struct KoalaBearInternalLayerParameters; + +impl InternalLayerBaseParameters for KoalaBearInternalLayerParameters { + type ArrayLike = [MontyField31; 15]; + + const INTERNAL_DIAG_MONTY: [MontyField31; 16] = INTERNAL_DIAG_MONTY_16; + + /// Perform the internal matrix multiplication: s -> (1 + Diag(V))s. + /// We ignore `state[0]` as it is handled separately. + fn internal_layer_mat_mul( + state: &mut [MontyField31; 16], + sum: MontyField31, + ) { + // The diagonal matrix is defined by the vector: + // V = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/8, 1/2^24, -1/2^8, -1/8, -1/16, -1/2^24] + state[1] += sum; + state[2] = state[2].double() + sum; + state[3] = state[3].halve() + sum; + state[4] = sum + state[4].double() + state[4]; + state[5] = sum + state[5].double().double(); + state[6] = sum - state[6].halve(); + state[7] = sum - (state[7].double() + state[7]); + state[8] = sum - state[8].double().double(); + state[9] = state[9].div_2exp_u64(8); + state[9] += sum; + state[10] = state[10].div_2exp_u64(3); + state[10] += sum; + state[11] = state[11].div_2exp_u64(24); + state[11] += sum; + state[12] = state[12].div_2exp_u64(8); + state[12] = sum - state[12]; + state[13] = state[13].div_2exp_u64(3); + state[13] = sum - state[13]; + state[14] = state[14].div_2exp_u64(4); + state[14] = sum - state[14]; + state[15] = state[15].div_2exp_u64(24); + state[15] = sum - state[15]; + } + + fn generic_internal_linear_layer>(state: &mut [A; 16]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use multiplication. + // This could probably be improved slightly by making use of the + // mul_2exp_u64 and div_2exp_u64 but this would involve porting div_2exp_u64 to PrimeCharacteristicRing. + state + .iter_mut() + .zip(INTERNAL_DIAG_MONTY_16) + .skip(3) + .for_each(|(val, diag_elem)| { + *val = full_sum.clone() + val.clone() * diag_elem; + }); + } +} + +impl InternalLayerBaseParameters for KoalaBearInternalLayerParameters { + type ArrayLike = [MontyField31; 23]; + + const INTERNAL_DIAG_MONTY: [MontyField31; 24] = INTERNAL_DIAG_MONTY_24; + + /// Perform the internal matrix multiplication: s -> (1 + Diag(V))s. + /// We ignore `state[0]` as it is handled separately. + fn internal_layer_mat_mul( + state: &mut [MontyField31; 24], + sum: MontyField31, + ) { + // The diagonal matrix is defined by the vector: + // V = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/32, 1/64, 1/2^24, -1/2^8, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^9, -1/2^24] + state[1] += sum; + state[2] = state[2].double() + sum; + state[3] = state[3].halve() + sum; + state[4] = sum + state[4].double() + state[4]; + state[5] = sum + state[5].double().double(); + state[6] = sum - state[6].halve(); + state[7] = sum - (state[7].double() + state[7]); + state[8] = sum - state[8].double().double(); + state[9] = state[9].div_2exp_u64(8); + state[9] += sum; + state[10] = state[10].div_2exp_u64(2); + state[10] += sum; + state[11] = state[11].div_2exp_u64(3); + state[11] += sum; + state[12] = state[12].div_2exp_u64(4); + state[12] += sum; + state[13] = state[13].div_2exp_u64(5); + state[13] += sum; + state[14] = state[14].div_2exp_u64(6); + state[14] += sum; + state[15] = state[15].div_2exp_u64(24); + state[15] += sum; + state[16] = state[16].div_2exp_u64(8); + state[16] = sum - state[16]; + state[17] = state[17].div_2exp_u64(3); + state[17] = sum - state[17]; + state[18] = state[18].div_2exp_u64(4); + state[18] = sum - state[18]; + state[19] = state[19].div_2exp_u64(5); + state[19] = sum - state[19]; + state[20] = state[20].div_2exp_u64(6); + state[20] = sum - state[20]; + state[21] = state[21].div_2exp_u64(7); + state[21] = sum - state[21]; + state[22] = state[22].div_2exp_u64(9); + state[22] = sum - state[22]; + state[23] = state[23].div_2exp_u64(24); + state[23] = sum - state[23]; + } + + fn generic_internal_linear_layer>(state: &mut [A; 24]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use multiplication. + // This could probably be improved slightly by making use of the + // mul_2exp_u64 and div_2exp_u64 but this would involve porting div_2exp_u64 to PrimeCharacteristicRing. + state + .iter_mut() + .zip(INTERNAL_DIAG_MONTY_24) + .skip(3) + .for_each(|(val, diag_elem)| { + *val = full_sum.clone() + val.clone() * diag_elem; + }); + } +} + +impl InternalLayerParameters for KoalaBearInternalLayerParameters {} +impl InternalLayerParameters for KoalaBearInternalLayerParameters {} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::{Rng, SeedableRng}; + use rand_xoshiro::Xoroshiro128Plus; + + use super::*; + + type F = KoalaBear; + + // We need to make some round constants. We use Xoroshiro128Plus for this as we can easily match this PRNG in sage. + // See: https://github.com/0xPolygonZero/hash-constants for the sage code used to create all these tests. + + /// Test on a roughly random input. + /// This random input is generated by the following sage code: + /// set_random_seed(16) + /// vector([KB.random_element() for t in range(16)]). + #[test] + fn test_poseidon2_width_16_random() { + let mut input: [F; 16] = KoalaBear::new_array([ + 894848333, 1437655012, 1200606629, 1690012884, 71131202, 1749206695, 1717947831, + 120589055, 19776022, 42382981, 1831865506, 724844064, 171220207, 1299207443, 227047920, + 1783754913, + ]); + + let expected: [F; 16] = KoalaBear::new_array([ + 652590279, 1200629963, 1013089423, 1840372851, 19101828, 561050015, 1714865585, + 994637181, 498949829, 729884572, 1957973925, 263012103, 535029297, 2121808603, + 964663675, 1473622080, + ]); + + let mut rng = Xoroshiro128Plus::seed_from_u64(1); + let perm = Poseidon2KoalaBear::new_from_rng_128(&mut rng); + + perm.permute_mut(&mut input); + assert_eq!(input, expected); + } + + /// Test on a roughly random input. + /// This random input is generated by the following sage code: + /// set_random_seed(24) + /// vector([KB.random_element() for t in range(24)]). + #[test] + fn test_poseidon2_width_24_random() { + let mut input: [F; 24] = KoalaBear::new_array([ + 886409618, 1327899896, 1902407911, 591953491, 648428576, 1844789031, 1198336108, + 355597330, 1799586834, 59617783, 790334801, 1968791836, 559272107, 31054313, + 1042221543, 474748436, 135686258, 263665994, 1962340735, 1741539604, 2026927696, + 449439011, 1131357108, 50869465, + ]); + + let expected: [F; 24] = KoalaBear::new_array([ + 3825456, 486989921, 613714063, 282152282, 1027154688, 1171655681, 879344953, + 1090688809, 1960721991, 1604199242, 1329947150, 1535171244, 781646521, 1156559780, + 1875690339, 368140677, 457503063, 304208551, 1919757655, 835116474, 1293372648, + 1254825008, 810923913, 1773631109, + ]); + + let mut rng = Xoroshiro128Plus::seed_from_u64(1); + let perm = Poseidon2KoalaBear::new_from_rng_128(&mut rng); + + perm.permute_mut(&mut input); + assert_eq!(input, expected); + } + + /// Test the generic internal layer against the optimized internal layer + /// for a random input of width 16. + #[test] + fn test_generic_internal_linear_layer_16() { + let mut rng = Xoroshiro128Plus::seed_from_u64(1); + let mut input1: [F; 16] = rng.random(); + let mut input2 = input1; + + let part_sum: F = input1[1..].iter().copied().sum(); + let full_sum = part_sum + input1[0]; + + input1[0] = part_sum - input1[0]; + + KoalaBearInternalLayerParameters::internal_layer_mat_mul(&mut input1, full_sum); + KoalaBearInternalLayerParameters::generic_internal_linear_layer(&mut input2); + + assert_eq!(input1, input2); + } + + /// Test the generic internal layer against the optimized internal layer + /// for a random input of width 16. + #[test] + fn test_generic_internal_linear_layer_24() { + let mut rng = Xoroshiro128Plus::seed_from_u64(1); + let mut input1: [F; 24] = rng.random(); + let mut input2 = input1; + + let part_sum: F = input1[1..].iter().copied().sum(); + let full_sum = part_sum + input1[0]; + + input1[0] = part_sum - input1[0]; + + KoalaBearInternalLayerParameters::internal_layer_mat_mul(&mut input1, full_sum); + KoalaBearInternalLayerParameters::generic_internal_linear_layer(&mut input2); + + assert_eq!(input1, input2); + } +} diff --git a/CoqOfRust/plonky3/koala-bear/src/poseidon2.v b/CoqOfRust/plonky3/koala-bear/src/poseidon2.v new file mode 100644 index 000000000..f4381e57e --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/poseidon2.v @@ -0,0 +1,4954 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module poseidon2. + Axiom Poseidon2InternalLayerKoalaBear : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_koala_bear::poseidon2::Poseidon2InternalLayerKoalaBear") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ WIDTH ] + [ + Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters"; + Ty.path "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters" + ]). + + Axiom Poseidon2ExternalLayerKoalaBear : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_koala_bear::poseidon2::Poseidon2ExternalLayerKoalaBear") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ WIDTH ] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ]). + + Definition value_KOALABEAR_S_BOX_DEGREE + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U64 3 |))). + + Global Instance Instance_IsConstant_value_KOALABEAR_S_BOX_DEGREE : + M.IsFunction.C "p3_koala_bear::poseidon2::KOALABEAR_S_BOX_DEGREE" value_KOALABEAR_S_BOX_DEGREE. + Admitted. + Global Typeclasses Opaque value_KOALABEAR_S_BOX_DEGREE. + + Axiom Poseidon2KoalaBear : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_koala_bear::poseidon2::Poseidon2KoalaBear") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ + WIDTH; + M.unevaluated_const + (mk_str (| "p3_koala_bear_poseidon2_Poseidon2KoalaBear_discriminant" |)) + ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ WIDTH ] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ]; + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ WIDTH ] + [ + Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters"; + Ty.path "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters" + ] + ]). + + Axiom GenericPoseidon2LinearLayersKoalaBear : + (Ty.path "p3_koala_bear::poseidon2::GenericPoseidon2LinearLayersKoalaBear") = + (Ty.apply + (Ty.path "p3_monty_31::poseidon2::GenericPoseidon2LinearLayersMonty31") + [] + [ + Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters"; + Ty.path "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters" + ]). + + Definition value_INTERNAL_DIAG_MONTY_16 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ + Value.Array + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 2 + ] + |); + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 2; + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 1 + ] + |); + Value.Integer IntegerKind.U32 3; + Value.Integer IntegerKind.U32 4; + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 1 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 3 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 4 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 8 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 3 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 127 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 8 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 3 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 4 + ] + |); + Value.Integer IntegerKind.U32 127 + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_INTERNAL_DIAG_MONTY_16 : + M.IsFunction.C "p3_koala_bear::poseidon2::INTERNAL_DIAG_MONTY_16" value_INTERNAL_DIAG_MONTY_16. + Admitted. + Global Typeclasses Opaque value_INTERNAL_DIAG_MONTY_16. + + Definition value_INTERNAL_DIAG_MONTY_24 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + "new_array", + [ Value.Integer IntegerKind.Usize 24 ], + [] + |), + [ + Value.Array + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 2 + ] + |); + Value.Integer IntegerKind.U32 1; + Value.Integer IntegerKind.U32 2; + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 1 + ] + |); + Value.Integer IntegerKind.U32 3; + Value.Integer IntegerKind.U32 4; + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 1 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 3 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 4 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 8 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 2 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 3 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 4 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 5 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 6 + ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 127 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 8 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 3 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 4 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 5 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 6 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 7 + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 9 + ] + |); + Value.Integer IntegerKind.U32 127 + ] + ] + |) + |))). + + Global Instance Instance_IsConstant_value_INTERNAL_DIAG_MONTY_24 : + M.IsFunction.C "p3_koala_bear::poseidon2::INTERNAL_DIAG_MONTY_24" value_INTERNAL_DIAG_MONTY_24. + Admitted. + Global Typeclasses Opaque value_INTERNAL_DIAG_MONTY_24. + + (* StructTuple + { + name := "KoalaBearInternalLayerParameters"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_fmt_Debug_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "KoalaBearInternalLayerParameters" |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + + Module Impl_core_clone_Clone_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + + Module Impl_core_default_Default_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + + Module Impl_p3_monty_31_poseidon2_InternalLayerBaseParameters_Usize_16_p3_koala_bear_koala_bear_KoalaBearParameters_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters". + + (* type ArrayLike = [MontyField31; 15]; *) + Definition _ArrayLike : Ty.t := + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ]. + + (* const INTERNAL_DIAG_MONTY: [MontyField31; 16] = INTERNAL_DIAG_MONTY_16; *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] *) + Definition value_INTERNAL_DIAG_MONTY + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (get_constant (| + "p3_koala_bear::poseidon2::INTERNAL_DIAG_MONTY_16", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + |))). + + (* + fn internal_layer_mat_mul( + state: &mut [MontyField31; 16], + sum: MontyField31, + ) { + // The diagonal matrix is defined by the vector: + // V = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/8, 1/2^24, -1/2^8, -1/8, -1/16, -1/2^24] + state[1] += sum; + state[2] = state[2].double() + sum; + state[3] = state[3].halve() + sum; + state[4] = sum + state[4].double() + state[4]; + state[5] = sum + state[5].double().double(); + state[6] = sum - state[6].halve(); + state[7] = sum - (state[7].double() + state[7]); + state[8] = sum - state[8].double().double(); + state[9] = state[9].div_2exp_u64(8); + state[9] += sum; + state[10] = state[10].div_2exp_u64(3); + state[10] += sum; + state[11] = state[11].div_2exp_u64(24); + state[11] += sum; + state[12] = state[12].div_2exp_u64(8); + state[12] = sum - state[12]; + state[13] = state[13].div_2exp_u64(3); + state[13] = sum - state[13]; + state[14] = state[14].div_2exp_u64(4); + state[14] = sum - state[14]; + state[15] = state[15].div_2exp_u64(24); + state[15] = sum - state[15]; + } + *) + Definition internal_layer_mat_mul (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ state; sum ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let sum := M.alloc (| sum |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.read (| sum |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.read (| sum |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 5 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 5 + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 6 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 6 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |) + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 8 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 8 + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |) + |); + Value.Integer IntegerKind.U64 8 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |) + |); + Value.Integer IntegerKind.U64 3 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |) + |); + Value.Integer IntegerKind.U64 24 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |) + |); + Value.Integer IntegerKind.U64 8 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |) + |); + Value.Integer IntegerKind.U64 3 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |) + |); + Value.Integer IntegerKind.U64 4 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |) + |); + Value.Integer IntegerKind.U64 24 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn generic_internal_linear_layer>(state: &mut [A; 16]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use multiplication. + // This could probably be improved slightly by making use of the + // mul_2exp_u64 and div_2exp_u64 but this would involve porting div_2exp_u64 to PrimeCharacteristicRing. + state + .iter_mut() + .zip(INTERNAL_DIAG_MONTY_16) + .skip(3) + .for_each(|(val, diag_elem)| { + *val = full_sum.clone() + val.clone() * diag_elem; + }); + } + *) + Definition generic_internal_linear_layer + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ A ], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ part_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + [], + [], + "sum", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + [], + [], + "cloned", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ A ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ A ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| state |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ full_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, part_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Sub", A, [], [ A ], "sub", [], [] |), + [ + M.read (| part_sum |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ A ]; + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ], + [], + [], + "skip", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.read (| + get_constant (| + "p3_koala_bear::poseidon2::INTERNAL_DIAG_MONTY_16", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 3 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ A ]; + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ + Ty.path + "p3_koala_bear::koala_bear::KoalaBearParameters" + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let val := M.copy (| γ0_0 |) in + let diag_elem := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| val |) |), + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Add", + A, + [], + [ A ], + "add", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + Ty.path + "p3_koala_bear::koala_bear::KoalaBearParameters" + ] + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| val |) |) + |) + ] + |); + M.read (| diag_elem |) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::poseidon2::InternalLayerBaseParameters" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 16 ] + (* Trait polymorphic types *) [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + Self + (* Instance *) + [ + ("ArrayLike", InstanceField.Ty _ArrayLike); + ("value_INTERNAL_DIAG_MONTY", InstanceField.Method value_INTERNAL_DIAG_MONTY); + ("internal_layer_mat_mul", InstanceField.Method internal_layer_mat_mul); + ("generic_internal_linear_layer", InstanceField.Method generic_internal_linear_layer) + ]. + End Impl_p3_monty_31_poseidon2_InternalLayerBaseParameters_Usize_16_p3_koala_bear_koala_bear_KoalaBearParameters_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + + Module Impl_p3_monty_31_poseidon2_InternalLayerBaseParameters_Usize_24_p3_koala_bear_koala_bear_KoalaBearParameters_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters". + + (* type ArrayLike = [MontyField31; 23]; *) + Definition _ArrayLike : Ty.t := + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 23 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ]. + + (* const INTERNAL_DIAG_MONTY: [MontyField31; 24] = INTERNAL_DIAG_MONTY_24; *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] *) + Definition value_INTERNAL_DIAG_MONTY + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (get_constant (| + "p3_koala_bear::poseidon2::INTERNAL_DIAG_MONTY_24", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + |))). + + (* + fn internal_layer_mat_mul( + state: &mut [MontyField31; 24], + sum: MontyField31, + ) { + // The diagonal matrix is defined by the vector: + // V = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/32, 1/64, 1/2^24, -1/2^8, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^9, -1/2^24] + state[1] += sum; + state[2] = state[2].double() + sum; + state[3] = state[3].halve() + sum; + state[4] = sum + state[4].double() + state[4]; + state[5] = sum + state[5].double().double(); + state[6] = sum - state[6].halve(); + state[7] = sum - (state[7].double() + state[7]); + state[8] = sum - state[8].double().double(); + state[9] = state[9].div_2exp_u64(8); + state[9] += sum; + state[10] = state[10].div_2exp_u64(2); + state[10] += sum; + state[11] = state[11].div_2exp_u64(3); + state[11] += sum; + state[12] = state[12].div_2exp_u64(4); + state[12] += sum; + state[13] = state[13].div_2exp_u64(5); + state[13] += sum; + state[14] = state[14].div_2exp_u64(6); + state[14] += sum; + state[15] = state[15].div_2exp_u64(24); + state[15] += sum; + state[16] = state[16].div_2exp_u64(8); + state[16] = sum - state[16]; + state[17] = state[17].div_2exp_u64(3); + state[17] = sum - state[17]; + state[18] = state[18].div_2exp_u64(4); + state[18] = sum - state[18]; + state[19] = state[19].div_2exp_u64(5); + state[19] = sum - state[19]; + state[20] = state[20].div_2exp_u64(6); + state[20] = sum - state[20]; + state[21] = state[21].div_2exp_u64(7); + state[21] = sum - state[21]; + state[22] = state[22].div_2exp_u64(9); + state[22] = sum - state[22]; + state[23] = state[23].div_2exp_u64(24); + state[23] = sum - state[23]; + } + *) + Definition internal_layer_mat_mul (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ state; sum ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let sum := M.alloc (| sum |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.read (| sum |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.read (| sum |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 5 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 5 + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 6 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 6 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |) + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 7 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 8 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 8 + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |) + |); + Value.Integer IntegerKind.U64 8 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 9 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |) + |); + Value.Integer IntegerKind.U64 2 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 10 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |) + |); + Value.Integer IntegerKind.U64 3 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 11 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |) + |); + Value.Integer IntegerKind.U64 4 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 12 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |) + |); + Value.Integer IntegerKind.U64 5 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 13 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |) + |); + Value.Integer IntegerKind.U64 6 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 14 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |) + |); + Value.Integer IntegerKind.U64 24 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 15 + |) + |); + M.read (| sum |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 16 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 16 + |) + |); + Value.Integer IntegerKind.U64 8 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 16 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 16 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 17 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 17 + |) + |); + Value.Integer IntegerKind.U64 3 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 17 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 17 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 18 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 18 + |) + |); + Value.Integer IntegerKind.U64 4 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 18 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 18 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 19 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 19 + |) + |); + Value.Integer IntegerKind.U64 5 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 19 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 19 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 20 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 20 + |) + |); + Value.Integer IntegerKind.U64 6 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 20 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 20 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 21 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 21 + |) + |); + Value.Integer IntegerKind.U64 7 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 21 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 21 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 22 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 22 + |) + |); + Value.Integer IntegerKind.U64 9 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 22 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 22 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 23 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 23 + |) + |); + Value.Integer IntegerKind.U64 24 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 23 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ], + "sub", + [], + [] + |), + [ + M.read (| sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 23 + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn generic_internal_linear_layer>(state: &mut [A; 24]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use multiplication. + // This could probably be improved slightly by making use of the + // mul_2exp_u64 and div_2exp_u64 but this would involve porting div_2exp_u64 to PrimeCharacteristicRing. + state + .iter_mut() + .zip(INTERNAL_DIAG_MONTY_24) + .skip(3) + .for_each(|(val, diag_elem)| { + *val = full_sum.clone() + val.clone() * diag_elem; + }); + } + *) + Definition generic_internal_linear_layer + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ A ], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ part_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + [], + [], + "sum", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + [], + [], + "cloned", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ A ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ A ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| state |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ full_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, part_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Sub", A, [], [ A ], "sub", [], [] |), + [ + M.read (| part_sum |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ A ]; + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ], + [], + [], + "skip", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.read (| + get_constant (| + "p3_koala_bear::poseidon2::INTERNAL_DIAG_MONTY_24", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + ] + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 3 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ A ]; + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ + Ty.path + "p3_koala_bear::koala_bear::KoalaBearParameters" + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let val := M.copy (| γ0_0 |) in + let diag_elem := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| val |) |), + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Add", + A, + [], + [ A ], + "add", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + Ty.path + "p3_koala_bear::koala_bear::KoalaBearParameters" + ] + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| val |) |) + |) + ] + |); + M.read (| diag_elem |) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::poseidon2::InternalLayerBaseParameters" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 24 ] + (* Trait polymorphic types *) [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + Self + (* Instance *) + [ + ("ArrayLike", InstanceField.Ty _ArrayLike); + ("value_INTERNAL_DIAG_MONTY", InstanceField.Method value_INTERNAL_DIAG_MONTY); + ("internal_layer_mat_mul", InstanceField.Method internal_layer_mat_mul); + ("generic_internal_linear_layer", InstanceField.Method generic_internal_linear_layer) + ]. + End Impl_p3_monty_31_poseidon2_InternalLayerBaseParameters_Usize_24_p3_koala_bear_koala_bear_KoalaBearParameters_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + + Module Impl_p3_monty_31_poseidon2_InternalLayerParameters_Usize_16_p3_koala_bear_koala_bear_KoalaBearParameters_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters". + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::poseidon2::InternalLayerParameters" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 16 ] + (* Trait polymorphic types *) [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + Self + (* Instance *) []. + End Impl_p3_monty_31_poseidon2_InternalLayerParameters_Usize_16_p3_koala_bear_koala_bear_KoalaBearParameters_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + + Module Impl_p3_monty_31_poseidon2_InternalLayerParameters_Usize_24_p3_koala_bear_koala_bear_KoalaBearParameters_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. + Definition Self : Ty.t := Ty.path "p3_koala_bear::poseidon2::KoalaBearInternalLayerParameters". + + Axiom Implements : + M.IsTraitInstance + "p3_monty_31::poseidon2::InternalLayerParameters" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 24 ] + (* Trait polymorphic types *) [ Ty.path "p3_koala_bear::koala_bear::KoalaBearParameters" ] + Self + (* Instance *) []. + End Impl_p3_monty_31_poseidon2_InternalLayerParameters_Usize_24_p3_koala_bear_koala_bear_KoalaBearParameters_for_p3_koala_bear_poseidon2_KoalaBearInternalLayerParameters. +End poseidon2. diff --git a/CoqOfRust/plonky3/koala-bear/src/x86_64_avx2/mod.rs b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx2/mod.rs new file mode 100644 index 000000000..d47a7ccc5 --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx2/mod.rs @@ -0,0 +1,4 @@ +mod packing; +mod poseidon2; + +pub use packing::*; diff --git a/CoqOfRust/plonky3/koala-bear/src/x86_64_avx2/packing.rs b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx2/packing.rs new file mode 100644 index 000000000..639ec9f1e --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx2/packing.rs @@ -0,0 +1,35 @@ +use core::arch::x86_64::__m256i; +use core::mem::transmute; + +use p3_monty_31::{MontyParametersAVX2, PackedMontyField31AVX2}; + +use crate::KoalaBearParameters; + +pub type PackedKoalaBearAVX2 = PackedMontyField31AVX2; + +const WIDTH: usize = 8; + +impl MontyParametersAVX2 for KoalaBearParameters { + const PACKED_P: __m256i = unsafe { transmute::<[u32; WIDTH], _>([0x7f000001; WIDTH]) }; + const PACKED_MU: __m256i = unsafe { transmute::<[u32; WIDTH], _>([0x81000001; WIDTH]) }; +} + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::WIDTH; + use crate::KoalaBear; + + const SPECIAL_VALS: [KoalaBear; WIDTH] = KoalaBear::new_array([ + 0x00000000, 0x00000001, 0x7f000000, 0x7effffff, 0x3f800000, 0x0ffffffe, 0x68000003, + 0x70000002, + ]); + + test_packed_field!( + crate::PackedKoalaBearAVX2, + &[crate::PackedKoalaBearAVX2::ZERO], + &[crate::PackedKoalaBearAVX2::ONE], + p3_monty_31::PackedMontyField31AVX2::(super::SPECIAL_VALS) + ); +} diff --git a/CoqOfRust/plonky3/koala-bear/src/x86_64_avx2/poseidon2.rs b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx2/poseidon2.rs new file mode 100644 index 000000000..881f8c9c9 --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx2/poseidon2.rs @@ -0,0 +1,251 @@ +use core::arch::x86_64::{self, __m256i}; +use core::mem::transmute; + +use p3_monty_31::{ + InternalLayerParametersAVX2, mul_2exp_neg_n_avx2, mul_2exp_neg_two_adicity_avx2, + mul_neg_2exp_neg_n_avx2, mul_neg_2exp_neg_two_adicity_avx2, +}; + +use crate::{KoalaBearInternalLayerParameters, KoalaBearParameters}; + +// Godbolt file showing that these all compile to the expected instructions. (Potentially plus a few memory ops): +// https://godbolt.org/z/xK91MKsdd + +// We reimplement multiplication by +/- 2^{-8} here as there is an extra trick we can do specifically in the KoalaBear case. +// This lets us replace a left shift by _mm256_bslli_epi128 which can be performed on Port 5. This takes a small amount +// of pressure off Ports 0, 1. + +/// Multiply a vector of Monty31 field elements in canonical form by 2**{-8}. +/// This is specialised to the KoalaBear prime which allows us to replace a +/// shifts by a twiddle. +/// # Safety +/// +/// Input must be given in canonical form. +/// Output is not in canonical form, outputs are only guaranteed to lie in (-P, P). +#[inline(always)] +unsafe fn mul_2exp_neg_8(input: __m256i) -> __m256i { + // We want this to compile to: + // vpsrld hi, val, 8 + // vpmaddubsw lo, val, [r; 8] + // vpslldq lo, lo, 2 + // vpsubd t, hi, lo + // throughput: 1.333 + // latency: 7 + unsafe { + const ONE_TWENTY_SEVEN: __m256i = unsafe { transmute([127; 8]) }; // P = r*2^j + 1 = 127 * 2^24 + 1 + let hi = x86_64::_mm256_srli_epi32::<8>(input); + + // Whilst it generically does something else, provided + // each entry of odd_factor is < 2^7, _mm256_maddubs_epi16 + // performs an element wise multiplication of odd_factor with + // the bottom 8 bits of input interpreted as an unsigned integer + // Thus lo contains r*x_lo. + let lo = x86_64::_mm256_maddubs_epi16(input, ONE_TWENTY_SEVEN); + + // As the high 16 bits of each 32 bit word are all 0 + // we don't need to worry about shifting the high bits of one + // word into the low bits of another. Thus we can use + // _mm256_bslli_epi128 which can run on Port 5 as it is classed as + // a swizzle operation. + let lo_shft = x86_64::_mm256_bslli_epi128::<2>(lo); + x86_64::_mm256_sub_epi32(hi, lo_shft) + } +} + +/// Multiply a vector of Monty31 field elements in canonical form by 2**{-8}. +/// This is specialised to the KoalaBear prime which allows us to replace a +/// shift by a twiddle. +/// # Safety +/// +/// Input must be given in canonical form. +/// Output is not in canonical form, outputs are only guaranteed to lie in (-P, P). +#[inline(always)] +unsafe fn mul_neg_2exp_neg_8(input: __m256i) -> __m256i { + // We want this to compile to: + // vpsrld hi, val, 8 + // vpmaddubsw lo, val, [r; 8] + // vpslldq lo, lo, 2 + // vpsubd t, lo, hi + // throughput: 1.333 + // latency: 7 + unsafe { + const ONE_TWENTY_SEVEN: __m256i = unsafe { transmute([127; 8]) }; // P = r*2^j + 1 = 127 * 2^24 + 1 + let hi = x86_64::_mm256_srli_epi32::<8>(input); + + // Whilst it generically does something else, provided + // each entry of odd_factor is < 2^7, _mm256_maddubs_epi16 + // performs an element wise multiplication of odd_factor with + // the bottom 8 bits of input interpreted as an unsigned integer + // Thus lo contains r*x_lo. + let lo = x86_64::_mm256_maddubs_epi16(input, ONE_TWENTY_SEVEN); + + // As the high 16 bits of each 32 bit word are all 0 + // we don't need to worry about shifting the high bits of one + // word into the low bits of another. Thus we can use + // _mm256_bslli_epi128 which can run on Port 5 as it is classed as + // a swizzle operation. + let lo_shft = x86_64::_mm256_bslli_epi128::<2>(lo); + x86_64::_mm256_sub_epi32(lo_shft, hi) + } +} + +impl InternalLayerParametersAVX2 for KoalaBearInternalLayerParameters { + type ArrayLike = [__m256i; 15]; + + /// For the KoalaBear field and width 16 we multiply by the diagonal matrix: + /// + /// D = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/8, 1/2^24, -1/2^8, -1/8, -1/16, -1/2^24] + /// The first 9 entries are handled elsewhere, this function handles all the positive/negative inverse powers of two. + /// The inputs must be in canonical form, otherwise the result is undefined. + /// Even when the inputs are in canonical form, we make no guarantees on the output except that, provided + /// the output is piped directly into add_sum the vector will be modified such that x[i] = D[i]*x[i] + sum. + #[inline(always)] + unsafe fn diagonal_mul_remainder(input: &mut [__m256i; 15]) { + unsafe { + // As far as we know this is optimal in that it need the fewest instructions to perform all of these + // multiplications. (Note that -1, 0 are not allowed on the diagonal for technical reasons). + // If there exist other number b for which x*b mod P can be computed quickly this diagonal can be updated. + + // input[8]-> sum + input[8]/2^8 + input[8] = mul_2exp_neg_8(input[8]); + + // input[9] -> sum + input[9]/2^3 + input[9] = mul_2exp_neg_n_avx2::(input[9]); + + // input[10] -> sum + input[10]/2^24 + input[10] = mul_2exp_neg_two_adicity_avx2::(input[10]); + + // input[11] -> sum - input[11]/2^8 + input[11] = mul_neg_2exp_neg_8(input[11]); + + // input[12] -> sum - input[12]/2^3 + input[12] = mul_neg_2exp_neg_n_avx2::(input[12]); + + // input[13] -> sum - input[13]/2^4 + input[13] = mul_neg_2exp_neg_n_avx2::(input[13]); + + // input[14] -> sum - input[14]/2^24 + input[14] = mul_neg_2exp_neg_two_adicity_avx2::(input[14]); + } + } +} + +impl InternalLayerParametersAVX2 for KoalaBearInternalLayerParameters { + type ArrayLike = [__m256i; 23]; + + /// For the KoalaBear field and width 1246 we multiply by the diagonal matrix: + /// + /// D = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/32, 1/64, 1/2^24, -1/2^8, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^9, -1/2^24] + /// The first 9 entries are handled elsewhere, this function handles all the positive/negative inverse powers of two. + /// The inputs must be in canonical form, otherwise the result is undefined. + /// Even when the inputs are in canonical form, we make no guarantees on the output except that, provided + /// the output is piped directly into add_sum, the vector will be modified such that x[i] = D[i]*x[i] + sum. + #[inline(always)] + unsafe fn diagonal_mul_remainder(input: &mut [__m256i; 23]) { + unsafe { + // As far as we know this is optimal in that it need the fewest instructions to perform all of these + // multiplications. (Note that -1, 0 are not allowed on the diagonal for technical reasons). + // If there exist other number b for which x*b mod P can be computed quickly this diagonal can be updated. + + // input[8] -> sum + input[8]/2^8 + input[8] = mul_2exp_neg_8(input[8]); + + // input[9] -> sum + input[9]/2^2 + input[9] = mul_2exp_neg_n_avx2::(input[9]); + + // input[10] -> sum + input[10]/2^3 + input[10] = mul_2exp_neg_n_avx2::(input[10]); + + // input[11] -> sum + input[11]/2^4 + input[11] = mul_2exp_neg_n_avx2::(input[11]); + + // input[12] -> sum + input[12]/2^5 + input[12] = mul_2exp_neg_n_avx2::(input[12]); + + // input[13] -> sum + input[13]/2^6 + input[13] = mul_2exp_neg_n_avx2::(input[13]); + + // input[14] -> sum + input[14]/2^24 + input[14] = mul_2exp_neg_two_adicity_avx2::(input[14]); + + // input[15] -> sum - input[15]/2^8 + input[15] = mul_neg_2exp_neg_8(input[15]); + + // input[16] -> sum - input[16]/2^3 + input[16] = mul_neg_2exp_neg_n_avx2::(input[16]); + + // input[17] -> sum - input[17]/2^4 + input[17] = mul_neg_2exp_neg_n_avx2::(input[17]); + + // input[18] -> sum - input[18]/2^5 + input[18] = mul_neg_2exp_neg_n_avx2::(input[18]); + + // input[19] -> sum - input[19]/2^6 + input[19] = mul_neg_2exp_neg_n_avx2::(input[19]); + + // input[20] -> sum - input[20]/2^7 + input[20] = mul_neg_2exp_neg_n_avx2::(input[20]); + + // input[21] -> sum - input[21]/2^9 + input[21] = mul_neg_2exp_neg_n_avx2::(input[21]); + + // input[22] -> sum - input[22]/2^24 + input[22] = mul_neg_2exp_neg_two_adicity_avx2::(input[22]); + } + } +} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use crate::{KoalaBear, PackedKoalaBearAVX2, Poseidon2KoalaBear}; + + type F = KoalaBear; + type Perm16 = Poseidon2KoalaBear<16>; + type Perm24 = Poseidon2KoalaBear<24>; + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_avx2_poseidon2_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm16::new_from_rng_128(&mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + + assert_eq!(avx2_output, expected); + } + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_avx2_poseidon2_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm24::new_from_rng_128(&mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + + assert_eq!(avx2_output, expected); + } +} diff --git a/CoqOfRust/plonky3/koala-bear/src/x86_64_avx512/mod.rs b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx512/mod.rs new file mode 100644 index 000000000..d47a7ccc5 --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx512/mod.rs @@ -0,0 +1,4 @@ +mod packing; +mod poseidon2; + +pub use packing::*; diff --git a/CoqOfRust/plonky3/koala-bear/src/x86_64_avx512/packing.rs b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx512/packing.rs new file mode 100644 index 000000000..cef0df1eb --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx512/packing.rs @@ -0,0 +1,36 @@ +use core::arch::x86_64::__m512i; +use core::mem::transmute; + +use p3_monty_31::{MontyParametersAVX512, PackedMontyField31AVX512}; + +use crate::KoalaBearParameters; + +pub type PackedKoalaBearAVX512 = PackedMontyField31AVX512; + +const WIDTH: usize = 16; + +impl MontyParametersAVX512 for KoalaBearParameters { + const PACKED_P: __m512i = unsafe { transmute::<[u32; WIDTH], _>([0x7f000001; WIDTH]) }; + const PACKED_MU: __m512i = unsafe { transmute::<[u32; WIDTH], _>([0x81000001; WIDTH]) }; +} + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::WIDTH; + use crate::KoalaBear; + + const SPECIAL_VALS: [KoalaBear; WIDTH] = KoalaBear::new_array([ + 0x00000000, 0x00000001, 0x78000000, 0x77ffffff, 0x3c000000, 0x0ffffffe, 0x68000003, + 0x70000002, 0x00000000, 0x00000001, 0x78000000, 0x77ffffff, 0x3c000000, 0x0ffffffe, + 0x68000003, 0x70000002, + ]); + + test_packed_field!( + crate::PackedKoalaBearAVX512, + &[crate::PackedKoalaBearAVX512::ZERO], + &[crate::PackedKoalaBearAVX512::ONE], + p3_monty_31::PackedMontyField31AVX512::(super::SPECIAL_VALS) + ); +} diff --git a/CoqOfRust/plonky3/koala-bear/src/x86_64_avx512/poseidon2.rs b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx512/poseidon2.rs new file mode 100644 index 000000000..16248e5d4 --- /dev/null +++ b/CoqOfRust/plonky3/koala-bear/src/x86_64_avx512/poseidon2.rs @@ -0,0 +1,185 @@ +use core::arch::x86_64::__m512i; + +use p3_monty_31::{ + InternalLayerParametersAVX512, mul_neg_2exp_neg_8_avx512, mul_neg_2exp_neg_n_avx512, + mul_neg_2exp_neg_two_adicity_avx512, +}; + +use crate::{KoalaBearInternalLayerParameters, KoalaBearParameters}; + +impl InternalLayerParametersAVX512 for KoalaBearInternalLayerParameters { + type ArrayLike = [__m512i; 15]; + + /// For the KoalaBear field and width 16 we multiply by the diagonal matrix: + /// D = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/8, 1/2^24, -1/2^8, -1/8, -1/16, -1/2^24]. + /// The inputs must be in canonical form, otherwise the result is undefined. + /// Even when the inputs are in canonical form, we make no guarantees on the output except that, provided + /// the output is piped directly into add_sum the vector will be modified such that x[i] = D[i]*x[i] + sum. + #[inline(always)] + unsafe fn diagonal_mul_remainder(input: &mut [__m512i; 15]) { + unsafe { + // As far as we know this is optimal in that it need the fewest instructions to perform all of these + // multiplications. (Note that -1, 0 are not allowed on the diagonal for technical reasons). + // If there exist other number b for which x*b mod P can be computed quickly this diagonal can be updated. + + // This following 3 muls (from input[8] to input[10]) output the negative of what we want. + // This will be handled in add_sum. + + // input[8]-> sum + input[8]/2^8 + input[8] = mul_neg_2exp_neg_8_avx512::(input[8]); + + // input[9] -> sum + input[9]/2^3 + input[9] = mul_neg_2exp_neg_n_avx512::(input[9]); + + // input[10] -> sum + input[10]/2^24 + input[10] = + mul_neg_2exp_neg_two_adicity_avx512::(input[10]); + + // The remaining muls output the correct value again. + + // input[11] -> sum - input[11]/2^8 + input[11] = mul_neg_2exp_neg_8_avx512::(input[11]); + + // input[12] -> sum - input[12]/2^3 + input[12] = mul_neg_2exp_neg_n_avx512::(input[12]); + + // input[13] -> sum - input[13]/2^4 + input[13] = mul_neg_2exp_neg_n_avx512::(input[13]); + + // input[14] -> sum - input[14]/2^24 + input[14] = + mul_neg_2exp_neg_two_adicity_avx512::(input[14]); + } + } + + /// There are 3 positive inverse powers of two after the 4: 1/2^8, 1/8, 1/2^24, + const NUM_POS: usize = 3; +} + +impl InternalLayerParametersAVX512 for KoalaBearInternalLayerParameters { + type ArrayLike = [__m512i; 23]; + + /// For the KoalaBear field and width 24 we multiply by the diagonal matrix: + /// D = [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4, 1/2^8, 1/4, 1/8, 1/16, 1/32, 1/64, 1/2^24, -1/2^8, -1/8, -1/16, -1/32, -1/64, -1/2^7, -1/2^9, -1/2^24] + /// The inputs must be in canonical form, otherwise the result is undefined. + /// Even when the inputs are in canonical form, we make no guarantees on the output except that, provided + /// the output is piped directly into add_sum, the vector will be modified such that x[i] = D[i]*x[i] + sum. + #[inline(always)] + unsafe fn diagonal_mul_remainder(input: &mut [__m512i; 23]) { + unsafe { + // As far as we know this is optimal in that it need the fewest instructions to perform all of these + // multiplications. (Note that -1, 0 are not allowed on the diagonal for technical reasons). + // If there exist other number b for which x*b mod P can be computed quickly this diagonal can be updated. + + // This following 7 muls (from input[8] to input[14]) output the negative of what we want. + // This will be handled in add_sum. + + // input[8] -> sum + input[8]/2^8 + input[8] = mul_neg_2exp_neg_8_avx512::(input[8]); + + // input[9] -> sum + input[9]/2^2 + input[9] = mul_neg_2exp_neg_n_avx512::(input[9]); + + // input[10] -> sum + input[10]/2^3 + input[10] = mul_neg_2exp_neg_n_avx512::(input[10]); + + // input[11] -> sum + input[11]/2^4 + input[11] = mul_neg_2exp_neg_n_avx512::(input[11]); + + // input[12] -> sum + input[12]/2^5 + input[12] = mul_neg_2exp_neg_n_avx512::(input[12]); + + // input[13] -> sum + input[13]/2^6 + input[13] = mul_neg_2exp_neg_n_avx512::(input[13]); + + // input[14] -> sum + input[14]/2^24 + input[14] = + mul_neg_2exp_neg_two_adicity_avx512::(input[14]); + + // The remaining muls output the correct value again. + + // input[15] -> sum - input[15]/2^8 + input[15] = mul_neg_2exp_neg_8_avx512::(input[15]); + + // input[16] -> sum - input[16]/2^3 + input[16] = mul_neg_2exp_neg_n_avx512::(input[16]); + + // input[17] -> sum - input[17]/2^4 + input[17] = mul_neg_2exp_neg_n_avx512::(input[17]); + + // input[18] -> sum - input[18]/2^5 + input[18] = mul_neg_2exp_neg_n_avx512::(input[18]); + + // input[19] -> sum - input[19]/2^6 + input[19] = mul_neg_2exp_neg_n_avx512::(input[19]); + + // input[20] -> sum - input[20]/2^7 + input[20] = mul_neg_2exp_neg_n_avx512::(input[20]); + + // input[21] -> sum - input[21]/2^9 + input[21] = mul_neg_2exp_neg_n_avx512::(input[21]); + + // input[22] -> sum - input[22]/2^24 + input[22] = + mul_neg_2exp_neg_two_adicity_avx512::(input[22]); + } + } + + /// There are 7 positive inverse powers of two after the 4: 1/2^8, 1/4, 1/8, 1/16, 1/32, 1/64, 1/2^24; + const NUM_POS: usize = 7; +} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use crate::{KoalaBear, PackedKoalaBearAVX512, Poseidon2KoalaBear}; + + type F = KoalaBear; + type Perm16 = Poseidon2KoalaBear<16>; + type Perm24 = Poseidon2KoalaBear<24>; + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_avx512_poseidon2_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm16::new_from_rng_128(&mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx512_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx512_input); + + let avx512_output = avx512_input.map(|x| x.0[0]); + + assert_eq!(avx512_output, expected); + } + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_avx512_poseidon2_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm24::new_from_rng_128(&mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx512_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx512_input); + + let avx512_output = avx512_input.map(|x| x.0[0]); + + assert_eq!(avx512_output, expected); + } +} diff --git a/CoqOfRust/plonky3/matrix/links/dense.v b/CoqOfRust/plonky3/matrix/links/dense.v new file mode 100644 index 000000000..21c7cb455 --- /dev/null +++ b/CoqOfRust/plonky3/matrix/links/dense.v @@ -0,0 +1,56 @@ +Require Import CoqOfRust.CoqOfRust. +Require Import CoqOfRust.links.M. +Require Import plonky3.matrix.dense. + +(* TODO: + - in the future, check the detail of the proof +*) + +(* +pub struct DenseMatrix> { + pub values: V, + pub width: usize, + _phantom: PhantomData, +} +*) +Module DenseMatrix. + Record t (T V : Set) : Set := { + values : V; + width : Usize.t; + }. + Arguments t : clear implicits. + + Parameter to_value : forall {T V : Set}, t T V -> Value.t. + + Global Instance IsLink (T V : Set) `{Link T} `{Link V} : Link (t T V) := { + Φ := Ty.apply (Ty.path "p3_matrix::dense::DenseMatrix") [] [ Φ T; Φ V ]; + φ := to_value; + }. + + Definition of_ty (T_ty V_ty : Ty.t) : + OfTy.t T_ty -> OfTy.t V_ty -> + OfTy.t (Ty.apply (Ty.path "p3_matrix::dense::DenseMatrix") [] [ T_ty ; V_ty ]). + (* TODO: check the proof in the future *) + Proof. intros [T] [V]. eapply OfTy.Make with (A := t T V). now subst. Defined. + Smpl Add eapply of_ty : of_ty. +End DenseMatrix. + +(* +pub type RowMajorMatrix = DenseMatrix>; +*) +Module RowMajorMatrix. + Definition t (T : Set) := DenseMatrix.t T (list T). + + Parameter to_value : forall {T : Set}, t T -> Value.t. + + Global Instance IsLink (T : Set) `{Link T} : Link (t T) := { + Φ := Ty.apply (Ty.path "p3_matrix::dense::RowMajorMatrix") [] [ Φ T ]; + φ := to_value; + }. + + Definition of_ty (T_ty : Ty.t) : + OfTy.t T_ty -> + OfTy.t (Ty.apply (Ty.path "p3_matrix::dense::RowMajorMatrix") [] [ T_ty ]). + Proof. intros [T]. eapply OfTy.Make with (A := t T). now subst. Defined. + Smpl Add eapply of_ty : of_ty. +End RowMajorMatrix. \ No newline at end of file diff --git a/CoqOfRust/plonky3/maybe-rayon/src/lib.rs b/CoqOfRust/plonky3/maybe-rayon/src/lib.rs new file mode 100644 index 000000000..10af5be0f --- /dev/null +++ b/CoqOfRust/plonky3/maybe-rayon/src/lib.rs @@ -0,0 +1,78 @@ +#![no_std] + +#[cfg(feature = "parallel")] +pub mod prelude { + use core::marker::{Send, Sync}; + use core::ops::Fn; + + pub use rayon::prelude::*; + pub use rayon::{current_num_threads, join}; + + pub trait SharedExt: ParallelIterator { + fn par_fold_reduce(self, identity: Id, fold_op: F, reduce_op: R) -> Acc + where + Acc: Send, + Id: Fn() -> Acc + Sync + Send, + F: Fn(Acc, Self::Item) -> Acc + Sync + Send, + R: Fn(Acc, Acc) -> Acc + Sync + Send; + } + + impl SharedExt for I { + #[inline] + fn par_fold_reduce(self, identity: Id, fold_op: F, reduce_op: R) -> Acc + where + Acc: Send, + Id: Fn() -> Acc + Sync + Send, + F: Fn(Acc, Self::Item) -> Acc + Sync + Send, + R: Fn(Acc, Acc) -> Acc + Sync + Send, + { + self.fold(&identity, fold_op).reduce(&identity, reduce_op) + } + } +} + +#[cfg(feature = "parallel")] +pub mod iter { + pub use rayon::iter::{repeat, repeatn as repeat_n}; +} + +#[cfg(not(feature = "parallel"))] +mod serial; + +#[cfg(not(feature = "parallel"))] +pub mod prelude { + pub use core::iter::{ + ExactSizeIterator as IndexedParallelIterator, Iterator as ParallelIterator, + }; + use core::marker::{Send, Sync}; + use core::ops::Fn; + + pub use super::serial::*; + + pub trait SharedExt: ParallelIterator { + fn par_fold_reduce(self, identity: Id, fold_op: F, reduce_op: R) -> Acc + where + Acc: Send, + Id: Fn() -> Acc + Sync + Send, + F: Fn(Acc, Self::Item) -> Acc + Sync + Send, + R: Fn(Acc, Acc) -> Acc + Sync + Send; + } + + impl SharedExt for I { + #[inline] + fn par_fold_reduce(self, identity: Id, fold_op: F, _reduce_op: R) -> Acc + where + Acc: Send, + Id: Fn() -> Acc + Sync + Send, + F: Fn(Acc, Self::Item) -> Acc + Sync + Send, + R: Fn(Acc, Acc) -> Acc + Sync + Send, + { + self.fold(identity(), fold_op) + } + } +} + +#[cfg(not(feature = "parallel"))] +pub mod iter { + pub use core::iter::{repeat, repeat_n}; +} diff --git a/CoqOfRust/plonky3/maybe-rayon/src/lib.v b/CoqOfRust/plonky3/maybe-rayon/src/lib.v new file mode 100644 index 000000000..06917ed65 --- /dev/null +++ b/CoqOfRust/plonky3/maybe-rayon/src/lib.v @@ -0,0 +1,77 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module prelude. + (* Trait *) + (* Empty module 'SharedExt' *) + + Module Impl_p3_maybe_rayon_prelude_SharedExt_where_core_iter_traits_iterator_Iterator_I_for_I. + Definition Self (I : Ty.t) : Ty.t := I. + + (* + fn par_fold_reduce(self, identity: Id, fold_op: F, _reduce_op: R) -> Acc + where + Acc: Send, + Id: Fn() -> Acc + Sync + Send, + F: Fn(Acc, Self::Item) -> Acc + Sync + Send, + R: Fn(Acc, Acc) -> Acc + Sync + Send, + { + self.fold(identity(), fold_op) + } + *) + Definition par_fold_reduce + (I : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self I in + match ε, τ, α with + | [], [ Acc; Id; F; R ], [ self; identity; fold_op; _reduce_op ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let identity := M.alloc (| identity |) in + let fold_op := M.alloc (| fold_op |) in + let _reduce_op := M.alloc (| _reduce_op |) in + M.call_closure (| + Acc, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "fold", + [], + [ Acc; F ] + |), + [ + M.read (| self |); + M.call_closure (| + Acc, + M.get_trait_method (| + "core::ops::function::Fn", + Id, + [], + [ Ty.tuple [] ], + "call", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, identity |); Value.Tuple [] ] + |); + M.read (| fold_op |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (I : Ty.t), + M.IsTraitInstance + "p3_maybe_rayon::prelude::SharedExt" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self I) + (* Instance *) [ ("par_fold_reduce", InstanceField.Method (par_fold_reduce I)) ]. + End Impl_p3_maybe_rayon_prelude_SharedExt_where_core_iter_traits_iterator_Iterator_I_for_I. +End prelude. diff --git a/CoqOfRust/plonky3/maybe-rayon/src/serial.rs b/CoqOfRust/plonky3/maybe-rayon/src/serial.rs new file mode 100644 index 000000000..dc8c0c222 --- /dev/null +++ b/CoqOfRust/plonky3/maybe-rayon/src/serial.rs @@ -0,0 +1,184 @@ +use core::iter::{FlatMap, IntoIterator, Iterator}; +use core::marker::{Send, Sized, Sync}; +use core::ops::{Fn, FnOnce}; +use core::option::Option; +use core::slice::{ + Chunks, ChunksExact, ChunksExactMut, ChunksMut, RChunks, RChunksExact, RChunksExactMut, + RChunksMut, Split, SplitMut, Windows, +}; + +pub trait IntoParallelIterator { + type Iter: Iterator; + type Item: Send; + + fn into_par_iter(self) -> Self::Iter; +} +impl IntoParallelIterator for T +where + T::Item: Send, +{ + type Iter = T::IntoIter; + type Item = T::Item; + + fn into_par_iter(self) -> Self::Iter { + self.into_iter() + } +} + +pub trait IntoParallelRefIterator<'data> { + type Iter: Iterator; + type Item: Send + 'data; + + fn par_iter(&'data self) -> Self::Iter; +} + +impl<'data, I: 'data + ?Sized> IntoParallelRefIterator<'data> for I +where + &'data I: IntoParallelIterator, +{ + type Iter = <&'data I as IntoParallelIterator>::Iter; + type Item = <&'data I as IntoParallelIterator>::Item; + + fn par_iter(&'data self) -> Self::Iter { + self.into_par_iter() + } +} + +pub trait IntoParallelRefMutIterator<'data> { + type Iter: Iterator; + type Item: Send + 'data; + + fn par_iter_mut(&'data mut self) -> Self::Iter; +} + +impl<'data, I: 'data + ?Sized> IntoParallelRefMutIterator<'data> for I +where + &'data mut I: IntoParallelIterator, +{ + type Iter = <&'data mut I as IntoParallelIterator>::Iter; + type Item = <&'data mut I as IntoParallelIterator>::Item; + + fn par_iter_mut(&'data mut self) -> Self::Iter { + self.into_par_iter() + } +} + +pub trait ParallelSlice { + /// Returns a plain slice, which is used to implement the rest of the + /// parallel methods. + fn as_parallel_slice(&self) -> &[T]; + + fn par_split

(&self, separator: P) -> Split<'_, T, P> + where + P: Fn(&T) -> bool + Sync + Send, + { + self.as_parallel_slice().split(separator) + } + + fn par_windows(&self, window_size: usize) -> Windows<'_, T> { + self.as_parallel_slice().windows(window_size) + } + + fn par_chunks(&self, chunk_size: usize) -> Chunks<'_, T> { + self.as_parallel_slice().chunks(chunk_size) + } + + fn par_chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> { + self.as_parallel_slice().chunks_exact(chunk_size) + } + + fn par_rchunks(&self, chunk_size: usize) -> RChunks<'_, T> { + self.as_parallel_slice().rchunks(chunk_size) + } + + fn par_rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T> { + self.as_parallel_slice().rchunks_exact(chunk_size) + } +} + +impl ParallelSlice for [T] { + #[inline] + fn as_parallel_slice(&self) -> &[T] { + self + } +} + +pub trait ParallelSliceMut { + /// Returns a plain mutable slice, which is used to implement the rest of + /// the parallel methods. + fn as_parallel_slice_mut(&mut self) -> &mut [T]; + + fn par_split_mut

(&mut self, separator: P) -> SplitMut<'_, T, P> + where + P: Fn(&T) -> bool + Sync + Send, + { + self.as_parallel_slice_mut().split_mut(separator) + } + + fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> { + self.as_parallel_slice_mut().chunks_mut(chunk_size) + } + + fn par_chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> { + self.as_parallel_slice_mut().chunks_exact_mut(chunk_size) + } + + fn par_rchunks_mut(&mut self, chunk_size: usize) -> RChunksMut<'_, T> { + self.as_parallel_slice_mut().rchunks_mut(chunk_size) + } + + fn par_rchunks_exact_mut(&mut self, chunk_size: usize) -> RChunksExactMut<'_, T> { + self.as_parallel_slice_mut().rchunks_exact_mut(chunk_size) + } +} + +impl ParallelSliceMut for [T] { + #[inline] + fn as_parallel_slice_mut(&mut self) -> &mut [T] { + self + } +} + +pub trait ParIterExt: Iterator { + fn find_any

(self, predicate: P) -> Option + where + P: Fn(&Self::Item) -> bool + Sync + Send; + + fn flat_map_iter(self, map_op: F) -> FlatMap + where + Self: Sized, + U: IntoIterator, + F: Fn(Self::Item) -> U; +} + +impl ParIterExt for T { + fn find_any

(mut self, predicate: P) -> Option + where + P: Fn(&Self::Item) -> bool + Sync + Send, + { + self.find(predicate) + } + + fn flat_map_iter(self, map_op: F) -> FlatMap + where + Self: Sized, + U: IntoIterator, + F: Fn(Self::Item) -> U, + { + self.flat_map(map_op) + } +} + +pub fn join(oper_a: A, oper_b: B) -> (RA, RB) +where + A: FnOnce() -> RA, + B: FnOnce() -> RB, +{ + let result_a = oper_a(); + let result_b = oper_b(); + (result_a, result_b) +} + +pub const fn current_num_threads() -> usize { + 1 +} diff --git a/CoqOfRust/plonky3/maybe-rayon/src/serial.v b/CoqOfRust/plonky3/maybe-rayon/src/serial.v new file mode 100644 index 000000000..6af97e185 --- /dev/null +++ b/CoqOfRust/plonky3/maybe-rayon/src/serial.v @@ -0,0 +1,960 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module serial. + (* Trait *) + (* Empty module 'IntoParallelIterator' *) + + Module Impl_p3_maybe_rayon_serial_IntoParallelIterator_where_core_iter_traits_collect_IntoIterator_T_where_core_marker_Send_associated_in_trait_core_iter_traits_collect_IntoIterator___T_Item_for_T. + Definition Self (T : Ty.t) : Ty.t := T. + + (* type Iter = T::IntoIter; *) + Definition _Iter (T : Ty.t) : Ty.t := + Ty.associated_in_trait "core::iter::traits::collect::IntoIterator" [] [] T "IntoIter". + + (* type Item = T::Item; *) + Definition _Item (T : Ty.t) : Ty.t := + Ty.associated_in_trait "core::iter::traits::collect::IntoIterator" [] [] T "Item". + + (* + fn into_par_iter(self) -> Self::Iter { + self.into_iter() + } + *) + Definition into_par_iter (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait "core::iter::traits::collect::IntoIterator" [] [] T "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + T, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| self |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "p3_maybe_rayon::serial::IntoParallelIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) + [ + ("Iter", InstanceField.Ty (_Iter T)); + ("Item", InstanceField.Ty (_Item T)); + ("into_par_iter", InstanceField.Method (into_par_iter T)) + ]. + End Impl_p3_maybe_rayon_serial_IntoParallelIterator_where_core_iter_traits_collect_IntoIterator_T_where_core_marker_Send_associated_in_trait_core_iter_traits_collect_IntoIterator___T_Item_for_T. + + (* Trait *) + (* Empty module 'IntoParallelRefIterator' *) + + Module Impl_p3_maybe_rayon_serial_IntoParallelRefIterator_where_core_marker_Sized_I_where_p3_maybe_rayon_serial_IntoParallelIterator_ref__I_for_I. + Definition Self (I : Ty.t) : Ty.t := I. + + (* type Iter = <&'data I as IntoParallelIterator>::Iter; *) + Definition _Iter (I : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_maybe_rayon::serial::IntoParallelIterator" + [] + [] + (Ty.apply (Ty.path "&") [] [ I ]) + "Iter". + + (* type Item = <&'data I as IntoParallelIterator>::Item; *) + Definition _Item (I : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_maybe_rayon::serial::IntoParallelIterator" + [] + [] + (Ty.apply (Ty.path "&") [] [ I ]) + "Item". + + (* + fn par_iter(&'data self) -> Self::Iter { + self.into_par_iter() + } + *) + Definition par_iter (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self I in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "p3_maybe_rayon::serial::IntoParallelIterator" + [] + [] + (Ty.apply (Ty.path "&") [] [ I ]) + "Iter", + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelIterator", + Ty.apply (Ty.path "&") [] [ I ], + [], + [], + "into_par_iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (I : Ty.t), + M.IsTraitInstance + "p3_maybe_rayon::serial::IntoParallelRefIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self I) + (* Instance *) + [ + ("Iter", InstanceField.Ty (_Iter I)); + ("Item", InstanceField.Ty (_Item I)); + ("par_iter", InstanceField.Method (par_iter I)) + ]. + End Impl_p3_maybe_rayon_serial_IntoParallelRefIterator_where_core_marker_Sized_I_where_p3_maybe_rayon_serial_IntoParallelIterator_ref__I_for_I. + + (* Trait *) + (* Empty module 'IntoParallelRefMutIterator' *) + + Module Impl_p3_maybe_rayon_serial_IntoParallelRefMutIterator_where_core_marker_Sized_I_where_p3_maybe_rayon_serial_IntoParallelIterator_ref_mut_I_for_I. + Definition Self (I : Ty.t) : Ty.t := I. + + (* type Iter = <&'data mut I as IntoParallelIterator>::Iter; *) + Definition _Iter (I : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_maybe_rayon::serial::IntoParallelIterator" + [] + [] + (Ty.apply (Ty.path "&mut") [] [ I ]) + "Iter". + + (* type Item = <&'data mut I as IntoParallelIterator>::Item; *) + Definition _Item (I : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_maybe_rayon::serial::IntoParallelIterator" + [] + [] + (Ty.apply (Ty.path "&mut") [] [ I ]) + "Item". + + (* + fn par_iter_mut(&'data mut self) -> Self::Iter { + self.into_par_iter() + } + *) + Definition par_iter_mut (I : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self I in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "p3_maybe_rayon::serial::IntoParallelIterator" + [] + [] + (Ty.apply (Ty.path "&mut") [] [ I ]) + "Iter", + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelIterator", + Ty.apply (Ty.path "&mut") [] [ I ], + [], + [], + "into_par_iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (I : Ty.t), + M.IsTraitInstance + "p3_maybe_rayon::serial::IntoParallelRefMutIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self I) + (* Instance *) + [ + ("Iter", InstanceField.Ty (_Iter I)); + ("Item", InstanceField.Ty (_Item I)); + ("par_iter_mut", InstanceField.Method (par_iter_mut I)) + ]. + End Impl_p3_maybe_rayon_serial_IntoParallelRefMutIterator_where_core_marker_Sized_I_where_p3_maybe_rayon_serial_IntoParallelIterator_ref_mut_I_for_I. + + (* Trait *) + Module ParallelSlice. + Definition par_split + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ P ], [ self; separator ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let separator := M.alloc (| separator |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Split") [] [ T; P ], + M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "split", [], [ P ] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSlice", + Self, + [], + [ T ], + "as_parallel_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| separator |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_split : + forall (T : Ty.t), + M.IsProvidedMethod "p3_maybe_rayon::serial::ParallelSlice" "par_split" (par_split T). + Definition par_windows + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; window_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let window_size := M.alloc (| window_size |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Windows") [] [ T ], + M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "windows", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSlice", + Self, + [], + [ T ], + "as_parallel_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| window_size |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_windows : + forall (T : Ty.t), + M.IsProvidedMethod "p3_maybe_rayon::serial::ParallelSlice" "par_windows" (par_windows T). + Definition par_chunks + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; chunk_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chunk_size := M.alloc (| chunk_size |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Chunks") [] [ T ], + M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "chunks", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSlice", + Self, + [], + [ T ], + "as_parallel_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| chunk_size |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_chunks : + forall (T : Ty.t), + M.IsProvidedMethod "p3_maybe_rayon::serial::ParallelSlice" "par_chunks" (par_chunks T). + Definition par_chunks_exact + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; chunk_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chunk_size := M.alloc (| chunk_size |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExact") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "chunks_exact", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSlice", + Self, + [], + [ T ], + "as_parallel_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| chunk_size |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_chunks_exact : + forall (T : Ty.t), + M.IsProvidedMethod + "p3_maybe_rayon::serial::ParallelSlice" + "par_chunks_exact" + (par_chunks_exact T). + Definition par_rchunks + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; chunk_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chunk_size := M.alloc (| chunk_size |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::RChunks") [] [ T ], + M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "rchunks", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSlice", + Self, + [], + [ T ], + "as_parallel_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| chunk_size |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_rchunks : + forall (T : Ty.t), + M.IsProvidedMethod "p3_maybe_rayon::serial::ParallelSlice" "par_rchunks" (par_rchunks T). + Definition par_rchunks_exact + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; chunk_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chunk_size := M.alloc (| chunk_size |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::RChunksExact") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "rchunks_exact", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSlice", + Self, + [], + [ T ], + "as_parallel_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| chunk_size |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_rchunks_exact : + forall (T : Ty.t), + M.IsProvidedMethod + "p3_maybe_rayon::serial::ParallelSlice" + "par_rchunks_exact" + (par_rchunks_exact T). + End ParallelSlice. + + Module Impl_p3_maybe_rayon_serial_ParallelSlice_where_core_marker_Sync_T_T_for_slice_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ T ]. + + (* + fn as_parallel_slice(&self) -> &[T] { + self + } + *) + Definition as_parallel_slice + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| self |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "p3_maybe_rayon::serial::ParallelSlice" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self T) + (* Instance *) [ ("as_parallel_slice", InstanceField.Method (as_parallel_slice T)) ]. + End Impl_p3_maybe_rayon_serial_ParallelSlice_where_core_marker_Sync_T_T_for_slice_T. + + (* Trait *) + Module ParallelSliceMut. + Definition par_split_mut + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ P ], [ self; separator ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let separator := M.alloc (| separator |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::SplitMut") [] [ T; P ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "split_mut", + [], + [ P ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Self, + [], + [ T ], + "as_parallel_slice_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| separator |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_split_mut : + forall (T : Ty.t), + M.IsProvidedMethod + "p3_maybe_rayon::serial::ParallelSliceMut" + "par_split_mut" + (par_split_mut T). + Definition par_chunks_mut + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; chunk_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chunk_size := M.alloc (| chunk_size |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksMut") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "chunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Self, + [], + [ T ], + "as_parallel_slice_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| chunk_size |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_chunks_mut : + forall (T : Ty.t), + M.IsProvidedMethod + "p3_maybe_rayon::serial::ParallelSliceMut" + "par_chunks_mut" + (par_chunks_mut T). + Definition par_chunks_exact_mut + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; chunk_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chunk_size := M.alloc (| chunk_size |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Self, + [], + [ T ], + "as_parallel_slice_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| chunk_size |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_chunks_exact_mut : + forall (T : Ty.t), + M.IsProvidedMethod + "p3_maybe_rayon::serial::ParallelSliceMut" + "par_chunks_exact_mut" + (par_chunks_exact_mut T). + Definition par_rchunks_mut + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; chunk_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chunk_size := M.alloc (| chunk_size |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::RChunksMut") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "rchunks_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Self, + [], + [ T ], + "as_parallel_slice_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| chunk_size |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_rchunks_mut : + forall (T : Ty.t), + M.IsProvidedMethod + "p3_maybe_rayon::serial::ParallelSliceMut" + "par_rchunks_mut" + (par_rchunks_mut T). + Definition par_rchunks_exact_mut + (T Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; chunk_size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chunk_size := M.alloc (| chunk_size |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::RChunksExactMut") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "rchunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Self, + [], + [ T ], + "as_parallel_slice_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.read (| chunk_size |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_par_rchunks_exact_mut : + forall (T : Ty.t), + M.IsProvidedMethod + "p3_maybe_rayon::serial::ParallelSliceMut" + "par_rchunks_exact_mut" + (par_rchunks_exact_mut T). + End ParallelSliceMut. + + Module Impl_p3_maybe_rayon_serial_ParallelSliceMut_where_core_marker_Send_T_T_for_slice_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ T ]. + + (* + fn as_parallel_slice_mut(&mut self) -> &mut [T] { + self + } + *) + Definition as_parallel_slice_mut + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "p3_maybe_rayon::serial::ParallelSliceMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self T) + (* Instance *) + [ ("as_parallel_slice_mut", InstanceField.Method (as_parallel_slice_mut T)) ]. + End Impl_p3_maybe_rayon_serial_ParallelSliceMut_where_core_marker_Send_T_T_for_slice_T. + + (* Trait *) + (* Empty module 'ParIterExt' *) + + Module Impl_p3_maybe_rayon_serial_ParIterExt_where_core_iter_traits_iterator_Iterator_T_for_T. + Definition Self (T : Ty.t) : Ty.t := T. + + (* + fn find_any

(mut self, predicate: P) -> Option + where + P: Fn(&Self::Item) -> bool + Sync + Send, + { + self.find(predicate) + } + *) + Definition find_any (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [ P ], [ self; predicate ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let predicate := M.alloc (| predicate |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.associated_in_trait "core::iter::traits::iterator::Iterator" [] [] T "Item" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + T, + [], + [], + "find", + [], + [ P ] + |), + [ M.borrow (| Pointer.Kind.MutRef, self |); M.read (| predicate |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn flat_map_iter(self, map_op: F) -> FlatMap + where + Self: Sized, + U: IntoIterator, + F: Fn(Self::Item) -> U, + { + self.flat_map(map_op) + } + *) + Definition flat_map_iter (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [ U; F ], [ self; map_op ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let map_op := M.alloc (| map_op |) in + M.call_closure (| + Ty.apply (Ty.path "core::iter::adapters::flatten::FlatMap") [] [ T; U; F ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + T, + [], + [], + "flat_map", + [], + [ U; F ] + |), + [ M.read (| self |); M.read (| map_op |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "p3_maybe_rayon::serial::ParIterExt" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) + [ + ("find_any", InstanceField.Method (find_any T)); + ("flat_map_iter", InstanceField.Method (flat_map_iter T)) + ]. + End Impl_p3_maybe_rayon_serial_ParIterExt_where_core_iter_traits_iterator_Iterator_T_for_T. + + (* + pub fn join(oper_a: A, oper_b: B) -> (RA, RB) + where + A: FnOnce() -> RA, + B: FnOnce() -> RB, + { + let result_a = oper_a(); + let result_b = oper_b(); + (result_a, result_b) + } + *) + Definition join (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ A; B; RA; RB ], [ oper_a; oper_b ] => + ltac:(M.monadic + (let oper_a := M.alloc (| oper_a |) in + let oper_b := M.alloc (| oper_b |) in + M.read (| + let~ result_a : Ty.apply (Ty.path "*") [] [ RA ] := + M.alloc (| + M.call_closure (| + RA, + M.get_trait_method (| + "core::ops::function::FnOnce", + A, + [], + [ Ty.tuple [] ], + "call_once", + [], + [] + |), + [ M.read (| oper_a |); Value.Tuple [] ] + |) + |) in + let~ result_b : Ty.apply (Ty.path "*") [] [ RB ] := + M.alloc (| + M.call_closure (| + RB, + M.get_trait_method (| + "core::ops::function::FnOnce", + B, + [], + [ Ty.tuple [] ], + "call_once", + [], + [] + |), + [ M.read (| oper_b |); Value.Tuple [] ] + |) + |) in + M.alloc (| Value.Tuple [ M.read (| result_a |); M.read (| result_b |) ] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_join : M.IsFunction.C "p3_maybe_rayon::serial::join" join. + Admitted. + Global Typeclasses Opaque join. + + (* + pub const fn current_num_threads() -> usize { + 1 + } + *) + Definition current_num_threads (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => ltac:(M.monadic (Value.Integer IntegerKind.Usize 1)) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_current_num_threads : + M.IsFunction.C "p3_maybe_rayon::serial::current_num_threads" current_num_threads. + Admitted. + Global Typeclasses Opaque current_num_threads. +End serial. diff --git a/CoqOfRust/plonky3/mds/src/butterflies.rs b/CoqOfRust/plonky3/mds/src/butterflies.rs new file mode 100644 index 000000000..627d2f8e4 --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/butterflies.rs @@ -0,0 +1,42 @@ +use p3_field::{Algebra, Field}; + +/// DIT butterfly. +#[inline] +pub(crate) fn dit_butterfly, const N: usize>( + values: &mut [A; N], + idx_1: usize, + idx_2: usize, + twiddle: F, +) { + let val_1 = values[idx_1].clone(); + let val_2 = values[idx_2].clone() * twiddle; + values[idx_1] = val_1.clone() + val_2.clone(); + values[idx_2] = val_1 - val_2; +} + +/// DIF butterfly. +#[inline] +pub(crate) fn dif_butterfly, const N: usize>( + values: &mut [A; N], + idx_1: usize, + idx_2: usize, + twiddle: F, +) { + let val_1 = values[idx_1].clone(); + let val_2 = values[idx_2].clone(); + values[idx_1] = val_1.clone() + val_2.clone(); + values[idx_2] = (val_1 - val_2) * twiddle; +} + +/// Butterfly with twiddle factor 1 (works in either DIT or DIF). +#[inline] +pub(crate) fn twiddle_free_butterfly, const N: usize>( + values: &mut [A; N], + idx_1: usize, + idx_2: usize, +) { + let val_1 = values[idx_1].clone(); + let val_2 = values[idx_2].clone(); + values[idx_1] = val_1.clone() + val_2.clone(); + values[idx_2] = val_1 - val_2; +} diff --git a/CoqOfRust/plonky3/mds/src/butterflies.v b/CoqOfRust/plonky3/mds/src/butterflies.v new file mode 100644 index 000000000..d07412820 --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/butterflies.v @@ -0,0 +1,325 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module butterflies. + (* + pub(crate) fn dit_butterfly, const N: usize>( + values: &mut [A; N], + idx_1: usize, + idx_2: usize, + twiddle: F, + ) { + let val_1 = values[idx_1].clone(); + let val_2 = values[idx_2].clone() * twiddle; + values[idx_1] = val_1.clone() + val_2.clone(); + values[idx_2] = val_1 - val_2; + } + *) + Definition dit_butterfly (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ F; A ], [ values; idx_1; idx_2; twiddle ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let idx_1 := M.alloc (| idx_1 |) in + let idx_2 := M.alloc (| idx_2 |) in + let twiddle := M.alloc (| twiddle |) in + M.read (| + let~ val_1 : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_1 |) + |) + |) + ] + |) + |) in + let~ val_2 : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Mul", A, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_2 |) + |) + |) + ] + |); + M.read (| twiddle |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_1 |) + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, val_1 |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, val_2 |) ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_2 |) + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Sub", A, [], [ A ], "sub", [], [] |), + [ M.read (| val_1 |); M.read (| val_2 |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dit_butterfly : + M.IsFunction.C "p3_mds::butterflies::dit_butterfly" dit_butterfly. + Admitted. + Global Typeclasses Opaque dit_butterfly. + + (* + pub(crate) fn dif_butterfly, const N: usize>( + values: &mut [A; N], + idx_1: usize, + idx_2: usize, + twiddle: F, + ) { + let val_1 = values[idx_1].clone(); + let val_2 = values[idx_2].clone(); + values[idx_1] = val_1.clone() + val_2.clone(); + values[idx_2] = (val_1 - val_2) * twiddle; + } + *) + Definition dif_butterfly (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ F; A ], [ values; idx_1; idx_2; twiddle ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let idx_1 := M.alloc (| idx_1 |) in + let idx_2 := M.alloc (| idx_2 |) in + let twiddle := M.alloc (| twiddle |) in + M.read (| + let~ val_1 : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_1 |) + |) + |) + ] + |) + |) in + let~ val_2 : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_2 |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_1 |) + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, val_1 |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, val_2 |) ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_2 |) + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Mul", A, [], [ F ], "mul", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Sub", A, [], [ A ], "sub", [], [] |), + [ M.read (| val_1 |); M.read (| val_2 |) ] + |); + M.read (| twiddle |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dif_butterfly : + M.IsFunction.C "p3_mds::butterflies::dif_butterfly" dif_butterfly. + Admitted. + Global Typeclasses Opaque dif_butterfly. + + (* + pub(crate) fn twiddle_free_butterfly, const N: usize>( + values: &mut [A; N], + idx_1: usize, + idx_2: usize, + ) { + let val_1 = values[idx_1].clone(); + let val_2 = values[idx_2].clone(); + values[idx_1] = val_1.clone() + val_2.clone(); + values[idx_2] = val_1 - val_2; + } + *) + Definition twiddle_free_butterfly (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ F; A ], [ values; idx_1; idx_2 ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let idx_1 := M.alloc (| idx_1 |) in + let idx_2 := M.alloc (| idx_2 |) in + M.read (| + let~ val_1 : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_1 |) + |) + |) + ] + |) + |) in + let~ val_2 : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_2 |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_1 |) + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, val_1 |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, val_2 |) ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| values |) |), + M.read (| idx_2 |) + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Sub", A, [], [ A ], "sub", [], [] |), + [ M.read (| val_1 |); M.read (| val_2 |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_twiddle_free_butterfly : + M.IsFunction.C "p3_mds::butterflies::twiddle_free_butterfly" twiddle_free_butterfly. + Admitted. + Global Typeclasses Opaque twiddle_free_butterfly. +End butterflies. diff --git a/CoqOfRust/plonky3/mds/src/coset_mds.rs b/CoqOfRust/plonky3/mds/src/coset_mds.rs new file mode 100644 index 000000000..84032f272 --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/coset_mds.rs @@ -0,0 +1,174 @@ +use alloc::vec::Vec; + +use p3_field::{Algebra, Field, TwoAdicField}; +use p3_symmetric::Permutation; +use p3_util::{log2_strict_usize, reverse_slice_index_bits}; + +use crate::MdsPermutation; +use crate::butterflies::{dif_butterfly, dit_butterfly, twiddle_free_butterfly}; + +/// A Reed-Solomon based MDS permutation. +/// +/// An MDS permutation which works by interpreting the input as evaluations of a polynomial over a +/// power-of-two subgroup, and computing evaluations over a coset of that subgroup. This can be +/// viewed as returning the parity elements of a systematic Reed-Solomon code. Since Reed-Solomon +/// codes are MDS, this is an MDS permutation. +#[derive(Clone, Debug)] +pub struct CosetMds { + fft_twiddles: Vec, + ifft_twiddles: Vec, + weights: [F; N], +} + +impl Default for CosetMds +where + F: TwoAdicField, +{ + fn default() -> Self { + let log_n = log2_strict_usize(N); + + let root = F::two_adic_generator(log_n); + let root_inv = root.inverse(); + let mut fft_twiddles: Vec = root.powers().take(N / 2).collect(); + let mut ifft_twiddles: Vec = root_inv.powers().take(N / 2).collect(); + reverse_slice_index_bits(&mut fft_twiddles); + reverse_slice_index_bits(&mut ifft_twiddles); + + let shift = F::GENERATOR; + let mut weights: [F; N] = shift + .powers() + .take(N) + .collect::>() + .try_into() + .unwrap(); + reverse_slice_index_bits(&mut weights); + Self { + fft_twiddles, + ifft_twiddles, + weights, + } + } +} + +impl, const N: usize> Permutation<[A; N]> for CosetMds { + fn permute(&self, mut input: [A; N]) -> [A; N] { + self.permute_mut(&mut input); + input + } + + fn permute_mut(&self, values: &mut [A; N]) { + // Inverse DFT, except we skip bit reversal and rescaling by 1/N. + bowers_g_t(values, &self.ifft_twiddles); + + // Multiply by powers of the coset shift (see default coset LDE impl for an explanation) + for (value, weight) in values.iter_mut().zip(self.weights) { + *value = value.clone() * weight; + } + + // DFT, assuming bit-reversed input. + bowers_g(values, &self.fft_twiddles); + } +} + +impl, const N: usize> MdsPermutation for CosetMds {} + +/// Executes the Bowers G network. This is like a DFT, except it assumes the input is in +/// bit-reversed order. +#[inline] +fn bowers_g, const N: usize>(values: &mut [A; N], twiddles: &[F]) { + let log_n = log2_strict_usize(N); + for log_half_block_size in 0..log_n { + bowers_g_layer(values, log_half_block_size, twiddles); + } +} + +/// Executes the Bowers G^T network. This is like an inverse DFT, except we skip rescaling by +/// `1/N`, and the output is bit-reversed. +#[inline] +fn bowers_g_t, const N: usize>(values: &mut [A; N], twiddles: &[F]) { + let log_n = log2_strict_usize(N); + for log_half_block_size in (0..log_n).rev() { + bowers_g_t_layer(values, log_half_block_size, twiddles); + } +} + +/// One layer of a Bowers G network. Equivalent to `bowers_g_t_layer` except for the butterfly. +#[inline] +fn bowers_g_layer, const N: usize>( + values: &mut [A; N], + log_half_block_size: usize, + twiddles: &[F], +) { + let log_block_size = log_half_block_size + 1; + let half_block_size = 1 << log_half_block_size; + let num_blocks = N >> log_block_size; + + // Unroll first iteration with a twiddle factor of 1. + for hi in 0..half_block_size { + let lo = hi + half_block_size; + twiddle_free_butterfly(values, hi, lo); + } + + for (block, &twiddle) in (1..num_blocks).zip(&twiddles[1..]) { + let block_start = block << log_block_size; + for hi in block_start..block_start + half_block_size { + let lo = hi + half_block_size; + dif_butterfly(values, hi, lo, twiddle); + } + } +} + +/// One layer of a Bowers G^T network. Equivalent to `bowers_g_layer` except for the butterfly. +#[inline] +fn bowers_g_t_layer, const N: usize>( + values: &mut [A; N], + log_half_block_size: usize, + twiddles: &[F], +) { + let log_block_size = log_half_block_size + 1; + let half_block_size = 1 << log_half_block_size; + let num_blocks = N >> log_block_size; + + // Unroll first iteration with a twiddle factor of 1. + for hi in 0..half_block_size { + let lo = hi + half_block_size; + twiddle_free_butterfly(values, hi, lo); + } + + for (block, &twiddle) in (1..num_blocks).zip(&twiddles[1..]) { + let block_start = block << log_block_size; + for hi in block_start..block_start + half_block_size { + let lo = hi + half_block_size; + dit_butterfly(values, hi, lo, twiddle); + } + } +} + +#[cfg(test)] +mod tests { + use p3_baby_bear::BabyBear; + use p3_dft::{NaiveDft, TwoAdicSubgroupDft}; + use p3_field::{Field, PrimeCharacteristicRing}; + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use crate::coset_mds::CosetMds; + + #[test] + fn matches_naive() { + type F = BabyBear; + const N: usize = 8; + + let mut rng = SmallRng::seed_from_u64(1); + let mut arr: [F; N] = rng.random(); + + let shift = F::GENERATOR; + let mut coset_lde_naive = NaiveDft.coset_lde(arr.to_vec(), 0, shift); + coset_lde_naive + .iter_mut() + .for_each(|x| *x *= F::from_u8(N as u8)); + CosetMds::default().permute_mut(&mut arr); + assert_eq!(coset_lde_naive, arr); + } +} diff --git a/CoqOfRust/plonky3/mds/src/coset_mds.v b/CoqOfRust/plonky3/mds/src/coset_mds.v new file mode 100644 index 000000000..78b34ecc6 --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/coset_mds.v @@ -0,0 +1,2305 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module coset_mds. + (* StructRecord + { + name := "CosetMds"; + const_params := [ "N" ]; + ty_params := [ "F" ]; + fields := + [ + ("fft_twiddles", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]); + ("ifft_twiddles", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]); + ("weights", Ty.apply (Ty.path "array") [ N ] [ F ]) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_mds_coset_mds_CosetMds_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_mds::coset_mds::CosetMds") [ N ] [ F ]. + + (* Clone *) + Definition clone + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_mds::coset_mds::CosetMds" + [ + ("fft_twiddles", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::coset_mds::CosetMds", + "fft_twiddles" + |) + |) + |) + |) + ] + |)); + ("ifft_twiddles", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::coset_mds::CosetMds", + "ifft_twiddles" + |) + |) + |) + |) + ] + |)); + ("weights", + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ N ] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::coset_mds::CosetMds", + "weights" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) [ ("clone", InstanceField.Method (clone N F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_mds_coset_mds_CosetMds_N_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_mds_coset_mds_CosetMds_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_mds::coset_mds::CosetMds") [ N ] [ F ]. + + (* Debug *) + Definition fmt + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "CosetMds" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "fft_twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::coset_mds::CosetMds", + "fft_twiddles" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "ifft_twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::coset_mds::CosetMds", + "ifft_twiddles" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "weights" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::coset_mds::CosetMds", + "weights" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_mds_coset_mds_CosetMds_N_F. + + Module Impl_core_default_Default_where_p3_field_field_TwoAdicField_F_for_p3_mds_coset_mds_CosetMds_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_mds::coset_mds::CosetMds") [ N ] [ F ]. + + (* + fn default() -> Self { + let log_n = log2_strict_usize(N); + + let root = F::two_adic_generator(log_n); + let root_inv = root.inverse(); + let mut fft_twiddles: Vec = root.powers().take(N / 2).collect(); + let mut ifft_twiddles: Vec = root_inv.powers().take(N / 2).collect(); + reverse_slice_index_bits(&mut fft_twiddles); + reverse_slice_index_bits(&mut ifft_twiddles); + + let shift = F::GENERATOR; + let mut weights: [F; N] = shift + .powers() + .take(N) + .collect::>() + .try_into() + .unwrap(); + reverse_slice_index_bits(&mut weights); + Self { + fft_twiddles, + ifft_twiddles, + weights, + } + } + *) + Definition default + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.read (| + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ N ] + |) + |) in + let~ root : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_n |) ] + |) + |) in + let~ root_inv : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, root |) ] + |) + |) in + let~ fft_twiddles : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, root |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ N; Value.Integer IntegerKind.Usize 2 ] + |) + ] + |) + ] + |) + |) in + let~ ifft_twiddles : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, root_inv |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ N; Value.Integer IntegerKind.Usize 2 ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, fft_twiddles |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, ifft_twiddles |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ shift : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| get_constant (| "p3_field::field::Field::GENERATOR", F |) |) in + let~ weights : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ N ] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ F ] ], + "try_into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, shift |) ] + |); + N + ] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, weights |) |) + |)) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_mds::coset_mds::CosetMds" + [ + ("fft_twiddles", M.read (| fft_twiddles |)); + ("ifft_twiddles", M.read (| ifft_twiddles |)); + ("weights", M.read (| weights |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) [ ("default", InstanceField.Method (default N F)) ]. + End Impl_core_default_Default_where_p3_field_field_TwoAdicField_F_for_p3_mds_coset_mds_CosetMds_N_F. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_TwoAdicField_F_where_p3_field_field_Algebra_A_F_array_N_A_for_p3_mds_coset_mds_CosetMds_N_F. + Definition Self (N : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_mds::coset_mds::CosetMds") [ N ] [ F ]. + + (* + fn permute(&self, mut input: [A; N]) -> [A; N] { + self.permute_mut(&mut input); + input + } + *) + Definition permute + (N : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F A in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.apply (Ty.path "p3_mds::coset_mds::CosetMds") [ N ] [ F ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ A ] ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, input |) |) + |) + ] + |) + |) in + input + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, values: &mut [A; N]) { + // Inverse DFT, except we skip bit reversal and rescaling by 1/N. + bowers_g_t(values, &self.ifft_twiddles); + + // Multiply by powers of the coset shift (see default coset LDE impl for an explanation) + for (value, weight) in values.iter_mut().zip(self.weights) { + *value = value.clone() * weight; + } + + // DFT, assuming bit-reversed input. + bowers_g(values, &self.fft_twiddles); + } + *) + Definition permute_mut + (N : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F A in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_mds::coset_mds::bowers_g_t", [ N ], [ F; A ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| values |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::coset_mds::CosetMds", + "ifft_twiddles" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ N ] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "array") [ N ] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| values |) |) + |)) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::coset_mds::CosetMds", + "weights" + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ A ]; F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ N ] + [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let value := M.copy (| γ1_0 |) in + let weight := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| value |) |), + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Mul", + A, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |) + ] + |); + M.read (| weight |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_mds::coset_mds::bowers_g", [ N ], [ F; A ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| values |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::coset_mds::CosetMds", + "fft_twiddles" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F A : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ A ] ] + (Self N F A) + (* Instance *) + [ + ("permute", InstanceField.Method (permute N F A)); + ("permute_mut", InstanceField.Method (permute_mut N F A)) + ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_TwoAdicField_F_where_p3_field_field_Algebra_A_F_array_N_A_for_p3_mds_coset_mds_CosetMds_N_F. + + Module Impl_p3_mds_MdsPermutation_where_p3_field_field_TwoAdicField_F_where_p3_field_field_Algebra_A_F_N_A_for_p3_mds_coset_mds_CosetMds_N_F. + Definition Self (N : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_mds::coset_mds::CosetMds") [ N ] [ F ]. + + Axiom Implements : + forall (N : Value.t) (F A : Ty.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ N ] + (* Trait polymorphic types *) [ A ] + (Self N F A) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_where_p3_field_field_TwoAdicField_F_where_p3_field_field_Algebra_A_F_N_A_for_p3_mds_coset_mds_CosetMds_N_F. + + (* + fn bowers_g, const N: usize>(values: &mut [A; N], twiddles: &[F]) { + let log_n = log2_strict_usize(N); + for log_half_block_size in 0..log_n { + bowers_g_layer(values, log_half_block_size, twiddles); + } + } + *) + Definition bowers_g (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ F; A ], [ values; twiddles ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ N ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", M.read (| log_n |)) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_half_block_size := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::coset_mds::bowers_g_layer", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| values |) |) + |); + M.read (| log_half_block_size |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_bowers_g : + M.IsFunction.C "p3_mds::coset_mds::bowers_g" bowers_g. + Admitted. + Global Typeclasses Opaque bowers_g. + + (* + fn bowers_g_t, const N: usize>(values: &mut [A; N], twiddles: &[F]) { + let log_n = log2_strict_usize(N); + for log_half_block_size in (0..log_n).rev() { + bowers_g_t_layer(values, log_half_block_size, twiddles); + } + } + *) + Definition bowers_g_t (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ F; A ], [ values; twiddles ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ N ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| log_n |)) + ] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log_half_block_size := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::coset_mds::bowers_g_t_layer", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| values |) |) + |); + M.read (| log_half_block_size |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_bowers_g_t : + M.IsFunction.C "p3_mds::coset_mds::bowers_g_t" bowers_g_t. + Admitted. + Global Typeclasses Opaque bowers_g_t. + + (* + fn bowers_g_layer, const N: usize>( + values: &mut [A; N], + log_half_block_size: usize, + twiddles: &[F], + ) { + let log_block_size = log_half_block_size + 1; + let half_block_size = 1 << log_half_block_size; + let num_blocks = N >> log_block_size; + + // Unroll first iteration with a twiddle factor of 1. + for hi in 0..half_block_size { + let lo = hi + half_block_size; + twiddle_free_butterfly(values, hi, lo); + } + + for (block, &twiddle) in (1..num_blocks).zip(&twiddles[1..]) { + let block_start = block << log_block_size; + for hi in block_start..block_start + half_block_size { + let lo = hi + half_block_size; + dif_butterfly(values, hi, lo, twiddle); + } + } + } + *) + Definition bowers_g_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ F; A ], [ values; log_half_block_size; twiddles ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let log_half_block_size := M.alloc (| log_half_block_size |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ log_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_half_block_size |); Value.Integer IntegerKind.Usize 1 ] + |) + |) in + let~ half_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_half_block_size |) ] + |) + |) in + let~ num_blocks : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ N; M.read (| log_block_size |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| half_block_size |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let hi := M.copy (| γ0_0 |) in + let~ lo : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| hi |); M.read (| half_block_size |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::butterflies::twiddle_free_butterfly", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| values |) |) + |); + M.read (| hi |); + M.read (| lo |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 1); + ("end_", M.read (| num_blocks |)) + ]; + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ F ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.apply (Ty.path "&") [] [ F ] ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let block := M.copy (| γ1_0 |) in + let γ1_1 := M.read (| γ1_1 |) in + let twiddle := M.copy (| γ1_1 |) in + let~ block_start : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ M.read (| block |); M.read (| log_block_size |) ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| block_start |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| block_start |); + M.read (| half_block_size |) + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let hi := M.copy (| γ0_0 |) in + let~ lo : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| hi |); + M.read (| half_block_size |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::butterflies::dif_butterfly", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| values |) + |) + |); + M.read (| hi |); + M.read (| lo |); + M.read (| twiddle |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_bowers_g_layer : + M.IsFunction.C "p3_mds::coset_mds::bowers_g_layer" bowers_g_layer. + Admitted. + Global Typeclasses Opaque bowers_g_layer. + + (* + fn bowers_g_t_layer, const N: usize>( + values: &mut [A; N], + log_half_block_size: usize, + twiddles: &[F], + ) { + let log_block_size = log_half_block_size + 1; + let half_block_size = 1 << log_half_block_size; + let num_blocks = N >> log_block_size; + + // Unroll first iteration with a twiddle factor of 1. + for hi in 0..half_block_size { + let lo = hi + half_block_size; + twiddle_free_butterfly(values, hi, lo); + } + + for (block, &twiddle) in (1..num_blocks).zip(&twiddles[1..]) { + let block_start = block << log_block_size; + for hi in block_start..block_start + half_block_size { + let lo = hi + half_block_size; + dit_butterfly(values, hi, lo, twiddle); + } + } + } + *) + Definition bowers_g_t_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ F; A ], [ values; log_half_block_size; twiddles ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let log_half_block_size := M.alloc (| log_half_block_size |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ log_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_half_block_size |); Value.Integer IntegerKind.Usize 1 ] + |) + |) in + let~ half_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_half_block_size |) ] + |) + |) in + let~ num_blocks : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ N; M.read (| log_block_size |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| half_block_size |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let hi := M.copy (| γ0_0 |) in + let~ lo : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| hi |); M.read (| half_block_size |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::butterflies::twiddle_free_butterfly", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| values |) |) + |); + M.read (| hi |); + M.read (| lo |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 1); + ("end_", M.read (| num_blocks |)) + ]; + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ F ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.apply (Ty.path "&") [] [ F ] ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let block := M.copy (| γ1_0 |) in + let γ1_1 := M.read (| γ1_1 |) in + let twiddle := M.copy (| γ1_1 |) in + let~ block_start : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ M.read (| block |); M.read (| log_block_size |) ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| block_start |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| block_start |); + M.read (| half_block_size |) + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let hi := M.copy (| γ0_0 |) in + let~ lo : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| hi |); + M.read (| half_block_size |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::butterflies::dit_butterfly", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| values |) + |) + |); + M.read (| hi |); + M.read (| lo |); + M.read (| twiddle |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_bowers_g_t_layer : + M.IsFunction.C "p3_mds::coset_mds::bowers_g_t_layer" bowers_g_t_layer. + Admitted. + Global Typeclasses Opaque bowers_g_t_layer. +End coset_mds. diff --git a/CoqOfRust/plonky3/mds/src/integrated_coset_mds.rs b/CoqOfRust/plonky3/mds/src/integrated_coset_mds.rs new file mode 100644 index 000000000..7fb4ca5cd --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/integrated_coset_mds.rs @@ -0,0 +1,150 @@ +use alloc::vec::Vec; + +use p3_field::{Algebra, Field, Powers, TwoAdicField}; +use p3_symmetric::Permutation; +use p3_util::{log2_strict_usize, reverse_slice_index_bits}; + +use crate::MdsPermutation; +use crate::butterflies::{dif_butterfly, dit_butterfly, twiddle_free_butterfly}; + +/// Like `CosetMds`, with a few differences: +/// - (Bit reversed, a la Bowers) DIF + DIT rather than DIT + DIF +/// - We skip bit reversals of the inputs and outputs +/// - We don't weight by `1/N`, since this doesn't affect the MDS property +/// - We integrate the coset shifts into the DIF's twiddle factors +#[derive(Clone, Debug)] +pub struct IntegratedCosetMds { + ifft_twiddles: Vec, + fft_twiddles: Vec>, +} + +impl Default for IntegratedCosetMds { + fn default() -> Self { + let log_n = log2_strict_usize(N); + let root = F::two_adic_generator(log_n); + let root_inv = root.inverse(); + let coset_shift = F::GENERATOR; + + let mut ifft_twiddles: Vec = root_inv.powers().take(N / 2).collect(); + reverse_slice_index_bits(&mut ifft_twiddles); + + let fft_twiddles: Vec> = (0..log_n) + .map(|layer| { + let shift_power = coset_shift.exp_power_of_2(layer); + let powers = Powers { + base: root.exp_power_of_2(layer), + current: shift_power, + }; + let mut twiddles: Vec<_> = powers.take(N >> (layer + 1)).collect(); + reverse_slice_index_bits(&mut twiddles); + twiddles + }) + .collect(); + + Self { + ifft_twiddles, + fft_twiddles, + } + } +} + +impl, const N: usize> Permutation<[A; N]> for IntegratedCosetMds { + fn permute(&self, mut input: [A; N]) -> [A; N] { + self.permute_mut(&mut input); + input + } + + fn permute_mut(&self, values: &mut [A; N]) { + let log_n = log2_strict_usize(N); + + // Bit-reversed DIF, aka Bowers G + for layer in 0..log_n { + bowers_g_layer(values, layer, &self.ifft_twiddles); + } + + // Bit-reversed DIT, aka Bowers G^T + for layer in (0..log_n).rev() { + bowers_g_t_layer(values, layer, &self.fft_twiddles[layer]); + } + } +} + +impl, const N: usize> MdsPermutation for IntegratedCosetMds {} + +#[inline] +fn bowers_g_layer, const N: usize>( + values: &mut [A; N], + log_half_block_size: usize, + twiddles: &[F], +) { + let log_block_size = log_half_block_size + 1; + let half_block_size = 1 << log_half_block_size; + let num_blocks = N >> log_block_size; + + // Unroll first iteration with a twiddle factor of 1. + for hi in 0..half_block_size { + let lo = hi + half_block_size; + twiddle_free_butterfly(values, hi, lo); + } + + for (block, &twiddle) in (1..num_blocks).zip(&twiddles[1..]) { + let block_start = block << log_block_size; + for hi in block_start..block_start + half_block_size { + let lo = hi + half_block_size; + dif_butterfly(values, hi, lo, twiddle); + } + } +} + +#[inline] +fn bowers_g_t_layer, const N: usize>( + values: &mut [A; N], + log_half_block_size: usize, + twiddles: &[F], +) { + let log_block_size = log_half_block_size + 1; + let half_block_size = 1 << log_half_block_size; + let num_blocks = N >> log_block_size; + + for (block, &twiddle) in (0..num_blocks).zip(twiddles) { + let block_start = block << log_block_size; + for hi in block_start..block_start + half_block_size { + let lo = hi + half_block_size; + dit_butterfly(values, hi, lo, twiddle); + } + } +} + +#[cfg(test)] +mod tests { + use p3_baby_bear::BabyBear; + use p3_dft::{NaiveDft, TwoAdicSubgroupDft}; + use p3_field::{Field, PrimeCharacteristicRing}; + use p3_symmetric::Permutation; + use p3_util::reverse_slice_index_bits; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use crate::integrated_coset_mds::IntegratedCosetMds; + + type F = BabyBear; + const N: usize = 16; + + #[test] + fn matches_naive() { + let mut rng = SmallRng::seed_from_u64(1); + let mut arr: [F; N] = rng.random(); + + let mut arr_rev = arr.to_vec(); + reverse_slice_index_bits(&mut arr_rev); + + let shift = F::GENERATOR; + let mut coset_lde_naive = NaiveDft.coset_lde(arr_rev, 0, shift); + reverse_slice_index_bits(&mut coset_lde_naive); + coset_lde_naive + .iter_mut() + .for_each(|x| *x *= F::from_u8(N as u8)); + IntegratedCosetMds::default().permute_mut(&mut arr); + assert_eq!(coset_lde_naive, arr); + } +} diff --git a/CoqOfRust/plonky3/mds/src/integrated_coset_mds.v b/CoqOfRust/plonky3/mds/src/integrated_coset_mds.v new file mode 100644 index 000000000..bf2478cd7 --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/integrated_coset_mds.v @@ -0,0 +1,2032 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module integrated_coset_mds. + (* StructRecord + { + name := "IntegratedCosetMds"; + const_params := [ "N" ]; + ty_params := [ "F" ]; + fields := + [ + ("ifft_twiddles", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]); + ("fft_twiddles", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_mds_integrated_coset_mds_IntegratedCosetMds_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_mds::integrated_coset_mds::IntegratedCosetMds") [ N ] [ F ]. + + (* Clone *) + Definition clone + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_mds::integrated_coset_mds::IntegratedCosetMds" + [ + ("ifft_twiddles", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::integrated_coset_mds::IntegratedCosetMds", + "ifft_twiddles" + |) + |) + |) + |) + ] + |)); + ("fft_twiddles", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::integrated_coset_mds::IntegratedCosetMds", + "fft_twiddles" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) [ ("clone", InstanceField.Method (clone N F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_mds_integrated_coset_mds_IntegratedCosetMds_N_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_mds_integrated_coset_mds_IntegratedCosetMds_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_mds::integrated_coset_mds::IntegratedCosetMds") [ N ] [ F ]. + + (* Debug *) + Definition fmt + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "IntegratedCosetMds" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "ifft_twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::integrated_coset_mds::IntegratedCosetMds", + "ifft_twiddles" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "fft_twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::integrated_coset_mds::IntegratedCosetMds", + "fft_twiddles" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_mds_integrated_coset_mds_IntegratedCosetMds_N_F. + + Module Impl_core_default_Default_where_p3_field_field_TwoAdicField_F_for_p3_mds_integrated_coset_mds_IntegratedCosetMds_N_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_mds::integrated_coset_mds::IntegratedCosetMds") [ N ] [ F ]. + + (* + fn default() -> Self { + let log_n = log2_strict_usize(N); + let root = F::two_adic_generator(log_n); + let root_inv = root.inverse(); + let coset_shift = F::GENERATOR; + + let mut ifft_twiddles: Vec = root_inv.powers().take(N / 2).collect(); + reverse_slice_index_bits(&mut ifft_twiddles); + + let fft_twiddles: Vec> = (0..log_n) + .map(|layer| { + let shift_power = coset_shift.exp_power_of_2(layer); + let powers = Powers { + base: root.exp_power_of_2(layer), + current: shift_power, + }; + let mut twiddles: Vec<_> = powers.take(N >> (layer + 1)).collect(); + reverse_slice_index_bits(&mut twiddles); + twiddles + }) + .collect(); + + Self { + ifft_twiddles, + fft_twiddles, + } + } + *) + Definition default + (N : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.read (| + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ N ] + |) + |) in + let~ root : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::TwoAdicField", + F, + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_n |) ] + |) + |) in + let~ root_inv : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "p3_field::field::Field", F, [], [], "inverse", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, root |) ] + |) + |) in + let~ coset_shift : Ty.apply (Ty.path "*") [] [ F ] := + M.copy (| get_constant (| "p3_field::field::Field::GENERATOR", F |) |) in + let~ ifft_twiddles : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, root_inv |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ N; Value.Integer IntegerKind.Usize 2 ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits", [], [ F ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, ifft_twiddles |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ fft_twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| log_n |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let layer := M.copy (| γ |) in + M.read (| + let~ shift_power : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, coset_shift |); + M.read (| layer |) + ] + |) + |) in + let~ powers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ] := + M.alloc (| + Value.StructRecord + "p3_field::field::Powers" + [ + ("base", + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, root |); + M.read (| layer |) + ] + |)); + ("current", M.read (| shift_power |)) + ] + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.read (| powers |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + N; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| layer |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::reverse_slice_index_bits", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + twiddles + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + twiddles + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_mds::integrated_coset_mds::IntegratedCosetMds" + [ + ("ifft_twiddles", M.read (| ifft_twiddles |)); + ("fft_twiddles", M.read (| fft_twiddles |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) [ ("default", InstanceField.Method (default N F)) ]. + End Impl_core_default_Default_where_p3_field_field_TwoAdicField_F_for_p3_mds_integrated_coset_mds_IntegratedCosetMds_N_F. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_Field_F_where_p3_field_field_Algebra_A_F_array_N_A_for_p3_mds_integrated_coset_mds_IntegratedCosetMds_N_F. + Definition Self (N : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_mds::integrated_coset_mds::IntegratedCosetMds") [ N ] [ F ]. + + (* + fn permute(&self, mut input: [A; N]) -> [A; N] { + self.permute_mut(&mut input); + input + } + *) + Definition permute + (N : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F A in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.apply + (Ty.path "p3_mds::integrated_coset_mds::IntegratedCosetMds") + [ N ] + [ F ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ A ] ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, input |) |) + |) + ] + |) + |) in + input + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, values: &mut [A; N]) { + let log_n = log2_strict_usize(N); + + // Bit-reversed DIF, aka Bowers G + for layer in 0..log_n { + bowers_g_layer(values, layer, &self.ifft_twiddles); + } + + // Bit-reversed DIT, aka Bowers G^T + for layer in (0..log_n).rev() { + bowers_g_t_layer(values, layer, &self.fft_twiddles[layer]); + } + } + *) + Definition permute_mut + (N : Value.t) + (F A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N F A in + match ε, τ, α with + | [], [], [ self; values ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let values := M.alloc (| values |) in + M.read (| + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ N ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| log_n |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let layer := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::integrated_coset_mds::bowers_g_layer", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| values |) |) + |); + M.read (| layer |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::integrated_coset_mds::IntegratedCosetMds", + "ifft_twiddles" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| log_n |)) + ] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let layer := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::integrated_coset_mds::bowers_g_t_layer", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| values |) |) + |); + M.read (| layer |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mds::integrated_coset_mds::IntegratedCosetMds", + "fft_twiddles" + |) + |); + M.read (| layer |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (F A : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ A ] ] + (Self N F A) + (* Instance *) + [ + ("permute", InstanceField.Method (permute N F A)); + ("permute_mut", InstanceField.Method (permute_mut N F A)) + ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_Field_F_where_p3_field_field_Algebra_A_F_array_N_A_for_p3_mds_integrated_coset_mds_IntegratedCosetMds_N_F. + + Module Impl_p3_mds_MdsPermutation_where_p3_field_field_Field_F_where_p3_field_field_Algebra_A_F_N_A_for_p3_mds_integrated_coset_mds_IntegratedCosetMds_N_F. + Definition Self (N : Value.t) (F A : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_mds::integrated_coset_mds::IntegratedCosetMds") [ N ] [ F ]. + + Axiom Implements : + forall (N : Value.t) (F A : Ty.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ N ] + (* Trait polymorphic types *) [ A ] + (Self N F A) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_where_p3_field_field_Field_F_where_p3_field_field_Algebra_A_F_N_A_for_p3_mds_integrated_coset_mds_IntegratedCosetMds_N_F. + + (* + fn bowers_g_layer, const N: usize>( + values: &mut [A; N], + log_half_block_size: usize, + twiddles: &[F], + ) { + let log_block_size = log_half_block_size + 1; + let half_block_size = 1 << log_half_block_size; + let num_blocks = N >> log_block_size; + + // Unroll first iteration with a twiddle factor of 1. + for hi in 0..half_block_size { + let lo = hi + half_block_size; + twiddle_free_butterfly(values, hi, lo); + } + + for (block, &twiddle) in (1..num_blocks).zip(&twiddles[1..]) { + let block_start = block << log_block_size; + for hi in block_start..block_start + half_block_size { + let lo = hi + half_block_size; + dif_butterfly(values, hi, lo, twiddle); + } + } + } + *) + Definition bowers_g_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ F; A ], [ values; log_half_block_size; twiddles ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let log_half_block_size := M.alloc (| log_half_block_size |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ log_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_half_block_size |); Value.Integer IntegerKind.Usize 1 ] + |) + |) in + let~ half_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_half_block_size |) ] + |) + |) in + let~ num_blocks : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ N; M.read (| log_block_size |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| half_block_size |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let hi := M.copy (| γ0_0 |) in + let~ lo : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| hi |); M.read (| half_block_size |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::butterflies::twiddle_free_butterfly", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| values |) |) + |); + M.read (| hi |); + M.read (| lo |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 1); + ("end_", M.read (| num_blocks |)) + ]; + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ F ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.apply (Ty.path "&") [] [ F ] ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let block := M.copy (| γ1_0 |) in + let γ1_1 := M.read (| γ1_1 |) in + let twiddle := M.copy (| γ1_1 |) in + let~ block_start : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ M.read (| block |); M.read (| log_block_size |) ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| block_start |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| block_start |); + M.read (| half_block_size |) + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let hi := M.copy (| γ0_0 |) in + let~ lo : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| hi |); + M.read (| half_block_size |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::butterflies::dif_butterfly", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| values |) + |) + |); + M.read (| hi |); + M.read (| lo |); + M.read (| twiddle |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_bowers_g_layer : + M.IsFunction.C "p3_mds::integrated_coset_mds::bowers_g_layer" bowers_g_layer. + Admitted. + Global Typeclasses Opaque bowers_g_layer. + + (* + fn bowers_g_t_layer, const N: usize>( + values: &mut [A; N], + log_half_block_size: usize, + twiddles: &[F], + ) { + let log_block_size = log_half_block_size + 1; + let half_block_size = 1 << log_half_block_size; + let num_blocks = N >> log_block_size; + + for (block, &twiddle) in (0..num_blocks).zip(twiddles) { + let block_start = block << log_block_size; + for hi in block_start..block_start + half_block_size { + let lo = hi + half_block_size; + dit_butterfly(values, hi, lo, twiddle); + } + } + } + *) + Definition bowers_g_t_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ F; A ], [ values; log_half_block_size; twiddles ] => + ltac:(M.monadic + (let values := M.alloc (| values |) in + let log_half_block_size := M.alloc (| log_half_block_size |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ log_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_half_block_size |); Value.Integer IntegerKind.Usize 1 ] + |) + |) in + let~ half_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_half_block_size |) ] + |) + |) in + let~ num_blocks : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ N; M.read (| log_block_size |) ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| num_blocks |)) + ]; + M.read (| twiddles |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.apply (Ty.path "&") [] [ F ] ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let block := M.copy (| γ1_0 |) in + let γ1_1 := M.read (| γ1_1 |) in + let twiddle := M.copy (| γ1_1 |) in + let~ block_start : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ M.read (| block |); M.read (| log_block_size |) ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| block_start |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| block_start |); + M.read (| half_block_size |) + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let hi := M.copy (| γ0_0 |) in + let~ lo : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| hi |); + M.read (| half_block_size |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::butterflies::dit_butterfly", + [ N ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| values |) + |) + |); + M.read (| hi |); + M.read (| lo |); + M.read (| twiddle |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_bowers_g_t_layer : + M.IsFunction.C "p3_mds::integrated_coset_mds::bowers_g_t_layer" bowers_g_t_layer. + Admitted. + Global Typeclasses Opaque bowers_g_t_layer. +End integrated_coset_mds. diff --git a/CoqOfRust/plonky3/mds/src/karatsuba_convolution.rs b/CoqOfRust/plonky3/mds/src/karatsuba_convolution.rs new file mode 100644 index 000000000..86a440ff3 --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/karatsuba_convolution.rs @@ -0,0 +1,388 @@ +//! Calculate the convolution of two vectors using a Karatsuba-style +//! decomposition and the CRT. +//! +//! This is not a new idea, but we did have the pleasure of +//! reinventing it independently. Some references: +//! - `` +//! - `` +//! +//! Given a vector v \in F^N, let v(x) \in F[x] denote the polynomial +//! v_0 + v_1 x + ... + v_{N - 1} x^{N - 1}. Then w is equal to the +//! convolution v * u if and only if w(x) = v(x)u(x) mod x^N - 1. +//! Additionally, define the negacyclic convolution by w(x) = v(x)u(x) +//! mod x^N + 1. Using the Chinese remainder theorem we can compute +//! w(x) as +//! w(x) = 1/2 (w_0(x) + w_1(x)) + x^{N/2}/2 (w_0(x) - w_1(x)) +//! where +//! w_0 = v(x)u(x) mod x^{N/2} - 1 +//! w_1 = v(x)u(x) mod x^{N/2} + 1 +//! +//! To compute w_0 and w_1 we first compute +//! v_0(x) = v(x) mod x^{N/2} - 1 +//! v_1(x) = v(x) mod x^{N/2} + 1 +//! u_0(x) = u(x) mod x^{N/2} - 1 +//! u_1(x) = u(x) mod x^{N/2} + 1 +//! +//! Now w_0 is the convolution of v_0 and u_0 which we can compute +//! recursively. For w_1 we compute the negacyclic convolution +//! v_1(x)u_1(x) mod x^{N/2} + 1 using Karatsuba. +//! +//! There are 2 possible approaches to applying Karatsuba which mirror +//! the DIT vs DIF approaches to FFT's, the left/right decomposition +//! or the even/odd decomposition. The latter seems to have fewer +//! operations and so it is the one implemented below, though it does +//! require a bit more data manipulation. It works as follows: +//! +//! Define the even v_e and odd v_o parts so that v(x) = (v_e(x^2) + x v_o(x^2)). +//! Then v(x)u(x) +//! = (v_e(x^2)u_e(x^2) + x^2 v_o(x^2)u_o(x^2)) +//! + x ((v_e(x^2) + v_o(x^2))(u_e(x^2) + u_o(x^2)) +//! - (v_e(x^2)u_e(x^2) + v_o(x^2)u_o(x^2))) +//! This reduces the problem to 3 negacyclic convolutions of size N/2 which +//! can be computed recursively. +//! +//! Of course, for small sizes we just explicitly write out the O(n^2) +//! approach. + +use core::ops::{Add, AddAssign, Neg, ShrAssign, Sub, SubAssign}; + +/// This trait collects the operations needed by `Convolve` below. +/// +/// TODO: Think of a better name for this. +pub trait RngElt: + Add + + AddAssign + + Copy + + Default + + Neg + + ShrAssign + + Sub + + SubAssign +{ +} + +impl RngElt for i64 {} +impl RngElt for i128 {} + +/// Template function to perform convolution of vectors. +/// +/// Roughly speaking, for a convolution of size `N`, it should be +/// possible to add `N` elements of type `T` without overflowing, and +/// similarly for `U`. Then multiplication via `Self::mul` should +/// produce an element of type `V` which will not overflow after about +/// `N` additions (this is an over-estimate). +/// +/// For example usage, see `{mersenne-31,baby-bear,goldilocks}/src/mds.rs`. +/// +/// NB: In practice, one of the parameters to the convolution will be +/// constant (the MDS matrix). After inspecting Godbolt output, it +/// seems that the compiler does indeed generate single constants as +/// inputs to the multiplication, rather than doing all that +/// arithmetic on the constant values every time. Note however that, +/// for MDS matrices with large entries (N >= 24), these compile-time +/// generated constants will be about N times bigger than they need to +/// be in principle, which could be a potential avenue for some minor +/// improvements. +/// +/// NB: If primitive multiplications are still the bottleneck, a +/// further possibility would be to find an MDS matrix some of whose +/// entries are powers of 2. Then the multiplication can be replaced +/// with a shift, which on most architectures has better throughput +/// and latency, and is issued on different ports (1*p06) to +/// multiplication (1*p1). +pub trait Convolve { + /// Given an input element, retrieve the corresponding internal + /// element that will be used in calculations. + fn read(input: F) -> T; + + /// Given input vectors `lhs` and `rhs`, calculate their dot + /// product. The result can be reduced with respect to the modulus + /// (of `F`), but it must have the same lower 10 bits as the dot + /// product if all inputs are considered integers. See + /// `monty-31/src/mds.rs::barrett_red_monty31()` for an example + /// of how this can be implemented in practice. + fn parity_dot(lhs: [T; N], rhs: [U; N]) -> V; + + /// Convert an internal element of type `V` back into an external + /// element. + fn reduce(z: V) -> F; + + /// Convolve `lhs` and `rhs`. + /// + /// The parameter `conv` should be the function in this trait that + /// corresponds to length `N`. + #[inline(always)] + fn apply( + lhs: [F; N], + rhs: [U; N], + conv: C, + ) -> [F; N] { + let lhs = lhs.map(Self::read); + let mut output = [V::default(); N]; + conv(lhs, rhs, &mut output); + output.map(Self::reduce) + } + + #[inline(always)] + fn conv3(lhs: [T; 3], rhs: [U; 3], output: &mut [V]) { + output[0] = Self::parity_dot(lhs, [rhs[0], rhs[2], rhs[1]]); + output[1] = Self::parity_dot(lhs, [rhs[1], rhs[0], rhs[2]]); + output[2] = Self::parity_dot(lhs, [rhs[2], rhs[1], rhs[0]]); + } + + #[inline(always)] + fn negacyclic_conv3(lhs: [T; 3], rhs: [U; 3], output: &mut [V]) { + output[0] = Self::parity_dot(lhs, [rhs[0], -rhs[2], -rhs[1]]); + output[1] = Self::parity_dot(lhs, [rhs[1], rhs[0], -rhs[2]]); + output[2] = Self::parity_dot(lhs, [rhs[2], rhs[1], rhs[0]]); + } + + #[inline(always)] + fn conv4(lhs: [T; 4], rhs: [U; 4], output: &mut [V]) { + // NB: This is just explicitly implementing + // conv_n_recursive::<4, 2, _, _>(lhs, rhs, output, Self::conv2, Self::negacyclic_conv2) + let u_p = [lhs[0] + lhs[2], lhs[1] + lhs[3]]; + let u_m = [lhs[0] - lhs[2], lhs[1] - lhs[3]]; + let v_p = [rhs[0] + rhs[2], rhs[1] + rhs[3]]; + let v_m = [rhs[0] - rhs[2], rhs[1] - rhs[3]]; + + output[0] = Self::parity_dot(u_m, [v_m[0], -v_m[1]]); + output[1] = Self::parity_dot(u_m, [v_m[1], v_m[0]]); + output[2] = Self::parity_dot(u_p, v_p); + output[3] = Self::parity_dot(u_p, [v_p[1], v_p[0]]); + + output[0] += output[2]; + output[1] += output[3]; + + output[0] >>= 1; + output[1] >>= 1; + + output[2] -= output[0]; + output[3] -= output[1]; + } + + #[inline(always)] + fn negacyclic_conv4(lhs: [T; 4], rhs: [U; 4], output: &mut [V]) { + output[0] = Self::parity_dot(lhs, [rhs[0], -rhs[3], -rhs[2], -rhs[1]]); + output[1] = Self::parity_dot(lhs, [rhs[1], rhs[0], -rhs[3], -rhs[2]]); + output[2] = Self::parity_dot(lhs, [rhs[2], rhs[1], rhs[0], -rhs[3]]); + output[3] = Self::parity_dot(lhs, [rhs[3], rhs[2], rhs[1], rhs[0]]); + } + + #[inline(always)] + fn conv6(lhs: [T; 6], rhs: [U; 6], output: &mut [V]) { + conv_n_recursive::<6, 3, T, U, V, _, _>( + lhs, + rhs, + output, + Self::conv3, + Self::negacyclic_conv3, + ) + } + + #[inline(always)] + fn negacyclic_conv6(lhs: [T; 6], rhs: [U; 6], output: &mut [V]) { + negacyclic_conv_n_recursive::<6, 3, T, U, V, _>(lhs, rhs, output, Self::negacyclic_conv3) + } + + #[inline(always)] + fn conv8(lhs: [T; 8], rhs: [U; 8], output: &mut [V]) { + conv_n_recursive::<8, 4, T, U, V, _, _>( + lhs, + rhs, + output, + Self::conv4, + Self::negacyclic_conv4, + ) + } + + #[inline(always)] + fn negacyclic_conv8(lhs: [T; 8], rhs: [U; 8], output: &mut [V]) { + negacyclic_conv_n_recursive::<8, 4, T, U, V, _>(lhs, rhs, output, Self::negacyclic_conv4) + } + + #[inline(always)] + fn conv12(lhs: [T; 12], rhs: [U; 12], output: &mut [V]) { + conv_n_recursive::<12, 6, T, U, V, _, _>( + lhs, + rhs, + output, + Self::conv6, + Self::negacyclic_conv6, + ) + } + + #[inline(always)] + fn negacyclic_conv12(lhs: [T; 12], rhs: [U; 12], output: &mut [V]) { + negacyclic_conv_n_recursive::<12, 6, T, U, V, _>(lhs, rhs, output, Self::negacyclic_conv6) + } + + #[inline(always)] + fn conv16(lhs: [T; 16], rhs: [U; 16], output: &mut [V]) { + conv_n_recursive::<16, 8, T, U, V, _, _>( + lhs, + rhs, + output, + Self::conv8, + Self::negacyclic_conv8, + ) + } + + #[inline(always)] + fn negacyclic_conv16(lhs: [T; 16], rhs: [U; 16], output: &mut [V]) { + negacyclic_conv_n_recursive::<16, 8, T, U, V, _>(lhs, rhs, output, Self::negacyclic_conv8) + } + + #[inline(always)] + fn conv24(lhs: [T; 24], rhs: [U; 24], output: &mut [V]) { + conv_n_recursive::<24, 12, T, U, V, _, _>( + lhs, + rhs, + output, + Self::conv12, + Self::negacyclic_conv12, + ) + } + + #[inline(always)] + fn conv32(lhs: [T; 32], rhs: [U; 32], output: &mut [V]) { + conv_n_recursive::<32, 16, T, U, V, _, _>( + lhs, + rhs, + output, + Self::conv16, + Self::negacyclic_conv16, + ) + } + + #[inline(always)] + fn negacyclic_conv32(lhs: [T; 32], rhs: [U; 32], output: &mut [V]) { + negacyclic_conv_n_recursive::<32, 16, T, U, V, _>(lhs, rhs, output, Self::negacyclic_conv16) + } + + #[inline(always)] + fn conv64(lhs: [T; 64], rhs: [U; 64], output: &mut [V]) { + conv_n_recursive::<64, 32, T, U, V, _, _>( + lhs, + rhs, + output, + Self::conv32, + Self::negacyclic_conv32, + ) + } +} + +/// Compute output(x) = lhs(x)rhs(x) mod x^N - 1. +/// Do this recursively using a convolution and negacyclic convolution of size HALF_N = N/2. +#[inline(always)] +fn conv_n_recursive( + lhs: [T; N], + rhs: [U; N], + output: &mut [V], + inner_conv: C, + inner_negacyclic_conv: NC, +) where + T: RngElt, + U: RngElt, + V: RngElt, + C: Fn([T; HALF_N], [U; HALF_N], &mut [V]), + NC: Fn([T; HALF_N], [U; HALF_N], &mut [V]), +{ + debug_assert_eq!(2 * HALF_N, N); + // NB: The compiler is smart enough not to initialise these arrays. + let mut lhs_pos = [T::default(); HALF_N]; // lhs_pos = lhs(x) mod x^{N/2} - 1 + let mut lhs_neg = [T::default(); HALF_N]; // lhs_neg = lhs(x) mod x^{N/2} + 1 + let mut rhs_pos = [U::default(); HALF_N]; // rhs_pos = rhs(x) mod x^{N/2} - 1 + let mut rhs_neg = [U::default(); HALF_N]; // rhs_neg = rhs(x) mod x^{N/2} + 1 + + for i in 0..HALF_N { + let s = lhs[i]; + let t = lhs[i + HALF_N]; + + lhs_pos[i] = s + t; + lhs_neg[i] = s - t; + + let s = rhs[i]; + let t = rhs[i + HALF_N]; + + rhs_pos[i] = s + t; + rhs_neg[i] = s - t; + } + + let (left, right) = output.split_at_mut(HALF_N); + + // left = w1 = lhs(x)rhs(x) mod x^{N/2} + 1 + inner_negacyclic_conv(lhs_neg, rhs_neg, left); + + // right = w0 = lhs(x)rhs(x) mod x^{N/2} - 1 + inner_conv(lhs_pos, rhs_pos, right); + + for i in 0..HALF_N { + left[i] += right[i]; // w_0 + w_1 + left[i] >>= 1; // (w_0 + w_1)/2 + right[i] -= left[i]; // (w_0 - w_1)/2 + } +} + +/// Compute output(x) = lhs(x)rhs(x) mod x^N + 1. +/// Do this recursively using three negacyclic convolutions of size HALF_N = N/2. +#[inline(always)] +fn negacyclic_conv_n_recursive( + lhs: [T; N], + rhs: [U; N], + output: &mut [V], + inner_negacyclic_conv: NC, +) where + T: RngElt, + U: RngElt, + V: RngElt, + NC: Fn([T; HALF_N], [U; HALF_N], &mut [V]), +{ + debug_assert_eq!(2 * HALF_N, N); + // NB: The compiler is smart enough not to initialise these arrays. + let mut lhs_even = [T::default(); HALF_N]; + let mut lhs_odd = [T::default(); HALF_N]; + let mut lhs_sum = [T::default(); HALF_N]; + let mut rhs_even = [U::default(); HALF_N]; + let mut rhs_odd = [U::default(); HALF_N]; + let mut rhs_sum = [U::default(); HALF_N]; + + for i in 0..HALF_N { + let s = lhs[2 * i]; + let t = lhs[2 * i + 1]; + lhs_even[i] = s; + lhs_odd[i] = t; + lhs_sum[i] = s + t; + + let s = rhs[2 * i]; + let t = rhs[2 * i + 1]; + rhs_even[i] = s; + rhs_odd[i] = t; + rhs_sum[i] = s + t; + } + + let mut even_s_conv = [V::default(); HALF_N]; + let (left, right) = output.split_at_mut(HALF_N); + + // Recursively compute the size N/2 negacyclic convolutions of + // the even parts, odd parts, and sums. + inner_negacyclic_conv(lhs_even, rhs_even, &mut even_s_conv); + inner_negacyclic_conv(lhs_odd, rhs_odd, left); + inner_negacyclic_conv(lhs_sum, rhs_sum, right); + + // Adjust so that the correct values are in right and + // even_s_conv respectively: + right[0] -= even_s_conv[0] + left[0]; + even_s_conv[0] -= left[HALF_N - 1]; + + for i in 1..HALF_N { + right[i] -= even_s_conv[i] + left[i]; + even_s_conv[i] += left[i - 1]; + } + + // Interleave even_s_conv and right in the output: + for i in 0..HALF_N { + output[2 * i] = even_s_conv[i]; + output[2 * i + 1] = output[i + HALF_N]; + } +} diff --git a/CoqOfRust/plonky3/mds/src/karatsuba_convolution.v b/CoqOfRust/plonky3/mds/src/karatsuba_convolution.v new file mode 100644 index 000000000..adedaff05 --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/karatsuba_convolution.v @@ -0,0 +1,3756 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module karatsuba_convolution. + (* Trait *) + (* Empty module 'RngElt' *) + + Module Impl_p3_mds_karatsuba_convolution_RngElt_for_i64. + Definition Self : Ty.t := Ty.path "i64". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::karatsuba_convolution::RngElt" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_mds_karatsuba_convolution_RngElt_for_i64. + + Module Impl_p3_mds_karatsuba_convolution_RngElt_for_i128. + Definition Self : Ty.t := Ty.path "i128". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::karatsuba_convolution::RngElt" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_mds_karatsuba_convolution_RngElt_for_i128. + + (* Trait *) + Module Convolve. + Definition apply + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ N ], [ C ], [ lhs; rhs; conv ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let conv := M.alloc (| conv |) in + M.read (| + let~ lhs : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ N ] [ T ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ N ] [ F ], + "map", + [], + [ Ty.function [ F ] T; T ] + |), + [ + M.read (| lhs |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "read", + [], + [] + |) + ] + |) + |) in + let~ output : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ N ] [ V ] ] := + M.alloc (| + repeat (| + M.call_closure (| + V, + M.get_trait_method (| "core::default::Default", V, [], [], "default", [], [] |), + [] + |), + N + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::function::Fn", + C, + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "array") [ N ] [ T ]; + Ty.apply (Ty.path "array") [ N ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, conv |); + Value.Tuple + [ + M.read (| lhs |); + M.read (| rhs |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, output |) |) + |)) + ] + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ N ] [ V ], + "map", + [], + [ Ty.function [ V ] F; F ] + |), + [ + M.read (| output |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "reduce", + [], + [] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_apply : + forall (F T U V : Ty.t), + M.IsProvidedMethod "p3_mds::karatsuba_convolution::Convolve" "apply" (apply F T U V). + Definition conv3 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.read (| lhs |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.read (| lhs |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.read (| lhs |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_conv3 : + forall (F T U V : Ty.t), + M.IsProvidedMethod "p3_mds::karatsuba_convolution::Convolve" "conv3" (conv3 F T U V). + Definition negacyclic_conv3 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.read (| lhs |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Neg", + U, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Neg", + U, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.read (| lhs |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Neg", + U, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.read (| lhs |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_negacyclic_conv3 : + forall (F T U V : Ty.t), + M.IsProvidedMethod + "p3_mds::karatsuba_convolution::Convolve" + "negacyclic_conv3" + (negacyclic_conv3 F T U V). + Definition conv4 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.read (| + let~ u_p : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ T ] ] := + M.alloc (| + Value.Array + [ + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Add", T, [], [ T ], "add", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| lhs, Value.Integer IntegerKind.Usize 0 |) + |); + M.read (| + M.SubPointer.get_array_field (| lhs, Value.Integer IntegerKind.Usize 2 |) + |) + ] + |); + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Add", T, [], [ T ], "add", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| lhs, Value.Integer IntegerKind.Usize 1 |) + |); + M.read (| + M.SubPointer.get_array_field (| lhs, Value.Integer IntegerKind.Usize 3 |) + |) + ] + |) + ] + |) in + let~ u_m : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ T ] ] := + M.alloc (| + Value.Array + [ + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Sub", T, [], [ T ], "sub", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| lhs, Value.Integer IntegerKind.Usize 0 |) + |); + M.read (| + M.SubPointer.get_array_field (| lhs, Value.Integer IntegerKind.Usize 2 |) + |) + ] + |); + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Sub", T, [], [ T ], "sub", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| lhs, Value.Integer IntegerKind.Usize 1 |) + |); + M.read (| + M.SubPointer.get_array_field (| lhs, Value.Integer IntegerKind.Usize 3 |) + |) + ] + |) + ] + |) in + let~ v_p : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ U ] ] := + M.alloc (| + Value.Array + [ + M.call_closure (| + U, + M.get_trait_method (| "core::ops::arith::Add", U, [], [ U ], "add", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| rhs, Value.Integer IntegerKind.Usize 0 |) + |); + M.read (| + M.SubPointer.get_array_field (| rhs, Value.Integer IntegerKind.Usize 2 |) + |) + ] + |); + M.call_closure (| + U, + M.get_trait_method (| "core::ops::arith::Add", U, [], [ U ], "add", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| rhs, Value.Integer IntegerKind.Usize 1 |) + |); + M.read (| + M.SubPointer.get_array_field (| rhs, Value.Integer IntegerKind.Usize 3 |) + |) + ] + |) + ] + |) in + let~ v_m : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ U ] ] := + M.alloc (| + Value.Array + [ + M.call_closure (| + U, + M.get_trait_method (| "core::ops::arith::Sub", U, [], [ U ], "sub", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| rhs, Value.Integer IntegerKind.Usize 0 |) + |); + M.read (| + M.SubPointer.get_array_field (| rhs, Value.Integer IntegerKind.Usize 2 |) + |) + ] + |); + M.call_closure (| + U, + M.get_trait_method (| "core::ops::arith::Sub", U, [], [ U ], "sub", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| rhs, Value.Integer IntegerKind.Usize 1 |) + |); + M.read (| + M.SubPointer.get_array_field (| rhs, Value.Integer IntegerKind.Usize 3 |) + |) + ] + |) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.read (| u_m |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + v_m, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Neg", + U, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + v_m, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.read (| u_m |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + v_m, + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + v_m, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ M.read (| u_p |); M.read (| v_p |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.read (| u_p |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + v_p, + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + v_p, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + V, + [], + [ V ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + V, + [], + [ V ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::ShrAssign", + V, + [], + [ Ty.path "u32" ], + "shr_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::ShrAssign", + V, + [], + [ Ty.path "u32" ], + "shr_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + V, + [], + [ V ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + V, + [], + [ V ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_conv4 : + forall (F T U V : Ty.t), + M.IsProvidedMethod "p3_mds::karatsuba_convolution::Convolve" "conv4" (conv4 F T U V). + Definition negacyclic_conv4 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.read (| lhs |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Neg", + U, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Neg", + U, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Neg", + U, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.read (| lhs |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Neg", + U, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Neg", + U, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.read (| lhs |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Neg", + U, + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + ] + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + V, + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "parity_dot", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.read (| lhs |); + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 3 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + rhs, + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_negacyclic_conv4 : + forall (F T U V : Ty.t), + M.IsProvidedMethod + "p3_mds::karatsuba_convolution::Convolve" + "negacyclic_conv4" + (negacyclic_conv4 F T U V). + Definition conv6 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::conv_n_recursive", + [ Value.Integer IntegerKind.Usize 6; Value.Integer IntegerKind.Usize 3 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 3 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 3 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []); + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 3 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 3 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "conv3", + [], + [] + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv3", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_conv6 : + forall (F T U V : Ty.t), + M.IsProvidedMethod "p3_mds::karatsuba_convolution::Convolve" "conv6" (conv6 F T U V). + Definition negacyclic_conv6 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::negacyclic_conv_n_recursive", + [ Value.Integer IntegerKind.Usize 6; Value.Integer IntegerKind.Usize 3 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 3 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 3 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv3", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_negacyclic_conv6 : + forall (F T U V : Ty.t), + M.IsProvidedMethod + "p3_mds::karatsuba_convolution::Convolve" + "negacyclic_conv6" + (negacyclic_conv6 F T U V). + Definition conv8 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::conv_n_recursive", + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 4 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []); + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "conv4", + [], + [] + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv4", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_conv8 : + forall (F T U V : Ty.t), + M.IsProvidedMethod "p3_mds::karatsuba_convolution::Convolve" "conv8" (conv8 F T U V). + Definition negacyclic_conv8 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::negacyclic_conv_n_recursive", + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 4 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv4", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_negacyclic_conv8 : + forall (F T U V : Ty.t), + M.IsProvidedMethod + "p3_mds::karatsuba_convolution::Convolve" + "negacyclic_conv8" + (negacyclic_conv8 F T U V). + Definition conv12 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::conv_n_recursive", + [ Value.Integer IntegerKind.Usize 12; Value.Integer IntegerKind.Usize 6 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 6 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 6 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []); + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 6 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 6 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "conv6", + [], + [] + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv6", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_conv12 : + forall (F T U V : Ty.t), + M.IsProvidedMethod "p3_mds::karatsuba_convolution::Convolve" "conv12" (conv12 F T U V). + Definition negacyclic_conv12 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::negacyclic_conv_n_recursive", + [ Value.Integer IntegerKind.Usize 12; Value.Integer IntegerKind.Usize 6 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 6 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 6 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv6", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_negacyclic_conv12 : + forall (F T U V : Ty.t), + M.IsProvidedMethod + "p3_mds::karatsuba_convolution::Convolve" + "negacyclic_conv12" + (negacyclic_conv12 F T U V). + Definition conv16 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::conv_n_recursive", + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 8 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []); + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "conv8", + [], + [] + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv8", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_conv16 : + forall (F T U V : Ty.t), + M.IsProvidedMethod "p3_mds::karatsuba_convolution::Convolve" "conv16" (conv16 F T U V). + Definition negacyclic_conv16 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::negacyclic_conv_n_recursive", + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 8 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv8", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_negacyclic_conv16 : + forall (F T U V : Ty.t), + M.IsProvidedMethod + "p3_mds::karatsuba_convolution::Convolve" + "negacyclic_conv16" + (negacyclic_conv16 F T U V). + Definition conv24 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::conv_n_recursive", + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 12 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 12 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 12 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []); + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 12 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 12 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "conv12", + [], + [] + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv12", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_conv24 : + forall (F T U V : Ty.t), + M.IsProvidedMethod "p3_mds::karatsuba_convolution::Convolve" "conv24" (conv24 F T U V). + Definition conv32 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::conv_n_recursive", + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 16 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []); + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "conv16", + [], + [] + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv16", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_conv32 : + forall (F T U V : Ty.t), + M.IsProvidedMethod "p3_mds::karatsuba_convolution::Convolve" "conv32" (conv32 F T U V). + Definition negacyclic_conv32 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::negacyclic_conv_n_recursive", + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 16 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 16 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv16", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_negacyclic_conv32 : + forall (F T U V : Ty.t), + M.IsProvidedMethod + "p3_mds::karatsuba_convolution::Convolve" + "negacyclic_conv32" + (negacyclic_conv32 F T U V). + Definition conv64 + (F T U V Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ lhs; rhs; output ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mds::karatsuba_convolution::conv_n_recursive", + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 32 ], + [ + T; + U; + V; + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []); + Ty.function + [ + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ T ]; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| lhs |); + M.read (| rhs |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "conv32", + [], + [] + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Self, + [], + [ F; T; U; V ], + "negacyclic_conv32", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_conv64 : + forall (F T U V : Ty.t), + M.IsProvidedMethod "p3_mds::karatsuba_convolution::Convolve" "conv64" (conv64 F T U V). + End Convolve. + + (* + fn conv_n_recursive( + lhs: [T; N], + rhs: [U; N], + output: &mut [V], + inner_conv: C, + inner_negacyclic_conv: NC, + ) where + T: RngElt, + U: RngElt, + V: RngElt, + C: Fn([T; HALF_N], [U; HALF_N], &mut [V]), + NC: Fn([T; HALF_N], [U; HALF_N], &mut [V]), + { + debug_assert_eq!(2 * HALF_N, N); + // NB: The compiler is smart enough not to initialise these arrays. + let mut lhs_pos = [T::default(); HALF_N]; // lhs_pos = lhs(x) mod x^{N/2} - 1 + let mut lhs_neg = [T::default(); HALF_N]; // lhs_neg = lhs(x) mod x^{N/2} + 1 + let mut rhs_pos = [U::default(); HALF_N]; // rhs_pos = rhs(x) mod x^{N/2} - 1 + let mut rhs_neg = [U::default(); HALF_N]; // rhs_neg = rhs(x) mod x^{N/2} + 1 + + for i in 0..HALF_N { + let s = lhs[i]; + let t = lhs[i + HALF_N]; + + lhs_pos[i] = s + t; + lhs_neg[i] = s - t; + + let s = rhs[i]; + let t = rhs[i + HALF_N]; + + rhs_pos[i] = s + t; + rhs_neg[i] = s - t; + } + + let (left, right) = output.split_at_mut(HALF_N); + + // left = w1 = lhs(x)rhs(x) mod x^{N/2} + 1 + inner_negacyclic_conv(lhs_neg, rhs_neg, left); + + // right = w0 = lhs(x)rhs(x) mod x^{N/2} - 1 + inner_conv(lhs_pos, rhs_pos, right); + + for i in 0..HALF_N { + left[i] += right[i]; // w_0 + w_1 + left[i] >>= 1; // (w_0 + w_1)/2 + right[i] -= left[i]; // (w_0 - w_1)/2 + } + } + *) + Definition conv_n_recursive (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N; HALF_N ], [ T; U; V; C; NC ], [ lhs; rhs; output; inner_conv; inner_negacyclic_conv ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + let inner_conv := M.alloc (| inner_conv |) in + let inner_negacyclic_conv := M.alloc (| inner_negacyclic_conv |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; HALF_N ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ lhs_pos : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ T ] ] := + M.alloc (| + repeat (| + M.call_closure (| + T, + M.get_trait_method (| "core::default::Default", T, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + let~ lhs_neg : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ T ] ] := + M.alloc (| + repeat (| + M.call_closure (| + T, + M.get_trait_method (| "core::default::Default", T, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + let~ rhs_pos : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ U ] ] := + M.alloc (| + repeat (| + M.call_closure (| + U, + M.get_trait_method (| "core::default::Default", U, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + let~ rhs_neg : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ U ] ] := + M.alloc (| + repeat (| + M.call_closure (| + U, + M.get_trait_method (| "core::default::Default", U, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", HALF_N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ s : Ty.apply (Ty.path "*") [] [ T ] := + M.copy (| + M.SubPointer.get_array_field (| lhs, M.read (| i |) |) + |) in + let~ t : Ty.apply (Ty.path "*") [] [ T ] := + M.copy (| + M.SubPointer.get_array_field (| + lhs, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| i |); HALF_N ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + lhs_pos, + M.read (| i |) + |), + M.call_closure (| + T, + M.get_trait_method (| + "core::ops::arith::Add", + T, + [], + [ T ], + "add", + [], + [] + |), + [ M.read (| s |); M.read (| t |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + lhs_neg, + M.read (| i |) + |), + M.call_closure (| + T, + M.get_trait_method (| + "core::ops::arith::Sub", + T, + [], + [ T ], + "sub", + [], + [] + |), + [ M.read (| s |); M.read (| t |) ] + |) + |) + |) in + let~ s : Ty.apply (Ty.path "*") [] [ U ] := + M.copy (| + M.SubPointer.get_array_field (| rhs, M.read (| i |) |) + |) in + let~ t : Ty.apply (Ty.path "*") [] [ U ] := + M.copy (| + M.SubPointer.get_array_field (| + rhs, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| i |); HALF_N ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + rhs_pos, + M.read (| i |) + |), + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Add", + U, + [], + [ U ], + "add", + [], + [] + |), + [ M.read (| s |); M.read (| t |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + rhs_neg, + M.read (| i |) + |), + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Sub", + U, + [], + [ U ], + "sub", + [], + [] + |), + [ M.read (| s |); M.read (| t |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ V ], + "split_at_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); HALF_N ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left := M.copy (| γ0_0 |) in + let right := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::function::Fn", + NC, + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "array") [ HALF_N ] [ T ]; + Ty.apply (Ty.path "array") [ HALF_N ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, inner_negacyclic_conv |); + Value.Tuple + [ + M.read (| lhs_neg |); + M.read (| rhs_neg |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| left |) |) |) + ] + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::function::Fn", + C, + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "array") [ HALF_N ] [ T ]; + Ty.apply (Ty.path "array") [ HALF_N ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, inner_conv |); + Value.Tuple + [ + M.read (| lhs_pos |); + M.read (| rhs_pos |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| right |) |) |) + ] + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", HALF_N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + V, + [], + [ V ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| left |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| right |) |), + M.read (| i |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::ShrAssign", + V, + [], + [ Ty.path "u32" ], + "shr_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| left |) |), + M.read (| i |) + |) + |); + Value.Integer IntegerKind.U32 1 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + V, + [], + [ V ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| right |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| left |) |), + M.read (| i |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_conv_n_recursive : + M.IsFunction.C "p3_mds::karatsuba_convolution::conv_n_recursive" conv_n_recursive. + Admitted. + Global Typeclasses Opaque conv_n_recursive. + + (* + fn negacyclic_conv_n_recursive( + lhs: [T; N], + rhs: [U; N], + output: &mut [V], + inner_negacyclic_conv: NC, + ) where + T: RngElt, + U: RngElt, + V: RngElt, + NC: Fn([T; HALF_N], [U; HALF_N], &mut [V]), + { + debug_assert_eq!(2 * HALF_N, N); + // NB: The compiler is smart enough not to initialise these arrays. + let mut lhs_even = [T::default(); HALF_N]; + let mut lhs_odd = [T::default(); HALF_N]; + let mut lhs_sum = [T::default(); HALF_N]; + let mut rhs_even = [U::default(); HALF_N]; + let mut rhs_odd = [U::default(); HALF_N]; + let mut rhs_sum = [U::default(); HALF_N]; + + for i in 0..HALF_N { + let s = lhs[2 * i]; + let t = lhs[2 * i + 1]; + lhs_even[i] = s; + lhs_odd[i] = t; + lhs_sum[i] = s + t; + + let s = rhs[2 * i]; + let t = rhs[2 * i + 1]; + rhs_even[i] = s; + rhs_odd[i] = t; + rhs_sum[i] = s + t; + } + + let mut even_s_conv = [V::default(); HALF_N]; + let (left, right) = output.split_at_mut(HALF_N); + + // Recursively compute the size N/2 negacyclic convolutions of + // the even parts, odd parts, and sums. + inner_negacyclic_conv(lhs_even, rhs_even, &mut even_s_conv); + inner_negacyclic_conv(lhs_odd, rhs_odd, left); + inner_negacyclic_conv(lhs_sum, rhs_sum, right); + + // Adjust so that the correct values are in right and + // even_s_conv respectively: + right[0] -= even_s_conv[0] + left[0]; + even_s_conv[0] -= left[HALF_N - 1]; + + for i in 1..HALF_N { + right[i] -= even_s_conv[i] + left[i]; + even_s_conv[i] += left[i - 1]; + } + + // Interleave even_s_conv and right in the output: + for i in 0..HALF_N { + output[2 * i] = even_s_conv[i]; + output[2 * i + 1] = output[i + HALF_N]; + } + } + *) + Definition negacyclic_conv_n_recursive + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ N; HALF_N ], [ T; U; V; NC ], [ lhs; rhs; output; inner_negacyclic_conv ] => + ltac:(M.monadic + (let lhs := M.alloc (| lhs |) in + let rhs := M.alloc (| rhs |) in + let output := M.alloc (| output |) in + let inner_negacyclic_conv := M.alloc (| inner_negacyclic_conv |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; HALF_N ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ lhs_even : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ T ] ] := + M.alloc (| + repeat (| + M.call_closure (| + T, + M.get_trait_method (| "core::default::Default", T, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + let~ lhs_odd : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ T ] ] := + M.alloc (| + repeat (| + M.call_closure (| + T, + M.get_trait_method (| "core::default::Default", T, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + let~ lhs_sum : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ T ] ] := + M.alloc (| + repeat (| + M.call_closure (| + T, + M.get_trait_method (| "core::default::Default", T, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + let~ rhs_even : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ U ] ] := + M.alloc (| + repeat (| + M.call_closure (| + U, + M.get_trait_method (| "core::default::Default", U, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + let~ rhs_odd : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ U ] ] := + M.alloc (| + repeat (| + M.call_closure (| + U, + M.get_trait_method (| "core::default::Default", U, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + let~ rhs_sum : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ U ] ] := + M.alloc (| + repeat (| + M.call_closure (| + U, + M.get_trait_method (| "core::default::Default", U, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", HALF_N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ s : Ty.apply (Ty.path "*") [] [ T ] := + M.copy (| + M.SubPointer.get_array_field (| + lhs, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| i |) ] + |) + |) + |) in + let~ t : Ty.apply (Ty.path "*") [] [ T ] := + M.copy (| + M.SubPointer.get_array_field (| + lhs, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| i |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + lhs_even, + M.read (| i |) + |), + M.read (| s |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + lhs_odd, + M.read (| i |) + |), + M.read (| t |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + lhs_sum, + M.read (| i |) + |), + M.call_closure (| + T, + M.get_trait_method (| + "core::ops::arith::Add", + T, + [], + [ T ], + "add", + [], + [] + |), + [ M.read (| s |); M.read (| t |) ] + |) + |) + |) in + let~ s : Ty.apply (Ty.path "*") [] [ U ] := + M.copy (| + M.SubPointer.get_array_field (| + rhs, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| i |) ] + |) + |) + |) in + let~ t : Ty.apply (Ty.path "*") [] [ U ] := + M.copy (| + M.SubPointer.get_array_field (| + rhs, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| i |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + rhs_even, + M.read (| i |) + |), + M.read (| s |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + rhs_odd, + M.read (| i |) + |), + M.read (| t |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + rhs_sum, + M.read (| i |) + |), + M.call_closure (| + U, + M.get_trait_method (| + "core::ops::arith::Add", + U, + [], + [ U ], + "add", + [], + [] + |), + [ M.read (| s |); M.read (| t |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ even_s_conv : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ HALF_N ] [ V ] ] := + M.alloc (| + repeat (| + M.call_closure (| + V, + M.get_trait_method (| "core::default::Default", V, [], [], "default", [], [] |), + [] + |), + HALF_N + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ V ], + "split_at_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |); HALF_N ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left := M.copy (| γ0_0 |) in + let right := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::function::Fn", + NC, + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "array") [ HALF_N ] [ T ]; + Ty.apply (Ty.path "array") [ HALF_N ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, inner_negacyclic_conv |); + Value.Tuple + [ + M.read (| lhs_even |); + M.read (| rhs_even |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, even_s_conv |) |) + |)) + ] + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::function::Fn", + NC, + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "array") [ HALF_N ] [ T ]; + Ty.apply (Ty.path "array") [ HALF_N ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, inner_negacyclic_conv |); + Value.Tuple + [ + M.read (| lhs_odd |); + M.read (| rhs_odd |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| left |) |) |) + ] + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::function::Fn", + NC, + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "array") [ HALF_N ] [ T ]; + Ty.apply (Ty.path "array") [ HALF_N ] [ U ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ V ] ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, inner_negacyclic_conv |); + Value.Tuple + [ + M.read (| lhs_sum |); + M.read (| rhs_sum |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| right |) |) |) + ] + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + V, + [], + [ V ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| right |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + V, + M.get_trait_method (| + "core::ops::arith::Add", + V, + [], + [ V ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + even_s_conv, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| left |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + V, + [], + [ V ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + even_s_conv, + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| left |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ HALF_N; Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 1); ("end_", HALF_N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::SubAssign", + V, + [], + [ V ], + "sub_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| right |) |), + M.read (| i |) + |) + |); + M.call_closure (| + V, + M.get_trait_method (| + "core::ops::arith::Add", + V, + [], + [ V ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + even_s_conv, + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| left |) |), + M.read (| i |) + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + V, + [], + [ V ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + even_s_conv, + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| left |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", HALF_N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 2; + M.read (| i |) + ] + |) + |), + M.read (| + M.SubPointer.get_array_field (| + even_s_conv, + M.read (| i |) + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 2; + M.read (| i |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |), + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| output |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| i |); HALF_N ] + |) + |) + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_negacyclic_conv_n_recursive : + M.IsFunction.C + "p3_mds::karatsuba_convolution::negacyclic_conv_n_recursive" + negacyclic_conv_n_recursive. + Admitted. + Global Typeclasses Opaque negacyclic_conv_n_recursive. +End karatsuba_convolution. diff --git a/CoqOfRust/plonky3/mds/src/lib.rs b/CoqOfRust/plonky3/mds/src/lib.rs new file mode 100644 index 000000000..3e5ee260c --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/lib.rs @@ -0,0 +1,15 @@ +//! A library dealing with maximum distance separable transformations. + +#![no_std] + +extern crate alloc; + +use p3_symmetric::Permutation; + +mod butterflies; +pub mod coset_mds; +pub mod integrated_coset_mds; +pub mod karatsuba_convolution; +pub mod util; + +pub trait MdsPermutation: Permutation<[T; WIDTH]> {} diff --git a/CoqOfRust/plonky3/mds/src/lib.v b/CoqOfRust/plonky3/mds/src/lib.v new file mode 100644 index 000000000..235aea3fd --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/lib.v @@ -0,0 +1,5 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +(* Trait *) +(* Empty module 'MdsPermutation' *) diff --git a/CoqOfRust/plonky3/mds/src/util.rs b/CoqOfRust/plonky3/mds/src/util.rs new file mode 100644 index 000000000..0e4c36133 --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/util.rs @@ -0,0 +1,191 @@ +use core::ops::{AddAssign, Mul}; + +use p3_dft::TwoAdicSubgroupDft; +use p3_field::{PrimeCharacteristicRing, TwoAdicField}; + +// NB: These are all MDS for M31, BabyBear and Goldilocks +// const MATRIX_CIRC_MDS_8_2EXP: [u64; 8] = [1, 1, 2, 1, 8, 32, 4, 256]; +// const MATRIX_CIRC_MDS_8_SML: [u64; 8] = [4, 1, 2, 9, 10, 5, 1, 1]; +// Much smaller: [1, 1, -1, 2, 3, 8, 2, -3] but need to deal with the -ve's + +// const MATRIX_CIRC_MDS_12_2EXP: [u64; 12] = [1, 1, 2, 1, 8, 32, 2, 256, 4096, 8, 65536, 1024]; +// const MATRIX_CIRC_MDS_12_SML: [u64; 12] = [9, 7, 4, 1, 16, 2, 256, 128, 3, 32, 1, 1]; +// const MATRIX_CIRC_MDS_12_SML: [u64; 12] = [1, 1, 2, 1, 8, 9, 10, 7, 5, 9, 4, 10]; + +// Trying to maximise the # of 1's in the vector. +// Not clear exactly what we should be optimising here but that seems reasonable. +// const MATRIX_CIRC_MDS_16_SML: [u64; 16] = +// [1, 1, 51, 1, 11, 17, 2, 1, 101, 63, 15, 2, 67, 22, 13, 3]; +// 1, 1, 51, 52, 11, 63, 1, 2, 1, 2, 15, 67, 2, 22, 13, 3 +// [1, 1, 2, 1, 8, 32, 2, 65, 77, 8, 91, 31, 3, 65, 32, 7]; + +/// This will throw an error if N = 0 but it's hard to imagine this case coming up. +#[inline(always)] +pub fn dot_product(u: [T; N], v: [T; N]) -> T +where + T: Copy + AddAssign + Mul, +{ + debug_assert_ne!(N, 0); + let mut dp = u[0] * v[0]; + for i in 1..N { + dp += u[i] * v[i]; + } + dp +} + +/// Given the first row `circ_matrix` of an NxN circulant matrix, say +/// C, return the product `C*input`. +/// +/// NB: This function is a naive implementation of the n² +/// evaluation. It is a placeholder until we have FFT implementations +/// for all combinations of field and size. +pub fn apply_circulant( + circ_matrix: &[u64; N], + input: [R; N], +) -> [R; N] { + let mut matrix = circ_matrix.map(R::from_u64); + + let mut output = [R::ZERO; N]; + for out_i in output.iter_mut().take(N - 1) { + *out_i = R::dot_product(&matrix, &input); + matrix.rotate_right(1); + } + output[N - 1] = R::dot_product(&matrix, &input); + output +} + +/// Given the first row of a circulant matrix, return the first column. +/// +/// For example if, `v = [0, 1, 2, 3, 4, 5]` then `output = [0, 5, 4, 3, 2, 1]`, +/// i.e. the first element is the same and the other elements are reversed. +/// +/// This is useful to prepare a circulant matrix for input to an FFT +/// algorithm, which expects the first column of the matrix rather +/// than the first row (as we normally store them). +/// +/// NB: The algorithm is inefficient but simple enough that this +/// function can be declared `const`, and that is the intended context +/// for use. +pub const fn first_row_to_first_col(v: &[T; N]) -> [T; N] { + let mut output = *v; + let mut i = 1; + while i < N { + // Reverse elements + output[i] = v[N - i]; + i += 1; + } + output +} + +/// Use the convolution theorem to calculate the product of the given +/// circulant matrix and the given vector. +/// +/// The circulant matrix must be specified by its first *column*, not its first row. If you have +/// the row as an array, you can obtain the column with `first_row_to_first_col()`. +#[inline] +pub fn apply_circulant_fft>( + fft: FFT, + column: [u64; N], + input: &[F; N], +) -> [F; N] { + let column = column.map(F::from_u64).to_vec(); + let matrix = fft.dft(column); + let input = fft.dft(input.to_vec()); + + // point-wise product + let product = matrix.iter().zip(input).map(|(&x, y)| x * y).collect(); + + let output = fft.idft(product); + output.try_into().unwrap() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_first_row_to_first_col_even_length() { + let input = [0, 1, 2, 3, 4, 5]; + let output = [0, 5, 4, 3, 2, 1]; + + assert_eq!(first_row_to_first_col(&input), output); + } + + #[test] + fn test_first_row_to_first_col_odd_length() { + let input = [10, 20, 30, 40, 50]; + let output = [10, 50, 40, 30, 20]; + + assert_eq!(first_row_to_first_col(&input), output); + } + + #[test] + fn test_first_row_to_first_col_single_element() { + let input = [42]; + let output = [42]; + + assert_eq!(first_row_to_first_col(&input), output); + } + + #[test] + fn test_first_row_to_first_col_all_zeros() { + let input = [0; 6]; + let output = [0; 6]; + + assert_eq!(first_row_to_first_col(&input), output); + } + + #[test] + fn test_first_row_to_first_col_negative_numbers() { + let input = [-1, -2, -3, -4]; + let output = [-1, -4, -3, -2]; + + assert_eq!(first_row_to_first_col(&input), output); + } + + #[test] + fn test_first_row_to_first_col_large_numbers() { + let input = [1_000_000, 2_000_000, 3_000_000, 4_000_000]; + let output = [1_000_000, 4_000_000, 3_000_000, 2_000_000]; + + assert_eq!(first_row_to_first_col(&input), output); + } + + #[test] + fn test_basic_dot_product() { + let u = [1, 2, 3]; + let v = [4, 5, 6]; + assert_eq!(dot_product(u, v), 4 + 2 * 5 + 3 * 6); + } + + #[test] + fn test_single_element() { + let u = [7]; + let v = [8]; + assert_eq!(dot_product(u, v), 7 * 8); + } + + #[test] + fn test_all_zeros() { + let u = [0; 4]; + let v = [0; 4]; + assert_eq!(dot_product(u, v), 0); + } + + #[test] + fn test_negative_numbers() { + let u = [-1, -2, -3]; + let v = [-4, -5, -6]; + assert_eq!(dot_product(u, v), (-1) * (-4) + (-2) * (-5) + (-3) * (-6)); + } + + #[test] + fn test_large_numbers() { + let u = [1_000_000, 2_000_000, 3_000_000]; + let v = [4, 5, 6]; + assert_eq!( + dot_product(u, v), + 1_000_000 * 4 + 2_000_000 * 5 + 3_000_000 * 6 + ); + } +} diff --git a/CoqOfRust/plonky3/mds/src/util.v b/CoqOfRust/plonky3/mds/src/util.v new file mode 100644 index 000000000..d1ef560c1 --- /dev/null +++ b/CoqOfRust/plonky3/mds/src/util.v @@ -0,0 +1,1020 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module util. + (* + pub fn dot_product(u: [T; N], v: [T; N]) -> T + where + T: Copy + AddAssign + Mul, + { + debug_assert_ne!(N, 0); + let mut dp = u[0] * v[0]; + for i in 1..N { + dp += u[i] * v[i]; + } + dp + } + *) + Definition dot_product (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ T ], [ u; v ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + let v := M.alloc (| v |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 0 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Ne" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ dp : Ty.apply (Ty.path "*") [] [ T ] := + M.alloc (| + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Mul", T, [], [ T ], "mul", [], [] |), + [ + M.read (| + M.SubPointer.get_array_field (| u, Value.Integer IntegerKind.Usize 0 |) + |); + M.read (| + M.SubPointer.get_array_field (| v, Value.Integer IntegerKind.Usize 0 |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 1); ("end_", N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + T, + [], + [ T ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, dp |); + M.call_closure (| + T, + M.get_trait_method (| + "core::ops::arith::Mul", + T, + [], + [ T ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + u, + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + v, + M.read (| i |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + dp + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dot_product : + M.IsFunction.C "p3_mds::util::dot_product" dot_product. + Admitted. + Global Typeclasses Opaque dot_product. + + (* + pub fn apply_circulant( + circ_matrix: &[u64; N], + input: [R; N], + ) -> [R; N] { + let mut matrix = circ_matrix.map(R::from_u64); + + let mut output = [R::ZERO; N]; + for out_i in output.iter_mut().take(N - 1) { + *out_i = R::dot_product(&matrix, &input); + matrix.rotate_right(1); + } + output[N - 1] = R::dot_product(&matrix, &input); + output + } + *) + Definition apply_circulant (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ R ], [ circ_matrix; input ] => + ltac:(M.monadic + (let circ_matrix := M.alloc (| circ_matrix |) in + let input := M.alloc (| input |) in + M.read (| + let~ matrix : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ N ] [ R ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u64" ], + "map", + [], + [ Ty.function [ Ty.path "u64" ] R; R ] + |), + [ + M.read (| M.deref (| M.read (| circ_matrix |) |) |); + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "from_u64", + [], + [] + |) + ] + |) + |) in + let~ output : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ N ] [ R ] ] := + M.alloc (| + repeat (| + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", R |) |), + N + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ R ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ R ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion (M.borrow (| Pointer.Kind.MutRef, output |)) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ N; Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&mut") [] [ R ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ R ] ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let out_i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| out_i |) |), + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ N ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, matrix |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, input |) |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "rotate_right", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.MutRef, matrix |)); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + output, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ N; Value.Integer IntegerKind.Usize 1 ] + |) + |), + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "dot_product", + [ N ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, matrix |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, input |) |) + |) + ] + |) + |) + |) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_apply_circulant : + M.IsFunction.C "p3_mds::util::apply_circulant" apply_circulant. + Admitted. + Global Typeclasses Opaque apply_circulant. + + (* + pub const fn first_row_to_first_col(v: &[T; N]) -> [T; N] { + let mut output = *v; + let mut i = 1; + while i < N { + // Reverse elements + output[i] = v[N - i]; + i += 1; + } + output + } + *) + Definition first_row_to_first_col (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ T ], [ v ] => + ltac:(M.monadic + (let v := M.alloc (| v |) in + M.read (| + let~ output : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ N ] [ T ] ] := + M.copy (| M.deref (| M.read (| v |) |) |) in + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| Ty.path "bool", BinOp.lt, [ M.read (| i |); N ] |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| output, M.read (| i |) |), + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| v |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ N; M.read (| i |) ] + |) + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_first_row_to_first_col : + M.IsFunction.C "p3_mds::util::first_row_to_first_col" first_row_to_first_col. + Admitted. + Global Typeclasses Opaque first_row_to_first_col. + + (* + pub fn apply_circulant_fft>( + fft: FFT, + column: [u64; N], + input: &[F; N], + ) -> [F; N] { + let column = column.map(F::from_u64).to_vec(); + let matrix = fft.dft(column); + let input = fft.dft(input.to_vec()); + + // point-wise product + let product = matrix.iter().zip(input).map(|(&x, y)| x * y).collect(); + + let output = fft.idft(product); + output.try_into().unwrap() + } + *) + Definition apply_circulant_fft (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ F; FFT ], [ fft; column; input ] => + ltac:(M.monadic + (let fft := M.alloc (| fft |) in + let column := M.alloc (| column |) in + let input := M.alloc (| input |) in + M.read (| + let~ column : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "to_vec", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u64" ], + "map", + [], + [ Ty.function [ Ty.path "u64" ] F; F ] + |), + [ + M.read (| column |); + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_u64", + [], + [] + |) + ] + |) + |) + |)) + ] + |) + |) in + let~ matrix : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + FFT, + [], + [ F ], + "dft", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, fft |); M.read (| column |) ] + |) + |) in + let~ input : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + FFT, + [], + [ F ], + "dft", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, fft |); + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "to_vec", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |)) + ] + |) + ] + |) + |) in + let~ product : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ]; F ] ] ] F + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ]; + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ]; F ] ] ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ]; F ] ] ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, matrix |) ] + |) + |) + |) + ] + |); + M.read (| input |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ F ]; F ] ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ output : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + FFT, + [], + [ F ], + "idft", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, fft |); M.read (| product |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ N ] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ F ]; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ F ]; + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ F ] ], + "try_into", + [], + [] + |), + [ M.read (| output |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_apply_circulant_fft : + M.IsFunction.C "p3_mds::util::apply_circulant_fft" apply_circulant_fft. + Admitted. + Global Typeclasses Opaque apply_circulant_fft. +End util. diff --git a/CoqOfRust/plonky3/merkle-tree/src/hiding_mmcs.rs b/CoqOfRust/plonky3/merkle-tree/src/hiding_mmcs.rs new file mode 100644 index 000000000..18f7b9f7f --- /dev/null +++ b/CoqOfRust/plonky3/merkle-tree/src/hiding_mmcs.rs @@ -0,0 +1,204 @@ +use alloc::vec::Vec; +use core::cell::RefCell; + +use itertools::Itertools; +use p3_commit::Mmcs; +use p3_field::PackedValue; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::stack::HorizontalPair; +use p3_matrix::{Dimensions, Matrix}; +use p3_symmetric::{CryptographicHasher, Hash, PseudoCompressionFunction}; +use p3_util::zip_eq::zip_eq; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; +use serde::de::DeserializeOwned; +use serde::{Deserialize, Serialize}; + +use crate::{MerkleTree, MerkleTreeError, MerkleTreeMmcs}; + +/// A vector commitment scheme backed by a `MerkleTree`. +/// +/// This is similar to `MerkleTreeMmcs`, but each leaf is "salted" with random elements. This is +/// done to turn the Merkle tree into a hiding commitment. See e.g. Section 3 of +/// [Interactive Oracle Proofs](https://eprint.iacr.org/2016/116). +/// +/// `SALT_ELEMS` should be set such that the product of `SALT_ELEMS` with the size of the value +/// (`P::Value`) is at least the target security parameter. +/// +/// `R` should be an appropriately seeded cryptographically secure pseudorandom number generator +/// (CSPRNG). Something like `ThreadRng` may work, although it relies on the operating system to +/// provide sufficient entropy. +/// +/// Generics: +/// - `P`: a leaf value +/// - `PW`: an element of a digest +/// - `H`: the leaf hasher +/// - `C`: the digest compression function +/// - `R`: a random number generator for blinding leaves +#[derive(Clone, Debug)] +pub struct MerkleTreeHidingMmcs +{ + inner: MerkleTreeMmcs, + rng: RefCell, +} + +impl + MerkleTreeHidingMmcs +{ + pub fn new(hash: H, compress: C, rng: R) -> Self { + let inner = MerkleTreeMmcs::new(hash, compress); + Self { + inner, + rng: rng.into(), + } + } +} + +impl Mmcs + for MerkleTreeHidingMmcs +where + P: PackedValue, + P::Value: Serialize + DeserializeOwned, + PW: PackedValue, + H: CryptographicHasher + + CryptographicHasher + + Sync, + C: PseudoCompressionFunction<[PW::Value; DIGEST_ELEMS], 2> + + PseudoCompressionFunction<[PW; DIGEST_ELEMS], 2> + + Sync, + R: Rng + Clone, + PW::Value: Eq, + [PW::Value; DIGEST_ELEMS]: Serialize + for<'de> Deserialize<'de>, + StandardUniform: Distribution, +{ + type ProverData = + MerkleTree>, DIGEST_ELEMS>; + type Commitment = Hash; + /// The first item is salts; the second is the usual Merkle proof (sibling digests). + type Proof = (Vec>, Vec<[PW::Value; DIGEST_ELEMS]>); + type Error = MerkleTreeError; + + fn commit>( + &self, + inputs: Vec, + ) -> (Self::Commitment, Self::ProverData) { + let salted_inputs = inputs + .into_iter() + .map(|mat| { + let salts = + RowMajorMatrix::rand(&mut *self.rng.borrow_mut(), mat.height(), SALT_ELEMS); + HorizontalPair::new(mat, salts) + }) + .collect(); + self.inner.commit(salted_inputs) + } + + fn open_batch>( + &self, + index: usize, + prover_data: &Self::ProverData, + ) -> (Vec>, Self::Proof) { + let (salted_openings, siblings) = self.inner.open_batch(index, prover_data); + let (openings, salts): (Vec<_>, Vec<_>) = salted_openings + .into_iter() + .map(|row| { + let (a, b) = row.split_at(row.len() - SALT_ELEMS); + (a.to_vec(), b.to_vec()) + }) + .unzip(); + (openings, (salts, siblings)) + } + + fn get_matrices<'a, M: Matrix>( + &self, + prover_data: &'a Self::ProverData, + ) -> Vec<&'a M> { + prover_data.leaves.iter().map(|mat| &mat.first).collect() + } + + fn verify_batch( + &self, + commit: &Self::Commitment, + dimensions: &[Dimensions], + index: usize, + opened_values: &[Vec], + proof: &Self::Proof, + ) -> Result<(), Self::Error> { + let (salts, siblings) = proof; + + let opened_salted_values = zip_eq(opened_values, salts, MerkleTreeError::WrongBatchSize)? + .map(|(opened, salt)| opened.iter().chain(salt.iter()).copied().collect_vec()) + .collect_vec(); + + self.inner + .verify_batch(commit, dimensions, index, &opened_salted_values, siblings) + } +} + +#[cfg(test)] +mod tests { + use alloc::vec; + + use itertools::Itertools; + use p3_baby_bear::{BabyBear, Poseidon2BabyBear}; + use p3_commit::Mmcs; + use p3_field::{Field, PrimeCharacteristicRing}; + use p3_matrix::Matrix; + use p3_matrix::dense::RowMajorMatrix; + use p3_symmetric::{PaddingFreeSponge, TruncatedPermutation}; + use rand::SeedableRng; + use rand::rngs::SmallRng; + + use super::MerkleTreeHidingMmcs; + use crate::MerkleTreeError; + + type F = BabyBear; + const SALT_ELEMS: usize = 4; + + type Perm = Poseidon2BabyBear<16>; + type MyHash = PaddingFreeSponge; + type MyCompress = TruncatedPermutation; + type MyMmcs = MerkleTreeHidingMmcs< + ::Packing, + ::Packing, + MyHash, + MyCompress, + SmallRng, + 8, + SALT_ELEMS, + >; + + #[test] + #[should_panic] + fn mismatched_heights() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash, compress, rng); + + // attempt to commit to a mat with 8 rows and a mat with 7 rows. this should panic. + let large_mat = RowMajorMatrix::new([1, 2, 3, 4, 5, 6, 7, 8].map(F::from_u8).to_vec(), 1); + let small_mat = RowMajorMatrix::new([1, 2, 3, 4, 5, 6, 7].map(F::from_u8).to_vec(), 1); + let _ = mmcs.commit(vec![large_mat, small_mat]); + } + + #[test] + fn different_widths() -> Result<(), MerkleTreeError> { + let mut rng = SmallRng::seed_from_u64(1); + // 10 mats with 32 rows where the ith mat has i + 1 cols + let mats = (0..10) + .map(|i| RowMajorMatrix::::rand(&mut rng, 32, i + 1)) + .collect_vec(); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash, compress, rng); + + let dims = mats.iter().map(|m| m.dimensions()).collect_vec(); + + let (commit, prover_data) = mmcs.commit(mats); + let (opened_values, proof) = mmcs.open_batch(17, &prover_data); + mmcs.verify_batch(&commit, &dims, 17, &opened_values, &proof) + } +} diff --git a/CoqOfRust/plonky3/merkle-tree/src/hiding_mmcs.v b/CoqOfRust/plonky3/merkle-tree/src/hiding_mmcs.v new file mode 100644 index 000000000..2d2b18382 --- /dev/null +++ b/CoqOfRust/plonky3/merkle-tree/src/hiding_mmcs.v @@ -0,0 +1,4090 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module hiding_mmcs. + (* StructRecord + { + name := "MerkleTreeHidingMmcs"; + const_params := [ "DIGEST_ELEMS"; "SALT_ELEMS" ]; + ty_params := [ "P"; "PW"; "H"; "C"; "R" ]; + fields := + [ + ("inner", + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ]); + ("rng", Ty.apply (Ty.path "core::cell::RefCell") [] [ R ]) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_P_where_core_clone_Clone_PW_where_core_clone_Clone_H_where_core_clone_Clone_C_where_core_clone_Clone_R_for_p3_merkle_tree_hiding_mmcs_MerkleTreeHidingMmcs_DIGEST_ELEMS_SALT_ELEMS_P_PW_H_C_R. + Definition Self (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs") + [ DIGEST_ELEMS; SALT_ELEMS ] + [ P; PW; H; C; R ]. + + (* Clone *) + Definition clone + (DIGEST_ELEMS SALT_ELEMS : Value.t) + (P PW H C R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS SALT_ELEMS P PW H C R in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs" + [ + ("inner", + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs", + "inner" + |) + |) + |) + |) + ] + |)); + ("rng", + M.call_closure (| + Ty.apply (Ty.path "core::cell::RefCell") [] [ R ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::cell::RefCell") [] [ R ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs", + "rng" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS SALT_ELEMS P PW H C R) + (* Instance *) + [ ("clone", InstanceField.Method (clone DIGEST_ELEMS SALT_ELEMS P PW H C R)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_P_where_core_clone_Clone_PW_where_core_clone_Clone_H_where_core_clone_Clone_C_where_core_clone_Clone_R_for_p3_merkle_tree_hiding_mmcs_MerkleTreeHidingMmcs_DIGEST_ELEMS_SALT_ELEMS_P_PW_H_C_R. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_P_where_core_fmt_Debug_PW_where_core_fmt_Debug_H_where_core_fmt_Debug_C_where_core_fmt_Debug_R_for_p3_merkle_tree_hiding_mmcs_MerkleTreeHidingMmcs_DIGEST_ELEMS_SALT_ELEMS_P_PW_H_C_R. + Definition Self (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs") + [ DIGEST_ELEMS; SALT_ELEMS ] + [ P; PW; H; C; R ]. + + (* Debug *) + Definition fmt + (DIGEST_ELEMS SALT_ELEMS : Value.t) + (P PW H C R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS SALT_ELEMS P PW H C R in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "MerkleTreeHidingMmcs" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inner" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs", + "inner" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "rng" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs", + "rng" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS SALT_ELEMS P PW H C R) + (* Instance *) [ ("fmt", InstanceField.Method (fmt DIGEST_ELEMS SALT_ELEMS P PW H C R)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_P_where_core_fmt_Debug_PW_where_core_fmt_Debug_H_where_core_fmt_Debug_C_where_core_fmt_Debug_R_for_p3_merkle_tree_hiding_mmcs_MerkleTreeHidingMmcs_DIGEST_ELEMS_SALT_ELEMS_P_PW_H_C_R. + + Module Impl_p3_merkle_tree_hiding_mmcs_MerkleTreeHidingMmcs_DIGEST_ELEMS_SALT_ELEMS_P_PW_H_C_R. + Definition Self (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs") + [ DIGEST_ELEMS; SALT_ELEMS ] + [ P; PW; H; C; R ]. + + (* + pub fn new(hash: H, compress: C, rng: R) -> Self { + let inner = MerkleTreeMmcs::new(hash, compress); + Self { + inner, + rng: rng.into(), + } + } + *) + Definition new + (DIGEST_ELEMS SALT_ELEMS : Value.t) + (P PW H C R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS SALT_ELEMS P PW H C R in + match ε, τ, α with + | [], [], [ hash; compress; rng ] => + ltac:(M.monadic + (let hash := M.alloc (| hash |) in + let compress := M.alloc (| compress |) in + let rng := M.alloc (| rng |) in + M.read (| + let~ inner : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ], + "new", + [], + [] + |), + [ M.read (| hash |); M.read (| compress |) ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs" + [ + ("inner", M.read (| inner |)); + ("rng", + M.call_closure (| + Ty.apply (Ty.path "core::cell::RefCell") [] [ R ], + M.get_trait_method (| + "core::convert::Into", + R, + [], + [ Ty.apply (Ty.path "core::cell::RefCell") [] [ R ] ], + "into", + [], + [] + |), + [ M.read (| rng |) ] + |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t), + M.IsAssociatedFunction.C + (Self DIGEST_ELEMS SALT_ELEMS P PW H C R) + "new" + (new DIGEST_ELEMS SALT_ELEMS P PW H C R). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_merkle_tree_hiding_mmcs_MerkleTreeHidingMmcs_DIGEST_ELEMS_SALT_ELEMS_P_PW_H_C_R. + + Module Impl_p3_commit_mmcs_Mmcs_where_p3_field_packed_PackedValue_P_where_serde_ser_Serialize_associated_in_trait_p3_field_packed_PackedValue___P_Value_where_serde_de_DeserializeOwned_associated_in_trait_p3_field_packed_PackedValue___P_Value_where_p3_field_packed_PackedValue_PW_where_p3_symmetric_hasher_CryptographicHasher_H_associated_in_trait_p3_field_packed_PackedValue___P_Value_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_p3_symmetric_hasher_CryptographicHasher_H_P_array_DIGEST_ELEMS_PW_where_core_marker_Sync_H_where_p3_symmetric_compression_PseudoCompressionFunction_C_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_p3_symmetric_compression_PseudoCompressionFunction_C_array_DIGEST_ELEMS_PW_where_core_marker_Sync_C_where_rand_rng_Rng_R_where_core_clone_Clone_R_where_core_cmp_Eq_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_serde_ser_Serialize_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_serde_de_Deserialize_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_rand_distr_distribution_Distribution_rand_distr_StandardUniform_associated_in_trait_p3_field_packed_PackedValue___P_Value_associated_in_trait_p3_field_packed_PackedValue___P_Value_for_p3_merkle_tree_hiding_mmcs_MerkleTreeHidingMmcs_DIGEST_ELEMS_SALT_ELEMS_P_PW_H_C_R. + Definition Self (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs") + [ DIGEST_ELEMS; SALT_ELEMS ] + [ P; PW; H; C; R ]. + + (* + type ProverData = + MerkleTree>, DIGEST_ELEMS>; + *) + Definition _ProverData (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value"; + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]. + + (* type Commitment = Hash; *) + Definition _Commitment (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::hash::Hash") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ]. + + (* type Proof = (Vec>, Vec<[PW::Value; DIGEST_ELEMS]>); *) + Definition _Proof (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t) : Ty.t := + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" ]; + Ty.path "alloc::alloc::Global" + ] + ]. + + (* type Error = MerkleTreeError; *) + Definition _Error (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t) : Ty.t := + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError". + + (* + fn commit>( + &self, + inputs: Vec, + ) -> (Self::Commitment, Self::ProverData) { + let salted_inputs = inputs + .into_iter() + .map(|mat| { + let salts = + RowMajorMatrix::rand(&mut *self.rng.borrow_mut(), mat.height(), SALT_ELEMS); + HorizontalPair::new(mat, salts) + }) + .collect(); + self.inner.commit(salted_inputs) + } + *) + Definition commit + (DIGEST_ELEMS SALT_ELEMS : Value.t) + (P PW H C R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS SALT_ELEMS P PW H C R in + match ε, τ, α with + | [], [ M_ ], [ self; inputs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let inputs := M.alloc (| inputs |) in + M.read (| + let~ salted_inputs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ M_; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ M_ ] ] + (Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ M_; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ M_ ] ] + (Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ M_; Ty.path "alloc::alloc::Global" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ Ty.tuple [ M_ ] ] + (Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ M_; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| inputs |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ M_ ] ] + (Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let mat := M.copy (| γ |) in + M.read (| + let~ salts : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ], + "rand", + [], + [ R ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ R ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "core::cell::RefMut") + [] + [ R ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::cell::RefMut") + [] + [ R ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::cell::RefCell") + [] + [ R ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs", + "rng" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |); + SALT_ELEMS + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "new", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + |), + [ M.read (| mat |); M.read (| salts |) ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "p3_symmetric::hash::Hash") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ]; + Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value"; + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ], + [], + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ], + "commit", + [], + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs", + "inner" + |) + |); + M.read (| salted_inputs |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn open_batch>( + &self, + index: usize, + prover_data: &Self::ProverData, + ) -> (Vec>, Self::Proof) { + let (salted_openings, siblings) = self.inner.open_batch(index, prover_data); + let (openings, salts): (Vec<_>, Vec<_>) = salted_openings + .into_iter() + .map(|row| { + let (a, b) = row.split_at(row.len() - SALT_ELEMS); + (a.to_vec(), b.to_vec()) + }) + .unzip(); + (openings, (salts, siblings)) + } + *) + Definition open_batch + (DIGEST_ELEMS SALT_ELEMS : Value.t) + (P PW H C R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS SALT_ELEMS P PW H C R in + match ε, τ, α with + | [], [ M_ ], [ self; index; prover_data ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let index := M.alloc (| index |) in + let prover_data := M.alloc (| prover_data |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ], + [], + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ], + "open_batch", + [], + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs", + "inner" + |) + |); + M.read (| index |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| prover_data |) |) |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let salted_openings := M.copy (| γ0_0 |) in + let siblings := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]) + ], + [], + [], + "unzip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| salted_openings |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let row := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "split_at", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + row + |) + ] + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + row + |) + ] + |); + SALT_ELEMS + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let a := M.copy (| γ0_0 |) in + let b := M.copy (| γ0_1 |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| a |) |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| b |) |) + |) + ] + |) + ] + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let openings := M.copy (| γ0_0 |) in + let salts := M.copy (| γ0_1 |) in + M.alloc (| + Value.Tuple + [ + M.read (| openings |); + Value.Tuple [ M.read (| salts |); M.read (| siblings |) ] + ] + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn get_matrices<'a, M: Matrix>( + &self, + prover_data: &'a Self::ProverData, + ) -> Vec<&'a M> { + prover_data.leaves.iter().map(|mat| &mat.first).collect() + } + *) + Definition get_matrices + (DIGEST_ELEMS SALT_ELEMS : Value.t) + (P PW H C R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS SALT_ELEMS P PW H C R in + match ε, τ, α with + | [], [ M_ ], [ self; prover_data ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let prover_data := M.alloc (| prover_data |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply (Ty.path "&") [] [ M_ ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply (Ty.path "&") [] [ M_ ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply (Ty.path "&") [] [ M_ ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| prover_data |) |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "leaves" + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::HorizontalPair") + [] + [ + M_; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + ] + (Ty.apply (Ty.path "&") [] [ M_ ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let mat := M.copy (| γ |) in + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| mat |) |), + "p3_matrix::stack::HorizontalPair", + "first" + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn verify_batch( + &self, + commit: &Self::Commitment, + dimensions: &[Dimensions], + index: usize, + opened_values: &[Vec], + proof: &Self::Proof, + ) -> Result<(), Self::Error> { + let (salts, siblings) = proof; + + let opened_salted_values = zip_eq(opened_values, salts, MerkleTreeError::WrongBatchSize)? + .map(|(opened, salt)| opened.iter().chain(salt.iter()).copied().collect_vec()) + .collect_vec(); + + self.inner + .verify_batch(commit, dimensions, index, &opened_salted_values, siblings) + } + *) + Definition verify_batch + (DIGEST_ELEMS SALT_ELEMS : Value.t) + (P PW H C R : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS SALT_ELEMS P PW H C R in + match ε, τ, α with + | [], [], [ self; commit; dimensions; index; opened_values; proof ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let commit := M.alloc (| commit |) in + let dimensions := M.alloc (| dimensions |) in + let index := M.alloc (| index |) in + let opened_values := M.alloc (| opened_values |) in + let proof := M.alloc (| proof |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ] + (Ty.apply + (Ty.path "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs") + [ DIGEST_ELEMS; SALT_ELEMS ] + [ P; PW; H; C; R ]) + "Error" + ]) (| + ltac:(M.monadic + (M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" ] + ], + proof, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let salts := M.alloc (| γ1_0 |) in + let siblings := M.alloc (| γ1_1 |) in + let~ opened_salted_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" + ]; + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" + ] + |), + [ + M.read (| opened_values |); + M.read (| salts |); + Value.StructTuple + "p3_merkle_tree::mmcs::MerkleTreeError::WrongBatchSize" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.path + "p3_merkle_tree::mmcs::MerkleTreeError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.path + "p3_merkle_tree::mmcs::MerkleTreeError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "p3_merkle_tree::mmcs::MerkleTreeError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let opened := M.copy (| γ0_0 |) in + let salt := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + [], + [], + "copied", + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + opened + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| salt |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" ], + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ], + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "verify_batch", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::hiding_mmcs::MerkleTreeHidingMmcs", + "inner" + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| commit |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| dimensions |) |) + |); + M.read (| index |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, opened_salted_values |) + |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| siblings |) |) |) + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS SALT_ELEMS : Value.t) (P PW H C R : Ty.t), + M.IsTraitInstance + "p3_commit::mmcs::Mmcs" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ] + (Self DIGEST_ELEMS SALT_ELEMS P PW H C R) + (* Instance *) + [ + ("ProverData", InstanceField.Ty (_ProverData DIGEST_ELEMS SALT_ELEMS P PW H C R)); + ("Commitment", InstanceField.Ty (_Commitment DIGEST_ELEMS SALT_ELEMS P PW H C R)); + ("Proof", InstanceField.Ty (_Proof DIGEST_ELEMS SALT_ELEMS P PW H C R)); + ("Error", InstanceField.Ty (_Error DIGEST_ELEMS SALT_ELEMS P PW H C R)); + ("commit", InstanceField.Method (commit DIGEST_ELEMS SALT_ELEMS P PW H C R)); + ("open_batch", InstanceField.Method (open_batch DIGEST_ELEMS SALT_ELEMS P PW H C R)); + ("get_matrices", InstanceField.Method (get_matrices DIGEST_ELEMS SALT_ELEMS P PW H C R)); + ("verify_batch", InstanceField.Method (verify_batch DIGEST_ELEMS SALT_ELEMS P PW H C R)) + ]. + End Impl_p3_commit_mmcs_Mmcs_where_p3_field_packed_PackedValue_P_where_serde_ser_Serialize_associated_in_trait_p3_field_packed_PackedValue___P_Value_where_serde_de_DeserializeOwned_associated_in_trait_p3_field_packed_PackedValue___P_Value_where_p3_field_packed_PackedValue_PW_where_p3_symmetric_hasher_CryptographicHasher_H_associated_in_trait_p3_field_packed_PackedValue___P_Value_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_p3_symmetric_hasher_CryptographicHasher_H_P_array_DIGEST_ELEMS_PW_where_core_marker_Sync_H_where_p3_symmetric_compression_PseudoCompressionFunction_C_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_p3_symmetric_compression_PseudoCompressionFunction_C_array_DIGEST_ELEMS_PW_where_core_marker_Sync_C_where_rand_rng_Rng_R_where_core_clone_Clone_R_where_core_cmp_Eq_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_serde_ser_Serialize_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_serde_de_Deserialize_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_rand_distr_distribution_Distribution_rand_distr_StandardUniform_associated_in_trait_p3_field_packed_PackedValue___P_Value_associated_in_trait_p3_field_packed_PackedValue___P_Value_for_p3_merkle_tree_hiding_mmcs_MerkleTreeHidingMmcs_DIGEST_ELEMS_SALT_ELEMS_P_PW_H_C_R. +End hiding_mmcs. diff --git a/CoqOfRust/plonky3/merkle-tree/src/lib.rs b/CoqOfRust/plonky3/merkle-tree/src/lib.rs new file mode 100644 index 000000000..9c9fae516 --- /dev/null +++ b/CoqOfRust/plonky3/merkle-tree/src/lib.rs @@ -0,0 +1,11 @@ +#![no_std] + +extern crate alloc; + +mod hiding_mmcs; +mod merkle_tree; +mod mmcs; + +pub use hiding_mmcs::*; +pub use merkle_tree::*; +pub use mmcs::*; diff --git a/CoqOfRust/plonky3/merkle-tree/src/merkle_tree.rs b/CoqOfRust/plonky3/merkle-tree/src/merkle_tree.rs new file mode 100644 index 000000000..13711cf86 --- /dev/null +++ b/CoqOfRust/plonky3/merkle-tree/src/merkle_tree.rs @@ -0,0 +1,364 @@ +use alloc::vec; +use alloc::vec::Vec; +use core::array; +use core::cmp::Reverse; +use core::marker::PhantomData; + +use itertools::Itertools; +use p3_field::PackedValue; +use p3_matrix::Matrix; +use p3_maybe_rayon::prelude::*; +use p3_symmetric::{CryptographicHasher, Hash, PseudoCompressionFunction}; +use serde::{Deserialize, Serialize}; +use tracing::instrument; + +/// A binary Merkle tree for packed data. It has leaves of type `F` and digests of type +/// `[W; DIGEST_ELEMS]`. +/// +/// This generally shouldn't be used directly. If you're using a Merkle tree as an MMCS, +/// see `MerkleTreeMmcs`. +#[derive(Debug, Serialize, Deserialize)] +pub struct MerkleTree { + pub(crate) leaves: Vec, + // Enable serialization for this type whenever the underlying array type supports it (len 1-32). + #[serde(bound(serialize = "[W; DIGEST_ELEMS]: Serialize"))] + // Enable deserialization for this type whenever the underlying array type supports it (len 1-32). + #[serde(bound(deserialize = "[W; DIGEST_ELEMS]: Deserialize<'de>"))] + pub(crate) digest_layers: Vec>, + _phantom: PhantomData, +} + +impl, const DIGEST_ELEMS: usize> + MerkleTree +{ + /// Matrix heights need not be powers of two. However, if the heights of two given matrices + /// round up to the same power of two, they must be equal. + #[instrument(name = "build merkle tree", level = "debug", skip_all, + fields(dimensions = alloc::format!("{:?}", leaves.iter().map(|l| l.dimensions()).collect::>())))] + pub fn new(h: &H, c: &C, leaves: Vec) -> Self + where + P: PackedValue, + PW: PackedValue, + H: CryptographicHasher + + CryptographicHasher + + Sync, + C: PseudoCompressionFunction<[W; DIGEST_ELEMS], 2> + + PseudoCompressionFunction<[PW; DIGEST_ELEMS], 2> + + Sync, + { + assert!(!leaves.is_empty(), "No matrices given?"); + + assert_eq!(P::WIDTH, PW::WIDTH, "Packing widths must match"); + + let mut leaves_largest_first = leaves + .iter() + .sorted_by_key(|l| Reverse(l.height())) + .peekable(); + + // check height property + assert!( + leaves_largest_first + .clone() + .map(|m| m.height()) + .tuple_windows() + .all(|(curr, next)| curr == next + || curr.next_power_of_two() != next.next_power_of_two()), + "matrix heights that round up to the same power of two must be equal" + ); + + let max_height = leaves_largest_first.peek().unwrap().height(); + let tallest_matrices = leaves_largest_first + .peeking_take_while(|m| m.height() == max_height) + .collect_vec(); + + let mut digest_layers = vec![first_digest_layer::( + h, + tallest_matrices, + )]; + loop { + let prev_layer = digest_layers.last().unwrap().as_slice(); + if prev_layer.len() == 1 { + break; + } + let next_layer_len = (prev_layer.len() / 2).next_power_of_two(); + + // The matrices that get injected at this layer. + let matrices_to_inject = leaves_largest_first + .peeking_take_while(|m| m.height().next_power_of_two() == next_layer_len) + .collect_vec(); + + let next_digests = compress_and_inject::( + prev_layer, + matrices_to_inject, + h, + c, + ); + digest_layers.push(next_digests); + } + + Self { + leaves, + digest_layers, + _phantom: PhantomData, + } + } + + #[must_use] + pub fn root(&self) -> Hash + where + W: Copy, + { + self.digest_layers.last().unwrap()[0].into() + } +} + +#[instrument(name = "first digest layer", level = "debug", skip_all)] +fn first_digest_layer( + h: &H, + tallest_matrices: Vec<&M>, +) -> Vec<[PW::Value; DIGEST_ELEMS]> +where + P: PackedValue, + PW: PackedValue, + H: CryptographicHasher + + CryptographicHasher + + Sync, + M: Matrix, +{ + let width = PW::WIDTH; + let max_height = tallest_matrices[0].height(); + // we always want to return an even number of digests, except when it's the root. + let max_height_padded = if max_height == 1 { + 1 + } else { + max_height + max_height % 2 + }; + + let default_digest = [PW::Value::default(); DIGEST_ELEMS]; + let mut digests = vec![default_digest; max_height_padded]; + + digests[0..max_height] + .par_chunks_exact_mut(width) + .enumerate() + .for_each(|(i, digests_chunk)| { + let first_row = i * width; + let packed_digest: [PW; DIGEST_ELEMS] = h.hash_iter( + tallest_matrices + .iter() + .flat_map(|m| m.vertically_packed_row(first_row)), + ); + for (dst, src) in digests_chunk.iter_mut().zip(unpack_array(packed_digest)) { + *dst = src; + } + }); + + // If our packing width did not divide max_height, fall back to single-threaded scalar code + // for the last bit. + #[allow(clippy::needless_range_loop)] + for i in (max_height / width * width)..max_height { + digests[i] = h.hash_iter(tallest_matrices.iter().flat_map(|m| m.row(i))); + } + + // Everything has been initialized so we can safely cast. + digests +} + +/// Compress `n` digests from the previous layer into `n/2` digests, while potentially mixing in +/// some leaf data, if there are input matrices with (padded) height `n/2`. +fn compress_and_inject( + prev_layer: &[[PW::Value; DIGEST_ELEMS]], + matrices_to_inject: Vec<&M>, + h: &H, + c: &C, +) -> Vec<[PW::Value; DIGEST_ELEMS]> +where + P: PackedValue, + PW: PackedValue, + H: CryptographicHasher + + CryptographicHasher + + Sync, + C: PseudoCompressionFunction<[PW::Value; DIGEST_ELEMS], 2> + + PseudoCompressionFunction<[PW; DIGEST_ELEMS], 2> + + Sync, + M: Matrix, +{ + if matrices_to_inject.is_empty() { + return compress::(prev_layer, c); + } + + let width = PW::WIDTH; + let next_len = matrices_to_inject[0].height(); + // We always want to return an even number of digests, except when it's the root. + let next_len_padded = if prev_layer.len() == 2 { + 1 + } else { + // Round prev_layer.len() / 2 up to the next even integer. + (prev_layer.len() / 2 + 1) & !1 + }; + + let default_digest = [PW::Value::default(); DIGEST_ELEMS]; + let mut next_digests = vec![default_digest; next_len_padded]; + next_digests[0..next_len] + .par_chunks_exact_mut(width) + .enumerate() + .for_each(|(i, digests_chunk)| { + let first_row = i * width; + let left = array::from_fn(|j| PW::from_fn(|k| prev_layer[2 * (first_row + k)][j])); + let right = array::from_fn(|j| PW::from_fn(|k| prev_layer[2 * (first_row + k) + 1][j])); + let mut packed_digest = c.compress([left, right]); + let tallest_digest = h.hash_iter( + matrices_to_inject + .iter() + .flat_map(|m| m.vertically_packed_row(first_row)), + ); + packed_digest = c.compress([packed_digest, tallest_digest]); + for (dst, src) in digests_chunk.iter_mut().zip(unpack_array(packed_digest)) { + *dst = src; + } + }); + + // If our packing width did not divide next_len, fall back to single-threaded scalar code + // for the last bit. + for i in (next_len / width * width)..next_len { + let left = prev_layer[2 * i]; + let right = prev_layer[2 * i + 1]; + let digest = c.compress([left, right]); + let rows_digest = h.hash_iter(matrices_to_inject.iter().flat_map(|m| m.row(i))); + next_digests[i] = c.compress([digest, rows_digest]); + } + + // At this point, we've exceeded the height of the matrices to inject, so we continue the + // process above except with default_digest in place of an input digest. + // We only need go as far as half the length of the previous layer. + for i in next_len..(prev_layer.len() / 2) { + let left = prev_layer[2 * i]; + let right = prev_layer[2 * i + 1]; + let digest = c.compress([left, right]); + next_digests[i] = c.compress([digest, default_digest]); + } + + next_digests +} + +/// Compress `n` digests from the previous layer into `n/2` digests. +fn compress( + prev_layer: &[[P::Value; DIGEST_ELEMS]], + c: &C, +) -> Vec<[P::Value; DIGEST_ELEMS]> +where + P: PackedValue, + C: PseudoCompressionFunction<[P::Value; DIGEST_ELEMS], 2> + + PseudoCompressionFunction<[P; DIGEST_ELEMS], 2> + + Sync, +{ + let width = P::WIDTH; + // Always return an even number of digests, except when it's the root. + let next_len_padded = if prev_layer.len() == 2 { + 1 + } else { + // Round prev_layer.len() / 2 up to the next even integer. + (prev_layer.len() / 2 + 1) & !1 + }; + let next_len = prev_layer.len() / 2; + + let default_digest = [P::Value::default(); DIGEST_ELEMS]; + let mut next_digests = vec![default_digest; next_len_padded]; + + next_digests[0..next_len] + .par_chunks_exact_mut(width) + .enumerate() + .for_each(|(i, digests_chunk)| { + let first_row = i * width; + let left = array::from_fn(|j| P::from_fn(|k| prev_layer[2 * (first_row + k)][j])); + let right = array::from_fn(|j| P::from_fn(|k| prev_layer[2 * (first_row + k) + 1][j])); + let packed_digest = c.compress([left, right]); + for (dst, src) in digests_chunk.iter_mut().zip(unpack_array(packed_digest)) { + *dst = src; + } + }); + + // If our packing width did not divide next_len, fall back to single-threaded scalar code + // for the last bit. + for i in (next_len / width * width)..next_len { + let left = prev_layer[2 * i]; + let right = prev_layer[2 * i + 1]; + next_digests[i] = c.compress([left, right]); + } + + // Everything has been initialized so we can safely cast. + next_digests +} + +/// Converts a packed array `[P; N]` into its underlying `P::WIDTH` scalar arrays. +#[inline] +fn unpack_array( + packed_digest: [P; N], +) -> impl Iterator { + (0..P::WIDTH).map(move |j| packed_digest.map(|p| p.as_slice()[j])) +} + +#[cfg(test)] +mod tests { + use p3_symmetric::PseudoCompressionFunction; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + + #[derive(Clone, Copy)] + struct DummyCompressionFunction; + + impl PseudoCompressionFunction<[u8; 32], 2> for DummyCompressionFunction { + fn compress(&self, input: [[u8; 32]; 2]) -> [u8; 32] { + let mut output = [0u8; 32]; + for (i, o) in output.iter_mut().enumerate() { + // Simple XOR-based compression + *o = input[0][i] ^ input[1][i]; + } + output + } + } + + #[test] + fn test_compress_even_length() { + let prev_layer = [[0x01; 32], [0x02; 32], [0x03; 32], [0x04; 32]]; + let compressor = DummyCompressionFunction; + let expected = vec![ + [0x03; 32], // 0x01 ^ 0x02 + [0x07; 32], // 0x03 ^ 0x04 + ]; + let result = compress::(&prev_layer, &compressor); + assert_eq!(result, expected); + } + + #[test] + fn test_compress_odd_length() { + let prev_layer = [[0x05; 32], [0x06; 32], [0x07; 32]]; + let compressor = DummyCompressionFunction; + let expected = vec![ + [0x03; 32], // 0x05 ^ 0x06 + [0x00; 32], + ]; + let result = compress::(&prev_layer, &compressor); + assert_eq!(result, expected); + } + + #[test] + fn test_compress_random_values() { + let mut rng = SmallRng::seed_from_u64(1); + let prev_layer: Vec<[u8; 32]> = (0..8).map(|_| rng.random()).collect(); + let compressor = DummyCompressionFunction; + let expected: Vec<[u8; 32]> = prev_layer + .chunks_exact(2) + .map(|pair| { + let mut result = [0u8; 32]; + for (i, r) in result.iter_mut().enumerate() { + *r = pair[0][i] ^ pair[1][i]; + } + result + }) + .collect(); + let result = compress::(&prev_layer, &compressor); + assert_eq!(result, expected); + } +} diff --git a/CoqOfRust/plonky3/merkle-tree/src/merkle_tree.v b/CoqOfRust/plonky3/merkle-tree/src/merkle_tree.v new file mode 100644 index 000000000..c4d0de8e9 --- /dev/null +++ b/CoqOfRust/plonky3/merkle-tree/src/merkle_tree.v @@ -0,0 +1,10837 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module merkle_tree. + (* StructRecord + { + name := "MerkleTree"; + const_params := [ "DIGEST_ELEMS" ]; + ty_params := [ "F"; "W"; "M_" ]; + fields := + [ + ("leaves", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ M_; Ty.path "alloc::alloc::Global" ]); + ("digest_layers", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_W_where_core_fmt_Debug_M__for_p3_merkle_tree_merkle_tree_MerkleTree_DIGEST_ELEMS_F_W_M_. + Definition Self (DIGEST_ELEMS : Value.t) (F W M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") [ DIGEST_ELEMS ] [ F; W; M_ ]. + + (* Debug *) + Definition fmt + (DIGEST_ELEMS : Value.t) + (F W M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W M_ in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "MerkleTree" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "leaves" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "leaves" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "digest_layers" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "digest_layers" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W M_ : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W M_) + (* Instance *) [ ("fmt", InstanceField.Method (fmt DIGEST_ELEMS F W M_)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_W_where_core_fmt_Debug_M__for_p3_merkle_tree_merkle_tree_MerkleTree_DIGEST_ELEMS_F_W_M_. + + Module underscore. + Module Impl_serde_ser_Serialize_where_serde_ser_Serialize_array_DIGEST_ELEMS_W_where_serde_ser_Serialize_M__for_p3_merkle_tree_merkle_tree_MerkleTree_DIGEST_ELEMS_F_W_M_. + Definition Self (DIGEST_ELEMS : Value.t) (F W M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") [ DIGEST_ELEMS ] [ F; W; M_ ]. + + (* Serialize *) + Definition serialize + (DIGEST_ELEMS : Value.t) + (F W M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W M_ in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "MerkleTree" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "leaves" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "leaves" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "digest_layers" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "digest_layers" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ] ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "_phantom" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "_phantom" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W M_ : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W M_) + (* Instance *) [ ("serialize", InstanceField.Method (serialize DIGEST_ELEMS F W M_)) ]. + End Impl_serde_ser_Serialize_where_serde_ser_Serialize_array_DIGEST_ELEMS_W_where_serde_ser_Serialize_M__for_p3_merkle_tree_merkle_tree_MerkleTree_DIGEST_ELEMS_F_W_M_. + Module Impl_serde_de_Deserialize_where_serde_de_Deserialize_array_DIGEST_ELEMS_W_where_serde_de_Deserialize_M__for_p3_merkle_tree_merkle_tree_MerkleTree_DIGEST_ELEMS_F_W_M_. + Definition Self (DIGEST_ELEMS : Value.t) (F W M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") [ DIGEST_ELEMS ] [ F; W; M_ ]. + + (* Deserialize *) + Definition deserialize + (DIGEST_ELEMS : Value.t) + (F W M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W M_ in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") + [ DIGEST_ELEMS ] + [ F; W; M_ ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::_'1::deserialize::__Visitor") + [ DIGEST_ELEMS ] + [ F; W; M_ ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "MerkleTree" |); + M.read (| + get_constant (| + "p3_merkle_tree::merkle_tree::_'1::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_merkle_tree::merkle_tree::_'1::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W M_ : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W M_) + (* Instance *) + [ ("deserialize", InstanceField.Method (deserialize DIGEST_ELEMS F W M_)) ]. + End Impl_serde_de_Deserialize_where_serde_de_Deserialize_array_DIGEST_ELEMS_W_where_serde_de_Deserialize_M__for_p3_merkle_tree_merkle_tree_MerkleTree_DIGEST_ELEMS_F_W_M_. + End underscore. + + + Module Impl_p3_merkle_tree_merkle_tree_MerkleTree_DIGEST_ELEMS_F_W_M_. + Definition Self (DIGEST_ELEMS : Value.t) (F W M_ : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") [ DIGEST_ELEMS ] [ F; W; M_ ]. + + (* + #[instrument(name = "build merkle tree", level = "debug", skip_all, + fields(dimensions = alloc::format!("{:?}", leaves.iter().map(|l| l.dimensions()).collect::>())))] + *) + Definition new + (DIGEST_ELEMS : Value.t) + (F W M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W M_ in + match ε, τ, α with + | [], [ P; PW; H; C ], [ h; c; leaves ] => + ltac:(M.monadic + (let h := M.alloc (| h |) in + let c := M.alloc (| c |) in + let leaves := M.alloc (| leaves |) in + M.catch_return + (Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") + [ DIGEST_ELEMS ] + [ F; W; M_ ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_merkle_tree::merkle_tree::new::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_merkle_tree::merkle_tree::new::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_merkle_tree::merkle_tree::new::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ + Ty.path + "alloc::string::String" + ] + |), + [ + M.read (| + let~ + res : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.path + "alloc::string::String" + ] := + M.alloc (| + M.call_closure (| + Ty.path + "alloc::string::String", + M.get_function (| + "alloc::fmt::format", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "core::fmt::Arguments", + M.get_associated_function (| + Ty.path + "core::fmt::Arguments", + "new_v1", + [ + Value.Integer + IntegerKind.Usize + 1; + Value.Integer + IntegerKind.Usize + 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "" + |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path + "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path + "core::fmt::rt::Argument", + "new_debug", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + M_ + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + M_ + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.path + "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + M_ + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + M_ + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + M_ + ], + [], + [], + "map", + [], + [ + Ty.path + "p3_matrix::Dimensions"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + M_ + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + M_ + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + M_ + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + M_ + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + M_; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + leaves + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + M_ + ] + ] + ] + (Ty.path + "p3_matrix::Dimensions") + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (let + l := + M.copy (| + γ + |) in + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + F + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + l + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_merkle_tree::merkle_tree::new::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") + [ DIGEST_ELEMS ] + [ F; W; M_ ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ], + "is_empty", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, leaves |) ] + |) + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ mk_str (| "No matrices given?" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Packing widths must match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ leaves_largest_first : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "peekable", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ M_ ], + [], + [], + "sorted_by_key", + [], + [ + Ty.apply (Ty.path "core::cmp::Reverse") [] [ Ty.path "usize" ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.apply (Ty.path "core::cmp::Reverse") [] [ Ty.path "usize" ]) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ M_ ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ M_ ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ M_ ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, leaves |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.apply + (Ty.path "core::cmp::Reverse") + [] + [ Ty.path "usize" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let l := M.copy (| γ |) in + Value.StructTuple + "core::cmp::Reverse" + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| M.deref (| M.read (| l |) |) |) + |) + |) + ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ M_ ] ] ] + (Ty.path "usize") + ]; + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] + ], + [], + [], + "all", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + (Ty.path "usize") + ]; + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + (Ty.path "usize") + ], + [], + [], + "tuple_windows", + [], + [ Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + (Ty.path "usize") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "map", + [], + [ + Ty.path "usize"; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + (Ty.path "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + leaves_largest_first + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ] + ] + ] + (Ty.path "usize") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := M.copy (| γ |) in + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| m |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.path "usize"; Ty.path "usize" ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let curr := M.copy (| γ0_0 |) in + let next := M.copy (| γ0_1 |) in + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| curr |); M.read (| next |) ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "next_power_of_two", + [], + [] + |), + [ M.read (| curr |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "next_power_of_two", + [], + [] + |), + [ M.read (| next |) ] + |) + ] + |))) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "matrix heights that round up to the same power of two must be equal" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| "p3_matrix::Matrix", M_, [], [ F ], "height", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ], + "peek", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, leaves_largest_first |) ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ tallest_matrices : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ] ] + ] + (Ty.path "bool") + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.path "bool") + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "peeking_take_while", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, leaves_largest_first |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| M.deref (| M.read (| m |) |) |) + |) + |) + ] + |); + M.read (| max_height |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ digest_layers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_merkle_tree::merkle_tree::first_digest_layer", + [ DIGEST_ELEMS ], + [ P; PW; H; M_ ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| h |) |) + |); + M.read (| tallest_matrices |) + ] + |) + ] + |) + ] + |) + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ prev_layer : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ W ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ], + "last", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ W ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ W ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, digest_layers |) ] + |) + |) + |) + ] + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prev_layer |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ next_layer_len : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "next_power_of_two", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prev_layer |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |) in + let~ matrices_to_inject : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.path "bool") + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.path "bool") + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "peeking_take_while", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, leaves_largest_first |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "next_power_of_two", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ F ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| M.read (| m |) |) + |) + |) + |) + ] + |) + ] + |); + M.read (| next_layer_len |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ next_digests : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_merkle_tree::merkle_tree::compress_and_inject", + [ DIGEST_ELEMS ], + [ P; PW; H; C; M_ ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prev_layer |) |) + |); + M.read (| matrices_to_inject |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| h |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| c |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, digest_layers |); + M.read (| next_digests |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + |) in + M.alloc (| + Value.StructRecord + "p3_merkle_tree::merkle_tree::MerkleTree" + [ + ("leaves", M.read (| leaves |)); + ("digest_layers", M.read (| digest_layers |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (DIGEST_ELEMS : Value.t) (F W M_ : Ty.t), + M.IsAssociatedFunction.C (Self DIGEST_ELEMS F W M_) "new" (new DIGEST_ELEMS F W M_). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn root(&self) -> Hash + where + W: Copy, + { + self.digest_layers.last().unwrap()[0].into() + } + *) + Definition root + (DIGEST_ELEMS : Value.t) + (F W M_ : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W M_ in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ], + [], + [ Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ] ], + "into", + [], + [] + |), + [ + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ] + ], + "last", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ W ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "digest_layers" + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_root : + forall (DIGEST_ELEMS : Value.t) (F W M_ : Ty.t), + M.IsAssociatedFunction.C (Self DIGEST_ELEMS F W M_) "root" (root DIGEST_ELEMS F W M_). + Admitted. + Global Typeclasses Opaque root. + End Impl_p3_merkle_tree_merkle_tree_MerkleTree_DIGEST_ELEMS_F_W_M_. + + (* #[instrument(name = "first digest layer", level = "debug", skip_all)] *) + Definition first_digest_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ DIGEST_ELEMS ], [ P; PW; H; M_ ], [ h; tallest_matrices ] => + ltac:(M.monadic + (let h := M.alloc (| h |) in + let tallest_matrices := M.alloc (| tallest_matrices |) in + M.catch_return + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" ]; + Ty.path "alloc::alloc::Global" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_merkle_tree::merkle_tree::first_digest_layer::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_merkle_tree::merkle_tree::first_digest_layer::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_merkle_tree::merkle_tree::first_digest_layer::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_merkle_tree::merkle_tree::first_digest_layer::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) in + let~ max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, tallest_matrices |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ max_height_padded : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| max_height |); Value.Integer IntegerKind.Usize 1 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.Integer IntegerKind.Usize 1 |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| max_height |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| max_height |); Value.Integer IntegerKind.Usize 2 ] + |) + ] + |) + |))) + ] + |) + |) in + let~ default_digest : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" ] + ] := + M.alloc (| + repeat (| + M.call_closure (| + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value", + M.get_trait_method (| + "core::default::Default", + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value", + [], + [], + "default", + [], + [] + |), + [] + |), + DIGEST_ELEMS + |) + |) in + let~ digests : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "alloc::vec::from_elem", + [], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ] + ] + |), + [ M.read (| default_digest |); M.read (| max_height_padded |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + [], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "par_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, digests |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| max_height |)) + ] + ] + |) + |) + |); + M.read (| width |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let i := M.copy (| γ0_0 |) in + let digests_chunk := M.copy (| γ0_1 |) in + M.read (| + let~ first_row : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| i |); M.read (| width |) ] + |) + |) in + let~ packed_digest : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ PW ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ PW ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + H, + [], + [ + P; + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ PW ] + ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ]; + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11") + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| h |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ]; + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + [], + [], + "flat_map", + [], + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + tallest_matrices + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := M.copy (| γ |) in + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "vertically_packed_row", + [], + [ P ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| m |) + |) + |) + |) + |); + M.read (| first_row |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ]; + Ty.associated_unknown + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ]; + Ty.associated_unknown + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ]; + Ty.associated_unknown + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + [], + [], + "zip", + [], + [ Ty.associated_unknown ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| digests_chunk |) + |) + |) + ] + |); + M.call_closure (| + Ty.associated_unknown, + M.get_function (| + "p3_merkle_tree::merkle_tree::unpack_array", + [ DIGEST_ELEMS ], + [ PW ] + |), + [ M.read (| packed_digest |) ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ]; + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ]; + Ty.associated_unknown + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let dst := M.copy (| γ1_0 |) in + let src := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| dst |) + |), + M.read (| src |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| max_height |); M.read (| width |) ] + |); + M.read (| width |) + ] + |)); + ("end_", M.read (| max_height |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, digests |); + M.read (| i |) + ] + |) + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + H, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ]; + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row") + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| h |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ]; + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + [], + [], + "flat_map", + [], + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + tallest_matrices + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := M.copy (| γ |) in + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "row", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| m |) + |) + |) + |) + |); + M.read (| i |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + digests + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_first_digest_layer : + M.IsFunction.C "p3_merkle_tree::merkle_tree::first_digest_layer" first_digest_layer. + Admitted. + Global Typeclasses Opaque first_digest_layer. + + (* + fn compress_and_inject( + prev_layer: &[[PW::Value; DIGEST_ELEMS]], + matrices_to_inject: Vec<&M>, + h: &H, + c: &C, + ) -> Vec<[PW::Value; DIGEST_ELEMS]> + where + P: PackedValue, + PW: PackedValue, + H: CryptographicHasher + + CryptographicHasher + + Sync, + C: PseudoCompressionFunction<[PW::Value; DIGEST_ELEMS], 2> + + PseudoCompressionFunction<[PW; DIGEST_ELEMS], 2> + + Sync, + M: Matrix, + { + if matrices_to_inject.is_empty() { + return compress::(prev_layer, c); + } + + let width = PW::WIDTH; + let next_len = matrices_to_inject[0].height(); + // We always want to return an even number of digests, except when it's the root. + let next_len_padded = if prev_layer.len() == 2 { + 1 + } else { + // Round prev_layer.len() / 2 up to the next even integer. + (prev_layer.len() / 2 + 1) & !1 + }; + + let default_digest = [PW::Value::default(); DIGEST_ELEMS]; + let mut next_digests = vec![default_digest; next_len_padded]; + next_digests[0..next_len] + .par_chunks_exact_mut(width) + .enumerate() + .for_each(|(i, digests_chunk)| { + let first_row = i * width; + let left = array::from_fn(|j| PW::from_fn(|k| prev_layer[2 * (first_row + k)][j])); + let right = array::from_fn(|j| PW::from_fn(|k| prev_layer[2 * (first_row + k) + 1][j])); + let mut packed_digest = c.compress([left, right]); + let tallest_digest = h.hash_iter( + matrices_to_inject + .iter() + .flat_map(|m| m.vertically_packed_row(first_row)), + ); + packed_digest = c.compress([packed_digest, tallest_digest]); + for (dst, src) in digests_chunk.iter_mut().zip(unpack_array(packed_digest)) { + *dst = src; + } + }); + + // If our packing width did not divide next_len, fall back to single-threaded scalar code + // for the last bit. + for i in (next_len / width * width)..next_len { + let left = prev_layer[2 * i]; + let right = prev_layer[2 * i + 1]; + let digest = c.compress([left, right]); + let rows_digest = h.hash_iter(matrices_to_inject.iter().flat_map(|m| m.row(i))); + next_digests[i] = c.compress([digest, rows_digest]); + } + + // At this point, we've exceeded the height of the matrices to inject, so we continue the + // process above except with default_digest in place of an input digest. + // We only need go as far as half the length of the previous layer. + for i in next_len..(prev_layer.len() / 2) { + let left = prev_layer[2 * i]; + let right = prev_layer[2 * i + 1]; + let digest = c.compress([left, right]); + next_digests[i] = c.compress([digest, default_digest]); + } + + next_digests + } + *) + Definition compress_and_inject (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ DIGEST_ELEMS ], [ P; PW; H; C; M_ ], [ prev_layer; matrices_to_inject; h; c ] => + ltac:(M.monadic + (let prev_layer := M.alloc (| prev_layer |) in + let matrices_to_inject := M.alloc (| matrices_to_inject |) in + let h := M.alloc (| h |) in + let c := M.alloc (| c |) in + M.catch_return + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" ]; + Ty.path "alloc::alloc::Global" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ], + "is_empty", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, matrices_to_inject |) ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_merkle_tree::merkle_tree::compress", + [ DIGEST_ELEMS ], + [ PW; C ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prev_layer |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| c |) |) |) + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) in + let~ next_len : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "&") [] [ M_ ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "&") [] [ M_ ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, matrices_to_inject |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ next_len_padded : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prev_layer |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.Integer IntegerKind.Usize 1 |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prev_layer |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + UnOp.not (| Value.Integer IntegerKind.Usize 1 |) + ] + |) + |))) + ] + |) + |) in + let~ default_digest : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" ] + ] := + M.alloc (| + repeat (| + M.call_closure (| + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value", + M.get_trait_method (| + "core::default::Default", + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value", + [], + [], + "default", + [], + [] + |), + [] + |), + DIGEST_ELEMS + |) + |) in + let~ next_digests : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "alloc::vec::from_elem", + [], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ] + ] + |), + [ M.read (| default_digest |); M.read (| next_len_padded |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + [], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "par_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, next_digests |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| next_len |)) + ] + ] + |) + |) + |); + M.read (| width |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let i := M.copy (| γ0_0 |) in + let digests_chunk := M.copy (| γ0_1 |) in + M.read (| + let~ first_row : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| i |); M.read (| width |) ] + |) + |) in + let~ left : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ PW ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ PW ], + M.get_function (| + "core::array::from_fn", + [ DIGEST_ELEMS ], + [ + PW; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] PW + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + PW + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.call_closure (| + PW, + M.get_trait_method (| + "p3_field::packed::PackedValue", + PW, + [], + [], + "from_fn", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.path "usize" ] + ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value") + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let k := + M.copy (| + γ + |) in + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + prev_layer + |) + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + Value.Integer + IntegerKind.Usize + 2; + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + first_row + |); + M.read (| + k + |) + ] + |) + ] + |) + |), + M.read (| + j + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ right : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ PW ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ PW ], + M.get_function (| + "core::array::from_fn", + [ DIGEST_ELEMS ], + [ + PW; + Ty.function [ Ty.tuple [ Ty.path "usize" ] ] PW + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + PW + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.call_closure (| + PW, + M.get_trait_method (| + "p3_field::packed::PackedValue", + PW, + [], + [], + "from_fn", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.path "usize" ] + ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value") + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let k := + M.copy (| + γ + |) in + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + prev_layer + |) + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + Value.Integer + IntegerKind.Usize + 2; + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + first_row + |); + M.read (| + k + |) + ] + |) + ] + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + |), + M.read (| + j + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ packed_digest : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ PW ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ PW ], + M.get_trait_method (| + "p3_symmetric::compression::PseudoCompressionFunction", + C, + [ Value.Integer IntegerKind.Usize 2 ], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ PW ] + ], + "compress", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| c |) |) + |); + Value.Array + [ M.read (| left |); M.read (| right |) ] + ] + |) + |) in + let~ tallest_digest : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ PW ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ PW ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + H, + [], + [ + P; + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ PW ] + ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ]; + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11") + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| h |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ]; + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + [], + [], + "flat_map", + [], + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + matrices_to_inject + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := M.copy (| γ |) in + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + P + ] + M_ + "{{synthetic}}'11", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "vertically_packed_row", + [], + [ P ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| m |) + |) + |) + |) + |); + M.read (| first_row |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + packed_digest, + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ PW ], + M.get_trait_method (| + "p3_symmetric::compression::PseudoCompressionFunction", + C, + [ Value.Integer IntegerKind.Usize 2 ], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ PW ] + ], + "compress", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| c |) |) + |); + Value.Array + [ + M.read (| packed_digest |); + M.read (| tallest_digest |) + ] + ] + |) + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ]; + Ty.associated_unknown + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ]; + Ty.associated_unknown + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ]; + Ty.associated_unknown + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + [], + [], + "zip", + [], + [ Ty.associated_unknown ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| digests_chunk |) + |) + |) + ] + |); + M.call_closure (| + Ty.associated_unknown, + M.get_function (| + "p3_merkle_tree::merkle_tree::unpack_array", + [ DIGEST_ELEMS ], + [ PW ] + |), + [ M.read (| packed_digest |) ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ]; + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ]; + Ty.associated_unknown + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let dst := M.copy (| γ1_0 |) in + let src := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| dst |) + |), + M.read (| src |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| next_len |); M.read (| width |) ] + |); + M.read (| width |) + ] + |)); + ("end_", M.read (| next_len |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ left : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| prev_layer |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| i |) + ] + |) + |) + |) in + let~ right : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| prev_layer |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 2; + M.read (| i |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) in + let~ digest : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ], + M.get_trait_method (| + "p3_symmetric::compression::PseudoCompressionFunction", + C, + [ Value.Integer IntegerKind.Usize 2 ], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "compress", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| c |) |) + |); + Value.Array + [ M.read (| left |); M.read (| right |) ] + ] + |) + |) in + let~ rows_digest : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + H, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ]; + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row") + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| h |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ]; + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + [], + [], + "flat_map", + [], + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ] ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + matrices_to_inject + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ M_ ] + ] + ] + ] + (Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let m := M.copy (| γ |) in + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "row", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.deref (| + M.read (| m |) + |) + |) + |) + |); + M.read (| i |) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + next_digests + |); + M.read (| i |) + ] + |) + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ], + M.get_trait_method (| + "p3_symmetric::compression::PseudoCompressionFunction", + C, + [ Value.Integer IntegerKind.Usize 2 ], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "compress", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| c |) |) + |); + Value.Array + [ M.read (| digest |); M.read (| rows_digest |) + ] + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| next_len |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prev_layer |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ left : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| prev_layer |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| i |) + ] + |) + |) + |) in + let~ right : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| prev_layer |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 2; + M.read (| i |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) in + let~ digest : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ], + M.get_trait_method (| + "p3_symmetric::compression::PseudoCompressionFunction", + C, + [ Value.Integer IntegerKind.Usize 2 ], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "compress", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| c |) |) + |); + Value.Array + [ M.read (| left |); M.read (| right |) ] + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + next_digests + |); + M.read (| i |) + ] + |) + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ], + M.get_trait_method (| + "p3_symmetric::compression::PseudoCompressionFunction", + C, + [ Value.Integer IntegerKind.Usize 2 ], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "compress", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| c |) |) + |); + Value.Array + [ + M.read (| digest |); + M.read (| default_digest |) + ] + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + next_digests + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_compress_and_inject : + M.IsFunction.C "p3_merkle_tree::merkle_tree::compress_and_inject" compress_and_inject. + Admitted. + Global Typeclasses Opaque compress_and_inject. + + (* + fn compress( + prev_layer: &[[P::Value; DIGEST_ELEMS]], + c: &C, + ) -> Vec<[P::Value; DIGEST_ELEMS]> + where + P: PackedValue, + C: PseudoCompressionFunction<[P::Value; DIGEST_ELEMS], 2> + + PseudoCompressionFunction<[P; DIGEST_ELEMS], 2> + + Sync, + { + let width = P::WIDTH; + // Always return an even number of digests, except when it's the root. + let next_len_padded = if prev_layer.len() == 2 { + 1 + } else { + // Round prev_layer.len() / 2 up to the next even integer. + (prev_layer.len() / 2 + 1) & !1 + }; + let next_len = prev_layer.len() / 2; + + let default_digest = [P::Value::default(); DIGEST_ELEMS]; + let mut next_digests = vec![default_digest; next_len_padded]; + + next_digests[0..next_len] + .par_chunks_exact_mut(width) + .enumerate() + .for_each(|(i, digests_chunk)| { + let first_row = i * width; + let left = array::from_fn(|j| P::from_fn(|k| prev_layer[2 * (first_row + k)][j])); + let right = array::from_fn(|j| P::from_fn(|k| prev_layer[2 * (first_row + k) + 1][j])); + let packed_digest = c.compress([left, right]); + for (dst, src) in digests_chunk.iter_mut().zip(unpack_array(packed_digest)) { + *dst = src; + } + }); + + // If our packing width did not divide next_len, fall back to single-threaded scalar code + // for the last bit. + for i in (next_len / width * width)..next_len { + let left = prev_layer[2 * i]; + let right = prev_layer[2 * i + 1]; + next_digests[i] = c.compress([left, right]); + } + + // Everything has been initialized so we can safely cast. + next_digests + } + *) + Definition compress (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ DIGEST_ELEMS ], [ P; C ], [ prev_layer; c ] => + ltac:(M.monadic + (let prev_layer := M.alloc (| prev_layer |) in + let c := M.alloc (| c |) in + M.read (| + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) in + let~ next_len_padded : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prev_layer |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.Integer IntegerKind.Usize 1 |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prev_layer |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + UnOp.not (| Value.Integer IntegerKind.Usize 1 |) + ] + |) + |))) + ] + |) + |) in + let~ next_len : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" + ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| prev_layer |) |) |) ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) in + let~ default_digest : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ] + ] := + M.alloc (| + repeat (| + M.call_closure (| + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value", + M.get_trait_method (| + "core::default::Default", + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value", + [], + [], + "default", + [], + [] + |), + [] + |), + DIGEST_ELEMS + |) + |) in + let~ next_digests : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "alloc::vec::from_elem", + [], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ] + ] + |), + [ M.read (| default_digest |); M.read (| next_len_padded |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" + ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" + ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + [], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + "par_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, next_digests |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| next_len |)) + ] + ] + |) + |) + |); + M.read (| width |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let i := M.copy (| γ0_0 |) in + let digests_chunk := M.copy (| γ0_1 |) in + M.read (| + let~ first_row : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| i |); M.read (| width |) ] + |) + |) in + let~ left : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ P ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ P ], + M.get_function (| + "core::array::from_fn", + [ DIGEST_ELEMS ], + [ P; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] P ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + P + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.call_closure (| + P, + M.get_trait_method (| + "p3_field::packed::PackedValue", + P, + [], + [], + "from_fn", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.path "usize" ] + ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let k := + M.copy (| + γ + |) in + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + prev_layer + |) + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + Value.Integer + IntegerKind.Usize + 2; + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + first_row + |); + M.read (| + k + |) + ] + |) + ] + |) + |), + M.read (| + j + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ right : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ P ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ P ], + M.get_function (| + "core::array::from_fn", + [ DIGEST_ELEMS ], + [ P; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] P ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + P + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.call_closure (| + P, + M.get_trait_method (| + "p3_field::packed::PackedValue", + P, + [], + [], + "from_fn", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.path "usize" ] + ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let k := + M.copy (| + γ + |) in + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + prev_layer + |) + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.mul, + [ + Value.Integer + IntegerKind.Usize + 2; + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + first_row + |); + M.read (| + k + |) + ] + |) + ] + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + |), + M.read (| + j + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ packed_digest : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ P ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ P ], + M.get_trait_method (| + "p3_symmetric::compression::PseudoCompressionFunction", + C, + [ Value.Integer IntegerKind.Usize 2 ], + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ P ] ], + "compress", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| c |) |) + |); + Value.Array [ M.read (| left |); M.read (| right |) ] + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]; + Ty.associated_unknown + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]; + Ty.associated_unknown + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]; + Ty.associated_unknown + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + [], + [], + "zip", + [], + [ Ty.associated_unknown ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| digests_chunk |) |) + |) + ] + |); + M.call_closure (| + Ty.associated_unknown, + M.get_function (| + "p3_merkle_tree::merkle_tree::unpack_array", + [ DIGEST_ELEMS ], + [ P ] + |), + [ M.read (| packed_digest |) ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]; + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]; + Ty.associated_unknown + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let dst := M.copy (| γ1_0 |) in + let src := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| dst |) |), + M.read (| src |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| next_len |); M.read (| width |) ] + |); + M.read (| width |) + ] + |)); + ("end_", M.read (| next_len |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ left : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| prev_layer |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| i |) ] + |) + |) + |) in + let~ right : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| prev_layer |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| i |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, next_digests |); + M.read (| i |) + ] + |) + |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + M.get_trait_method (| + "p3_symmetric::compression::PseudoCompressionFunction", + C, + [ Value.Integer IntegerKind.Usize 2 ], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + "compress", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| c |) |) + |); + Value.Array [ M.read (| left |); M.read (| right |) ] + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + next_digests + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_compress : + M.IsFunction.C "p3_merkle_tree::merkle_tree::compress" compress. + Admitted. + Global Typeclasses Opaque compress. + + (* + fn unpack_array( + packed_digest: [P; N], + ) -> impl Iterator { + (0..P::WIDTH).map(move |j| packed_digest.map(|p| p.as_slice()[j])) + } + *) + Definition unpack_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ P ], [ packed_digest ] => + ltac:(M.monadic + (let packed_digest := M.alloc (| packed_digest |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ N ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ N ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.read (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ N ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ N ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ N ] [ P ], + "map", + [], + [ + Ty.function + [ Ty.tuple [ P ] ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"); + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + |), + [ + M.read (| packed_digest |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ P ] ] + (Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let p := M.copy (| γ |) in + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + P, + [], + [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p |) ] + |) + |), + M.read (| j |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_unpack_array : + M.IsFunction.C "p3_merkle_tree::merkle_tree::unpack_array" unpack_array. + Admitted. + Global Typeclasses Opaque unpack_array. +End merkle_tree. diff --git a/CoqOfRust/plonky3/merkle-tree/src/mmcs.rs b/CoqOfRust/plonky3/merkle-tree/src/mmcs.rs new file mode 100644 index 000000000..8669dd789 --- /dev/null +++ b/CoqOfRust/plonky3/merkle-tree/src/mmcs.rs @@ -0,0 +1,628 @@ +//! A MerkleTreeMmcs is a generalization of the standard MerkleTree commitment scheme which supports +//! committing to several matrices of different dimensions. +//! +//! Say we wish to commit to 2 matrices M and N with dimensions (8, i) and (2, j) respectively. +//! Let H denote the hash function and C the compression function for our tree. +//! Then MerkleTreeMmcs produces a commitment to M and N using the following tree structure: +//! +//! ```rust,ignore +//! /// +//! /// root = c00 = C(c10, c11) +//! /// / \ +//! /// c10 = C(C(c20, c21), H(N[0])) c11 = C(C(c22, c23), H(N[1])) +//! /// / \ / \ +//! /// c20 = C(L, R) c21 = C(L, R) c22 = C(L, R) c23 = C(L, R) +//! /// L/ \R L/ \R L/ \R L/ \R +//! /// H(M[0]) H(M[1]) H(M[2]) H(M[3]) H(M[4]) H(M[5]) H(M[6]) H(M[7]) +//! ``` +//! E.g. we start by making a standard MerkleTree commitment for each row of M and then add in the rows of N when we +//! get to the correct level. A proof for the values of say `M[5]` and `N[1]` consists of the siblings `H(M[4]), c23, c10`. +//! + +use alloc::vec::Vec; +use core::cmp::Reverse; +use core::marker::PhantomData; + +use itertools::Itertools; +use p3_commit::Mmcs; +use p3_field::PackedValue; +use p3_matrix::{Dimensions, Matrix}; +use p3_symmetric::{CryptographicHasher, Hash, PseudoCompressionFunction}; +use p3_util::{log2_ceil_usize, log2_strict_usize}; +use serde::{Deserialize, Serialize}; + +use crate::MerkleTree; +use crate::MerkleTreeError::{ + EmptyBatch, IncompatibleHeights, RootMismatch, WrongBatchSize, WrongHeight, +}; + +/// A vector commitment scheme backed by a `MerkleTree`. +/// +/// Generics: +/// - `P`: a leaf value +/// - `PW`: an element of a digest +/// - `H`: the leaf hasher +/// - `C`: the digest compression function +#[derive(Copy, Clone, Debug)] +pub struct MerkleTreeMmcs { + hash: H, + compress: C, + _phantom: PhantomData<(P, PW)>, +} + +#[derive(Debug)] +pub enum MerkleTreeError { + WrongBatchSize, + WrongWidth, + WrongHeight { + log_max_height: usize, + num_siblings: usize, + }, + IncompatibleHeights, + RootMismatch, + EmptyBatch, +} + +impl MerkleTreeMmcs { + pub const fn new(hash: H, compress: C) -> Self { + Self { + hash, + compress, + _phantom: PhantomData, + } + } +} + +impl Mmcs + for MerkleTreeMmcs +where + P: PackedValue, + PW: PackedValue, + H: CryptographicHasher + + CryptographicHasher + + Sync, + C: PseudoCompressionFunction<[PW::Value; DIGEST_ELEMS], 2> + + PseudoCompressionFunction<[PW; DIGEST_ELEMS], 2> + + Sync, + PW::Value: Eq, + [PW::Value; DIGEST_ELEMS]: Serialize + for<'de> Deserialize<'de>, +{ + type ProverData = MerkleTree; + type Commitment = Hash; + type Proof = Vec<[PW::Value; DIGEST_ELEMS]>; + type Error = MerkleTreeError; + + fn commit>( + &self, + inputs: Vec, + ) -> (Self::Commitment, Self::ProverData) { + let tree = MerkleTree::new::(&self.hash, &self.compress, inputs); + let root = tree.root(); + (root, tree) + } + + /// Opens a batch of rows from committed matrices. + /// + /// Returns `(openings, proof)` where `openings` is a vector whose `i`th element is + /// the `j`th row of the ith matrix `M[i]`, with + /// `j == index >> (log2_ceil(max_height) - log2_ceil(M[i].height))` + /// and `proof` is the vector of sibling Merkle tree nodes allowing the verifier to + /// reconstruct the committed root. + fn open_batch>( + &self, + index: usize, + prover_data: &MerkleTree, + ) -> (Vec>, Self::Proof) { + let max_height = self.get_max_height(prover_data); + let log_max_height = log2_ceil_usize(max_height); + + // Get the matrix rows encountered along the path from the root to the given leaf index. + let openings = prover_data + .leaves + .iter() + .map(|matrix| { + let log2_height = log2_ceil_usize(matrix.height()); + let bits_reduced = log_max_height - log2_height; + let reduced_index = index >> bits_reduced; + matrix.row(reduced_index).collect() + }) + .collect_vec(); + + // Get all the siblings nodes corresponding to the path from the root to the given leaf index. + let proof = (0..log_max_height) + .map(|i| prover_data.digest_layers[i][(index >> i) ^ 1]) + .collect(); + + (openings, proof) + } + + fn get_matrices<'a, M: Matrix>( + &self, + prover_data: &'a Self::ProverData, + ) -> Vec<&'a M> { + prover_data.leaves.iter().collect() + } + + /// Verifies an opened batch of rows with respect to a given commitment. + /// + /// - `commit`: The merkle root of the tree. + /// - `dimensions`: A vector of the dimensions of the matrices committed to. + /// - `index`: The index of a leaf in the tree. + /// - `opened_values`: A vector of matrix rows. Assume that the tallest matrix committed + /// to has height `2^n >= M_tall.height() > 2^{n - 1}` and the `j`th matrix has height + /// `2^m >= Mj.height() > 2^{m - 1}`. Then `j`'th value of opened values must be the row `Mj[index >> (m - n)]`. + /// - `proof`: A vector of sibling nodes. The `i`th element should be the node at level `i` + /// with index `(index << i) ^ 1`. + /// + /// Returns nothing if the verification is successful, otherwise returns an error. + fn verify_batch( + &self, + commit: &Self::Commitment, + dimensions: &[Dimensions], + mut index: usize, + opened_values: &[Vec], + proof: &Self::Proof, + ) -> Result<(), Self::Error> { + // Check that the openings have the correct shape. + if dimensions.len() != opened_values.len() { + return Err(WrongBatchSize); + } + + // TODO: Disabled for now since TwoAdicFriPcs and CirclePcs currently pass 0 for width. + // for (dims, opened_vals) in zip_eq(dimensions.iter(), opened_values) { + // if opened_vals.len() != dims.width { + // return Err(WrongWidth); + // } + // } + + let mut heights_tallest_first = dimensions + .iter() + .enumerate() + .sorted_by_key(|(_, dims)| Reverse(dims.height)) + .peekable(); + + // Matrix heights that round up to the same power of two must be equal + if !heights_tallest_first + .clone() + .map(|(_, dims)| dims.height) + .tuple_windows() + .all(|(curr, next)| { + curr == next || curr.next_power_of_two() != next.next_power_of_two() + }) + { + return Err(IncompatibleHeights); + } + + // Get the initial height padded to a power of two. As heights_tallest_first is sorted, + // the initial height will be the maximum height. + // Returns an error if either: + // 1. proof.len() != log_max_height + // 2. heights_tallest_first is empty. + let mut curr_height_padded = match heights_tallest_first.peek() { + Some((_, dims)) => { + let max_height = dims.height.next_power_of_two(); + let log_max_height = log2_strict_usize(max_height); + if proof.len() != log_max_height { + return Err(WrongHeight { + log_max_height, + num_siblings: proof.len(), + }); + } + max_height + } + None => return Err(EmptyBatch), + }; + + // Hash all matrix openings at the current height. + let mut root = self.hash.hash_iter_slices( + heights_tallest_first + .peeking_take_while(|(_, dims)| { + dims.height.next_power_of_two() == curr_height_padded + }) + .map(|(i, _)| opened_values[i].as_slice()), + ); + + for &sibling in proof { + // The last bit of index informs us whether the current node is on the left or right. + let (left, right) = if index & 1 == 0 { + (root, sibling) + } else { + (sibling, root) + }; + + // Combine the current node with the sibling node to get the parent node. + root = self.compress.compress([left, right]); + index >>= 1; + curr_height_padded >>= 1; + + // Check if there are any new matrix rows to inject at the next height. + let next_height = heights_tallest_first + .peek() + .map(|(_, dims)| dims.height) + .filter(|h| h.next_power_of_two() == curr_height_padded); + if let Some(next_height) = next_height { + // If there are new matrix rows, hash the rows together and then combine with the current root. + let next_height_openings_digest = self.hash.hash_iter_slices( + heights_tallest_first + .peeking_take_while(|(_, dims)| dims.height == next_height) + .map(|(i, _)| opened_values[i].as_slice()), + ); + + root = self.compress.compress([root, next_height_openings_digest]); + } + } + + // The computed root should equal the committed one. + if commit == &root { + Ok(()) + } else { + Err(RootMismatch) + } + } +} + +#[cfg(test)] +mod tests { + use alloc::vec; + + use itertools::Itertools; + use p3_baby_bear::{BabyBear, Poseidon2BabyBear}; + use p3_commit::Mmcs; + use p3_field::{Field, PrimeCharacteristicRing}; + use p3_matrix::dense::RowMajorMatrix; + use p3_matrix::{Dimensions, Matrix}; + use p3_symmetric::{ + CryptographicHasher, PaddingFreeSponge, PseudoCompressionFunction, TruncatedPermutation, + }; + use rand::SeedableRng; + use rand::rngs::SmallRng; + + use super::MerkleTreeMmcs; + + type F = BabyBear; + + type Perm = Poseidon2BabyBear<16>; + type MyHash = PaddingFreeSponge; + type MyCompress = TruncatedPermutation; + type MyMmcs = + MerkleTreeMmcs<::Packing, ::Packing, MyHash, MyCompress, 8>; + + #[test] + fn commit_single_1x8() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash.clone(), compress.clone()); + + // v = [2, 1, 2, 2, 0, 0, 1, 0] + let v = vec![ + F::TWO, + F::ONE, + F::TWO, + F::TWO, + F::ZERO, + F::ZERO, + F::ONE, + F::ZERO, + ]; + let (commit, _) = mmcs.commit_vec(v.clone()); + + let expected_result = compress.compress([ + compress.compress([ + compress.compress([hash.hash_item(v[0]), hash.hash_item(v[1])]), + compress.compress([hash.hash_item(v[2]), hash.hash_item(v[3])]), + ]), + compress.compress([ + compress.compress([hash.hash_item(v[4]), hash.hash_item(v[5])]), + compress.compress([hash.hash_item(v[6]), hash.hash_item(v[7])]), + ]), + ]); + assert_eq!(commit, expected_result); + } + + #[test] + fn commit_single_8x1() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash.clone(), compress); + + let mat = RowMajorMatrix::::rand(&mut rng, 1, 8); + let (commit, _) = mmcs.commit(vec![mat.clone()]); + + let expected_result = hash.hash_iter(mat.vertically_packed_row(0)); + assert_eq!(commit, expected_result); + } + + #[test] + fn commit_single_2x2() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash.clone(), compress.clone()); + + // mat = [ + // 0 1 + // 2 1 + // ] + let mat = RowMajorMatrix::new(vec![F::ZERO, F::ONE, F::TWO, F::ONE], 2); + + let (commit, _) = mmcs.commit(vec![mat]); + + let expected_result = compress.compress([ + hash.hash_slice(&[F::ZERO, F::ONE]), + hash.hash_slice(&[F::TWO, F::ONE]), + ]); + assert_eq!(commit, expected_result); + } + + #[test] + fn commit_single_2x3() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash.clone(), compress.clone()); + let default_digest = [F::ZERO; 8]; + + // mat = [ + // 0 1 + // 2 1 + // 2 2 + // ] + let mat = RowMajorMatrix::new(vec![F::ZERO, F::ONE, F::TWO, F::ONE, F::TWO, F::TWO], 2); + + let (commit, _) = mmcs.commit(vec![mat]); + + let expected_result = compress.compress([ + compress.compress([ + hash.hash_slice(&[F::ZERO, F::ONE]), + hash.hash_slice(&[F::TWO, F::ONE]), + ]), + compress.compress([hash.hash_slice(&[F::TWO, F::TWO]), default_digest]), + ]); + assert_eq!(commit, expected_result); + } + + #[test] + fn commit_mixed() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash.clone(), compress.clone()); + let default_digest = [F::ZERO; 8]; + + // mat_1 = [ + // 0 1 + // 2 1 + // 2 2 + // 2 1 + // 2 2 + // ] + let mat_1 = RowMajorMatrix::new( + vec![ + F::ZERO, + F::ONE, + F::TWO, + F::ONE, + F::TWO, + F::TWO, + F::TWO, + F::ONE, + F::TWO, + F::TWO, + ], + 2, + ); + // mat_2 = [ + // 1 2 1 + // 0 2 2 + // 1 2 1 + // ] + let mat_2 = RowMajorMatrix::new( + vec![ + F::ONE, + F::TWO, + F::ONE, + F::ZERO, + F::TWO, + F::TWO, + F::ONE, + F::TWO, + F::ONE, + ], + 3, + ); + + let (commit, prover_data) = mmcs.commit(vec![mat_1, mat_2]); + + let mat_1_leaf_hashes = [ + hash.hash_slice(&[F::ZERO, F::ONE]), + hash.hash_slice(&[F::TWO, F::ONE]), + hash.hash_slice(&[F::TWO, F::TWO]), + hash.hash_slice(&[F::TWO, F::ONE]), + hash.hash_slice(&[F::TWO, F::TWO]), + ]; + let mat_2_leaf_hashes = [ + hash.hash_slice(&[F::ONE, F::TWO, F::ONE]), + hash.hash_slice(&[F::ZERO, F::TWO, F::TWO]), + hash.hash_slice(&[F::ONE, F::TWO, F::ONE]), + ]; + + let expected_result = compress.compress([ + compress.compress([ + compress.compress([ + compress.compress([mat_1_leaf_hashes[0], mat_1_leaf_hashes[1]]), + mat_2_leaf_hashes[0], + ]), + compress.compress([ + compress.compress([mat_1_leaf_hashes[2], mat_1_leaf_hashes[3]]), + mat_2_leaf_hashes[1], + ]), + ]), + compress.compress([ + compress.compress([ + compress.compress([mat_1_leaf_hashes[4], default_digest]), + mat_2_leaf_hashes[2], + ]), + default_digest, + ]), + ]); + + assert_eq!(commit, expected_result); + + let (opened_values, _proof) = mmcs.open_batch(2, &prover_data); + assert_eq!( + opened_values, + vec![vec![F::TWO, F::TWO], vec![F::ZERO, F::TWO, F::TWO]] + ); + } + + #[test] + fn commit_either_order() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash, compress); + + let input_1 = RowMajorMatrix::::rand(&mut rng, 5, 8); + let input_2 = RowMajorMatrix::::rand(&mut rng, 3, 16); + + let (commit_1_2, _) = mmcs.commit(vec![input_1.clone(), input_2.clone()]); + let (commit_2_1, _) = mmcs.commit(vec![input_2, input_1]); + assert_eq!(commit_1_2, commit_2_1); + } + + #[test] + #[should_panic] + fn mismatched_heights() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash, compress); + + // attempt to commit to a mat with 8 rows and a mat with 7 rows. this should panic. + let large_mat = RowMajorMatrix::new([1, 2, 3, 4, 5, 6, 7, 8].map(F::from_u8).to_vec(), 1); + let small_mat = RowMajorMatrix::new([1, 2, 3, 4, 5, 6, 7].map(F::from_u8).to_vec(), 1); + let _ = mmcs.commit(vec![large_mat, small_mat]); + } + + #[test] + fn verify_tampered_proof_fails() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash, compress); + + // 4 8x1 matrixes, 4 8x2 matrixes + let mut mats = (0..4) + .map(|_| RowMajorMatrix::::rand(&mut rng, 8, 1)) + .collect_vec(); + let large_mat_dims = (0..4).map(|_| Dimensions { + height: 8, + width: 1, + }); + mats.extend((0..4).map(|_| RowMajorMatrix::::rand(&mut rng, 8, 2))); + let small_mat_dims = (0..4).map(|_| Dimensions { + height: 8, + width: 2, + }); + + let (commit, prover_data) = mmcs.commit(mats); + + // open the 3rd row of each matrix, mess with proof, and verify + let (opened_values, mut proof) = mmcs.open_batch(3, &prover_data); + proof[0][0] += F::ONE; + mmcs.verify_batch( + &commit, + &large_mat_dims.chain(small_mat_dims).collect_vec(), + 3, + &opened_values, + &proof, + ) + .expect_err("expected verification to fail"); + } + + #[test] + fn size_gaps() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash, compress); + + // 4 mats with 1000 rows, 8 columns + let mut mats = (0..4) + .map(|_| RowMajorMatrix::::rand(&mut rng, 1000, 8)) + .collect_vec(); + let large_mat_dims = (0..4).map(|_| Dimensions { + height: 1000, + width: 8, + }); + + // 5 mats with 70 rows, 8 columns + mats.extend((0..5).map(|_| RowMajorMatrix::::rand(&mut rng, 70, 8))); + let medium_mat_dims = (0..5).map(|_| Dimensions { + height: 70, + width: 8, + }); + + // 6 mats with 8 rows, 8 columns + mats.extend((0..6).map(|_| RowMajorMatrix::::rand(&mut rng, 8, 8))); + let small_mat_dims = (0..6).map(|_| Dimensions { + height: 8, + width: 8, + }); + + // 7 tiny mat with 1 row, 8 columns + mats.extend((0..7).map(|_| RowMajorMatrix::::rand(&mut rng, 1, 8))); + let tiny_mat_dims = (0..7).map(|_| Dimensions { + height: 1, + width: 8, + }); + + let (commit, prover_data) = mmcs.commit(mats); + + // open the 6th row of each matrix and verify + let (opened_values, proof) = mmcs.open_batch(6, &prover_data); + mmcs.verify_batch( + &commit, + &large_mat_dims + .chain(medium_mat_dims) + .chain(small_mat_dims) + .chain(tiny_mat_dims) + .collect_vec(), + 6, + &opened_values, + &proof, + ) + .expect("expected verification to succeed"); + } + + #[test] + fn different_widths() { + let mut rng = SmallRng::seed_from_u64(1); + let perm = Perm::new_from_rng_128(&mut rng); + let hash = MyHash::new(perm.clone()); + let compress = MyCompress::new(perm); + let mmcs = MyMmcs::new(hash, compress); + + // 10 mats with 32 rows where the ith mat has i + 1 cols + let mats = (0..10) + .map(|i| RowMajorMatrix::::rand(&mut rng, 32, i + 1)) + .collect_vec(); + let dims = mats.iter().map(|m| m.dimensions()).collect_vec(); + + let (commit, prover_data) = mmcs.commit(mats); + let (opened_values, proof) = mmcs.open_batch(17, &prover_data); + mmcs.verify_batch(&commit, &dims, 17, &opened_values, &proof) + .expect("expected verification to succeed"); + } +} diff --git a/CoqOfRust/plonky3/merkle-tree/src/mmcs.v b/CoqOfRust/plonky3/merkle-tree/src/mmcs.v new file mode 100644 index 000000000..69c5a3689 --- /dev/null +++ b/CoqOfRust/plonky3/merkle-tree/src/mmcs.v @@ -0,0 +1,4866 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module mmcs. + (* StructRecord + { + name := "MerkleTreeMmcs"; + const_params := [ "DIGEST_ELEMS" ]; + ty_params := [ "P"; "PW"; "H"; "C" ]; + fields := + [ + ("hash", H); + ("compress", C); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ Ty.tuple [ P; PW ] ]) + ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_P_where_core_marker_Copy_PW_where_core_marker_Copy_H_where_core_marker_Copy_C_for_p3_merkle_tree_mmcs_MerkleTreeMmcs_DIGEST_ELEMS_P_PW_H_C. + Definition Self (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") [ DIGEST_ELEMS ] [ P; PW; H; C ]. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS P PW H C) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_P_where_core_marker_Copy_PW_where_core_marker_Copy_H_where_core_marker_Copy_C_for_p3_merkle_tree_mmcs_MerkleTreeMmcs_DIGEST_ELEMS_P_PW_H_C. + + Module Impl_core_clone_Clone_where_core_clone_Clone_P_where_core_clone_Clone_PW_where_core_clone_Clone_H_where_core_clone_Clone_C_for_p3_merkle_tree_mmcs_MerkleTreeMmcs_DIGEST_ELEMS_P_PW_H_C. + Definition Self (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") [ DIGEST_ELEMS ] [ P; PW; H; C ]. + + (* Clone *) + Definition clone + (DIGEST_ELEMS : Value.t) + (P PW H C : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS P PW H C in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_merkle_tree::mmcs::MerkleTreeMmcs" + [ + ("hash", + M.call_closure (| + H, + M.get_trait_method (| "core::clone::Clone", H, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "hash" + |) + |) + |) + |) + ] + |)); + ("compress", + M.call_closure (| + C, + M.get_trait_method (| "core::clone::Clone", C, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "compress" + |) + |) + |) + |) + ] + |)); + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ Ty.tuple [ P; PW ] ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ Ty.tuple [ P; PW ] ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "_phantom" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS P PW H C) + (* Instance *) [ ("clone", InstanceField.Method (clone DIGEST_ELEMS P PW H C)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_P_where_core_clone_Clone_PW_where_core_clone_Clone_H_where_core_clone_Clone_C_for_p3_merkle_tree_mmcs_MerkleTreeMmcs_DIGEST_ELEMS_P_PW_H_C. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_P_where_core_fmt_Debug_PW_where_core_fmt_Debug_H_where_core_fmt_Debug_C_for_p3_merkle_tree_mmcs_MerkleTreeMmcs_DIGEST_ELEMS_P_PW_H_C. + Definition Self (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") [ DIGEST_ELEMS ] [ P; PW; H; C ]. + + (* Debug *) + Definition fmt + (DIGEST_ELEMS : Value.t) + (P PW H C : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS P PW H C in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "MerkleTreeMmcs" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "hash" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "hash" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "compress" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "compress" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS P PW H C) + (* Instance *) [ ("fmt", InstanceField.Method (fmt DIGEST_ELEMS P PW H C)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_P_where_core_fmt_Debug_PW_where_core_fmt_Debug_H_where_core_fmt_Debug_C_for_p3_merkle_tree_mmcs_MerkleTreeMmcs_DIGEST_ELEMS_P_PW_H_C. + + (* + Enum MerkleTreeError + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "WrongBatchSize"; + item := StructTuple []; + }; + { + name := "WrongWidth"; + item := StructTuple []; + }; + { + name := "WrongHeight"; + item := + StructRecord [ ("log_max_height", Ty.path "usize"); ("num_siblings", Ty.path "usize") ]; + }; + { + name := "IncompatibleHeights"; + item := StructTuple []; + }; + { + name := "RootMismatch"; + item := StructTuple []; + }; + { + name := "EmptyBatch"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_MerkleTreeError_WrongBatchSize : + M.IsDiscriminant "p3_merkle_tree::mmcs::MerkleTreeError::WrongBatchSize" 0. + Axiom IsDiscriminant_MerkleTreeError_WrongWidth : + M.IsDiscriminant "p3_merkle_tree::mmcs::MerkleTreeError::WrongWidth" 1. + Axiom IsDiscriminant_MerkleTreeError_WrongHeight : + M.IsDiscriminant "p3_merkle_tree::mmcs::MerkleTreeError::WrongHeight" 2. + Axiom IsDiscriminant_MerkleTreeError_IncompatibleHeights : + M.IsDiscriminant "p3_merkle_tree::mmcs::MerkleTreeError::IncompatibleHeights" 3. + Axiom IsDiscriminant_MerkleTreeError_RootMismatch : + M.IsDiscriminant "p3_merkle_tree::mmcs::MerkleTreeError::RootMismatch" 4. + Axiom IsDiscriminant_MerkleTreeError_EmptyBatch : + M.IsDiscriminant "p3_merkle_tree::mmcs::MerkleTreeError::EmptyBatch" 5. + + Module Impl_core_fmt_Debug_for_p3_merkle_tree_mmcs_MerkleTreeError. + Definition Self : Ty.t := Ty.path "p3_merkle_tree::mmcs::MerkleTreeError". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_merkle_tree::mmcs::MerkleTreeError::WrongBatchSize" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "WrongBatchSize" |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_merkle_tree::mmcs::MerkleTreeError::WrongWidth" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "WrongWidth" |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_merkle_tree::mmcs::MerkleTreeError::WrongHeight", + "log_max_height" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_merkle_tree::mmcs::MerkleTreeError::WrongHeight", + "num_siblings" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + let __self_1 := M.alloc (| γ1_1 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "WrongHeight" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "log_max_height" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "num_siblings" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_1 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_merkle_tree::mmcs::MerkleTreeError::IncompatibleHeights" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "IncompatibleHeights" |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_merkle_tree::mmcs::MerkleTreeError::RootMismatch" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "RootMismatch" |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_merkle_tree::mmcs::MerkleTreeError::EmptyBatch" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "EmptyBatch" |) |) |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_merkle_tree_mmcs_MerkleTreeError. + + Module Impl_p3_merkle_tree_mmcs_MerkleTreeMmcs_DIGEST_ELEMS_P_PW_H_C. + Definition Self (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") [ DIGEST_ELEMS ] [ P; PW; H; C ]. + + (* + pub const fn new(hash: H, compress: C) -> Self { + Self { + hash, + compress, + _phantom: PhantomData, + } + } + *) + Definition new + (DIGEST_ELEMS : Value.t) + (P PW H C : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS P PW H C in + match ε, τ, α with + | [], [], [ hash; compress ] => + ltac:(M.monadic + (let hash := M.alloc (| hash |) in + let compress := M.alloc (| compress |) in + Value.StructRecord + "p3_merkle_tree::mmcs::MerkleTreeMmcs" + [ + ("hash", M.read (| hash |)); + ("compress", M.read (| compress |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t), + M.IsAssociatedFunction.C (Self DIGEST_ELEMS P PW H C) "new" (new DIGEST_ELEMS P PW H C). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_merkle_tree_mmcs_MerkleTreeMmcs_DIGEST_ELEMS_P_PW_H_C. + + Module Impl_p3_commit_mmcs_Mmcs_where_p3_field_packed_PackedValue_P_where_p3_field_packed_PackedValue_PW_where_p3_symmetric_hasher_CryptographicHasher_H_associated_in_trait_p3_field_packed_PackedValue___P_Value_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_p3_symmetric_hasher_CryptographicHasher_H_P_array_DIGEST_ELEMS_PW_where_core_marker_Sync_H_where_p3_symmetric_compression_PseudoCompressionFunction_C_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_p3_symmetric_compression_PseudoCompressionFunction_C_array_DIGEST_ELEMS_PW_where_core_marker_Sync_C_where_core_cmp_Eq_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_serde_ser_Serialize_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_serde_de_Deserialize_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_associated_in_trait_p3_field_packed_PackedValue___P_Value_for_p3_merkle_tree_mmcs_MerkleTreeMmcs_DIGEST_ELEMS_P_PW_H_C. + Definition Self (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") [ DIGEST_ELEMS ] [ P; PW; H; C ]. + + (* type ProverData = MerkleTree; *) + Definition _ProverData (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value"; + M_ + ]. + + (* type Commitment = Hash; *) + Definition _Commitment (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::hash::Hash") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ]. + + (* type Proof = Vec<[PW::Value; DIGEST_ELEMS]>; *) + Definition _Proof (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t) : Ty.t := + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" ]; + Ty.path "alloc::alloc::Global" + ]. + + (* type Error = MerkleTreeError; *) + Definition _Error (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t) : Ty.t := + Ty.path "p3_merkle_tree::mmcs::MerkleTreeError". + + (* + fn commit>( + &self, + inputs: Vec, + ) -> (Self::Commitment, Self::ProverData) { + let tree = MerkleTree::new::(&self.hash, &self.compress, inputs); + let root = tree.root(); + (root, tree) + } + *) + Definition commit + (DIGEST_ELEMS : Value.t) + (P PW H C : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS P PW H C in + match ε, τ, α with + | [], [ M_ ], [ self; inputs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let inputs := M.alloc (| inputs |) in + M.read (| + let~ tree : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value"; + M_ + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value"; + M_ + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value"; + M_ + ], + "new", + [], + [ P; PW; H; C ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "hash" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "compress" + |) + |) + |) + |); + M.read (| inputs |) + ] + |) + |) in + let~ root : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::hash::Hash") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_symmetric::hash::Hash") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_merkle_tree::merkle_tree::MerkleTree") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value"; + M_ + ], + "root", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, tree |) ] + |) + |) in + M.alloc (| Value.Tuple [ M.read (| root |); M.read (| tree |) ] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn open_batch>( + &self, + index: usize, + prover_data: &MerkleTree, + ) -> (Vec>, Self::Proof) { + let max_height = self.get_max_height(prover_data); + let log_max_height = log2_ceil_usize(max_height); + + // Get the matrix rows encountered along the path from the root to the given leaf index. + let openings = prover_data + .leaves + .iter() + .map(|matrix| { + let log2_height = log2_ceil_usize(matrix.height()); + let bits_reduced = log_max_height - log2_height; + let reduced_index = index >> bits_reduced; + matrix.row(reduced_index).collect() + }) + .collect_vec(); + + // Get all the siblings nodes corresponding to the path from the root to the given leaf index. + let proof = (0..log_max_height) + .map(|i| prover_data.digest_layers[i][(index >> i) ^ 1]) + .collect(); + + (openings, proof) + } + *) + Definition open_batch + (DIGEST_ELEMS : Value.t) + (P PW H C : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS P PW H C in + match ε, τ, α with + | [], [ M_ ], [ self; index; prover_data ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let index := M.alloc (| index |) in + let prover_data := M.alloc (| prover_data |) in + M.read (| + let~ max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_commit::mmcs::Mmcs", + Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ], + [], + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ], + "get_max_height", + [], + [ M_ ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| prover_data |) |) |) + ] + |) + |) in + let~ log_max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_ceil_usize", [], [] |), + [ M.read (| max_height |) ] + |) + |) in + let~ openings : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ M_ ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ M_ ] ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ M_ ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ M_ ] ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ M_ ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ M_ ] ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ M_ ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ M_ ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ M_ ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| prover_data |) |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "leaves" + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ M_ ] ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let matrix := M.copy (| γ |) in + M.read (| + let~ log2_height : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_util::log2_ceil_usize", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "height", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| matrix |) |) + |) + ] + |) + ] + |) + |) in + let~ bits_reduced : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| log_max_height |); + M.read (| log2_height |) + ] + |) + |) in + let~ reduced_index : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| index |); M.read (| bits_reduced |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row", + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + M_ + "Row", + M.get_trait_method (| + "p3_matrix::Matrix", + M_, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ], + "row", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| matrix |) |) + |); + M.read (| reduced_index |) + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ proof : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| log_max_height |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| prover_data |) + |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "digest_layers" + |) + |); + M.read (| i |) + ] + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_xor, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| index |); M.read (| i |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [ M.read (| openings |); M.read (| proof |) ] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn get_matrices<'a, M: Matrix>( + &self, + prover_data: &'a Self::ProverData, + ) -> Vec<&'a M> { + prover_data.leaves.iter().collect() + } + *) + Definition get_matrices + (DIGEST_ELEMS : Value.t) + (P PW H C : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS P PW H C in + match ε, τ, α with + | [], [ M_ ], [ self; prover_data ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let prover_data := M.alloc (| prover_data |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ M_ ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "&") [] [ M_ ]; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ M_ ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ M_ ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ M_ ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ M_; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| prover_data |) |), + "p3_merkle_tree::merkle_tree::MerkleTree", + "leaves" + |) + |) + ] + |) + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn verify_batch( + &self, + commit: &Self::Commitment, + dimensions: &[Dimensions], + mut index: usize, + opened_values: &[Vec], + proof: &Self::Proof, + ) -> Result<(), Self::Error> { + // Check that the openings have the correct shape. + if dimensions.len() != opened_values.len() { + return Err(WrongBatchSize); + } + + // TODO: Disabled for now since TwoAdicFriPcs and CirclePcs currently pass 0 for width. + // for (dims, opened_vals) in zip_eq(dimensions.iter(), opened_values) { + // if opened_vals.len() != dims.width { + // return Err(WrongWidth); + // } + // } + + let mut heights_tallest_first = dimensions + .iter() + .enumerate() + .sorted_by_key(|(_, dims)| Reverse(dims.height)) + .peekable(); + + // Matrix heights that round up to the same power of two must be equal + if !heights_tallest_first + .clone() + .map(|(_, dims)| dims.height) + .tuple_windows() + .all(|(curr, next)| { + curr == next || curr.next_power_of_two() != next.next_power_of_two() + }) + { + return Err(IncompatibleHeights); + } + + // Get the initial height padded to a power of two. As heights_tallest_first is sorted, + // the initial height will be the maximum height. + // Returns an error if either: + // 1. proof.len() != log_max_height + // 2. heights_tallest_first is empty. + let mut curr_height_padded = match heights_tallest_first.peek() { + Some((_, dims)) => { + let max_height = dims.height.next_power_of_two(); + let log_max_height = log2_strict_usize(max_height); + if proof.len() != log_max_height { + return Err(WrongHeight { + log_max_height, + num_siblings: proof.len(), + }); + } + max_height + } + None => return Err(EmptyBatch), + }; + + // Hash all matrix openings at the current height. + let mut root = self.hash.hash_iter_slices( + heights_tallest_first + .peeking_take_while(|(_, dims)| { + dims.height.next_power_of_two() == curr_height_padded + }) + .map(|(i, _)| opened_values[i].as_slice()), + ); + + for &sibling in proof { + // The last bit of index informs us whether the current node is on the left or right. + let (left, right) = if index & 1 == 0 { + (root, sibling) + } else { + (sibling, root) + }; + + // Combine the current node with the sibling node to get the parent node. + root = self.compress.compress([left, right]); + index >>= 1; + curr_height_padded >>= 1; + + // Check if there are any new matrix rows to inject at the next height. + let next_height = heights_tallest_first + .peek() + .map(|(_, dims)| dims.height) + .filter(|h| h.next_power_of_two() == curr_height_padded); + if let Some(next_height) = next_height { + // If there are new matrix rows, hash the rows together and then combine with the current root. + let next_height_openings_digest = self.hash.hash_iter_slices( + heights_tallest_first + .peeking_take_while(|(_, dims)| dims.height == next_height) + .map(|(i, _)| opened_values[i].as_slice()), + ); + + root = self.compress.compress([root, next_height_openings_digest]); + } + } + + // The computed root should equal the committed one. + if commit == &root { + Ok(()) + } else { + Err(RootMismatch) + } + } + *) + Definition verify_batch + (DIGEST_ELEMS : Value.t) + (P PW H C : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS P PW H C in + match ε, τ, α with + | [], [], [ self; commit; dimensions; index; opened_values; proof ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let commit := M.alloc (| commit |) in + let dimensions := M.alloc (| dimensions |) in + let index := M.alloc (| index |) in + let opened_values := M.alloc (| opened_values |) in + let proof := M.alloc (| proof |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::mmcs::Mmcs" + [] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ] + (Ty.apply + (Ty.path "p3_merkle_tree::mmcs::MerkleTreeMmcs") + [ DIGEST_ELEMS ] + [ P; PW; H; C ]) + "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_matrix::Dimensions" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| dimensions |) |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| opened_values |) |) + |) + ] + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_merkle_tree::mmcs::MerkleTreeError::WrongBatchSize" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ heights_tallest_first : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "peekable", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ], + [], + [], + "sorted_by_key", + [], + [ + Ty.apply (Ty.path "core::cmp::Reverse") [] [ Ty.path "usize" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + ] + (Ty.apply (Ty.path "core::cmp::Reverse") [] [ Ty.path "usize" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_matrix::Dimensions" ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_matrix::Dimensions" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_matrix::Dimensions" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| dimensions |) |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::cmp::Reverse") + [] + [ Ty.path "usize" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let dims := M.alloc (| γ1_1 |) in + Value.StructTuple + "core::cmp::Reverse" + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| M.deref (| M.read (| dims |) |) |) + |), + "p3_matrix::Dimensions", + "height" + |) + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + (Ty.path "usize") + ]; + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] + ], + [], + [], + "all", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "itertools::tuple_impl::TupleWindows") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" + ] + ] + ] + ] + (Ty.path "usize") + ]; + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + (Ty.path "usize") + ], + [], + [], + "tuple_windows", + [], + [ Ty.tuple [ Ty.path "usize"; Ty.path "usize" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" + ] + ] + ] + ] + (Ty.path "usize") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "map", + [], + [ + Ty.path "usize"; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" + ] + ] + ] + ] + (Ty.path "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + heights_tallest_first + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + (Ty.path "usize") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let dims := M.copy (| γ0_1 |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| dims |) + |), + "p3_matrix::Dimensions", + "height" + |) + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.path "usize"; Ty.path "usize" ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let curr := M.copy (| γ0_0 |) in + let next := M.copy (| γ0_1 |) in + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| curr |); M.read (| next |) ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "next_power_of_two", + [], + [] + |), + [ M.read (| curr |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "next_power_of_two", + [], + [] + |), + [ M.read (| next |) ] + |) + ] + |))) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_merkle_tree::mmcs::MerkleTreeError::IncompatibleHeights" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ curr_height_padded : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "peek", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, heights_tallest_first |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let dims := M.alloc (| γ2_1 |) in + let~ max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "next_power_of_two", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| M.deref (| M.read (| dims |) |) |) |), + "p3_matrix::Dimensions", + "height" + |) + |) + ] + |) + |) in + let~ log_max_height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| max_height |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| proof |) |) + |) + ] + |); + M.read (| log_max_height |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructRecord + "p3_merkle_tree::mmcs::MerkleTreeError::WrongHeight" + [ + ("log_max_height", + M.read (| log_max_height |)); + ("num_siblings", + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| proof |) |) + |) + ] + |)) + ] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + max_height)); + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_merkle_tree::mmcs::MerkleTreeError::EmptyBatch" + [] + ] + |) + |) + |) + |))) + ] + |) + |) in + let~ root : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] PW "Value" ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + H, + [], + [ + Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value"; + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "hash_iter_slices", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + ] + (Ty.path "bool") + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]) + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "hash" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + ] + (Ty.path "bool") + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + ] + (Ty.path "bool") + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + ] + (Ty.path "bool") + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "peeking_take_while", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, heights_tallest_first |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" + ] + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let dims := M.alloc (| γ1_1 |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "next_power_of_two", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + M.deref (| M.read (| dims |) |) + |) + |), + "p3_matrix::Dimensions", + "height" + |) + |) + ] + |); + M.read (| curr_height_padded |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_matrix::Dimensions" ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let i := M.copy (| γ0_0 |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path "alloc::alloc::Global" + ], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| opened_values |) |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| proof |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let sibling := M.copy (| γ0_0 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ]; + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.bit_and, + [ + M.read (| index |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + Value.Tuple + [ M.read (| root |); M.read (| sibling |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ M.read (| sibling |); M.read (| root |) ] + |))) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let left := M.copy (| γ0_0 |) in + let right := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + root, + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ], + M.get_trait_method (| + "p3_symmetric::compression::PseudoCompressionFunction", + C, + [ Value.Integer IntegerKind.Usize 2 ], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "compress", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "compress" + |) + |); + Value.Array + [ + M.read (| left |); + M.read (| right |) + ] + ] + |) + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := index in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.read (| β |); + Value.Integer IntegerKind.I32 1 + ] + |) + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := curr_height_padded in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.read (| β |); + Value.Integer IntegerKind.I32 1 + ] + |) + |) + |) in + let~ next_height : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + "filter", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "usize" ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ], + "map", + [], + [ + Ty.path "usize"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + ] + (Ty.path "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + "peek", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + heights_tallest_first + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + ] + (Ty.path "usize") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let dims := + M.alloc (| + γ1_1 + |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + M.deref (| + M.read (| + dims + |) + |) + |) + |), + "p3_matrix::Dimensions", + "height" + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "usize" + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let h := + M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "next_power_of_two", + [], + [] + |), + [ + M.read (| + M.deref (| + M.read (| + h + |) + |) + |) + ] + |); + M.read (| + curr_height_padded + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := next_height in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let next_height := M.copy (| γ0_0 |) in + let~ next_height_openings_digest : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + H, + [], + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "hash_iter_slices", + [], + [ + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + ] + (Ty.path "bool") + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]) + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "hash" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + ] + (Ty.path "bool") + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + ] + (Ty.path "bool") + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "itertools::peeking_take_while::PeekingTakeWhile") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + ] + (Ty.path "bool") + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::peekable::Peekable") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "peeking_take_while", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + heights_tallest_first + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + ] + (Ty.path + "bool") + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + γ := + M.read (| + γ + |) in + let + γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let + γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + dims := + M.alloc (| + γ1_1 + |) in + M.call_closure (| + Ty.path + "bool", + BinOp.eq, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + M.deref (| + M.read (| + dims + |) + |) + |) + |), + "p3_matrix::Dimensions", + "height" + |) + |); + M.read (| + next_height + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let i := + M.copy (| + γ0_0 + |) in + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.path + "alloc::alloc::Global" + ], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + opened_values + |) + |), + M.read (| + i + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + root, + M.call_closure (| + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ], + M.get_trait_method (| + "p3_symmetric::compression::PseudoCompressionFunction", + C, + [ + Value.Integer + IntegerKind.Usize + 2 + ], + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + "compress", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_merkle_tree::mmcs::MerkleTreeMmcs", + "compress" + |) + |); + Value.Array + [ + M.read (| root |); + M.read (| + next_height_openings_digest + |) + ] + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "p3_merkle_tree::mmcs::MerkleTreeError" ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::hash::Hash") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value"; + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ DIGEST_ELEMS ] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + PW + "Value" + ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, commit |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| M.borrow (| Pointer.Kind.Ref, root |) |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple "core::result::Result::Ok" [ Value.Tuple [] ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_merkle_tree::mmcs::MerkleTreeError::RootMismatch" + [] + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (P PW H C : Ty.t), + M.IsTraitInstance + "p3_commit::mmcs::Mmcs" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.associated_in_trait "p3_field::packed::PackedValue" [] [] P "Value" ] + (Self DIGEST_ELEMS P PW H C) + (* Instance *) + [ + ("ProverData", InstanceField.Ty (_ProverData DIGEST_ELEMS P PW H C)); + ("Commitment", InstanceField.Ty (_Commitment DIGEST_ELEMS P PW H C)); + ("Proof", InstanceField.Ty (_Proof DIGEST_ELEMS P PW H C)); + ("Error", InstanceField.Ty (_Error DIGEST_ELEMS P PW H C)); + ("commit", InstanceField.Method (commit DIGEST_ELEMS P PW H C)); + ("open_batch", InstanceField.Method (open_batch DIGEST_ELEMS P PW H C)); + ("get_matrices", InstanceField.Method (get_matrices DIGEST_ELEMS P PW H C)); + ("verify_batch", InstanceField.Method (verify_batch DIGEST_ELEMS P PW H C)) + ]. + End Impl_p3_commit_mmcs_Mmcs_where_p3_field_packed_PackedValue_P_where_p3_field_packed_PackedValue_PW_where_p3_symmetric_hasher_CryptographicHasher_H_associated_in_trait_p3_field_packed_PackedValue___P_Value_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_p3_symmetric_hasher_CryptographicHasher_H_P_array_DIGEST_ELEMS_PW_where_core_marker_Sync_H_where_p3_symmetric_compression_PseudoCompressionFunction_C_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_p3_symmetric_compression_PseudoCompressionFunction_C_array_DIGEST_ELEMS_PW_where_core_marker_Sync_C_where_core_cmp_Eq_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_serde_ser_Serialize_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_where_serde_de_Deserialize_array_DIGEST_ELEMS_associated_in_trait_p3_field_packed_PackedValue___PW_Value_associated_in_trait_p3_field_packed_PackedValue___P_Value_for_p3_merkle_tree_mmcs_MerkleTreeMmcs_DIGEST_ELEMS_P_PW_H_C. +End mmcs. diff --git a/CoqOfRust/plonky3/mersenne-31/src/aarch64_neon/mod.rs b/CoqOfRust/plonky3/mersenne-31/src/aarch64_neon/mod.rs new file mode 100644 index 000000000..30b9a1acb --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/aarch64_neon/mod.rs @@ -0,0 +1,5 @@ +mod packing; +mod poseidon2; + +pub use packing::*; +pub use poseidon2::*; diff --git a/CoqOfRust/plonky3/mersenne-31/src/aarch64_neon/packing.rs b/CoqOfRust/plonky3/mersenne-31/src/aarch64_neon/packing.rs new file mode 100644 index 000000000..a5ad43f4d --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/aarch64_neon/packing.rs @@ -0,0 +1,576 @@ +use alloc::vec::Vec; +use core::arch::aarch64::{self, uint32x4_t}; +use core::iter::{Product, Sum}; +use core::mem::transmute; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; + +use p3_field::exponentiation::exp_1717986917; +use p3_field::{ + Algebra, Field, InjectiveMonomial, PackedField, PackedFieldPow2, PackedValue, + PermutationMonomial, PrimeCharacteristicRing, +}; +use p3_util::reconstitute_from_base; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; + +use crate::Mersenne31; + +const WIDTH: usize = 4; +const P: uint32x4_t = unsafe { transmute::<[u32; WIDTH], _>([0x7fffffff; WIDTH]) }; + +/// Vectorized NEON implementation of `Mersenne31` arithmetic. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(transparent)] // Needed to make `transmute`s safe. +pub struct PackedMersenne31Neon(pub [Mersenne31; WIDTH]); + +impl PackedMersenne31Neon { + #[inline] + #[must_use] + /// Get an arch-specific vector representing the packed values. + fn to_vector(self) -> uint32x4_t { + unsafe { + // Safety: `Mersenne31` is `repr(transparent)` so it can be transmuted to `u32`. It + // follows that `[Mersenne31; WIDTH]` can be transmuted to `[u32; WIDTH]`, which can be + // transmuted to `uint32x4_t`, since arrays are guaranteed to be contiguous in memory. + // Finally `PackedMersenne31Neon` is `repr(transparent)` so it can be transmuted to + // `[Mersenne31; WIDTH]`. + transmute(self) + } + } + + #[inline] + #[must_use] + /// Make a packed field vector from an arch-specific vector. + /// + /// SAFETY: The caller must ensure that each element of `vector` represents a valid + /// `Mersenne31`. In particular, each element of vector must be in `0..=P` (i.e. it fits in 31 + /// bits). + unsafe fn from_vector(vector: uint32x4_t) -> Self { + // Safety: It is up to the user to ensure that elements of `vector` represent valid + // `Mersenne31` values. We must only reason about memory representations. `uint32x4_t` can + // be transmuted to `[u32; WIDTH]` (since arrays elements are contiguous in memory), which + // can be transmuted to `[Mersenne31; WIDTH]` (since `Mersenne31` is `repr(transparent)`), + // which in turn can be transmuted to `PackedMersenne31Neon` (since `PackedMersenne31Neon` + // is also `repr(transparent)`). + unsafe { transmute(vector) } + } + + /// Copy `value` to all positions in a packed vector. This is the same as + /// `From::from`, but `const`. + #[inline] + #[must_use] + const fn broadcast(value: Mersenne31) -> Self { + Self([value; WIDTH]) + } +} + +impl Add for PackedMersenne31Neon { + type Output = Self; + #[inline] + fn add(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = add(lhs, rhs); + unsafe { + // Safety: `add` returns valid values when given valid values. + Self::from_vector(res) + } + } +} + +impl Mul for PackedMersenne31Neon { + type Output = Self; + #[inline] + fn mul(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = mul(lhs, rhs); + unsafe { + // Safety: `mul` returns valid values when given valid values. + Self::from_vector(res) + } + } +} + +impl Neg for PackedMersenne31Neon { + type Output = Self; + #[inline] + fn neg(self) -> Self { + let val = self.to_vector(); + let res = neg(val); + unsafe { + // Safety: `neg` returns valid values when given valid values. + Self::from_vector(res) + } + } +} + +impl Sub for PackedMersenne31Neon { + type Output = Self; + #[inline] + fn sub(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = sub(lhs, rhs); + unsafe { + // Safety: `sub` returns valid values when given valid values. + Self::from_vector(res) + } + } +} + +/// Given a `val` in `0, ..., 2 P`, return a `res` in `0, ..., P` such that `res = val (mod P)` +#[inline] +#[must_use] +fn reduce_sum(val: uint32x4_t) -> uint32x4_t { + // val is in 0, ..., 2 P. If val is in 0, ..., P - 1 then it is valid and + // u := (val - P) mod 2^32 is in P uint32x4_t { + // We want this to compile to: + // add t.4s, lhs.4s, rhs.4s + // sub u.4s, t.4s, P.4s + // umin res.4s, t.4s, u.4s + // throughput: .75 cyc/vec (5.33 els/cyc) + // latency: 6 cyc + + // lhs and rhs are in 0, ..., P, and we want the result to also be in that range. + // t := lhs + rhs is in 0, ..., 2 P, so we apply reduce_sum. + + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + let t = aarch64::vaddq_u32(lhs, rhs); + reduce_sum(t) + } +} + +/// Multiply two 31-bit numbers to obtain a 62-bit immediate result, and return the high 31 bits of +/// that result. Results are arbitrary if the inputs do not fit in 31 bits. +#[inline] +#[must_use] +fn mul_31x31_to_hi_31(lhs: uint32x4_t, rhs: uint32x4_t) -> uint32x4_t { + // This is just a wrapper around `aarch64::vqdmulhq_s32`, so we don't have to worry about the + // casting elsewhere. + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + aarch64::vreinterpretq_u32_s32(aarch64::vqdmulhq_s32( + aarch64::vreinterpretq_s32_u32(lhs), + aarch64::vreinterpretq_s32_u32(rhs), + )) + } +} + +/// Multiply vectors of Mersenne-31 field elements that fit in 31 bits. +/// If the inputs do not fit in 31 bits, the result is undefined. +#[inline] +#[must_use] +fn mul(lhs: uint32x4_t, rhs: uint32x4_t) -> uint32x4_t { + // We want this to compile to: + // sqdmulh prod_hi31.4s, lhs.4s, rhs.4s + // mul t.4s, lhs.4s, rhs.4s + // mla t.4s, prod_hi31.4s, P.4s + // sub u.4s, t.4s, P.4s + // umin res.4s, t.4s, u.4s + // throughput: 1.25 cyc/vec (3.2 els/cyc) + // latency: 10 cyc + + // We want to return res in 0, ..., P such that res = lhs * rhs (mod P). + // Let prod := lhs * rhs. Break it up into prod = 2^31 prod_hi31 + prod_lo31, where both limbs + // are in 0, ..., 2^31 - 1. Then prod = prod_hi31 + prod_lo31 (mod P), so let + // t := prod_hi31 + prod_lo31. + // Define prod_lo32 = prod mod 2^32 and observe that + // prod_lo32 = prod_lo31 + 2^31 (prod_hi31 mod 2) + // = prod_lo31 + 2^31 prod_hi31 (mod 2^32) + // Then + // t = prod_lo32 - 2^31 prod_hi31 + prod_hi31 (mod 2^32) + // = prod_lo32 - (2^31 - 1) prod_hi31 (mod 2^32) + // = prod_lo32 - prod_hi31 * P (mod 2^32) + // + // t is in 0, ..., 2 P, so we apply reduce_sum to get the result. + + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + let prod_hi31 = mul_31x31_to_hi_31(lhs, rhs); + let prod_lo32 = aarch64::vmulq_u32(lhs, rhs); + let t = aarch64::vmlsq_u32(prod_lo32, prod_hi31, P); + reduce_sum(t) + } +} + +/// Negate a vector of Mersenne-31 field elements that fit in 31 bits. +/// If the inputs do not fit in 31 bits, the result is undefined. +#[inline] +#[must_use] +fn neg(val: uint32x4_t) -> uint32x4_t { + // We want this to compile to: + // eor res.16b, val.16b, P.16b + // throughput: .25 cyc/vec (16 els/cyc) + // latency: 2 cyc + + // val is in 0, ..., P, so res := P - val is also in 0, ..., P. + + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + aarch64::vsubq_u32(P, val) + } +} + +/// Subtract vectors of Mersenne-31 field elements that fit in 31 bits. +/// If the inputs do not fit in 31 bits, the result is undefined. +#[inline] +#[must_use] +fn sub(lhs: uint32x4_t, rhs: uint32x4_t) -> uint32x4_t { + // We want this to compile to: + // sub res.4s, lhs.4s, rhs.4s + // cmhi underflow.4s, rhs.4s, lhs.4s + // mls res.4s, underflow.4s, P.4s + // throughput: .75 cyc/vec (5.33 els/cyc) + // latency: 5 cyc + + // lhs and rhs are in 0, ..., P, and we want the result to also be in that range. + // Define: diff := (lhs - rhs) mod 2^32 + // underflow := 2^32 - 1 if lhs =u rhs, then diff is in 0, ..., P and underflow is 0. res = diff is valid. + // 2. Otherwise, lhs for PackedMersenne31Neon { + #[inline] + fn from(value: Mersenne31) -> Self { + Self::broadcast(value) + } +} + +impl Default for PackedMersenne31Neon { + #[inline] + fn default() -> Self { + Mersenne31::default().into() + } +} + +impl AddAssign for PackedMersenne31Neon { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} + +impl MulAssign for PackedMersenne31Neon { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} + +impl SubAssign for PackedMersenne31Neon { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} + +impl Sum for PackedMersenne31Neon { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs + rhs).unwrap_or(Self::ZERO) + } +} + +impl Product for PackedMersenne31Neon { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs * rhs).unwrap_or(Self::ONE) + } +} + +impl PrimeCharacteristicRing for PackedMersenne31Neon { + type PrimeSubfield = Mersenne31; + + const ZERO: Self = Self::broadcast(Mersenne31::ZERO); + const ONE: Self = Self::broadcast(Mersenne31::ONE); + const TWO: Self = Self::broadcast(Mersenne31::TWO); + const NEG_ONE: Self = Self::broadcast(Mersenne31::NEG_ONE); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f.into() + } + + #[inline(always)] + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(Mersenne31::zero_vec(len * WIDTH)) } + } +} + +impl Algebra for PackedMersenne31Neon {} + +// Degree of the smallest permutation polynomial for Mersenne31. +// +// As p - 1 = 2×3^2×7×11×... the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 5. +impl InjectiveMonomial<5> for PackedMersenne31Neon {} + +impl PermutationMonomial<5> for PackedMersenne31Neon { + /// In the field `Mersenne31`, `a^{1/5}` is equal to a^{1717986917}. + /// + /// This follows from the calculation `5 * 1717986917 = 4*(2^31 - 2) + 1 = 1 mod p - 1`. + fn injective_exp_root_n(&self) -> Self { + exp_1717986917(*self) + } +} + +impl Add for PackedMersenne31Neon { + type Output = Self; + #[inline] + fn add(self, rhs: Mersenne31) -> Self { + self + Self::from(rhs) + } +} + +impl Mul for PackedMersenne31Neon { + type Output = Self; + #[inline] + fn mul(self, rhs: Mersenne31) -> Self { + self * Self::from(rhs) + } +} + +impl Sub for PackedMersenne31Neon { + type Output = Self; + #[inline] + fn sub(self, rhs: Mersenne31) -> Self { + self - Self::from(rhs) + } +} + +impl AddAssign for PackedMersenne31Neon { + #[inline] + fn add_assign(&mut self, rhs: Mersenne31) { + *self += Self::from(rhs) + } +} + +impl MulAssign for PackedMersenne31Neon { + #[inline] + fn mul_assign(&mut self, rhs: Mersenne31) { + *self *= Self::from(rhs) + } +} + +impl SubAssign for PackedMersenne31Neon { + #[inline] + fn sub_assign(&mut self, rhs: Mersenne31) { + *self -= Self::from(rhs) + } +} + +impl Sum for PackedMersenne31Neon { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator, + { + iter.sum::().into() + } +} + +impl Product for PackedMersenne31Neon { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator, + { + iter.product::().into() + } +} + +impl Div for PackedMersenne31Neon { + type Output = Self; + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: Mersenne31) -> Self { + self * rhs.inverse() + } +} + +impl Add for Mersenne31 { + type Output = PackedMersenne31Neon; + #[inline] + fn add(self, rhs: PackedMersenne31Neon) -> PackedMersenne31Neon { + PackedMersenne31Neon::from(self) + rhs + } +} + +impl Mul for Mersenne31 { + type Output = PackedMersenne31Neon; + #[inline] + fn mul(self, rhs: PackedMersenne31Neon) -> PackedMersenne31Neon { + PackedMersenne31Neon::from(self) * rhs + } +} + +impl Sub for Mersenne31 { + type Output = PackedMersenne31Neon; + #[inline] + fn sub(self, rhs: PackedMersenne31Neon) -> PackedMersenne31Neon { + PackedMersenne31Neon::from(self) - rhs + } +} + +impl Distribution for StandardUniform { + #[inline] + fn sample(&self, rng: &mut R) -> PackedMersenne31Neon { + PackedMersenne31Neon(rng.random()) + } +} + +#[inline] +#[must_use] +fn interleave1(v0: uint32x4_t, v1: uint32x4_t) -> (uint32x4_t, uint32x4_t) { + // We want this to compile to: + // trn1 res0.4s, v0.4s, v1.4s + // trn2 res1.4s, v0.4s, v1.4s + // throughput: .5 cyc/2 vec (16 els/cyc) + // latency: 2 cyc + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + (aarch64::vtrn1q_u32(v0, v1), aarch64::vtrn2q_u32(v0, v1)) + } +} + +#[inline] +#[must_use] +fn interleave2(v0: uint32x4_t, v1: uint32x4_t) -> (uint32x4_t, uint32x4_t) { + // We want this to compile to: + // trn1 res0.2d, v0.2d, v1.2d + // trn2 res1.2d, v0.2d, v1.2d + // throughput: .5 cyc/2 vec (16 els/cyc) + // latency: 2 cyc + + // To transpose 64-bit blocks, cast the [u32; 4] vectors to [u64; 2], transpose, and cast back. + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + let v0 = aarch64::vreinterpretq_u64_u32(v0); + let v1 = aarch64::vreinterpretq_u64_u32(v1); + ( + aarch64::vreinterpretq_u32_u64(aarch64::vtrn1q_u64(v0, v1)), + aarch64::vreinterpretq_u32_u64(aarch64::vtrn2q_u64(v0, v1)), + ) + } +} + +unsafe impl PackedValue for PackedMersenne31Neon { + type Value = Mersenne31; + + const WIDTH: usize = WIDTH; + + #[inline] + fn from_slice(slice: &[Mersenne31]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[Mersenne31; WIDTH]` can be transmuted to `PackedMersenne31Neon` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast + // is safe too. + &*slice.as_ptr().cast() + } + } + #[inline] + fn from_slice_mut(slice: &mut [Mersenne31]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[Mersenne31; WIDTH]` can be transmuted to `PackedMersenne31Neon` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast + // is safe too. + &mut *slice.as_mut_ptr().cast() + } + } + + /// Similar to `core:array::from_fn`. + #[inline] + fn from_fn Mersenne31>(f: F) -> Self { + let vals_arr: [_; WIDTH] = core::array::from_fn(f); + Self(vals_arr) + } + + #[inline] + fn as_slice(&self) -> &[Mersenne31] { + &self.0[..] + } + #[inline] + fn as_slice_mut(&mut self) -> &mut [Mersenne31] { + &mut self.0[..] + } +} + +unsafe impl PackedField for PackedMersenne31Neon { + type Scalar = Mersenne31; +} + +unsafe impl PackedFieldPow2 for PackedMersenne31Neon { + #[inline] + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { + let (v0, v1) = (self.to_vector(), other.to_vector()); + let (res0, res1) = match block_len { + 1 => interleave1(v0, v1), + 2 => interleave2(v0, v1), + 4 => (v0, v1), + _ => panic!("unsupported block_len"), + }; + unsafe { + // Safety: all values are in canonical form (we haven't changed them). + (Self::from_vector(res0), Self::from_vector(res1)) + } + } +} + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::{Mersenne31, PackedMersenne31Neon}; + + /// Zero has a redundant representation, so let's test both. + const ZEROS: PackedMersenne31Neon = PackedMersenne31Neon(Mersenne31::new_array([ + 0x00000000, 0x7fffffff, 0x00000000, 0x7fffffff, + ])); + + const SPECIAL_VALS: PackedMersenne31Neon = PackedMersenne31Neon(Mersenne31::new_array([ + 0x00000000, 0x00000001, 0x00000002, 0x7ffffffe, + ])); + + test_packed_field!( + crate::PackedMersenne31Neon, + &[super::ZEROS], + &[crate::PackedMersenne31Neon::ONE], + super::SPECIAL_VALS + ); +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/aarch64_neon/poseidon2.rs b/CoqOfRust/plonky3/mersenne-31/src/aarch64_neon/poseidon2.rs new file mode 100644 index 000000000..438029171 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/aarch64_neon/poseidon2.rs @@ -0,0 +1,135 @@ +//! Eventually this will hold a vectorized Neon implementation of Poseidon2 for PackedMersenne31Neon +//! Currently this is essentially a placeholder to allow compilation on Neon devices. +//! +//! Converting the AVX2/AVX512 code across to Neon is on the TODO list. + +use alloc::vec::Vec; + +use p3_poseidon2::{ + ExternalLayer, ExternalLayerConstants, ExternalLayerConstructor, GenericPoseidon2LinearLayers, + InternalLayer, InternalLayerConstructor, MDSMat4, add_rc_and_sbox_generic, + external_initial_permute_state, external_terminal_permute_state, +}; + +use crate::{GenericPoseidon2LinearLayersMersenne31, Mersenne31, PackedMersenne31Neon}; + +/// The internal layers of the Poseidon2 permutation. +#[derive(Debug, Clone)] +pub struct Poseidon2InternalLayerMersenne31 { + pub(crate) internal_constants: Vec, +} + +/// The external layers of the Poseidon2 permutation. +#[derive(Clone)] +pub struct Poseidon2ExternalLayerMersenne31 { + pub(crate) external_constants: ExternalLayerConstants, +} + +impl InternalLayerConstructor for Poseidon2InternalLayerMersenne31 { + fn new_from_constants(internal_constants: Vec) -> Self { + Self { internal_constants } + } +} + +impl ExternalLayerConstructor + for Poseidon2ExternalLayerMersenne31 +{ + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + Self { external_constants } + } +} + +impl InternalLayer + for Poseidon2InternalLayerMersenne31 +where + GenericPoseidon2LinearLayersMersenne31: + GenericPoseidon2LinearLayers, +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [PackedMersenne31Neon; WIDTH]) { + self.internal_constants.iter().for_each(|&rc| { + add_rc_and_sbox_generic(&mut state[0], rc); + GenericPoseidon2LinearLayersMersenne31::internal_linear_layer(state); + }) + } +} + +impl ExternalLayer + for Poseidon2ExternalLayerMersenne31 +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [PackedMersenne31Neon; WIDTH]) { + external_initial_permute_state( + state, + self.external_constants.get_initial_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [PackedMersenne31Neon; WIDTH]) { + external_terminal_permute_state( + state, + self.external_constants.get_terminal_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } +} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + use crate::Poseidon2Mersenne31; + + type F = Mersenne31; + type Perm16 = Poseidon2Mersenne31<16>; + type Perm24 = Poseidon2Mersenne31<24>; + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_neon_poseidon2_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm16::new_from_rng_128(&mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut neon_input = input.map(Into::::into); + poseidon2.permute_mut(&mut neon_input); + + let neon_output = neon_input.map(|x| x.0[0]); + + assert_eq!(neon_output, expected); + } + + /// Test that the output is the same as the scalar version on a random input. + #[test] + fn test_neon_poseidon2_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm24::new_from_rng_128(&mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut neon_input = input.map(Into::::into); + poseidon2.permute_mut(&mut neon_input); + + let neon_output = neon_input.map(|x| x.0[0]); + + assert_eq!(neon_output, expected); + } +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/complex.rs b/CoqOfRust/plonky3/mersenne-31/src/complex.rs new file mode 100644 index 000000000..e6e4d28ce --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/complex.rs @@ -0,0 +1,194 @@ +//! Implementation of the quadratic extension of the Mersenne31 field +//! by X^2 + 1. +//! +//! Note that X^2 + 1 is irreducible over p = Mersenne31 field because +//! kronecker(-1, p) = -1, that is, -1 is not square in F_p. + +use p3_field::PrimeCharacteristicRing; +use p3_field::extension::{Complex, ComplexExtendable, HasTwoAdicBinomialExtension}; + +use crate::Mersenne31; + +impl ComplexExtendable for Mersenne31 { + const CIRCLE_TWO_ADICITY: usize = 31; + + // sage: p = 2^31 - 1 + // sage: F = GF(p) + // sage: R. = F[] + // sage: F2. = F.extension(x^2 + 1) + // sage: F2.multiplicative_generator() + // u + 12 + const COMPLEX_GENERATOR: Complex = Complex::new_complex(Self::new(12), Self::ONE); + + fn circle_two_adic_generator(bits: usize) -> Complex { + // Generator of the whole 2^TWO_ADICITY group + // sage: p = 2^31 - 1 + // sage: F = GF(p) + // sage: R. = F[] + // sage: F2. = F.extension(x^2 + 1) + // sage: g = F2.multiplicative_generator()^((p^2 - 1) / 2^31); g + // 1584694829*u + 311014874 + // sage: assert(g.multiplicative_order() == 2^31) + // sage: assert(g.norm() == 1) + let base = Complex::new_complex(Self::new(311_014_874), Self::new(1_584_694_829)); + base.exp_power_of_2(Self::CIRCLE_TWO_ADICITY - bits) + } +} + +impl HasTwoAdicBinomialExtension<2> for Mersenne31 { + const EXT_TWO_ADICITY: usize = 32; + + fn ext_two_adic_generator(bits: usize) -> [Self; 2] { + // TODO: Consider a `match` which may speed this up. + assert!(bits <= Self::EXT_TWO_ADICITY); + // Generator of the whole 2^TWO_ADICITY group + // sage: p = 2^31 - 1 + // sage: F = GF(p) + // sage: R. = F[] + // sage: F2. = F.extension(x^2 + 1) + // sage: g = F2.multiplicative_generator()^((p^2 - 1) / 2^32); g + // 1117296306*u + 1166849849 + // sage: assert(g.multiplicative_order() == 2^32) + let base = Complex::::new_complex(Self::new(1_166_849_849), Self::new(1_117_296_306)); + base.exp_power_of_2(Self::EXT_TWO_ADICITY - bits).to_array() + } +} + +#[cfg(test)] +mod tests { + use num_bigint::BigUint; + use p3_field::PrimeField32; + use p3_field_testing::{test_field, test_two_adic_field}; + + use super::*; + + type Fi = Complex; + type F = Mersenne31; + + #[test] + fn add() { + // real part + assert_eq!(Fi::ONE + Fi::ONE, Fi::TWO); + assert_eq!(Fi::NEG_ONE + Fi::ONE, Fi::ZERO); + assert_eq!(Fi::NEG_ONE + Fi::TWO, Fi::ONE); + assert_eq!((Fi::NEG_ONE + Fi::NEG_ONE).real(), F::new(F::ORDER_U32 - 2)); + + // complex part + assert_eq!( + Fi::new_imag(F::ONE) + Fi::new_imag(F::ONE), + Fi::new_imag(F::TWO) + ); + assert_eq!( + Fi::new_imag(F::NEG_ONE) + Fi::new_imag(F::ONE), + Fi::new_imag(F::ZERO) + ); + assert_eq!( + Fi::new_imag(F::NEG_ONE) + Fi::new_imag(F::TWO), + Fi::new_imag(F::ONE) + ); + assert_eq!( + (Fi::new_imag(F::NEG_ONE) + Fi::new_imag(F::NEG_ONE)).imag(), + F::new(F::ORDER_U32 - 2) + ); + + // further tests + assert_eq!( + Fi::new_complex(F::ONE, F::TWO) + Fi::new_complex(F::ONE, F::ONE), + Fi::new_complex(F::TWO, F::new(3)) + ); + assert_eq!( + Fi::new_complex(F::NEG_ONE, F::NEG_ONE) + Fi::new_complex(F::ONE, F::ONE), + Fi::ZERO + ); + assert_eq!( + Fi::new_complex(F::NEG_ONE, F::ONE) + Fi::new_complex(F::TWO, F::new(F::ORDER_U32 - 2)), + Fi::new_complex(F::ONE, F::NEG_ONE) + ); + } + + #[test] + fn sub() { + // real part + assert_eq!(Fi::ONE - Fi::ONE, Fi::ZERO); + assert_eq!(Fi::TWO - Fi::TWO, Fi::ZERO); + assert_eq!(Fi::NEG_ONE - Fi::NEG_ONE, Fi::ZERO); + assert_eq!(Fi::TWO - Fi::ONE, Fi::ONE); + assert_eq!(Fi::NEG_ONE - Fi::ZERO, Fi::NEG_ONE); + + // complex part + assert_eq!(Fi::new_imag(F::ONE) - Fi::new_imag(F::ONE), Fi::ZERO); + assert_eq!(Fi::new_imag(F::TWO) - Fi::new_imag(F::TWO), Fi::ZERO); + assert_eq!( + Fi::new_imag(F::NEG_ONE) - Fi::new_imag(F::NEG_ONE), + Fi::ZERO + ); + assert_eq!( + Fi::new_imag(F::TWO) - Fi::new_imag(F::ONE), + Fi::new_imag(F::ONE) + ); + assert_eq!( + Fi::new_imag(F::NEG_ONE) - Fi::ZERO, + Fi::new_imag(F::NEG_ONE) + ); + } + + #[test] + fn mul() { + assert_eq!( + Fi::new_complex(F::TWO, F::TWO) * Fi::new_complex(F::new(4), F::new(5)), + Fi::new_complex(-F::TWO, F::new(18)) + ); + } + + #[test] + fn mul_2exp_u64() { + // real part + // 1 * 2^0 = 1. + assert_eq!(Fi::ONE.mul_2exp_u64(0), Fi::ONE); + // 2 * 2^30 = 2^31 = 1. + assert_eq!(Fi::TWO.mul_2exp_u64(30), Fi::ONE); + // 5 * 2^2 = 20. + assert_eq!( + Fi::new_real(F::new(5)).mul_2exp_u64(2), + Fi::new_real(F::new(20)) + ); + + // complex part + // i * 2^0 = i. + assert_eq!(Fi::new_imag(F::ONE).mul_2exp_u64(0), Fi::new_imag(F::ONE)); + // (2i) * 2^30 = (2^31) * i = i. + assert_eq!(Fi::new_imag(F::TWO).mul_2exp_u64(30), Fi::new_imag(F::ONE)); + // 5i * 2^2 = 20i. + assert_eq!( + Fi::new_imag(F::new(5)).mul_2exp_u64(2), + Fi::new_imag(F::new(20)) + ); + } + + // There is a redundant representation of zero but we already tested it + // when testing the base field. + const ZEROS: [Fi; 1] = [Fi::ZERO]; + const ONES: [Fi; 1] = [Fi::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P^2 - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 7] { + [ + (BigUint::from(2u8), 32), + (BigUint::from(3u8), 2), + (BigUint::from(7u8), 1), + (BigUint::from(11u8), 1), + (BigUint::from(31u8), 1), + (BigUint::from(151u8), 1), + (BigUint::from(331u16), 1), + ] + } + + test_field!( + super::Fi, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + test_two_adic_field!(p3_field::extension::Complex); +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/complex.v b/CoqOfRust/plonky3/mersenne-31/src/complex.v new file mode 100644 index 000000000..d8c5c8de8 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/complex.v @@ -0,0 +1,420 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module complex. + Module Impl_p3_field_extension_complex_ComplexExtendable_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const CIRCLE_TWO_ADICITY: usize = 31; *) + (* Ty.path "usize" *) + Definition value_CIRCLE_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 31 |))). + + (* const COMPLEX_GENERATOR: Complex = Complex::new_complex(Self::new(12), Self::ONE); *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] *) + Definition value_COMPLEX_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_complex", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 12 ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |) + |) + ] + |) + |))). + + (* + fn circle_two_adic_generator(bits: usize) -> Complex { + // Generator of the whole 2^TWO_ADICITY group + // sage: p = 2^31 - 1 + // sage: F = GF(p) + // sage: R. = F[] + // sage: F2. = F.extension(x^2 + 1) + // sage: g = F2.multiplicative_generator()^((p^2 - 1) / 2^31); g + // 1584694829*u + 311014874 + // sage: assert(g.multiplicative_order() == 2^31) + // sage: assert(g.norm() == 1) + let base = Complex::new_complex(Self::new(311_014_874), Self::new(1_584_694_829)); + base.exp_power_of_2(Self::CIRCLE_TWO_ADICITY - bits) + } + *) + Definition circle_two_adic_generator + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.read (| + let~ base : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_complex", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 311014874 ] + |); + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 1584694829 ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, base |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::extension::complex::ComplexExtendable::CIRCLE_TWO_ADICITY", + Ty.path "usize" + |) + |); + M.read (| bits |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::complex::ComplexExtendable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_CIRCLE_TWO_ADICITY", InstanceField.Method value_CIRCLE_TWO_ADICITY); + ("value_COMPLEX_GENERATOR", InstanceField.Method value_COMPLEX_GENERATOR); + ("circle_two_adic_generator", InstanceField.Method circle_two_adic_generator) + ]. + End Impl_p3_field_extension_complex_ComplexExtendable_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_extension_HasTwoAdicBinomialExtension_Usize_2_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const EXT_TWO_ADICITY: usize = 32; *) + (* Ty.path "usize" *) + Definition value_EXT_TWO_ADICITY (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 32 |))). + + (* + fn ext_two_adic_generator(bits: usize) -> [Self; 2] { + // TODO: Consider a `match` which may speed this up. + assert!(bits <= Self::EXT_TWO_ADICITY); + // Generator of the whole 2^TWO_ADICITY group + // sage: p = 2^31 - 1 + // sage: F = GF(p) + // sage: R. = F[] + // sage: F2. = F.extension(x^2 + 1) + // sage: g = F2.multiplicative_generator()^((p^2 - 1) / 2^32); g + // 1117296306*u + 1166849849 + // sage: assert(g.multiplicative_order() == 2^32) + let base = Complex::::new_complex(Self::new(1_166_849_849), Self::new(1_117_296_306)); + base.exp_power_of_2(Self::EXT_TWO_ADICITY - bits).to_array() + } + *) + Definition ext_two_adic_generator (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| bits |); + M.read (| + get_constant (| + "p3_field::extension::HasTwoAdicBinomialExtension::EXT_TWO_ADICITY", + Ty.path "usize" + |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits <= Self::EXT_TWO_ADICITY" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ base : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_complex", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 1166849849 ] + |); + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 1117296306 ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "to_array", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, base |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::extension::HasTwoAdicBinomialExtension::EXT_TWO_ADICITY", + Ty.path "usize" + |) + |); + M.read (| bits |) + ] + |) + ] + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::HasTwoAdicBinomialExtension" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 2 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_EXT_TWO_ADICITY", InstanceField.Method value_EXT_TWO_ADICITY); + ("ext_two_adic_generator", InstanceField.Method ext_two_adic_generator) + ]. + End Impl_p3_field_extension_HasTwoAdicBinomialExtension_Usize_2_for_p3_mersenne_31_mersenne_31_Mersenne31. +End complex. diff --git a/CoqOfRust/plonky3/mersenne-31/src/dft.rs b/CoqOfRust/plonky3/mersenne-31/src/dft.rs new file mode 100644 index 000000000..23c8992f1 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/dft.rs @@ -0,0 +1,241 @@ +//! Implementation of DFT for `Mersenne31`. +//! +//! Strategy follows: `` +//! In short, fold a Mersenne31 DFT of length n into a Mersenne31Complex DFT +//! of length n/2. Some pre/post-processing is necessary so that the result +//! of the transform behaves as expected wrt the convolution theorem etc. +//! +//! Note that we don't return the final n/2 - 1 elements since we know that +//! the "complex conjugate" of the (n-k)th element equals the kth element. +//! The convolution theorem maintains this relationship and so these final +//! n/2 - 1 elements are essentially redundant. + +use alloc::vec::Vec; + +use itertools::{Itertools, izip}; +use p3_dft::TwoAdicSubgroupDft; +use p3_field::extension::Complex; +use p3_field::{Field, PrimeCharacteristicRing, TwoAdicField}; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_util::log2_strict_usize; + +use crate::Mersenne31; + +type F = Mersenne31; +type C = Complex; + +/// Given an hxw matrix M = (m_{ij}) where h is even, return an +/// (h/2)xw matrix N whose (k,l) entry is +/// +/// Mersenne31Complex(m_{2k,l}, m_{2k+1,l}) +/// +/// i.e. the even rows become the real parts and the odd rows become +/// the imaginary parts. +/// +/// This packing is suitable as input to a Fourier Transform over the +/// domain Mersenne31Complex; it is inverse to `idft_postprocess()` +/// below. +fn dft_preprocess(input: RowMajorMatrix) -> RowMajorMatrix { + assert!(input.height() % 2 == 0, "input height must be even"); + RowMajorMatrix::new( + input + .rows() + .tuples() + .flat_map(|(row_0, row_1)| { + // For each pair of rows in input, convert each + // two-element column into a Mersenne31Complex + // treating the first row as the real part and the + // second row as the imaginary part. + row_0.zip(row_1).map(|(x, y)| C::new_complex(x, y)) + }) + .collect(), + input.width(), + ) +} + +/// Transform the result of applying the DFT to the packed +/// `Mersenne31` values so that the convolution theorem holds. +/// +/// Source: https://www.robinscheibler.org/2013/02/13/real-fft.html +/// +/// NB: This function and `idft_preprocess()` are inverses. +fn dft_postprocess(input: RowMajorMatrix) -> RowMajorMatrix { + let h = input.height(); + let log2_h = log2_strict_usize(h); // checks that h is a power of two + + // NB: The original real matrix had height 2h, hence log2(2h) = log2(h) + 1. + // omega is a 2h-th root of unity + let omega = C::two_adic_generator(log2_h + 1); + let mut omega_j = omega; + + let mut output = Vec::with_capacity((h + 1) * input.width()); + output.extend(input.first_row().map(|x| C::new_real(x.real() + x.imag()))); + + for j in 1..h { + let row = izip!(input.row(j), input.row(h - j)).map(|(x, y)| { + let even = x + y.conjugate(); + // odd = (x - y.conjugate()) * -i + let odd = C::new_complex(x.imag() + y.imag(), y.real() - x.real()); + (even + odd * omega_j).halve() + }); + output.extend(row); + omega_j *= omega; + } + + output.extend(input.first_row().map(|x| C::new_real(x.real() - x.imag()))); + debug_assert_eq!(output.len(), (h + 1) * input.width()); + RowMajorMatrix::new(output, input.width()) +} + +/// Undo the transform of the DFT matrix in `dft_postprocess()` so +/// that the inverse DFT can be applied. +/// +/// Source: https://www.robinscheibler.org/2013/02/13/real-fft.html +/// +/// NB: This function and `dft_postprocess()` are inverses. +fn idft_preprocess(input: RowMajorMatrix) -> RowMajorMatrix { + let h = input.height() - 1; + let log2_h = log2_strict_usize(h); // checks that h is a power of two + + // NB: The original real matrix had length 2h, hence log2(2h) = log2(h) + 1. + // omega is a 2n-th root of unity + let omega = C::two_adic_generator(log2_h + 1).inverse(); + let mut omega_j = C::ONE; + + let mut output = Vec::with_capacity(h * input.width()); + // TODO: Specialise j = 0 and j = n (which we know must be real)? + for j in 0..h { + let row = izip!(input.row(j), input.row(h - j)).map(|(x, y)| { + let even = x + y.conjugate(); + // odd = (x - y.conjugate()) * -i + let odd = C::new_complex(x.imag() + y.imag(), y.real() - x.real()); + (even - odd * omega_j).halve() + }); + output.extend(row); + omega_j *= omega; + } + RowMajorMatrix::new(output, input.width()) +} + +/// Given an (h/2)xw matrix M = (m_{kl}) = (a_{kl} + I*b_{kl}) (where +/// I is the imaginary unit), return the hxw matrix N whose (i,j) +/// entry is a_{i/2,j} if i is even and b_{(i-1)/2,j} if i is odd. +/// +/// This function is inverse to `dft_preprocess()` above. +fn idft_postprocess(input: RowMajorMatrix) -> RowMajorMatrix { + // Allocate necessary `Vec`s upfront: + // 1) The actual output, + // 2) A temporary buf to store the imaginary parts. + // This buf is filled and flushed per row + // throughout postprocessing to save on allocations. + let mut output = Vec::with_capacity(input.width() * input.height() * 2); + let mut buf = Vec::with_capacity(input.width()); + + // Convert each row of input into two rows, the first row + // having the real parts of the input, the second row + // having the imaginary parts. + for row in input.rows() { + for ext in row { + output.push(ext.real()); + buf.push(ext.imag()); + } + output.append(&mut buf); + } + + RowMajorMatrix::new(output, input.width()) +} + +/// The DFT for Mersenne31 +#[derive(Debug, Default, Clone)] +pub struct Mersenne31Dft; + +impl Mersenne31Dft { + /// Compute the DFT of each column of `mat`. + /// + /// NB: The DFT works by packing pairs of `Mersenne31` values into + /// a `Mersenne31Complex` and doing a (half-length) DFT on the + /// result. In particular, the type of the result elements are in + /// the extension field, not the domain field. + pub fn dft_batch>(mat: RowMajorMatrix) -> RowMajorMatrix { + let dft = Dft::default(); + dft_postprocess(dft.dft_batch(dft_preprocess(mat)).to_row_major_matrix()) + } + + /// Compute the inverse DFT of each column of `mat`. + /// + /// NB: See comment on `dft_batch()` for information on packing. + pub fn idft_batch>(mat: RowMajorMatrix) -> RowMajorMatrix { + let dft = Dft::default(); + idft_postprocess(dft.idft_batch(idft_preprocess(mat))) + } +} + +#[cfg(test)] +mod tests { + use rand::distr::{Distribution, StandardUniform}; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + use crate::Mersenne31ComplexRadix2Dit; + + type Base = Mersenne31; + type Dft = Mersenne31ComplexRadix2Dit; + + #[test] + fn consistency() + where + StandardUniform: Distribution, + { + const N: usize = 1 << 12; + let rng = SmallRng::seed_from_u64(1); + let input = rng + .sample_iter(StandardUniform) + .take(N) + .collect::>(); + let input = RowMajorMatrix::new_col(input); + let fft_input = Mersenne31Dft::dft_batch::(input.clone()); + let output = Mersenne31Dft::idft_batch::(fft_input); + assert_eq!(input, output); + } + + #[test] + fn convolution() + where + StandardUniform: Distribution, + { + const N: usize = 1 << 6; + let rng = SmallRng::seed_from_u64(1); + let v = rng + .sample_iter(StandardUniform) + .take(2 * N) + .collect::>(); + let a = RowMajorMatrix::new_col(v[..N].to_vec()); + let b = RowMajorMatrix::new_col(v[N..].to_vec()); + + let fft_a = Mersenne31Dft::dft_batch::(a.clone()); + let fft_b = Mersenne31Dft::dft_batch::(b.clone()); + + let fft_c = fft_a + .values + .iter() + .zip(fft_b.values.iter()) + .map(|(&xi, &yi)| xi * yi) + .collect(); + let fft_c = RowMajorMatrix::new_col(fft_c); + + let c = Mersenne31Dft::idft_batch::(fft_c); + + let mut conv = Vec::with_capacity(N); + for i in 0..N { + let mut t = Base::ZERO; + for j in 0..N { + t += a.values[j] * b.values[(N + i - j) % N]; + } + conv.push(t); + } + + assert_eq!(c.values, conv); + } +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/dft.v b/CoqOfRust/plonky3/mersenne-31/src/dft.v new file mode 100644 index 000000000..a0e9b432f --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/dft.v @@ -0,0 +1,7087 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module dft. + Axiom F : + (Ty.path "p3_mersenne_31::dft::F") = (Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"). + + Axiom C : + (Ty.path "p3_mersenne_31::dft::C") = + (Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]). + + (* + fn dft_preprocess(input: RowMajorMatrix) -> RowMajorMatrix { + assert!(input.height() % 2 == 0, "input height must be even"); + RowMajorMatrix::new( + input + .rows() + .tuples() + .flat_map(|(row_0, row_1)| { + // For each pair of rows in input, convert each + // two-element column into a Mersenne31Complex + // treating the first row as the real part and the + // second row as the imaginary part. + row_0.zip(row_1).map(|(x, y)| C::new_complex(x, y)) + }) + .collect(), + input.width(), + ) + } + *) + Definition dft_preprocess (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ mk_str (| "input height must be even" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "itertools::tuple_impl::Tuples") + [] + [ + Ty.associated_unknown; + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "itertools::tuple_impl::Tuples") + [] + [ + Ty.associated_unknown; + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::tuple_impl::Tuples") + [] + [ + Ty.associated_unknown; + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + ], + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::tuple_impl::Tuples") + [] + [ + Ty.associated_unknown; + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_unknown, + [], + [], + "tuples", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "rows", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let row_0 := M.copy (| γ0_0 |) in + let row_1 := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + |), + [ M.read (| row_0 |); M.read (| row_1 |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_complex", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dft_preprocess : + M.IsFunction.C "p3_mersenne_31::dft::dft_preprocess" dft_preprocess. + Admitted. + Global Typeclasses Opaque dft_preprocess. + + (* + fn dft_postprocess(input: RowMajorMatrix) -> RowMajorMatrix { + let h = input.height(); + let log2_h = log2_strict_usize(h); // checks that h is a power of two + + // NB: The original real matrix had height 2h, hence log2(2h) = log2(h) + 1. + // omega is a 2h-th root of unity + let omega = C::two_adic_generator(log2_h + 1); + let mut omega_j = omega; + + let mut output = Vec::with_capacity((h + 1) * input.width()); + output.extend(input.first_row().map(|x| C::new_real(x.real() + x.imag()))); + + for j in 1..h { + let row = izip!(input.row(j), input.row(h - j)).map(|(x, y)| { + let even = x + y.conjugate(); + // odd = (x - y.conjugate()) * -i + let odd = C::new_complex(x.imag() + y.imag(), y.real() - x.real()); + (even + odd * omega_j).halve() + }); + output.extend(row); + omega_j *= omega; + } + + output.extend(input.first_row().map(|x| C::new_real(x.real() - x.imag()))); + debug_assert_eq!(output.len(), (h + 1) * input.width()); + RowMajorMatrix::new(output, input.width()) + } + *) + Definition dft_postprocess (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + |) in + let~ log2_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ omega : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log2_h |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + |) in + let~ omega_j : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.copy (| omega |) in + let~ output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + "with_capacity", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| h |); Value.Integer IntegerKind.Usize 1 ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "extend", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, output |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "first_row", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_real", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "real", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |); + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "imag", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 1); ("end_", M.read (| h |)) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let j := M.copy (| γ0_0 |) in + let~ row : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "row", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, input |); + M.read (| j |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "row", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, input |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| h |); M.read (| j |) ] + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.read (| + let~ even : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "add", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "conjugate", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + y + |) + ] + |) + ] + |) + |) in + let~ odd : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_complex", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "imag", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + x + |) + ] + |); + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "imag", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + y + |) + ] + |) + ] + |); + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "sub", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "real", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + y + |) + ] + |); + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "real", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + x + |) + ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "add", + [], + [] + |), + [ + M.read (| even |); + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "mul", + [], + [] + |), + [ + M.read (| odd |); + M.read (| + omega_j + |) + ] + |) + ] + |) + |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "extend", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, output |); + M.read (| row |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, omega_j |); + M.read (| omega |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "extend", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, output |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "first_row", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_real", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "sub", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "real", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |); + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "imag", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, output |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| h |); Value.Integer IntegerKind.Usize 1 ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ + M.read (| output |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dft_postprocess : + M.IsFunction.C "p3_mersenne_31::dft::dft_postprocess" dft_postprocess. + Admitted. + Global Typeclasses Opaque dft_postprocess. + + (* + fn idft_preprocess(input: RowMajorMatrix) -> RowMajorMatrix { + let h = input.height() - 1; + let log2_h = log2_strict_usize(h); // checks that h is a power of two + + // NB: The original real matrix had length 2h, hence log2(2h) = log2(h) + 1. + // omega is a 2n-th root of unity + let omega = C::two_adic_generator(log2_h + 1).inverse(); + let mut omega_j = C::ONE; + + let mut output = Vec::with_capacity(h * input.width()); + // TODO: Specialise j = 0 and j = n (which we know must be real)? + for j in 0..h { + let row = izip!(input.row(j), input.row(h - j)).map(|(x, y)| { + let even = x + y.conjugate(); + // odd = (x - y.conjugate()) * -i + let odd = C::new_complex(x.imag() + y.imag(), y.real() - x.real()); + (even - odd * omega_j).halve() + }); + output.extend(row); + omega_j *= omega; + } + RowMajorMatrix::new(output, input.width()) + } + *) + Definition idft_preprocess (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ log2_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ omega : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "two_adic_generator", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log2_h |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + |) + |) + ] + |) + |) in + let~ omega_j : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.copy (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + |) + |) in + let~ output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + "with_capacity", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| h |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", M.read (| h |)) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let j := M.copy (| γ0_0 |) in + let~ row : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "row", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, input |); + M.read (| j |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "row", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, input |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| h |); M.read (| j |) ] + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.read (| + let~ even : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "add", + [], + [] + |), + [ + M.read (| x |); + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "conjugate", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + y + |) + ] + |) + ] + |) + |) in + let~ odd : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_complex", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "imag", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + x + |) + ] + |); + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "imag", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + y + |) + ] + |) + ] + |); + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "sub", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "real", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + y + |) + ] + |); + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "real", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + x + |) + ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "halve", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "sub", + [], + [] + |), + [ + M.read (| even |); + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "mul", + [], + [] + |), + [ + M.read (| odd |); + M.read (| + omega_j + |) + ] + |) + ] + |) + |) + |) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "extend", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]) + ] + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, output |); + M.read (| row |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, omega_j |); + M.read (| omega |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ + M.read (| output |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_idft_preprocess : + M.IsFunction.C "p3_mersenne_31::dft::idft_preprocess" idft_preprocess. + Admitted. + Global Typeclasses Opaque idft_preprocess. + + (* + fn idft_postprocess(input: RowMajorMatrix) -> RowMajorMatrix { + // Allocate necessary `Vec`s upfront: + // 1) The actual output, + // 2) A temporary buf to store the imaginary parts. + // This buf is filled and flushed per row + // throughout postprocessing to save on allocations. + let mut output = Vec::with_capacity(input.width() * input.height() * 2); + let mut buf = Vec::with_capacity(input.width()); + + // Convert each row of input into two rows, the first row + // having the real parts of the input, the second row + // having the imaginary parts. + for row in input.rows() { + for ext in row { + output.push(ext.real()); + buf.push(ext.imag()); + } + output.append(&mut buf); + } + + RowMajorMatrix::new(output, input.width()) + } + *) + Definition idft_postprocess (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + "with_capacity", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |) in + let~ buf : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + "with_capacity", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.associated_unknown, + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "rows", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_unknown, + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let row := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| row |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let ext := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + output + |); + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "real", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + ext + |) + ] + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + buf + |); + M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "imag", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + ext + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + "append", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, output |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, buf |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ + M.read (| output |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, input |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_idft_postprocess : + M.IsFunction.C "p3_mersenne_31::dft::idft_postprocess" idft_postprocess. + Admitted. + Global Typeclasses Opaque idft_postprocess. + + (* StructTuple + { + name := "Mersenne31Dft"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_fmt_Debug_for_p3_mersenne_31_dft_Mersenne31Dft. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::dft::Mersenne31Dft". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Mersenne31Dft" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_mersenne_31_dft_Mersenne31Dft. + + Module Impl_core_default_Default_for_p3_mersenne_31_dft_Mersenne31Dft. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::dft::Mersenne31Dft". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => ltac:(M.monadic (Value.StructTuple "p3_mersenne_31::dft::Mersenne31Dft" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_mersenne_31_dft_Mersenne31Dft. + + Module Impl_core_clone_Clone_for_p3_mersenne_31_dft_Mersenne31Dft. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::dft::Mersenne31Dft". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_mersenne_31::dft::Mersenne31Dft" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_mersenne_31_dft_Mersenne31Dft. + + Module Impl_p3_mersenne_31_dft_Mersenne31Dft. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::dft::Mersenne31Dft". + + (* + pub fn dft_batch>(mat: RowMajorMatrix) -> RowMajorMatrix { + let dft = Dft::default(); + dft_postprocess(dft.dft_batch(dft_preprocess(mat)).to_row_major_matrix()) + } + *) + Definition dft_batch (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ Dft ], [ mat ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_function (| "p3_mersenne_31::dft::dft_postprocess", [], [] |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + Dft + "Evaluations", + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + Dft + "Evaluations", + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "dft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_function (| "p3_mersenne_31::dft::dft_preprocess", [], [] |), + [ M.read (| mat |) ] + |) + ] + |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_dft_batch : + M.IsAssociatedFunction.C Self "dft_batch" dft_batch. + Admitted. + Global Typeclasses Opaque dft_batch. + + (* + pub fn idft_batch>(mat: RowMajorMatrix) -> RowMajorMatrix { + let dft = Dft::default(); + idft_postprocess(dft.idft_batch(idft_preprocess(mat))) + } + *) + Definition idft_batch (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ Dft ], [ mat ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + M.read (| + let~ dft : Ty.apply (Ty.path "*") [] [ Dft ] := + M.alloc (| + M.call_closure (| + Dft, + M.get_trait_method (| "core::default::Default", Dft, [], [], "default", [], [] |), + [] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_function (| "p3_mersenne_31::dft::idft_postprocess", [], [] |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "p3_dft::traits::TwoAdicSubgroupDft", + Dft, + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "idft_batch", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, dft |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_function (| "p3_mersenne_31::dft::idft_preprocess", [], [] |), + [ M.read (| mat |) ] + |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_idft_batch : + M.IsAssociatedFunction.C Self "idft_batch" idft_batch. + Admitted. + Global Typeclasses Opaque idft_batch. + End Impl_p3_mersenne_31_dft_Mersenne31Dft. +End dft. diff --git a/CoqOfRust/plonky3/mersenne-31/src/extension.rs b/CoqOfRust/plonky3/mersenne-31/src/extension.rs new file mode 100644 index 000000000..3b227824f --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/extension.rs @@ -0,0 +1,241 @@ +use p3_field::extension::{ + BinomiallyExtendable, Complex, HasComplexBinomialExtension, HasTwoAdicComplexBinomialExtension, +}; +use p3_field::{PrimeCharacteristicRing, TwoAdicField, field_to_array}; + +use crate::Mersenne31; + +impl BinomiallyExtendable<3> for Mersenne31 { + // ```sage + // p = 2^31 - 1 + // F = GF(p) + // R. = F[] + // assert (x^3 - 5).is_irreducible() + // ``` + const W: Self = Self::new(5); + + // ```sage + // F(5)^((p-1)/3) + // ``` + const DTH_ROOT: Self = Self::new(1513477735); + + // ```sage + // F.extension(x^3 - 5, 'u').multiplicative_generator() + // ``` + const EXT_GENERATOR: [Self; 3] = [Self::new(10), Self::ONE, Self::ZERO]; +} + +impl HasComplexBinomialExtension<2> for Mersenne31 { + // Verifiable in Sage with + // ```sage + // p = 2**31 - 1 # Mersenne31 + // F = GF(p) # The base field GF(p) + // R. = F[] # The polynomial ring over F + // K. = F.extension(x^2 + 1) # The complex extension field + // R2. = K[] + // f2 = y^2 - i - 2 + // assert f2.is_irreducible() + // ``` + const W: Complex = Complex::new_complex(Self::TWO, Self::ONE); + + // DTH_ROOT = W^((p^2 - 1)/2). + const DTH_ROOT: Complex = Complex::new_real(Self::new(2147483646)); + + // Verifiable in Sage with + // ```sage + // K2. = K.extension(f2) + // g = j + 6 + // for f in factor(p^4 - 1): + // assert g^((p^4-1) // f) != 1 + // ``` + const EXT_GENERATOR: [Complex; 2] = [Complex::new_real(Self::new(6)), Complex::ONE]; +} + +impl HasTwoAdicComplexBinomialExtension<2> for Mersenne31 { + const COMPLEX_EXT_TWO_ADICITY: usize = 33; + + fn complex_ext_two_adic_generator(bits: usize) -> [Complex; 2] { + assert!(bits <= 33); + if bits == 33 { + [ + Complex::ZERO, + Complex::new_complex(Self::new(1437746044), Self::new(946469285)), + ] + } else { + [Complex::two_adic_generator(bits), Complex::ZERO] + } + } +} + +impl HasComplexBinomialExtension<3> for Mersenne31 { + // Verifiable in Sage with + // ```sage + // p = 2**31 - 1 # Mersenne31 + // F = GF(p) # The base field GF(p) + // R. = F[] # The polynomial ring over F + // K. = F.extension(x^2 + 1) # The complex extension field + // R2. = K[] + // f2 = y^3 - 5*i + // assert f2.is_irreducible() + // ``` + const W: Complex = Complex::new_imag(Self::new(5)); + + // DTH_ROOT = W^((p^2 - 1)/2). + const DTH_ROOT: Complex = Complex::new_real(Self::new(634005911)); + + // Verifiable in Sage with + // ```sage + // K2. = K.extension(f2) + // g = j + 5 + // for f in factor(p^6 - 1): + // assert g^((p^6-1) // f) != 1 + // ``` + const EXT_GENERATOR: [Complex; 3] = [ + Complex::new_real(Self::new(5)), + Complex::new_real(Self::ONE), + Complex::ZERO, + ]; +} + +impl HasTwoAdicComplexBinomialExtension<3> for Mersenne31 { + const COMPLEX_EXT_TWO_ADICITY: usize = 32; + + fn complex_ext_two_adic_generator(bits: usize) -> [Complex; 3] { + field_to_array(Complex::two_adic_generator(bits)) + } +} + +#[cfg(test)] +mod test_cubic_extension { + use num_bigint::BigUint; + use p3_field::PrimeCharacteristicRing; + use p3_field::extension::BinomialExtensionField; + use p3_field_testing::test_field; + + use crate::Mersenne31; + + type F = Mersenne31; + type EF = BinomialExtensionField; + + // There is a redundant representation of zero but we already tested it + // when testing the base field. + const ZEROS: [EF; 1] = [EF::ZERO]; + const ONES: [EF; 1] = [EF::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P^3 - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 9] { + [ + (BigUint::from(2u8), 1), + (BigUint::from(3u8), 3), + (BigUint::from(7u8), 1), + (BigUint::from(11u8), 1), + (BigUint::from(31u8), 1), + (BigUint::from(151u8), 1), + (BigUint::from(331u16), 1), + (BigUint::from(529510939u32), 1), + (BigUint::from(2903110321u32), 1), + ] + } + + test_field!( + super::EF, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); +} + +#[cfg(test)] +mod test_cubic_complex_extension { + use num_bigint::BigUint; + use p3_field::PrimeCharacteristicRing; + use p3_field::extension::{BinomialExtensionField, Complex}; + use p3_field_testing::{test_field, test_two_adic_extension_field}; + + use crate::Mersenne31; + + type F = Complex; + type EF = BinomialExtensionField; + + // There is a redundant representation of zero but we already tested it + // when testing the base field. + const ZEROS: [EF; 1] = [EF::ZERO]; + const ONES: [EF; 1] = [EF::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P^6 - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 14] { + [ + (BigUint::from(2u8), 32), + (BigUint::from(3u8), 3), + (BigUint::from(7u8), 1), + (BigUint::from(11u8), 1), + (BigUint::from(13u8), 1), + (BigUint::from(31u8), 1), + (BigUint::from(43u8), 2), + (BigUint::from(79u8), 1), + (BigUint::from(151u8), 1), + (BigUint::from(331u16), 1), + (BigUint::from(1381u16), 1), + (BigUint::from(529510939u32), 1), + (BigUint::from(1758566101u32), 1), + (BigUint::from(2903110321u32), 1), + ] + } + + test_field!( + super::EF, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + + test_two_adic_extension_field!(super::F, super::EF); +} + +#[cfg(test)] +mod test_quadratic_complex_extension { + + use num_bigint::BigUint; + use p3_field::PrimeCharacteristicRing; + use p3_field::extension::{BinomialExtensionField, Complex}; + use p3_field_testing::{test_field, test_two_adic_extension_field}; + + use crate::Mersenne31; + + type F = Complex; + type EF = BinomialExtensionField; + + // There is a redundant representation of zero but we already tested it + // when testing the base field. + const ZEROS: [EF; 1] = [EF::ZERO]; + const ONES: [EF; 1] = [EF::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P^4 - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 11] { + [ + (BigUint::from(2u8), 33), + (BigUint::from(3u8), 2), + (BigUint::from(5u8), 1), + (BigUint::from(7u8), 1), + (BigUint::from(11u8), 1), + (BigUint::from(31u8), 1), + (BigUint::from(151u8), 1), + (BigUint::from(331u16), 1), + (BigUint::from(733u16), 1), + (BigUint::from(1709u16), 1), + (BigUint::from(368140581013u64), 1), + ] + } + + test_field!( + super::EF, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + + test_two_adic_extension_field!(super::F, super::EF); +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/extension.v b/CoqOfRust/plonky3/mersenne-31/src/extension.v new file mode 100644 index 000000000..f0dd6c18e --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/extension.v @@ -0,0 +1,800 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module extension. + Module Impl_p3_field_extension_BinomiallyExtendable_Usize_3_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const W: Self = Self::new(5); *) + (* Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" *) + Definition value_W (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 5 ] + |) + |))). + + (* const DTH_ROOT: Self = Self::new(1513477735); *) + (* Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" *) + Definition value_DTH_ROOT (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 1513477735 ] + |) + |))). + + (* const EXT_GENERATOR: [Self; 3] = [Self::new(10), Self::ONE, Self::ZERO]; *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] *) + Definition value_EXT_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 10 ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |) + |) + ] + |))). + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::BinomiallyExtendable" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 3 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_W", InstanceField.Method value_W); + ("value_DTH_ROOT", InstanceField.Method value_DTH_ROOT); + ("value_EXT_GENERATOR", InstanceField.Method value_EXT_GENERATOR) + ]. + End Impl_p3_field_extension_BinomiallyExtendable_Usize_3_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_extension_complex_HasComplexBinomialExtension_Usize_2_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const W: Complex = Complex::new_complex(Self::TWO, Self::ONE); *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] *) + Definition value_W (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_complex", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::TWO", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |) + |) + ] + |) + |))). + + (* const DTH_ROOT: Complex = Complex::new_real(Self::new(2147483646)); *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] *) + Definition value_DTH_ROOT (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_real", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 2147483646 ] + |) + ] + |) + |))). + + (* const EXT_GENERATOR: [Complex; 2] = [Complex::new_real(Self::new(6)), Complex::ONE]; *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] *) + Definition value_EXT_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_real", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 6 ] + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + |) + |) + ] + |))). + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::complex::HasComplexBinomialExtension" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 2 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_W", InstanceField.Method value_W); + ("value_DTH_ROOT", InstanceField.Method value_DTH_ROOT); + ("value_EXT_GENERATOR", InstanceField.Method value_EXT_GENERATOR) + ]. + End Impl_p3_field_extension_complex_HasComplexBinomialExtension_Usize_2_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_extension_complex_HasTwoAdicComplexBinomialExtension_Usize_2_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const COMPLEX_EXT_TWO_ADICITY: usize = 33; *) + (* Ty.path "usize" *) + Definition value_COMPLEX_EXT_TWO_ADICITY + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 33 |))). + + (* + fn complex_ext_two_adic_generator(bits: usize) -> [Complex; 2] { + assert!(bits <= 33); + if bits == 33 { + [ + Complex::ZERO, + Complex::new_complex(Self::new(1437746044), Self::new(946469285)), + ] + } else { + [Complex::two_adic_generator(bits), Complex::ZERO] + } + } + *) + Definition complex_ext_two_adic_generator + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ M.read (| bits |); Value.Integer IntegerKind.Usize 33 ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits <= 33" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| bits |); Value.Integer IntegerKind.Usize 33 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.Array + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_complex", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 1437746044 ] + |); + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 946469285 ] + |) + ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| bits |) ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + |) + |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::complex::HasTwoAdicComplexBinomialExtension" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 2 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_COMPLEX_EXT_TWO_ADICITY", InstanceField.Method value_COMPLEX_EXT_TWO_ADICITY); + ("complex_ext_two_adic_generator", InstanceField.Method complex_ext_two_adic_generator) + ]. + End Impl_p3_field_extension_complex_HasTwoAdicComplexBinomialExtension_Usize_2_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_extension_complex_HasComplexBinomialExtension_Usize_3_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const W: Complex = Complex::new_imag(Self::new(5)); *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] *) + Definition value_W (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_imag", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 5 ] + |) + ] + |) + |))). + + (* const DTH_ROOT: Complex = Complex::new_real(Self::new(634005911)); *) + (* Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] *) + Definition value_DTH_ROOT (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_real", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 634005911 ] + |) + ] + |) + |))). + + (* + const EXT_GENERATOR: [Complex; 3] = [ + Complex::new_real(Self::new(5)), + Complex::new_real(Self::ONE), + Complex::ZERO, + ]; + *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] *) + Definition value_EXT_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_real", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 5 ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_real", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + |) + |) + ] + |))). + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::complex::HasComplexBinomialExtension" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 3 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_W", InstanceField.Method value_W); + ("value_DTH_ROOT", InstanceField.Method value_DTH_ROOT); + ("value_EXT_GENERATOR", InstanceField.Method value_EXT_GENERATOR) + ]. + End Impl_p3_field_extension_complex_HasComplexBinomialExtension_Usize_3_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_extension_complex_HasTwoAdicComplexBinomialExtension_Usize_3_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const COMPLEX_EXT_TWO_ADICITY: usize = 32; *) + (* Ty.path "usize" *) + Definition value_COMPLEX_EXT_TWO_ADICITY + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 32 |))). + + (* + fn complex_ext_two_adic_generator(bits: usize) -> [Complex; 3] { + field_to_array(Complex::two_adic_generator(bits)) + } + *) + Definition complex_ext_two_adic_generator + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + M.get_function (| + "p3_field::helpers::field_to_array", + [ Value.Integer IntegerKind.Usize 3 ], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| bits |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::extension::complex::HasTwoAdicComplexBinomialExtension" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 3 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_COMPLEX_EXT_TWO_ADICITY", InstanceField.Method value_COMPLEX_EXT_TWO_ADICITY); + ("complex_ext_two_adic_generator", InstanceField.Method complex_ext_two_adic_generator) + ]. + End Impl_p3_field_extension_complex_HasTwoAdicComplexBinomialExtension_Usize_3_for_p3_mersenne_31_mersenne_31_Mersenne31. +End extension. diff --git a/CoqOfRust/plonky3/mersenne-31/src/lib.rs b/CoqOfRust/plonky3/mersenne-31/src/lib.rs new file mode 100644 index 000000000..cfede3bbe --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/lib.rs @@ -0,0 +1,69 @@ +//! The prime field `F_p` where `p = 2^31 - 1`. + +#![no_std] +#![cfg_attr( + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), + feature(stdarch_x86_avx512) +)] + +extern crate alloc; + +mod complex; +mod dft; +mod extension; +mod mds; +mod mersenne_31; +mod poseidon2; +mod radix_2_dit; + +pub use dft::Mersenne31Dft; +pub use mds::*; +pub use mersenne_31::*; +pub use poseidon2::*; +pub use radix_2_dit::Mersenne31ComplexRadix2Dit; + +#[cfg(all(target_arch = "aarch64", target_feature = "neon"))] +mod aarch64_neon; +#[cfg(all(target_arch = "aarch64", target_feature = "neon"))] +pub use aarch64_neon::*; + +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +mod x86_64_avx2; +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +pub use x86_64_avx2::*; + +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +mod x86_64_avx512; +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +pub use x86_64_avx512::*; + +#[cfg(not(any( + all(target_arch = "aarch64", target_feature = "neon"), + all(target_arch = "x86_64", target_feature = "avx2",), +)))] +mod no_packing; +#[cfg(not(any( + all(target_arch = "aarch64", target_feature = "neon"), + all(target_arch = "x86_64", target_feature = "avx2",), +)))] +pub use no_packing::*; diff --git a/CoqOfRust/plonky3/mersenne-31/src/mds.rs b/CoqOfRust/plonky3/mersenne-31/src/mds.rs new file mode 100644 index 000000000..aababa442 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/mds.rs @@ -0,0 +1,383 @@ +//! MDS matrices over the Mersenne31 field, and permutations defined by them. +//! +//! NB: Not all sizes have fast implementations of their permutations. +//! Supported sizes: 8, 12, 16, 32, 64. +//! Sizes 8 and 12 are from Plonky2, size 16 was found as part of concurrent +//! work by Angus Gruen and Hamish Ivey-Law. Other sizes are from Ulrich Haböck's +//! database. + +use p3_field::PrimeCharacteristicRing; +use p3_field::integers::QuotientMap; +use p3_mds::MdsPermutation; +use p3_mds::karatsuba_convolution::Convolve; +use p3_mds::util::{dot_product, first_row_to_first_col}; +use p3_symmetric::Permutation; + +use crate::Mersenne31; + +#[derive(Clone, Debug, Default)] +pub struct MdsMatrixMersenne31; + +/// Instantiate convolution for "small" RHS vectors over Mersenne31. +/// +/// Here "small" means N = len(rhs) <= 16 and sum(r for r in rhs) < +/// 2^24 (roughly), though in practice the sum will be less than 2^9. +struct SmallConvolveMersenne31; +impl Convolve for SmallConvolveMersenne31 { + /// Return the lift of an (almost) reduced Mersenne31 element. + /// The Mersenne31 implementation guarantees that + /// 0 <= input.value <= P < 2^31. + #[inline(always)] + fn read(input: Mersenne31) -> i64 { + input.value as i64 + } + + /// FIXME: Refactor the dot product + /// For a convolution of size N, |x| < N * 2^31 and (as per the + /// assumption above), |y| < 2^24. So the product is at most N * 2^55 + /// which will not overflow for N <= 16. + #[inline(always)] + fn parity_dot(u: [i64; N], v: [i64; N]) -> i64 { + dot_product(u, v) + } + + /// The assumptions above mean z < N^2 * 2^55, which is at most + /// 2^63 when N <= 16. + /// + /// NB: Even though intermediate values could be negative, the + /// output must be non-negative since the inputs were + /// non-negative. + #[inline(always)] + fn reduce(z: i64) -> Mersenne31 { + debug_assert!(z >= 0); + Mersenne31::from_u64(z as u64) + } +} + +/// Instantiate convolution for "large" RHS vectors over Mersenne31. +/// +/// Here "large" means the elements can be as big as the field +/// characteristic, and the size N of the RHS is <= 64. +struct LargeConvolveMersenne31; +impl Convolve for LargeConvolveMersenne31 { + /// Return the lift of an (almost) reduced Mersenne31 element. + /// The Mersenne31 implementation guarantees that + /// 0 <= input.value <= P < 2^31. + #[inline(always)] + fn read(input: Mersenne31) -> i64 { + input.value as i64 + } + + #[inline] + fn parity_dot(u: [i64; N], v: [i64; N]) -> i64 { + // For a convolution of size N, |x|, |y| < N * 2^31, so the product + // could be as much as N^2 * 2^62. This will overflow an i64, so + // we first widen to i128. + + let mut dp = 0i128; + for i in 0..N { + dp += u[i] as i128 * v[i] as i128; + } + + const LOWMASK: i128 = (1 << 42) - 1; // Gets the bits lower than 42. + const HIGHMASK: i128 = !LOWMASK; // Gets all bits higher than 42. + + let low_bits = (dp & LOWMASK) as i64; // low_bits < 2**42 + let high_bits = ((dp & HIGHMASK) >> 31) as i64; // |high_bits| < 2**(n - 31) + + // Proof that low_bits + high_bits is congruent to dp (mod p) + // and congruent to dp (mod 2^11): + // + // The individual bounds clearly show that low_bits + + // high_bits < 2**(n - 30). + // + // Next observe that low_bits + high_bits = input - (2**31 - + // 1) * (high_bits) = input mod P. + // + // Finally note that 2**11 divides high_bits and so low_bits + + // high_bits = low_bits mod 2**11 = input mod 2**11. + + low_bits + high_bits + } + + #[inline] + fn reduce(z: i64) -> Mersenne31 { + // After the dot product, the maximal size is N^2 * 2^62 < 2^74 + // as N = 64 is the biggest size. So, after the partial + // reduction, the output z of parity dot satisfies |z| < 2^44 + // (Where 44 is 74 - 30). + // + // In the recombining steps, conv maps (wo, w1) -> ((wo + w1)/2, + // (wo + w1)/2) which has no effect on the maximal size. (Indeed, + // it makes sizes almost strictly smaller). + // + // On the other hand, negacyclic_conv (ignoring the re-index) + // recombines as: (w0, w1, w2) -> (w0 + w1, w2 - w0 - w1). Hence + // if the input is <= K, the output is <= 3K. + // + // Thus the values appearing at the end are bounded by 3^n 2^44 + // where n is the maximal number of negacyclic_conv recombination + // steps. When N = 64, we need to recombine for singed_conv_32, + // singed_conv_16, singed_conv_8 so the overall bound will be 3^3 + // 2^44 < 32 * 2^44 < 2^49. + debug_assert!(z > -(1i64 << 49)); + debug_assert!(z < (1i64 << 49)); + + const MASK: i64 = (1 << 31) - 1; + // Morally, our value is a i62 not a i64 as the top 3 bits are + // guaranteed to be equal. + let low_bits = unsafe { + // This is safe as 0 <= z & MASK < 2^31 + Mersenne31::from_canonical_unchecked((z & MASK) as u32) + }; + + let high_bits = ((z >> 31) & MASK) as i32; + let sign_bits = (z >> 62) as i32; + + let high = unsafe { + // This is safe as high_bits + sign_bits > 0 as by assumption b[63] = b[61]. + Mersenne31::from_canonical_unchecked((high_bits + sign_bits) as u32) + }; + low_bits + high + } +} + +const MATRIX_CIRC_MDS_8_SML_ROW: [i64; 8] = [7, 1, 3, 8, 8, 3, 4, 9]; + +impl Permutation<[Mersenne31; 8]> for MdsMatrixMersenne31 { + fn permute(&self, input: [Mersenne31; 8]) -> [Mersenne31; 8] { + const MATRIX_CIRC_MDS_8_SML_COL: [i64; 8] = + first_row_to_first_col(&MATRIX_CIRC_MDS_8_SML_ROW); + SmallConvolveMersenne31::apply( + input, + MATRIX_CIRC_MDS_8_SML_COL, + SmallConvolveMersenne31::conv8, + ) + } + + fn permute_mut(&self, input: &mut [Mersenne31; 8]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixMersenne31 {} + +const MATRIX_CIRC_MDS_12_SML_ROW: [i64; 12] = [1, 1, 2, 1, 8, 9, 10, 7, 5, 9, 4, 10]; + +impl Permutation<[Mersenne31; 12]> for MdsMatrixMersenne31 { + fn permute(&self, input: [Mersenne31; 12]) -> [Mersenne31; 12] { + const MATRIX_CIRC_MDS_12_SML_COL: [i64; 12] = + first_row_to_first_col(&MATRIX_CIRC_MDS_12_SML_ROW); + SmallConvolveMersenne31::apply( + input, + MATRIX_CIRC_MDS_12_SML_COL, + SmallConvolveMersenne31::conv12, + ) + } + + fn permute_mut(&self, input: &mut [Mersenne31; 12]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixMersenne31 {} + +const MATRIX_CIRC_MDS_16_SML_ROW: [i64; 16] = + [1, 1, 51, 1, 11, 17, 2, 1, 101, 63, 15, 2, 67, 22, 13, 3]; + +impl Permutation<[Mersenne31; 16]> for MdsMatrixMersenne31 { + fn permute(&self, input: [Mersenne31; 16]) -> [Mersenne31; 16] { + const MATRIX_CIRC_MDS_16_SML_COL: [i64; 16] = + first_row_to_first_col(&MATRIX_CIRC_MDS_16_SML_ROW); + SmallConvolveMersenne31::apply( + input, + MATRIX_CIRC_MDS_16_SML_COL, + SmallConvolveMersenne31::conv16, + ) + } + + fn permute_mut(&self, input: &mut [Mersenne31; 16]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixMersenne31 {} + +#[rustfmt::skip] +const MATRIX_CIRC_MDS_32_MERSENNE31_ROW: [i64; 32] = [ + 0x1896DC78, 0x559D1E29, 0x04EBD732, 0x3FF449D7, + 0x2DB0E2CE, 0x26776B85, 0x76018E57, 0x1025FA13, + 0x06486BAB, 0x37706EBA, 0x25EB966B, 0x113C24E5, + 0x2AE20EC4, 0x5A27507C, 0x0CD38CF1, 0x761C10E5, + 0x19E3EF1A, 0x032C730F, 0x35D8AF83, 0x651DF13B, + 0x7EC3DB1A, 0x6A146994, 0x588F9145, 0x09B79455, + 0x7FDA05EC, 0x19FE71A8, 0x6988947A, 0x624F1D31, + 0x500BB628, 0x0B1428CE, 0x3A62E1D6, 0x77692387 +]; + +impl Permutation<[Mersenne31; 32]> for MdsMatrixMersenne31 { + fn permute(&self, input: [Mersenne31; 32]) -> [Mersenne31; 32] { + const MATRIX_CIRC_MDS_32_MERSENNE31_COL: [i64; 32] = + first_row_to_first_col(&MATRIX_CIRC_MDS_32_MERSENNE31_ROW); + LargeConvolveMersenne31::apply( + input, + MATRIX_CIRC_MDS_32_MERSENNE31_COL, + LargeConvolveMersenne31::conv32, + ) + } + + fn permute_mut(&self, input: &mut [Mersenne31; 32]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixMersenne31 {} + +#[rustfmt::skip] +const MATRIX_CIRC_MDS_64_MERSENNE31_ROW: [i64; 64] = [ + 0x570227A5, 0x3702983F, 0x4B7B3B0A, 0x74F13DE3, + 0x485314B0, 0x0157E2EC, 0x1AD2E5DE, 0x721515E3, + 0x5452ADA3, 0x0C74B6C1, 0x67DA9450, 0x33A48369, + 0x3BDBEE06, 0x7C678D5E, 0x160F16D3, 0x54888B8C, + 0x666C7AA6, 0x113B89E2, 0x2A403CE2, 0x18F9DF42, + 0x2A685E84, 0x49EEFDE5, 0x5D044806, 0x560A41F8, + 0x69EF1BD0, 0x2CD15786, 0x62E07766, 0x22A231E2, + 0x3CFCF40C, 0x4E8F63D8, 0x69657A15, 0x466B4B2D, + 0x4194B4D2, 0x1E9A85EA, 0x39709C27, 0x4B030BF3, + 0x655DCE1D, 0x251F8899, 0x5B2EA879, 0x1E10E42F, + 0x31F5BE07, 0x2AFBB7F9, 0x3E11021A, 0x5D97A17B, + 0x6F0620BD, 0x5DBFC31D, 0x76C4761D, 0x21938559, + 0x33777473, 0x71F0E92C, 0x0B9872A1, 0x4C2411F9, + 0x545B7C96, 0x20256BAF, 0x7B8B493E, 0x33AD525C, + 0x15EAEA1C, 0x6D2D1A21, 0x06A81D14, 0x3FACEB4F, + 0x130EC21C, 0x3C84C4F5, 0x50FD67C0, 0x30FDD85A, +]; + +impl Permutation<[Mersenne31; 64]> for MdsMatrixMersenne31 { + fn permute(&self, input: [Mersenne31; 64]) -> [Mersenne31; 64] { + const MATRIX_CIRC_MDS_64_MERSENNE31_COL: [i64; 64] = + first_row_to_first_col(&MATRIX_CIRC_MDS_64_MERSENNE31_ROW); + LargeConvolveMersenne31::apply( + input, + MATRIX_CIRC_MDS_64_MERSENNE31_COL, + LargeConvolveMersenne31::conv64, + ) + } + + fn permute_mut(&self, input: &mut [Mersenne31; 64]) { + *input = self.permute(*input); + } +} +impl MdsPermutation for MdsMatrixMersenne31 {} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + + use super::{MdsMatrixMersenne31, Mersenne31}; + + #[test] + fn mersenne8() { + let input: [Mersenne31; 8] = Mersenne31::new_array([ + 1741044457, 327154658, 318297696, 1528828225, 468360260, 1271368222, 1906288587, + 1521884224, + ]); + + let output = MdsMatrixMersenne31.permute(input); + + let expected: [Mersenne31; 8] = Mersenne31::new_array([ + 895992680, 1343855369, 2107796831, 266468728, 846686506, 252887121, 205223309, + 260248790, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn mersenne12() { + let input: [Mersenne31; 12] = Mersenne31::new_array([ + 1232740094, 661555540, 11024822, 1620264994, 471137070, 276755041, 1316882747, + 1023679816, 1675266989, 743211887, 44774582, 1990989306, + ]); + + let output = MdsMatrixMersenne31.permute(input); + + let expected: [Mersenne31; 12] = Mersenne31::new_array([ + 860812289, 399778981, 1228500858, 798196553, 673507779, 1116345060, 829764188, + 138346433, 578243475, 553581995, 578183208, 1527769050, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn mersenne16() { + let input: [Mersenne31; 16] = Mersenne31::new_array([ + 1431168444, 963811518, 88067321, 381314132, 908628282, 1260098295, 980207659, + 150070493, 357706876, 2014609375, 387876458, 1621671571, 183146044, 107201572, + 166536524, 2078440788, + ]); + + let output = MdsMatrixMersenne31.permute(input); + + let expected: [Mersenne31; 16] = Mersenne31::new_array([ + 1858869691, 1607793806, 1200396641, 1400502985, 1511630695, 187938132, 1332411488, + 2041577083, 2014246632, 802022141, 796807132, 1647212930, 813167618, 1867105010, + 508596277, 1457551581, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn mersenne32() { + let input: [Mersenne31; 32] = Mersenne31::new_array([ + 873912014, 1112497426, 300405095, 4255553, 1234979949, 156402357, 1952135954, + 718195399, 1041748465, 683604342, 184275751, 1184118518, 214257054, 1293941921, + 64085758, 710448062, 1133100009, 350114887, 1091675272, 671421879, 1226105999, + 546430131, 1298443967, 1787169653, 2129310791, 1560307302, 471771931, 1191484402, + 1550203198, 1541319048, 229197040, 839673789, + ]); + + let output = MdsMatrixMersenne31.permute(input); + + let expected: [Mersenne31; 32] = Mersenne31::new_array([ + 1439049928, 890642852, 694402307, 713403244, 553213342, 1049445650, 321709533, + 1195683415, 2118492257, 623077773, 96734062, 990488164, 1674607608, 749155000, + 353377854, 966432998, 1114654884, 1370359248, 1624965859, 685087760, 1631836645, + 1615931812, 2061986317, 1773551151, 1449911206, 1951762557, 545742785, 582866449, + 1379774336, 229242759, 1871227547, 752848413, + ]); + + assert_eq!(output, expected); + } + + #[test] + fn mersenne64() { + let input: [Mersenne31; 64] = Mersenne31::new_array([ + 837269696, 1509031194, 413915480, 1889329185, 315502822, 1529162228, 1454661012, + 1015826742, 973381409, 1414676304, 1449029961, 1968715566, 2027226497, 1721820509, + 434042616, 1436005045, 1680352863, 651591867, 260585272, 1078022153, 703990572, + 269504423, 1776357592, 1174979337, 1142666094, 1897872960, 1387995838, 250774418, + 776134750, 73930096, 194742451, 1860060380, 666407744, 669566398, 963802147, + 2063418105, 1772573581, 998923482, 701912753, 1716548204, 860820931, 1680395948, + 949886256, 1811558161, 501734557, 1671977429, 463135040, 1911493108, 207754409, + 608714758, 1553060084, 1558941605, 980281686, 2014426559, 650527801, 53015148, + 1521176057, 720530872, 713593252, 88228433, 1194162313, 1922416934, 1075145779, + 344403794, + ]); + + let output = MdsMatrixMersenne31.permute(input); + + let expected: [Mersenne31; 64] = Mersenne31::new_array([ + 1599981950, 252630853, 1171557270, 116468420, 1269245345, 666203050, 46155642, + 1701131520, 530845775, 508460407, 630407239, 1731628135, 1199144768, 295132047, + 77536342, 1472377703, 30752443, 1300339617, 18647556, 1267774380, 1194573079, + 1624665024, 646848056, 1667216490, 1184843555, 1250329476, 254171597, 1902035936, + 1706882202, 964921003, 952266538, 1215696284, 539510504, 1056507562, 1393151480, + 733644883, 1663330816, 1100715048, 991108703, 1671345065, 1376431774, 408310416, + 313176996, 743567676, 304660642, 1842695838, 958201635, 1650792218, 541570244, + 968523062, 1958918704, 1866282698, 849808680, 1193306222, 794153281, 822835360, + 135282913, 1149868448, 2068162123, 1474283743, 2039088058, 720305835, 746036736, + 671006610, + ]); + + assert_eq!(output, expected); + } +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/mds.v b/CoqOfRust/plonky3/mersenne-31/src/mds.v new file mode 100644 index 000000000..a3e28dc9b --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/mds.v @@ -0,0 +1,1800 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module mds. + (* StructTuple + { + name := "MdsMatrixMersenne31"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_clone_Clone_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_mersenne_31::mds::MdsMatrixMersenne31" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Module Impl_core_fmt_Debug_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "MdsMatrixMersenne31" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Module Impl_core_default_Default_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic (Value.StructTuple "p3_mersenne_31::mds::MdsMatrixMersenne31" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + (* StructTuple + { + name := "SmallConvolveMersenne31"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_p3_mds_karatsuba_convolution_Convolve_p3_mersenne_31_mersenne_31_Mersenne31_i64_i64_i64_for_p3_mersenne_31_mds_SmallConvolveMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::SmallConvolveMersenne31". + + (* + fn read(input: Mersenne31) -> i64 { + input.value as i64 + } + *) + Definition read (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.cast + (Ty.path "i64") + (M.read (| + M.SubPointer.get_struct_record_field (| + input, + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn parity_dot(u: [i64; N], v: [i64; N]) -> i64 { + dot_product(u, v) + } + *) + Definition parity_dot (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [ u; v ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + let v := M.alloc (| v |) in + M.call_closure (| + Ty.path "i64", + M.get_function (| "p3_mds::util::dot_product", [ N ], [ Ty.path "i64" ] |), + [ M.read (| u |); M.read (| v |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn reduce(z: i64) -> Mersenne31 { + debug_assert!(z >= 0); + Mersenne31::from_u64(z as u64) + } + *) + Definition reduce (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ z ] => + ltac:(M.monadic + (let z := M.alloc (| z |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| z |); Value.Integer IntegerKind.I64 0 ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: z >= 0" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "from_u64", + [], + [] + |), + [ M.cast (Ty.path "u64") (M.read (| z |)) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_mds::karatsuba_convolution::Convolve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ] + Self + (* Instance *) + [ + ("read", InstanceField.Method read); + ("parity_dot", InstanceField.Method parity_dot); + ("reduce", InstanceField.Method reduce) + ]. + End Impl_p3_mds_karatsuba_convolution_Convolve_p3_mersenne_31_mersenne_31_Mersenne31_i64_i64_i64_for_p3_mersenne_31_mds_SmallConvolveMersenne31. + + (* StructTuple + { + name := "LargeConvolveMersenne31"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_p3_mds_karatsuba_convolution_Convolve_p3_mersenne_31_mersenne_31_Mersenne31_i64_i64_i64_for_p3_mersenne_31_mds_LargeConvolveMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::LargeConvolveMersenne31". + + (* + fn read(input: Mersenne31) -> i64 { + input.value as i64 + } + *) + Definition read (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.cast + (Ty.path "i64") + (M.read (| + M.SubPointer.get_struct_record_field (| + input, + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn parity_dot(u: [i64; N], v: [i64; N]) -> i64 { + // For a convolution of size N, |x|, |y| < N * 2^31, so the product + // could be as much as N^2 * 2^62. This will overflow an i64, so + // we first widen to i128. + + let mut dp = 0i128; + for i in 0..N { + dp += u[i] as i128 * v[i] as i128; + } + + const LOWMASK: i128 = (1 << 42) - 1; // Gets the bits lower than 42. + const HIGHMASK: i128 = !LOWMASK; // Gets all bits higher than 42. + + let low_bits = (dp & LOWMASK) as i64; // low_bits < 2**42 + let high_bits = ((dp & HIGHMASK) >> 31) as i64; // |high_bits| < 2**(n - 31) + + // Proof that low_bits + high_bits is congruent to dp (mod p) + // and congruent to dp (mod 2^11): + // + // The individual bounds clearly show that low_bits + + // high_bits < 2**(n - 30). + // + // Next observe that low_bits + high_bits = input - (2**31 - + // 1) * (high_bits) = input mod P. + // + // Finally note that 2**11 divides high_bits and so low_bits + + // high_bits = low_bits mod 2**11 = input mod 2**11. + + low_bits + high_bits + } + *) + Definition parity_dot (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [ u; v ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + let v := M.alloc (| v |) in + M.read (| + let~ dp : Ty.apply (Ty.path "*") [] [ Ty.path "i128" ] := + M.alloc (| Value.Integer IntegerKind.I128 0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := dp in + M.write (| + β, + M.call_closure (| + Ty.path "i128", + BinOp.Wrap.add, + [ + M.read (| β |); + M.call_closure (| + Ty.path "i128", + BinOp.Wrap.mul, + [ + M.cast + (Ty.path "i128") + (M.read (| + M.SubPointer.get_array_field (| + u, + M.read (| i |) + |) + |)); + M.cast + (Ty.path "i128") + (M.read (| + M.SubPointer.get_array_field (| + v, + M.read (| i |) + |) + |)) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ low_bits : Ty.apply (Ty.path "*") [] [ Ty.path "i64" ] := + M.alloc (| + M.cast + (Ty.path "i64") + (M.call_closure (| + Ty.path "i128", + BinOp.Wrap.bit_and, + [ + M.read (| dp |); + M.read (| + get_constant (| + "p3_mersenne_31::mds::parity_dot::LOWMASK", + Ty.path "i128" + |) + |) + ] + |)) + |) in + let~ high_bits : Ty.apply (Ty.path "*") [] [ Ty.path "i64" ] := + M.alloc (| + M.cast + (Ty.path "i64") + (M.call_closure (| + Ty.path "i128", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "i128", + BinOp.Wrap.bit_and, + [ + M.read (| dp |); + M.read (| + get_constant (| + "p3_mersenne_31::mds::parity_dot::HIGHMASK", + Ty.path "i128" + |) + |) + ] + |); + Value.Integer IntegerKind.I32 31 + ] + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.add, + [ M.read (| low_bits |); M.read (| high_bits |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn reduce(z: i64) -> Mersenne31 { + // After the dot product, the maximal size is N^2 * 2^62 < 2^74 + // as N = 64 is the biggest size. So, after the partial + // reduction, the output z of parity dot satisfies |z| < 2^44 + // (Where 44 is 74 - 30). + // + // In the recombining steps, conv maps (wo, w1) -> ((wo + w1)/2, + // (wo + w1)/2) which has no effect on the maximal size. (Indeed, + // it makes sizes almost strictly smaller). + // + // On the other hand, negacyclic_conv (ignoring the re-index) + // recombines as: (w0, w1, w2) -> (w0 + w1, w2 - w0 - w1). Hence + // if the input is <= K, the output is <= 3K. + // + // Thus the values appearing at the end are bounded by 3^n 2^44 + // where n is the maximal number of negacyclic_conv recombination + // steps. When N = 64, we need to recombine for singed_conv_32, + // singed_conv_16, singed_conv_8 so the overall bound will be 3^3 + // 2^44 < 32 * 2^44 < 2^49. + debug_assert!(z > -(1i64 << 49)); + debug_assert!(z < (1i64 << 49)); + + const MASK: i64 = (1 << 31) - 1; + // Morally, our value is a i62 not a i64 as the top 3 bits are + // guaranteed to be equal. + let low_bits = unsafe { + // This is safe as 0 <= z & MASK < 2^31 + Mersenne31::from_canonical_unchecked((z & MASK) as u32) + }; + + let high_bits = ((z >> 31) & MASK) as i32; + let sign_bits = (z >> 62) as i32; + + let high = unsafe { + // This is safe as high_bits + sign_bits > 0 as by assumption b[63] = b[61]. + Mersenne31::from_canonical_unchecked((high_bits + sign_bits) as u32) + }; + low_bits + high + } + *) + Definition reduce (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ z ] => + ltac:(M.monadic + (let z := M.alloc (| z |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.read (| z |); + UnOp.neg (| + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I32 49 + ] + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: z > -(1i64 << 49)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| z |); + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I32 49 + ] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: z < (1i64 << 49)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ low_bits : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "u32" ], + "from_canonical_unchecked", + [], + [] + |), + [ + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "i64", + BinOp.Wrap.bit_and, + [ + M.read (| z |); + M.read (| + get_constant (| "p3_mersenne_31::mds::reduce::MASK", Ty.path "i64" |) + |) + ] + |)) + ] + |) + |) in + let~ high_bits : Ty.apply (Ty.path "*") [] [ Ty.path "i32" ] := + M.alloc (| + M.cast + (Ty.path "i32") + (M.call_closure (| + Ty.path "i64", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.shr, + [ M.read (| z |); Value.Integer IntegerKind.I32 31 ] + |); + M.read (| + get_constant (| "p3_mersenne_31::mds::reduce::MASK", Ty.path "i64" |) + |) + ] + |)) + |) in + let~ sign_bits : Ty.apply (Ty.path "*") [] [ Ty.path "i32" ] := + M.alloc (| + M.cast + (Ty.path "i32") + (M.call_closure (| + Ty.path "i64", + BinOp.Wrap.shr, + [ M.read (| z |); Value.Integer IntegerKind.I32 62 ] + |)) + |) in + let~ high : + Ty.apply (Ty.path "*") [] [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "u32" ], + "from_canonical_unchecked", + [], + [] + |), + [ + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "i32", + BinOp.Wrap.add, + [ M.read (| high_bits |); M.read (| sign_bits |) ] + |)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ M.read (| low_bits |); M.read (| high |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_mds::karatsuba_convolution::Convolve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ] + Self + (* Instance *) + [ + ("read", InstanceField.Method read); + ("parity_dot", InstanceField.Method parity_dot); + ("reduce", InstanceField.Method reduce) + ]. + End Impl_p3_mds_karatsuba_convolution_Convolve_p3_mersenne_31_mersenne_31_Mersenne31_i64_i64_i64_for_p3_mersenne_31_mds_LargeConvolveMersenne31. + + Definition value_MATRIX_CIRC_MDS_8_SML_ROW + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 7; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 3; + Value.Integer IntegerKind.I64 8; + Value.Integer IntegerKind.I64 8; + Value.Integer IntegerKind.I64 3; + Value.Integer IntegerKind.I64 4; + Value.Integer IntegerKind.I64 9 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_8_SML_ROW : + M.IsFunction.C "p3_mersenne_31::mds::MATRIX_CIRC_MDS_8_SML_ROW" value_MATRIX_CIRC_MDS_8_SML_ROW. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_8_SML_ROW. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_8_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + (* + fn permute(&self, input: [Mersenne31; 8]) -> [Mersenne31; 8] { + const MATRIX_CIRC_MDS_8_SML_COL: [i64; 8] = + first_row_to_first_col(&MATRIX_CIRC_MDS_8_SML_ROW); + SmallConvolveMersenne31::apply( + input, + MATRIX_CIRC_MDS_8_SML_COL, + SmallConvolveMersenne31::conv8, + ) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_mersenne_31::mds::SmallConvolveMersenne31", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 8 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_mersenne_31::mds::permute::MATRIX_CIRC_MDS_8_SML_COL", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_mersenne_31::mds::SmallConvolveMersenne31", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv8", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Mersenne31; 8]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_8_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Module Impl_p3_mds_MdsPermutation_Usize_8_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 8 ] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_8_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Definition value_MATRIX_CIRC_MDS_12_SML_ROW + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 2; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 8; + Value.Integer IntegerKind.I64 9; + Value.Integer IntegerKind.I64 10; + Value.Integer IntegerKind.I64 7; + Value.Integer IntegerKind.I64 5; + Value.Integer IntegerKind.I64 9; + Value.Integer IntegerKind.I64 4; + Value.Integer IntegerKind.I64 10 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_12_SML_ROW : + M.IsFunction.C + "p3_mersenne_31::mds::MATRIX_CIRC_MDS_12_SML_ROW" + value_MATRIX_CIRC_MDS_12_SML_ROW. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_12_SML_ROW. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_12_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + (* + fn permute(&self, input: [Mersenne31; 12]) -> [Mersenne31; 12] { + const MATRIX_CIRC_MDS_12_SML_COL: [i64; 12] = + first_row_to_first_col(&MATRIX_CIRC_MDS_12_SML_ROW); + SmallConvolveMersenne31::apply( + input, + MATRIX_CIRC_MDS_12_SML_COL, + SmallConvolveMersenne31::conv12, + ) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_mersenne_31::mds::SmallConvolveMersenne31", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 12 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_mersenne_31::mds::permute::MATRIX_CIRC_MDS_12_SML_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_mersenne_31::mds::SmallConvolveMersenne31", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv12", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Mersenne31; 12]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_12_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Module Impl_p3_mds_MdsPermutation_Usize_12_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 12 ] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_12_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Definition value_MATRIX_CIRC_MDS_16_SML_ROW + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 51; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 11; + Value.Integer IntegerKind.I64 17; + Value.Integer IntegerKind.I64 2; + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I64 101; + Value.Integer IntegerKind.I64 63; + Value.Integer IntegerKind.I64 15; + Value.Integer IntegerKind.I64 2; + Value.Integer IntegerKind.I64 67; + Value.Integer IntegerKind.I64 22; + Value.Integer IntegerKind.I64 13; + Value.Integer IntegerKind.I64 3 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_16_SML_ROW : + M.IsFunction.C + "p3_mersenne_31::mds::MATRIX_CIRC_MDS_16_SML_ROW" + value_MATRIX_CIRC_MDS_16_SML_ROW. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_16_SML_ROW. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_16_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + (* + fn permute(&self, input: [Mersenne31; 16]) -> [Mersenne31; 16] { + const MATRIX_CIRC_MDS_16_SML_COL: [i64; 16] = + first_row_to_first_col(&MATRIX_CIRC_MDS_16_SML_ROW); + SmallConvolveMersenne31::apply( + input, + MATRIX_CIRC_MDS_16_SML_COL, + SmallConvolveMersenne31::conv16, + ) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_mersenne_31::mds::SmallConvolveMersenne31", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 16 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_mersenne_31::mds::permute::MATRIX_CIRC_MDS_16_SML_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_mersenne_31::mds::SmallConvolveMersenne31", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv16", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Mersenne31; 16]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_16_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Module Impl_p3_mds_MdsPermutation_Usize_16_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 16 ] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_16_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Definition value_MATRIX_CIRC_MDS_32_MERSENNE31_ROW + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 412540024; + Value.Integer IntegerKind.I64 1436360233; + Value.Integer IntegerKind.I64 82564914; + Value.Integer IntegerKind.I64 1072974295; + Value.Integer IntegerKind.I64 766567118; + Value.Integer IntegerKind.I64 645360517; + Value.Integer IntegerKind.I64 1979813463; + Value.Integer IntegerKind.I64 270924307; + Value.Integer IntegerKind.I64 105409451; + Value.Integer IntegerKind.I64 930115258; + Value.Integer IntegerKind.I64 636196459; + Value.Integer IntegerKind.I64 289154277; + Value.Integer IntegerKind.I64 719457988; + Value.Integer IntegerKind.I64 1512525948; + Value.Integer IntegerKind.I64 215190769; + Value.Integer IntegerKind.I64 1981550821; + Value.Integer IntegerKind.I64 434368282; + Value.Integer IntegerKind.I64 53244687; + Value.Integer IntegerKind.I64 903393155; + Value.Integer IntegerKind.I64 1696461115; + Value.Integer IntegerKind.I64 2126764826; + Value.Integer IntegerKind.I64 1779722644; + Value.Integer IntegerKind.I64 1485803845; + Value.Integer IntegerKind.I64 163026005; + Value.Integer IntegerKind.I64 2144994796; + Value.Integer IntegerKind.I64 436105640; + Value.Integer IntegerKind.I64 1770558586; + Value.Integer IntegerKind.I64 1649351985; + Value.Integer IntegerKind.I64 1342944808; + Value.Integer IntegerKind.I64 185870542; + Value.Integer IntegerKind.I64 979558870; + Value.Integer IntegerKind.I64 2003379079 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_32_MERSENNE31_ROW : + M.IsFunction.C + "p3_mersenne_31::mds::MATRIX_CIRC_MDS_32_MERSENNE31_ROW" + value_MATRIX_CIRC_MDS_32_MERSENNE31_ROW. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_32_MERSENNE31_ROW. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_32_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + (* + fn permute(&self, input: [Mersenne31; 32]) -> [Mersenne31; 32] { + const MATRIX_CIRC_MDS_32_MERSENNE31_COL: [i64; 32] = + first_row_to_first_col(&MATRIX_CIRC_MDS_32_MERSENNE31_ROW); + LargeConvolveMersenne31::apply( + input, + MATRIX_CIRC_MDS_32_MERSENNE31_COL, + LargeConvolveMersenne31::conv32, + ) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_mersenne_31::mds::LargeConvolveMersenne31", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 32 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_mersenne_31::mds::permute::MATRIX_CIRC_MDS_32_MERSENNE31_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_mersenne_31::mds::LargeConvolveMersenne31", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv32", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Mersenne31; 32]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_32_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Module Impl_p3_mds_MdsPermutation_Usize_32_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 32 ] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_32_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Definition value_MATRIX_CIRC_MDS_64_MERSENNE31_ROW + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.I64 1459759013; + Value.Integer IntegerKind.I64 922916927; + Value.Integer IntegerKind.I64 1266367242; + Value.Integer IntegerKind.I64 1961967075; + Value.Integer IntegerKind.I64 1213404336; + Value.Integer IntegerKind.I64 22536940; + Value.Integer IntegerKind.I64 450029022; + Value.Integer IntegerKind.I64 1913984483; + Value.Integer IntegerKind.I64 1414704547; + Value.Integer IntegerKind.I64 208975553; + Value.Integer IntegerKind.I64 1742378064; + Value.Integer IntegerKind.I64 866419561; + Value.Integer IntegerKind.I64 1004269062; + Value.Integer IntegerKind.I64 2087161182; + Value.Integer IntegerKind.I64 370087635; + Value.Integer IntegerKind.I64 1418234764; + Value.Integer IntegerKind.I64 1718385318; + Value.Integer IntegerKind.I64 289114594; + Value.Integer IntegerKind.I64 708852962; + Value.Integer IntegerKind.I64 419028802; + Value.Integer IntegerKind.I64 711483012; + Value.Integer IntegerKind.I64 1240399333; + Value.Integer IntegerKind.I64 1560561670; + Value.Integer IntegerKind.I64 1443512824; + Value.Integer IntegerKind.I64 1777277904; + Value.Integer IntegerKind.I64 751916934; + Value.Integer IntegerKind.I64 1658877798; + Value.Integer IntegerKind.I64 581054946; + Value.Integer IntegerKind.I64 1023210508; + Value.Integer IntegerKind.I64 1318020056; + Value.Integer IntegerKind.I64 1768258069; + Value.Integer IntegerKind.I64 1181436717; + Value.Integer IntegerKind.I64 1100264658; + Value.Integer IntegerKind.I64 513443306; + Value.Integer IntegerKind.I64 963681319; + Value.Integer IntegerKind.I64 1258490867; + Value.Integer IntegerKind.I64 1700646429; + Value.Integer IntegerKind.I64 622823577; + Value.Integer IntegerKind.I64 1529784441; + Value.Integer IntegerKind.I64 504423471; + Value.Integer IntegerKind.I64 838188551; + Value.Integer IntegerKind.I64 721139705; + Value.Integer IntegerKind.I64 1041302042; + Value.Integer IntegerKind.I64 1570218363; + Value.Integer IntegerKind.I64 1862672573; + Value.Integer IntegerKind.I64 1572848413; + Value.Integer IntegerKind.I64 1992586781; + Value.Integer IntegerKind.I64 563316057; + Value.Integer IntegerKind.I64 863466611; + Value.Integer IntegerKind.I64 1911613740; + Value.Integer IntegerKind.I64 194540193; + Value.Integer IntegerKind.I64 1277432313; + Value.Integer IntegerKind.I64 1415281814; + Value.Integer IntegerKind.I64 539323311; + Value.Integer IntegerKind.I64 2072725822; + Value.Integer IntegerKind.I64 866996828; + Value.Integer IntegerKind.I64 367716892; + Value.Integer IntegerKind.I64 1831672353; + Value.Integer IntegerKind.I64 111680788; + Value.Integer IntegerKind.I64 1068297039; + Value.Integer IntegerKind.I64 319734300; + Value.Integer IntegerKind.I64 1015334133; + Value.Integer IntegerKind.I64 1358784448; + Value.Integer IntegerKind.I64 821942362 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_64_MERSENNE31_ROW : + M.IsFunction.C + "p3_mersenne_31::mds::MATRIX_CIRC_MDS_64_MERSENNE31_ROW" + value_MATRIX_CIRC_MDS_64_MERSENNE31_ROW. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_64_MERSENNE31_ROW. + + Module Impl_p3_symmetric_permutation_Permutation_array_Usize_64_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + (* + fn permute(&self, input: [Mersenne31; 64]) -> [Mersenne31; 64] { + const MATRIX_CIRC_MDS_64_MERSENNE31_COL: [i64; 64] = + first_row_to_first_col(&MATRIX_CIRC_MDS_64_MERSENNE31_ROW); + LargeConvolveMersenne31::apply( + input, + MATRIX_CIRC_MDS_64_MERSENNE31_COL, + LargeConvolveMersenne31::conv64, + ) + } + *) + Definition permute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_mersenne_31::mds::LargeConvolveMersenne31", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 64 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_mersenne_31::mds::permute::MATRIX_CIRC_MDS_64_MERSENNE31_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_mersenne_31::mds::LargeConvolveMersenne31", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv64", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Mersenne31; 64]) { + *input = self.permute( *input); + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + Self + (* Instance *) + [ + ("permute", InstanceField.Method permute); + ("permute_mut", InstanceField.Method permute_mut) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_Usize_64_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + + Module Impl_p3_mds_MdsPermutation_Usize_64_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mds::MdsMatrixMersenne31". + + Axiom Implements : + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 64 ] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_Usize_64_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mds_MdsMatrixMersenne31. +End mds. diff --git a/CoqOfRust/plonky3/mersenne-31/src/mersenne_31.rs b/CoqOfRust/plonky3/mersenne-31/src/mersenne_31.rs new file mode 100644 index 000000000..7f9cbe012 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/mersenne_31.rs @@ -0,0 +1,594 @@ +use alloc::vec; +use alloc::vec::Vec; +use core::fmt; +use core::fmt::{Debug, Display, Formatter}; +use core::hash::{Hash, Hasher}; +use core::iter::{Product, Sum}; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; + +use num_bigint::BigUint; +use p3_field::exponentiation::exp_1717986917; +use p3_field::integers::QuotientMap; +use p3_field::{ + Field, InjectiveMonomial, Packable, PermutationMonomial, PrimeCharacteristicRing, PrimeField, + PrimeField32, PrimeField64, halve_u32, quotient_map_large_iint, quotient_map_large_uint, + quotient_map_small_int, +}; +use p3_util::flatten_to_base; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; +use serde::de::Error; +use serde::{Deserialize, Deserializer, Serialize}; + +/// The Mersenne31 prime +const P: u32 = (1 << 31) - 1; + +/// The prime field `F_p` where `p = 2^31 - 1`. +#[derive(Copy, Clone, Default)] +#[repr(transparent)] // Important for reasoning about memory layout. +pub struct Mersenne31 { + /// Not necessarily canonical, but must fit in 31 bits. + pub(crate) value: u32, +} + +impl Mersenne31 { + /// Convert a u32 element into a Mersenne31 element. + /// + /// # Safety + /// The element must lie in the range: `[0, 2^31 - 1]`. + #[inline] + pub(crate) const fn new(value: u32) -> Self { + debug_assert!((value >> 31) == 0); + Self { value } + } + + /// Convert a u32 element into a Mersenne31 element. + /// + /// # Panics + /// This will panic if the element does not lie in the range: `[0, 2^31 - 1]`. + #[inline] + pub const fn new_checked(value: u32) -> Option { + if (value >> 31) == 0 { + Some(Self { value }) + } else { + None + } + } + + /// Convert a constant `u32` array into a constant array of field elements. + /// This allows inputs to be `> 2^31`, and just reduces them `mod P`. + /// + /// This means that this will be slower than `array.map(Mersenne31::new_checked)` but + /// has the advantage of being able to be used in `const` environments. + #[inline] + pub const fn new_array(input: [u32; N]) -> [Self; N] { + let mut output = [Self::ZERO; N]; + let mut i = 0; + while i < N { + output[i].value = input[i] % P; + i += 1; + } + output + } +} + +impl PartialEq for Mersenne31 { + #[inline] + fn eq(&self, other: &Self) -> bool { + self.as_canonical_u32() == other.as_canonical_u32() + } +} + +impl Eq for Mersenne31 {} + +impl Packable for Mersenne31 {} + +impl Hash for Mersenne31 { + fn hash(&self, state: &mut H) { + state.write_u32(self.to_unique_u32()); + } +} + +impl Ord for Mersenne31 { + #[inline] + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.as_canonical_u32().cmp(&other.as_canonical_u32()) + } +} + +impl PartialOrd for Mersenne31 { + #[inline] + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Display for Mersenne31 { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Display::fmt(&self.value, f) + } +} + +impl Debug for Mersenne31 { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Debug::fmt(&self.value, f) + } +} + +impl Distribution for StandardUniform { + fn sample(&self, rng: &mut R) -> Mersenne31 { + loop { + let next_u31 = rng.next_u32() >> 1; + let is_canonical = next_u31 != Mersenne31::ORDER_U32; + if is_canonical { + return Mersenne31::new(next_u31); + } + } + } +} + +impl Serialize for Mersenne31 { + fn serialize(&self, serializer: S) -> Result { + // No need to convert to canonical. + serializer.serialize_u32(self.value) + } +} + +impl<'a> Deserialize<'a> for Mersenne31 { + fn deserialize>(d: D) -> Result { + let val = u32::deserialize(d)?; + // Ensure that `val` satisfies our invariant. i.e. Not necessarily canonical, but must fit in 31 bits. + if val <= P { + Ok(Self::new(val)) + } else { + Err(D::Error::custom("Value is out of range")) + } + } +} + +impl PrimeCharacteristicRing for Mersenne31 { + type PrimeSubfield = Self; + + const ZERO: Self = Self { value: 0 }; + const ONE: Self = Self { value: 1 }; + const TWO: Self = Self { value: 2 }; + const NEG_ONE: Self = Self { + value: Self::ORDER_U32 - 1, + }; + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f + } + + #[inline] + fn from_bool(b: bool) -> Self { + Self::new(b as u32) + } + + #[inline] + fn mul_2exp_u64(&self, exp: u64) -> Self { + // In a Mersenne field, multiplication by 2^k is just a left rotation by k bits. + let exp = exp % 31; + let left = (self.value << exp) & ((1 << 31) - 1); + let right = self.value >> (31 - exp); + let rotated = left | right; + Self::new(rotated) + } + + #[inline] + fn sum_array(input: &[Self]) -> Self { + assert_eq!(N, input.len()); + // Benchmarking shows that for N <= 5 it's faster to sum the elements directly + // but for N > 5 it's faster to use the .sum() methods which passes through u64's + // allowing for delayed reductions. + match N { + 0 => Self::ZERO, + 1 => input[0], + 2 => input[0] + input[1], + 3 => input[0] + input[1] + input[2], + 4 => (input[0] + input[1]) + (input[2] + input[3]), + 5 => { + let lhs = input[0] + input[1]; + let rhs = input[2] + input[3]; + lhs + rhs + input[4] + } + _ => input.iter().copied().sum(), + } + } + + #[inline] + fn zero_vec(len: usize) -> Vec { + // SAFETY: + // Due to `#[repr(transparent)]`, Mersenne31 and u32 have the same size, alignment + // and memory layout making `flatten_to_base` safe. This this will create + // a vector Mersenne31 elements with value set to 0. + unsafe { flatten_to_base(vec![0u32; len]) } + } +} + +// Degree of the smallest permutation polynomial for Mersenne31. +// +// As p - 1 = 2×3^2×7×11×... the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 5. +impl InjectiveMonomial<5> for Mersenne31 {} + +impl PermutationMonomial<5> for Mersenne31 { + /// In the field `Mersenne31`, `a^{1/5}` is equal to a^{1717986917}. + /// + /// This follows from the calculation `5 * 1717986917 = 4*(2^31 - 2) + 1 = 1 mod p - 1`. + fn injective_exp_root_n(&self) -> Self { + exp_1717986917(*self) + } +} + +impl Field for Mersenne31 { + #[cfg(all(target_arch = "aarch64", target_feature = "neon"))] + type Packing = crate::PackedMersenne31Neon; + #[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) + ))] + type Packing = crate::PackedMersenne31AVX2; + #[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ))] + type Packing = crate::PackedMersenne31AVX512; + #[cfg(not(any( + all(target_arch = "aarch64", target_feature = "neon"), + all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) + ), + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), + )))] + type Packing = Self; + + // Sage: GF(2^31 - 1).multiplicative_generator() + const GENERATOR: Self = Self::new(7); + + #[inline] + fn is_zero(&self) -> bool { + self.value == 0 || self.value == Self::ORDER_U32 + } + + #[inline] + fn div_2exp_u64(&self, exp: u64) -> Self { + // In a Mersenne field, division by 2^k is just a right rotation by k bits. + let exp = (exp % 31) as u8; + let left = self.value >> exp; + let right = (self.value << (31 - exp)) & ((1 << 31) - 1); + let rotated = left | right; + Self::new(rotated) + } + + fn try_inverse(&self) -> Option { + if self.is_zero() { + return None; + } + + // From Fermat's little theorem, in a prime field `F_p`, the inverse of `a` is `a^(p-2)`. + // Here p-2 = 2147483645 = 1111111111111111111111111111101_2. + // Uses 30 Squares + 7 Multiplications => 37 Operations total. + + let p1 = *self; + let p101 = p1.exp_power_of_2(2) * p1; + let p1111 = p101.square() * p101; + let p11111111 = p1111.exp_power_of_2(4) * p1111; + let p111111110000 = p11111111.exp_power_of_2(4); + let p111111111111 = p111111110000 * p1111; + let p1111111111111111 = p111111110000.exp_power_of_2(4) * p11111111; + let p1111111111111111111111111111 = p1111111111111111.exp_power_of_2(12) * p111111111111; + let p1111111111111111111111111111101 = + p1111111111111111111111111111.exp_power_of_2(3) * p101; + Some(p1111111111111111111111111111101) + } + + #[inline] + fn halve(&self) -> Self { + Self::new(halve_u32::

(self.value)) + } + + #[inline] + fn order() -> BigUint { + P.into() + } +} + +// We can use some macros to implement QuotientMap for all integer types except for u32 and i32's. +quotient_map_small_int!(Mersenne31, u32, [u8, u16]); +quotient_map_small_int!(Mersenne31, i32, [i8, i16]); +quotient_map_large_uint!( + Mersenne31, + u32, + Mersenne31::ORDER_U32, + "`[0, 2^31 - 2]`", + "`[0, 2^31 - 1]`", + [u64, u128] +); +quotient_map_large_iint!( + Mersenne31, + i32, + "`[-2^30, 2^30]`", + "`[1 - 2^31, 2^31 - 1]`", + [(i64, u64), (i128, u128)] +); + +// We simple need to prove custom Mersenne31 impls for QuotientMap and QuotientMap +impl QuotientMap for Mersenne31 { + /// Convert a given `u32` integer into an element of the `Mersenne31` field. + #[inline] + fn from_int(int: u32) -> Self { + // To reduce `n` to 31 bits, we clear its MSB, then add it back in its reduced form. + let msb = int & (1 << 31); + let msb_reduced = msb >> 31; + Self::new(int ^ msb) + Self::new(msb_reduced) + } + + /// Convert a given `u32` integer into an element of the `Mersenne31` field. + /// + /// Returns none if the input does not lie in the range `[0, 2^31 - 1]`. + #[inline] + fn from_canonical_checked(int: u32) -> Option { + (int < Self::ORDER_U32).then(|| Self::new(int)) + } + + /// Convert a given `u32` integer into an element of the `Mersenne31` field. + /// + /// # Safety + /// The input must lie in the range: `[0, 2^31 - 1]`. + #[inline(always)] + unsafe fn from_canonical_unchecked(int: u32) -> Self { + debug_assert!(int < Self::ORDER_U32); + Self::new(int) + } +} + +impl QuotientMap for Mersenne31 { + /// Convert a given `i32` integer into an element of the `Mersenne31` field. + #[inline] + fn from_int(int: i32) -> Self { + if int >= 0 { + Self::new(int as u32) + } else if int > (-1 << 31) { + Self::new(Self::ORDER_U32.wrapping_add_signed(int)) + } else { + // The only other option is int = -(2^31) = -1 mod p. + Self::NEG_ONE + } + } + + /// Convert a given `i32` integer into an element of the `Mersenne31` field. + /// + /// Returns none if the input does not lie in the range `(-2^30, 2^30)`. + #[inline] + fn from_canonical_checked(int: i32) -> Option { + const TWO_EXP_30: i32 = 1 << 30; + const NEG_TWO_EXP_30_PLUS_1: i32 = (-1 << 30) + 1; + match int { + 0..TWO_EXP_30 => Some(Self::new(int as u32)), + NEG_TWO_EXP_30_PLUS_1..0 => Some(Self::new(Self::ORDER_U32.wrapping_add_signed(int))), + _ => None, + } + } + + /// Convert a given `i32` integer into an element of the `Mersenne31` field. + /// + /// # Safety + /// The input must lie in the range: `[1 - 2^31, 2^31 - 1]`. + #[inline(always)] + unsafe fn from_canonical_unchecked(int: i32) -> Self { + if int >= 0 { + Self::new(int as u32) + } else { + Self::new(Self::ORDER_U32.wrapping_add_signed(int)) + } + } +} + +impl PrimeField for Mersenne31 { + fn as_canonical_biguint(&self) -> BigUint { + ::as_canonical_u32(self).into() + } +} + +impl PrimeField32 for Mersenne31 { + const ORDER_U32: u32 = P; + + #[inline] + fn as_canonical_u32(&self) -> u32 { + // Since our invariant guarantees that `value` fits in 31 bits, there is only one possible + // `value` that is not canonical, namely 2^31 - 1 = p = 0. + if self.value == Self::ORDER_U32 { + 0 + } else { + self.value + } + } +} + +impl PrimeField64 for Mersenne31 { + const ORDER_U64: u64 = ::ORDER_U32 as u64; + + #[inline] + fn as_canonical_u64(&self) -> u64 { + self.as_canonical_u32().into() + } +} + +impl Add for Mersenne31 { + type Output = Self; + + #[inline] + fn add(self, rhs: Self) -> Self { + // See the following for a way to compute the sum that avoids + // the conditional which may be preferable on some + // architectures. + // https://github.com/Plonky3/Plonky3/blob/6049a30c3b1f5351c3eb0f7c994dc97e8f68d10d/mersenne-31/src/lib.rs#L249 + + // Working with i32 means we get a flag which informs us if overflow happened. + let (sum_i32, over) = (self.value as i32).overflowing_add(rhs.value as i32); + let sum_u32 = sum_i32 as u32; + let sum_corr = sum_u32.wrapping_sub(Self::ORDER_U32); + + // If self + rhs did not overflow, return it. + // If self + rhs overflowed, sum_corr = self + rhs - (2**31 - 1). + Self::new(if over { sum_corr } else { sum_u32 }) + } +} + +impl AddAssign for Mersenne31 { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} + +impl Sum for Mersenne31 { + #[inline] + fn sum>(iter: I) -> Self { + // This is faster than iter.reduce(|x, y| x + y).unwrap_or(Self::ZERO) for iterators of length >= 6. + // It assumes that iter.len() < 2^31. + + // This sum will not overflow so long as iter.len() < 2^33. + let sum = iter.map(|x| x.value as u64).sum::(); + + // sum is < 2^62 provided iter.len() < 2^31. + from_u62(sum) + } +} + +impl Sub for Mersenne31 { + type Output = Self; + + #[inline] + fn sub(self, rhs: Self) -> Self { + let (mut sub, over) = self.value.overflowing_sub(rhs.value); + + // If we didn't overflow we have the correct value. + // Otherwise we have added 2**32 = 2**31 + 1 mod 2**31 - 1. + // Hence we need to remove the most significant bit and subtract 1. + sub -= over as u32; + Self::new(sub & Self::ORDER_U32) + } +} + +impl SubAssign for Mersenne31 { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} + +impl Neg for Mersenne31 { + type Output = Self; + + #[inline] + fn neg(self) -> Self::Output { + // Can't underflow, since self.value is 31-bits and thus can't exceed ORDER. + Self::new(Self::ORDER_U32 - self.value) + } +} + +impl Mul for Mersenne31 { + type Output = Self; + + #[inline] + #[allow(clippy::cast_possible_truncation)] + fn mul(self, rhs: Self) -> Self { + let prod = u64::from(self.value) * u64::from(rhs.value); + from_u62(prod) + } +} + +impl MulAssign for Mersenne31 { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} + +impl Product for Mersenne31 { + #[inline] + fn product>(iter: I) -> Self { + iter.reduce(|x, y| x * y).unwrap_or(Self::ONE) + } +} + +impl Div for Mersenne31 { + type Output = Self; + + #[inline] + #[allow(clippy::suspicious_arithmetic_impl)] + fn div(self, rhs: Self) -> Self { + self * rhs.inverse() + } +} + +#[inline(always)] +pub(crate) fn from_u62(input: u64) -> Mersenne31 { + debug_assert!(input < (1 << 62)); + let input_lo = (input & ((1 << 31) - 1)) as u32; + let input_high = (input >> 31) as u32; + Mersenne31::new(input_lo) + Mersenne31::new(input_high) +} + +#[cfg(test)] +mod tests { + use num_bigint::BigUint; + use p3_field::{InjectiveMonomial, PermutationMonomial, PrimeCharacteristicRing}; + use p3_field_testing::{ + test_field, test_prime_field, test_prime_field_32, test_prime_field_64, + }; + + use crate::Mersenne31; + + type F = Mersenne31; + + #[test] + fn exp_root() { + // Confirm that (x^{1/5})^5 = x + + let m1 = F::from_u32(0x34167c58); + let m2 = F::from_u32(0x61f3207b); + + assert_eq!(m1.injective_exp_n().injective_exp_root_n(), m1); + assert_eq!(m2.injective_exp_n().injective_exp_root_n(), m2); + assert_eq!(F::TWO.injective_exp_n().injective_exp_root_n(), F::TWO); + } + + // Mersenne31 has a redundant representation of Zero but no redundant representation of One. + const ZEROS: [Mersenne31; 2] = [Mersenne31::ZERO, Mersenne31::new((1_u32 << 31) - 1)]; + const ONES: [Mersenne31; 1] = [Mersenne31::ONE]; + + // Get the prime factorization of the order of the multiplicative group. + // i.e. the prime factorization of P - 1. + fn multiplicative_group_prime_factorization() -> [(BigUint, u32); 7] { + [ + (BigUint::from(2u8), 1), + (BigUint::from(3u8), 2), + (BigUint::from(7u8), 1), + (BigUint::from(11u8), 1), + (BigUint::from(31u8), 1), + (BigUint::from(151u8), 1), + (BigUint::from(331u16), 1), + ] + } + + test_field!( + crate::Mersenne31, + &super::ZEROS, + &super::ONES, + &super::multiplicative_group_prime_factorization() + ); + test_prime_field!(crate::Mersenne31); + test_prime_field_64!(crate::Mersenne31); + test_prime_field_32!(crate::Mersenne31); +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/mersenne_31.v b/CoqOfRust/plonky3/mersenne-31/src/mersenne_31.v new file mode 100644 index 000000000..9f231d962 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/mersenne_31.v @@ -0,0 +1,4351 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module mersenne_31. + Definition value_P (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U32 1; Value.Integer IntegerKind.I32 31 ] + |); + Value.Integer IntegerKind.U32 1 + ] + |) + |))). + + Global Instance Instance_IsConstant_value_P : + M.IsFunction.C "p3_mersenne_31::mersenne_31::P" value_P. + Admitted. + Global Typeclasses Opaque value_P. + + (* StructRecord + { + name := "Mersenne31"; + const_params := []; + ty_params := []; + fields := [ ("value", Ty.path "u32") ]; + } *) + + Module Impl_core_marker_Copy_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_clone_Clone_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_default_Default_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_mersenne_31::mersenne_31::Mersenne31" + [ + ("value", + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "core::default::Default", + Ty.path "u32", + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + pub(crate) const fn new(value: u32) -> Self { + debug_assert!((value >> 31) == 0); + Self { value } + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ M.read (| value |); Value.Integer IntegerKind.I32 31 + ] + |); + Value.Integer IntegerKind.U32 0 + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: (value >> 31) == 0" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructRecord + "p3_mersenne_31::mersenne_31::Mersenne31" + [ ("value", M.read (| value |)) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.C Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub const fn new_checked(value: u32) -> Option { + if (value >> 31) == 0 { + Some(Self { value }) + } else { + None + } + } + *) + Definition new_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ M.read (| value |); Value.Integer IntegerKind.I32 31 ] + |); + Value.Integer IntegerKind.U32 0 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + Value.StructRecord + "p3_mersenne_31::mersenne_31::Mersenne31" + [ ("value", M.read (| value |)) ] + ] + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_checked : + M.IsAssociatedFunction.C Self "new_checked" new_checked. + Admitted. + Global Typeclasses Opaque new_checked. + + (* + pub const fn new_array(input: [u32; N]) -> [Self; N] { + let mut output = [Self::ZERO; N]; + let mut i = 0; + while i < N { + output[i].value = input[i] % P; + i += 1; + } + output + } + *) + Definition new_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] := + M.alloc (| + repeat (| + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |) + |), + N + |) + |) in + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| Ty.path "bool", BinOp.lt, [ M.read (| i |); N ] |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| output, M.read (| i |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |), + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.rem, + [ + M.read (| + M.SubPointer.get_array_field (| input, M.read (| i |) |) + |); + M.read (| + get_constant (| + "p3_mersenne_31::mersenne_31::P", + Ty.path "u32" + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_array : + M.IsAssociatedFunction.C Self "new_array" new_array. + Admitted. + Global Typeclasses Opaque new_array. + End Impl_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_cmp_PartialEq_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn eq(&self, other: &Self) -> bool { + self.as_canonical_u32() == other.as_canonical_u32() + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_cmp_Eq_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_cmp_Eq_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_packed_Packable_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + Axiom Implements : + M.IsTraitInstance + "p3_field::packed::Packable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_field_packed_Packable_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_hash_Hash_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn hash(&self, state: &mut H) { + state.write_u32(self.to_unique_u32()); + } + *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| "core::hash::Hasher", H, [], [], "write_u32", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "to_unique_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_cmp_Ord_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.as_canonical_u32().cmp(&other.as_canonical_u32()) + } + *) + Definition cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| "core::cmp::Ord", Ty.path "u32", [], [], "cmp", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("cmp", InstanceField.Method cmp) ]. + End Impl_core_cmp_Ord_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_cmp_PartialOrd_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_fmt_Display_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Display::fmt(&self.value, f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| "core::fmt::Display", Ty.path "u32", [], [], "fmt", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_fmt_Debug_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Debug::fmt(&self.value, f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| "core::fmt::Debug", Ty.path "u32", [], [], "fmt", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_rand_distr_distribution_Distribution_p3_mersenne_31_mersenne_31_Mersenne31_for_rand_distr_StandardUniform. + Definition Self : Ty.t := Ty.path "rand::distr::StandardUniform". + + (* + fn sample(&self, rng: &mut R) -> Mersenne31 { + loop { + let next_u31 = rng.next_u32() >> 1; + let is_canonical = next_u31 != Mersenne31::ORDER_U32; + if is_canonical { + return Mersenne31::new(next_u31); + } + } + } + *) + Definition sample (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ self; rng ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rng := M.alloc (| rng |) in + M.catch_return (Ty.path "p3_mersenne_31::mersenne_31::Mersenne31") (| + ltac:(M.monadic + (M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic + (let~ next_u31 : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "rand_core::RngCore", + R, + [], + [], + "next_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |) + ] + |); + Value.Integer IntegerKind.I32 1 + ] + |) + |) in + let~ is_canonical : Ty.apply (Ty.path "*") [] [ Ty.path "bool" ] := + M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.read (| next_u31 |); + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use is_canonical in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.read (| next_u31 |) ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "rand::distr::distribution::Distribution" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("sample", InstanceField.Method sample) ]. + End Impl_rand_distr_distribution_Distribution_p3_mersenne_31_mersenne_31_Mersenne31_for_rand_distr_StandardUniform. + + Module Impl_serde_ser_Serialize_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn serialize(&self, serializer: S) -> Result { + // No need to convert to canonical. + serializer.serialize_u32(self.value) + } + *) + Definition serialize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as S ], [ self; serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let serializer := M.alloc (| serializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Error" + ], + M.get_trait_method (| "serde::ser::Serializer", S, [], [], "serialize_u32", [], [] |), + [ + M.read (| serializer |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("serialize", InstanceField.Method serialize) ]. + End Impl_serde_ser_Serialize_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_serde_de_Deserialize_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn deserialize>(d: D) -> Result { + let val = u32::deserialize(d)?; + // Ensure that `val` satisfies our invariant. i.e. Not necessarily canonical, but must fit in 31 bits. + if val <= P { + Ok(Self::new(val)) + } else { + Err(D::Error::custom("Value is out of range")) + } + } + *) + Definition deserialize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ D ], [ d ] => + ltac:(M.monadic + (let d := M.alloc (| d |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ val : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ]; + Ty.path "u32" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u32"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u32"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ], + M.get_trait_method (| + "serde::de::Deserialize", + Ty.path "u32", + [], + [], + "deserialize", + [], + [ D ] + |), + [ M.read (| d |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| val |); + M.read (| + get_constant (| + "p3_mersenne_31::mersenne_31::P", + Ty.path "u32" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.read (| val |) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::result::Result::Err" + [ + M.call_closure (| + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error", + M.get_trait_method (| + "serde::de::Error", + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error", + [], + [], + "custom", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + |), + [ mk_str (| "Value is out of range" |) ] + |) + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("deserialize", InstanceField.Method deserialize) ]. + End Impl_serde_de_Deserialize_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_field_PrimeCharacteristicRing_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* type PrimeSubfield = Self; *) + Definition _PrimeSubfield : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const ZERO: Self = Self { value: 0 }; *) + (* Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" *) + Definition value_ZERO (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.StructRecord + "p3_mersenne_31::mersenne_31::Mersenne31" + [ ("value", Value.Integer IntegerKind.U32 0) ] + |))). + + (* const ONE: Self = Self { value: 1 }; *) + (* Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" *) + Definition value_ONE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.StructRecord + "p3_mersenne_31::mersenne_31::Mersenne31" + [ ("value", Value.Integer IntegerKind.U32 1) ] + |))). + + (* const TWO: Self = Self { value: 2 }; *) + (* Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" *) + Definition value_TWO (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.StructRecord + "p3_mersenne_31::mersenne_31::Mersenne31" + [ ("value", Value.Integer IntegerKind.U32 2) ] + |))). + + (* + const NEG_ONE: Self = Self { + value: Self::ORDER_U32 - 1, + }; + *) + (* Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" *) + Definition value_NEG_ONE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.StructRecord + "p3_mersenne_31::mersenne_31::Mersenne31" + [ + ("value", + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + Value.Integer IntegerKind.U32 1 + ] + |)) + ] + |))). + + (* + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f + } + *) + Definition from_prime_subfield (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.read (| f |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_bool(b: bool) -> Self { + Self::new(b as u32) + } + *) + Definition from_bool (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ b ] => + ltac:(M.monadic + (let b := M.alloc (| b |) in + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.cast (Ty.path "u32") (M.read (| b |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn mul_2exp_u64(&self, exp: u64) -> Self { + // In a Mersenne field, multiplication by 2^k is just a left rotation by k bits. + let exp = exp % 31; + let left = (self.value << exp) & ((1 << 31) - 1); + let right = self.value >> (31 - exp); + let rotated = left | right; + Self::new(rotated) + } + *) + Definition mul_2exp_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.read (| + let~ exp : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.rem, + [ M.read (| exp |); Value.Integer IntegerKind.U64 31 ] + |) + |) in + let~ left : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |); + M.read (| exp |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U32 1; Value.Integer IntegerKind.I32 31 ] + |); + Value.Integer IntegerKind.U32 1 + ] + |) + ] + |) + |) in + let~ right : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ Value.Integer IntegerKind.U64 31; M.read (| exp |) ] + |) + ] + |) + |) in + let~ rotated : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_or, + [ M.read (| left |); M.read (| right |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.read (| rotated |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn sum_array(input: &[Self]) -> Self { + assert_eq!(N, input.len()); + // Benchmarking shows that for N <= 5 it's faster to sum the elements directly + // but for N > 5 it's faster to use the .sum() methods which passes through u64's + // allowing for delayed reductions. + match N { + 0 => Self::ZERO, + 1 => input[0], + 2 => input[0] + input[1], + 3 => input[0] + input[1] + input[2], + 4 => (input[0] + input[1]) + (input[2] + input[3]), + 5 => { + let lhs = input[0] + input[1]; + let rhs = input[2] + input[3]; + lhs + rhs + input[4] + } + _ => input.iter().copied().sum(), + } + } + *) + Definition sum_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.alloc (| N |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 0 + |) in + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 1 + |) in + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 3 + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 4 + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 5 + |) in + let~ lhs : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ rhs : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ M.read (| lhs |); M.read (| rhs |) ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 4 + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + [], + [], + "sum", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + [], + [], + "copied", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) + ] + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn zero_vec(len: usize) -> Vec { + // SAFETY: + // Due to `#[repr(transparent)]`, Mersenne31 and u32 have the same size, alignment + // and memory layout making `flatten_to_base` safe. This this will create + // a vector Mersenne31 elements with value set to 0. + unsafe { flatten_to_base(vec![0u32; len]) } + } + *) + Definition zero_vec (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ len ] => + ltac:(M.monadic + (let len := M.alloc (| len |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; Ty.path "alloc::alloc::Global" ], + M.get_function (| + "p3_util::flatten_to_base", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; Ty.path "u32" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u32"; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloc::vec::from_elem", [], [ Ty.path "u32" ] |), + [ Value.Integer IntegerKind.U32 0; M.read (| len |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PrimeCharacteristicRing" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("PrimeSubfield", InstanceField.Ty _PrimeSubfield); + ("value_ZERO", InstanceField.Method value_ZERO); + ("value_ONE", InstanceField.Method value_ONE); + ("value_TWO", InstanceField.Method value_TWO); + ("value_NEG_ONE", InstanceField.Method value_NEG_ONE); + ("from_prime_subfield", InstanceField.Method from_prime_subfield); + ("from_bool", InstanceField.Method from_bool); + ("mul_2exp_u64", InstanceField.Method mul_2exp_u64); + ("sum_array", InstanceField.Method sum_array); + ("zero_vec", InstanceField.Method zero_vec) + ]. + End Impl_p3_field_field_PrimeCharacteristicRing_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_field_InjectiveMonomial_U64_5_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::InjectiveMonomial" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.U64 5 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_p3_field_field_InjectiveMonomial_U64_5_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_field_PermutationMonomial_U64_5_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn injective_exp_root_n(&self) -> Self { + exp_1717986917( *self) + } + *) + Definition injective_exp_root_n (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_function (| + "p3_field::exponentiation::exp_1717986917", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PermutationMonomial" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.U64 5 ] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("injective_exp_root_n", InstanceField.Method injective_exp_root_n) ]. + End Impl_p3_field_field_PermutationMonomial_U64_5_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_field_Field_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* type Packing = Self; *) + Definition _Packing : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const GENERATOR: Self = Self::new(7); *) + (* Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" *) + Definition value_GENERATOR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ Value.Integer IntegerKind.U32 7 ] + |) + |))). + + (* + fn is_zero(&self) -> bool { + self.value == 0 || self.value == Self::ORDER_U32 + } + *) + Definition is_zero (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |); + Value.Integer IntegerKind.U32 0 + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |); + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn div_2exp_u64(&self, exp: u64) -> Self { + // In a Mersenne field, division by 2^k is just a right rotation by k bits. + let exp = (exp % 31) as u8; + let left = self.value >> exp; + let right = (self.value << (31 - exp)) & ((1 << 31) - 1); + let rotated = left | right; + Self::new(rotated) + } + *) + Definition div_2exp_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.read (| + let~ exp : Ty.apply (Ty.path "*") [] [ Ty.path "u8" ] := + M.alloc (| + M.cast + (Ty.path "u8") + (M.call_closure (| + Ty.path "u64", + BinOp.Wrap.rem, + [ M.read (| exp |); Value.Integer IntegerKind.U64 31 ] + |)) + |) in + let~ left : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |); + M.read (| exp |) + ] + |) + |) in + let~ right : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |); + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.sub, + [ Value.Integer IntegerKind.U8 31; M.read (| exp |) ] + |) + ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U32 1; Value.Integer IntegerKind.I32 31 ] + |); + Value.Integer IntegerKind.U32 1 + ] + |) + ] + |) + |) in + let~ rotated : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_or, + [ M.read (| left |); M.read (| right |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.read (| rotated |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn try_inverse(&self) -> Option { + if self.is_zero() { + return None; + } + + // From Fermat's little theorem, in a prime field `F_p`, the inverse of `a` is `a^(p-2)`. + // Here p-2 = 2147483645 = 1111111111111111111111111111101_2. + // Uses 30 Squares + 7 Multiplications => 37 Operations total. + + let p1 = *self; + let p101 = p1.exp_power_of_2(2) * p1; + let p1111 = p101.square() * p101; + let p11111111 = p1111.exp_power_of_2(4) * p1111; + let p111111110000 = p11111111.exp_power_of_2(4); + let p111111111111 = p111111110000 * p1111; + let p1111111111111111 = p111111110000.exp_power_of_2(4) * p11111111; + let p1111111111111111111111111111 = p1111111111111111.exp_power_of_2(12) * p111111111111; + let p1111111111111111111111111111101 = + p1111111111111111111111111111.exp_power_of_2(3) * p101; + Some(p1111111111111111111111111111101) + } + *) + Definition try_inverse (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "p3_field::field::Field", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| Value.StructTuple "core::option::Option::None" [] |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ p1 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.copy (| M.deref (| M.read (| self |) |) |) in + let~ p101 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "exp_power_of_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p1 |); Value.Integer IntegerKind.Usize 2 ] + |); + M.read (| p1 |) + ] + |) + |) in + let~ p1111 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, p101 |) ] + |); + M.read (| p101 |) + ] + |) + |) in + let~ p11111111 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p1111 |); + Value.Integer IntegerKind.Usize 4 + ] + |); + M.read (| p1111 |) + ] + |) + |) in + let~ p111111110000 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p11111111 |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) in + let~ p111111111111 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "mul", + [], + [] + |), + [ M.read (| p111111110000 |); M.read (| p1111 |) ] + |) + |) in + let~ p1111111111111111 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p111111110000 |); + Value.Integer IntegerKind.Usize 4 + ] + |); + M.read (| p11111111 |) + ] + |) + |) in + let~ p1111111111111111111111111111 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p1111111111111111 |); + Value.Integer IntegerKind.Usize 12 + ] + |); + M.read (| p111111111111 |) + ] + |) + |) in + let~ p1111111111111111111111111111101 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "exp_power_of_2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, p1111111111111111111111111111 |); + Value.Integer IntegerKind.Usize 3 + ] + |); + M.read (| p101 |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.read (| p1111111111111111111111111111101 |) ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn halve(&self) -> Self { + Self::new(halve_u32::

(self.value)) + } + *) + Definition halve (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| + "p3_field::helpers::halve_u32", + [ Value.Integer IntegerKind.U32 2147483647 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn order() -> BigUint { + P.into() + } + *) + Definition order (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "core::convert::Into", + Ty.path "u32", + [], + [ Ty.path "num_bigint::biguint::BigUint" ], + "into", + [], + [] + |), + [ M.read (| get_constant (| "p3_mersenne_31::mersenne_31::P", Ty.path "u32" |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::Field" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Packing", InstanceField.Ty _Packing); + ("value_GENERATOR", InstanceField.Method value_GENERATOR); + ("is_zero", InstanceField.Method is_zero); + ("div_2exp_u64", InstanceField.Method div_2exp_u64); + ("try_inverse", InstanceField.Method try_inverse); + ("halve", InstanceField.Method halve); + ("order", InstanceField.Method order) + ]. + End Impl_p3_field_field_Field_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_integers_QuotientMap_u32_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn from_int(int: u32) -> Self { + // To reduce `n` to 31 bits, we clear its MSB, then add it back in its reduced form. + let msb = int & (1 << 31); + let msb_reduced = msb >> 31; + Self::new(int ^ msb) + Self::new(msb_reduced) + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ msb : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ + M.read (| int |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U32 1; Value.Integer IntegerKind.I32 31 ] + |) + ] + |) + |) in + let~ msb_reduced : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ M.read (| msb |); Value.Integer IntegerKind.I32 31 ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_xor, + [ M.read (| int |); M.read (| msb |) ] + |) + ] + |); + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.read (| msb_reduced |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: u32) -> Option { + (int < Self::ORDER_U32).then(|| Self::new(int)) + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.function [ Ty.tuple [] ] (Ty.path "p3_mersenne_31::mersenne_31::Mersenne31") + ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| int |); + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.path "p3_mersenne_31::mersenne_31::Mersenne31") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.read (| int |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: u32) -> Self { + debug_assert!(int < Self::ORDER_U32); + Self::new(int) + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| int |); + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: int < Self::ORDER_U32" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.read (| int |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u32" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. + End Impl_p3_field_integers_QuotientMap_u32_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_integers_QuotientMap_i32_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn from_int(int: i32) -> Self { + if int >= 0 { + Self::new(int as u32) + } else if int > (-1 << 31) { + Self::new(Self::ORDER_U32.wrapping_add_signed(int)) + } else { + // The only other option is int = -(2^31) = -1 mod p. + Self::NEG_ONE + } + } + *) + Definition from_int (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| int |); Value.Integer IntegerKind.I32 0 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.cast (Ty.path "u32") (M.read (| int |)) ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.read (| int |); + M.call_closure (| + Ty.path "i32", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.I32 (-1); + Value.Integer IntegerKind.I32 31 + ] + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.path "u32", + "wrapping_add_signed", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + M.read (| int |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (get_constant (| + "p3_field::field::PrimeCharacteristicRing::NEG_ONE", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: i32) -> Option { + const TWO_EXP_30: i32 = 1 << 30; + const NEG_TWO_EXP_30_PLUS_1: i32 = (-1 << 30) + 1; + match int { + 0..TWO_EXP_30 => Some(Self::new(int as u32)), + NEG_TWO_EXP_30_PLUS_1..0 => Some(Self::new(Self::ORDER_U32.wrapping_add_signed(int))), + _ => None, + } + } + *) + Definition from_canonical_checked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + int, + [ + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.cast (Ty.path "u32") (M.read (| int |)) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.path "u32", + "wrapping_add_signed", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + M.read (| int |) + ] + |) + ] + |) + ] + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: i32) -> Self { + if int >= 0 { + Self::new(int as u32) + } else { + Self::new(Self::ORDER_U32.wrapping_add_signed(int)) + } + } + *) + Definition from_canonical_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| int |); Value.Integer IntegerKind.I32 0 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.cast (Ty.path "u32") (M.read (| int |)) ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.path "u32", + "wrapping_add_signed", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |); + M.read (| int |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i32" ] + Self + (* Instance *) + [ + ("from_int", InstanceField.Method from_int); + ("from_canonical_checked", InstanceField.Method from_canonical_checked); + ("from_canonical_unchecked", InstanceField.Method from_canonical_unchecked) + ]. + End Impl_p3_field_integers_QuotientMap_i32_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_field_PrimeField_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn as_canonical_biguint(&self) -> BigUint { + ::as_canonical_u32(self).into() + } + *) + Definition as_canonical_biguint (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "core::convert::Into", + Ty.path "u32", + [], + [ Ty.path "num_bigint::biguint::BigUint" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PrimeField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("as_canonical_biguint", InstanceField.Method as_canonical_biguint) ]. + End Impl_p3_field_field_PrimeField_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_field_PrimeField32_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const ORDER_U32: u32 = P; *) + (* Ty.path "u32" *) + Definition value_ORDER_U32 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (get_constant (| "p3_mersenne_31::mersenne_31::P", Ty.path "u32" |))). + + (* + fn as_canonical_u32(&self) -> u32 { + // Since our invariant guarantees that `value` fits in 31 bits, there is only one possible + // `value` that is not canonical, namely 2^31 - 1 = p = 0. + if self.value == Self::ORDER_U32 { + 0 + } else { + self.value + } + } + *) + Definition as_canonical_u32 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |); + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.Integer IntegerKind.U32 0 |))); + fun γ => + ltac:(M.monadic + (M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PrimeField32" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_ORDER_U32", InstanceField.Method value_ORDER_U32); + ("as_canonical_u32", InstanceField.Method as_canonical_u32) + ]. + End Impl_p3_field_field_PrimeField32_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_p3_field_field_PrimeField64_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* const ORDER_U64: u64 = ::ORDER_U32 as u64; *) + (* Ty.path "u64" *) + Definition value_ORDER_U64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.cast + (Ty.path "u64") + (M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |)) + |))). + + (* + fn as_canonical_u64(&self) -> u64 { + self.as_canonical_u32().into() + } + *) + Definition as_canonical_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::convert::Into", + Ty.path "u32", + [], + [ Ty.path "u64" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_field::field::PrimeField64" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("value_ORDER_U64", InstanceField.Method value_ORDER_U64); + ("as_canonical_u64", InstanceField.Method as_canonical_u64) + ]. + End Impl_p3_field_field_PrimeField64_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_ops_arith_Add_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn add(self, rhs: Self) -> Self { + // See the following for a way to compute the sum that avoids + // the conditional which may be preferable on some + // architectures. + // https://github.com/Plonky3/Plonky3/blob/6049a30c3b1f5351c3eb0f7c994dc97e8f68d10d/mersenne-31/src/lib.rs#L249 + + // Working with i32 means we get a flag which informs us if overflow happened. + let (sum_i32, over) = (self.value as i32).overflowing_add(rhs.value as i32); + let sum_u32 = sum_i32 as u32; + let sum_corr = sum_u32.wrapping_sub(Self::ORDER_U32); + + // If self + rhs did not overflow, return it. + // If self + rhs overflowed, sum_corr = self + rhs - (2**31 - 1). + Self::new(if over { sum_corr } else { sum_u32 }) + } + *) + Definition add (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "i32"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "i32", "overflowing_add", [], [] |), + [ + M.cast + (Ty.path "i32") + (M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)); + M.cast + (Ty.path "i32") + (M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let sum_i32 := M.copy (| γ0_0 |) in + let over := M.copy (| γ0_1 |) in + let~ sum_u32 : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| M.cast (Ty.path "u32") (M.read (| sum_i32 |)) |) in + let~ sum_corr : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "wrapping_sub", [], [] |), + [ + M.read (| sum_u32 |); + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use over in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + sum_corr)); + fun γ => ltac:(M.monadic sum_u32) + ] + |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("add", InstanceField.Method add) ]. + End Impl_core_ops_arith_Add_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_ops_arith_AddAssign_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } + *) + Definition add_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("add_assign", InstanceField.Method add_assign) ]. + End Impl_core_ops_arith_AddAssign_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_iter_traits_accum_Sum_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn sum>(iter: I) -> Self { + // This is faster than iter.reduce(|x, y| x + y).unwrap_or(Self::ZERO) for iterators of length >= 6. + // It assumes that iter.len() < 2^31. + + // This sum will not overflow so long as iter.len() < 2^33. + let sum = iter.map(|x| x.value as u64).sum::(); + + // sum is < 2^62 provided iter.len() < 2^31. + from_u62(sum) + } + *) + Definition sum (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.read (| + let~ sum : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + I; + Ty.function + [ Ty.tuple [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] ] + (Ty.path "u64") + ], + [], + [], + "sum", + [], + [ Ty.path "u64" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + I; + Ty.function + [ Ty.tuple [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] ] + (Ty.path "u64") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "map", + [], + [ + Ty.path "u64"; + Ty.function + [ Ty.tuple [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] ] + (Ty.path "u64") + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + x, + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_function (| "p3_mersenne_31::mersenne_31::from_u62", [], [] |), + [ M.read (| sum |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::accum::Sum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("sum", InstanceField.Method sum) ]. + End Impl_core_iter_traits_accum_Sum_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_ops_arith_Sub_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn sub(self, rhs: Self) -> Self { + let (mut sub, over) = self.value.overflowing_sub(rhs.value); + + // If we didn't overflow we have the correct value. + // Otherwise we have added 2**32 = 2**31 + 1 mod 2**31 - 1. + // Hence we need to remove the most significant bit and subtract 1. + sub -= over as u32; + Self::new(sub & Self::ORDER_U32) + } + *) + Definition sub (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u32"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "u32", "overflowing_sub", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let sub := M.copy (| γ0_0 |) in + let over := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := sub in + M.write (| + β, + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ M.read (| β |); M.cast (Ty.path "u32") (M.read (| over |)) ] + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ + M.read (| sub |); + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("sub", InstanceField.Method sub) ]. + End Impl_core_ops_arith_Sub_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_ops_arith_SubAssign_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } + *) + Definition sub_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "sub", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("sub_assign", InstanceField.Method sub_assign) ]. + End Impl_core_ops_arith_SubAssign_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_ops_arith_Neg_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn neg(self) -> Self::Output { + // Can't underflow, since self.value is 31-bits and thus can't exceed ORDER. + Self::new(Self::ORDER_U32 - self.value) + } + *) + Definition neg (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField32::ORDER_U32", Ty.path "u32" |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("neg", InstanceField.Method neg) ]. + End Impl_core_ops_arith_Neg_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_ops_arith_Mul_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn mul(self, rhs: Self) -> Self { + let prod = u64::from(self.value) * u64::from(rhs.value); + from_u62(prod) + } + *) + Definition mul (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ prod : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::convert::From", + Ty.path "u64", + [], + [ Ty.path "u32" ], + "from", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |) + ] + |); + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::convert::From", + Ty.path "u64", + [], + [ Ty.path "u32" ], + "from", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_function (| "p3_mersenne_31::mersenne_31::from_u62", [], [] |), + [ M.read (| prod |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("mul", InstanceField.Method mul) ]. + End Impl_core_ops_arith_Mul_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_ops_arith_MulAssign_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } + *) + Definition mul_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "mul", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("mul_assign", InstanceField.Method mul_assign) ]. + End Impl_core_ops_arith_MulAssign_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_iter_traits_accum_Product_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn product>(iter: I) -> Self { + iter.reduce(|x, y| x * y).unwrap_or(Self::ONE) + } + *) + Definition product (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + (Ty.path "p3_mersenne_31::mersenne_31::Mersenne31") + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + (Ty.path "p3_mersenne_31::mersenne_31::Mersenne31") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + (Ty.path "p3_mersenne_31::mersenne_31::Mersenne31") + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := M.copy (| γ |) in + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::accum::Product" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("product", InstanceField.Method product) ]. + End Impl_core_iter_traits_accum_Product_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + Module Impl_core_ops_arith_Div_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "p3_mersenne_31::mersenne_31::Mersenne31". + + (* + fn div(self, rhs: Self) -> Self { + self * rhs.inverse() + } + *) + Definition div (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "mul", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::Field", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Div" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("Output", InstanceField.Ty _Output); ("div", InstanceField.Method div) ]. + End Impl_core_ops_arith_Div_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_mersenne_31_Mersenne31. + + (* + pub(crate) fn from_u62(input: u64) -> Mersenne31 { + debug_assert!(input < (1 << 62)); + let input_lo = (input & ((1 << 31) - 1)) as u32; + let input_high = (input >> 31) as u32; + Mersenne31::new(input_lo) + Mersenne31::new(input_high) + } + *) + Definition from_u62 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| input |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.U64 1; + Value.Integer IntegerKind.I32 62 + ] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: input < (1 << 62)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ input_lo : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_and, + [ + M.read (| input |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U64 1; Value.Integer IntegerKind.I32 31 ] + |); + Value.Integer IntegerKind.U64 1 + ] + |) + ] + |)) + |) in + let~ input_high : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shr, + [ M.read (| input |); Value.Integer IntegerKind.I32 31 ] + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.read (| input_lo |) ] + |); + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + "new", + [], + [] + |), + [ M.read (| input_high |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_from_u62 : + M.IsFunction.C "p3_mersenne_31::mersenne_31::from_u62" from_u62. + Admitted. + Global Typeclasses Opaque from_u62. +End mersenne_31. diff --git a/CoqOfRust/plonky3/mersenne-31/src/no_packing/mod.rs b/CoqOfRust/plonky3/mersenne-31/src/no_packing/mod.rs new file mode 100644 index 000000000..e056e09f2 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/no_packing/mod.rs @@ -0,0 +1,5 @@ +//! A couple of simple functions needed in the case that this is compiled without architecture optimizations available. + +mod poseidon2; + +pub use poseidon2::*; diff --git a/CoqOfRust/plonky3/mersenne-31/src/no_packing/poseidon2.rs b/CoqOfRust/plonky3/mersenne-31/src/no_packing/poseidon2.rs new file mode 100644 index 000000000..0bb6b7742 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/no_packing/poseidon2.rs @@ -0,0 +1,35 @@ +//! This file contains simple wrapper structs on top of which we can implement Poseidon2 Internal/ExternalLayer. +//! +//! They are used only in the case that none of the vectorization architectures (AVX2/AVX512/NEON) are available. + +use alloc::vec::Vec; + +use p3_poseidon2::{ExternalLayerConstants, ExternalLayerConstructor, InternalLayerConstructor}; + +use crate::Mersenne31; + +/// The internal layers of the Poseidon2 permutation. +#[derive(Debug, Clone)] +pub struct Poseidon2InternalLayerMersenne31 { + pub(crate) internal_constants: Vec, +} + +/// The external layers of the Poseidon2 permutation. +#[derive(Clone)] +pub struct Poseidon2ExternalLayerMersenne31 { + pub(crate) external_constants: ExternalLayerConstants, +} + +impl InternalLayerConstructor for Poseidon2InternalLayerMersenne31 { + fn new_from_constants(internal_constants: Vec) -> Self { + Self { internal_constants } + } +} + +impl ExternalLayerConstructor + for Poseidon2ExternalLayerMersenne31 +{ + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + Self { external_constants } + } +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/no_packing/poseidon2.v b/CoqOfRust/plonky3/mersenne-31/src/no_packing/poseidon2.v new file mode 100644 index 000000000..a2bd6be43 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/no_packing/poseidon2.v @@ -0,0 +1,305 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module no_packing. + Module poseidon2. + (* StructRecord + { + name := "Poseidon2InternalLayerMersenne31"; + const_params := []; + ty_params := []; + fields := + [ + ("internal_constants", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; Ty.path "alloc::alloc::Global" + ]) + ]; + } *) + + Module Impl_core_fmt_Debug_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2InternalLayerMersenne31. + Definition Self : Ty.t := + Ty.path "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Poseidon2InternalLayerMersenne31" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "internal_constants" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31", + "internal_constants" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2InternalLayerMersenne31. + + Module Impl_core_clone_Clone_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2InternalLayerMersenne31. + Definition Self : Ty.t := + Ty.path "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31" + [ + ("internal_constants", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31", + "internal_constants" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2InternalLayerMersenne31. + + (* StructRecord + { + name := "Poseidon2ExternalLayerMersenne31"; + const_params := [ "WIDTH" ]; + ty_params := []; + fields := + [ + ("external_constants", + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]) + ]; + } *) + + Module Impl_core_clone_Clone_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2ExternalLayerMersenne31_WIDTH. + Definition Self (WIDTH : Value.t) : Ty.t := + Ty.apply + (Ty.path "p3_mersenne_31::no_packing::poseidon2::Poseidon2ExternalLayerMersenne31") + [ WIDTH ] + []. + + (* Clone *) + Definition clone + (WIDTH : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_mersenne_31::no_packing::poseidon2::Poseidon2ExternalLayerMersenne31" + [ + ("external_constants", + M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::no_packing::poseidon2::Poseidon2ExternalLayerMersenne31", + "external_constants" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH)) ]. + End Impl_core_clone_Clone_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2ExternalLayerMersenne31_WIDTH. + + Module Impl_p3_poseidon2_internal_InternalLayerConstructor_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2InternalLayerMersenne31. + Definition Self : Ty.t := + Ty.path "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31". + + (* + fn new_from_constants(internal_constants: Vec) -> Self { + Self { internal_constants } + } + *) + Definition new_from_constants (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ internal_constants ] => + ltac:(M.monadic + (let internal_constants := M.alloc (| internal_constants |) in + Value.StructRecord + "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31" + [ ("internal_constants", M.read (| internal_constants |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayerConstructor" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("new_from_constants", InstanceField.Method new_from_constants) ]. + End Impl_p3_poseidon2_internal_InternalLayerConstructor_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2InternalLayerMersenne31. + + Module Impl_p3_poseidon2_external_ExternalLayerConstructor_WIDTH_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2ExternalLayerMersenne31_WIDTH. + Definition Self (WIDTH : Value.t) : Ty.t := + Ty.apply + (Ty.path "p3_mersenne_31::no_packing::poseidon2::Poseidon2ExternalLayerMersenne31") + [ WIDTH ] + []. + + (* + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + Self { external_constants } + } + *) + Definition new_from_constants + (WIDTH : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ external_constants ] => + ltac:(M.monadic + (let external_constants := M.alloc (| external_constants |) in + Value.StructRecord + "p3_mersenne_31::no_packing::poseidon2::Poseidon2ExternalLayerMersenne31" + [ ("external_constants", M.read (| external_constants |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t), + M.IsTraitInstance + "p3_poseidon2::external::ExternalLayerConstructor" + (* Trait polymorphic consts *) [ WIDTH ] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + (Self WIDTH) + (* Instance *) + [ ("new_from_constants", InstanceField.Method (new_from_constants WIDTH)) ]. + End Impl_p3_poseidon2_external_ExternalLayerConstructor_WIDTH_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2ExternalLayerMersenne31_WIDTH. + End poseidon2. +End no_packing. diff --git a/CoqOfRust/plonky3/mersenne-31/src/poseidon2.rs b/CoqOfRust/plonky3/mersenne-31/src/poseidon2.rs new file mode 100644 index 000000000..6eb5378b1 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/poseidon2.rs @@ -0,0 +1,235 @@ +//! Implementation of Poseidon2, see: `` +//! +//! For the diffusion matrix, 1 + Diag(V), we perform a search to find an optimized +//! vector V composed of elements with efficient multiplication algorithms in AVX2/AVX512/NEON. +//! +//! This leads to using small values (e.g. 1, 2) where multiplication is implemented using addition +//! and powers of 2 where multiplication is implemented using shifts. +//! Additionally, for technical reasons, having the first entry be -2 is useful. +//! +//! Optimized Diagonal for Mersenne31 width 16: +//! [-2, 2^0, 2, 4, 8, 16, 32, 64, 2^7, 2^8, 2^10, 2^12, 2^13, 2^14, 2^15, 2^16] +//! Optimized Diagonal for Mersenne31 width 24: +//! [-2, 2^0, 2, 4, 8, 16, 32, 64, 2^7, 2^8, 2^9, 2^10, 2^11, 2^12, 2^13, 2^14, 2^15, 2^16, 2^17, 2^18, 2^19, 2^20, 2^21, 2^22] +//! See poseidon2\src\diffusion.rs for information on how to double check these matrices in Sage. + +use p3_field::Algebra; +use p3_poseidon2::{ + ExternalLayer, GenericPoseidon2LinearLayers, InternalLayer, MDSMat4, Poseidon2, + add_rc_and_sbox_generic, external_initial_permute_state, external_terminal_permute_state, + internal_permute_state, +}; + +use crate::{ + Mersenne31, Poseidon2ExternalLayerMersenne31, Poseidon2InternalLayerMersenne31, from_u62, +}; + +/// Degree of the chosen permutation polynomial for Mersenne31, used as the Poseidon2 S-Box. +/// +/// As p - 1 = 2×3^2×7×11×... the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 5. +/// Currently pub(crate) as it is used in the default neon implementation. Once that is optimized +/// this should no longer be public. +pub(crate) const MERSENNE31_S_BOX_DEGREE: u64 = 5; + +/// An implementation of the Poseidon2 hash function specialised to run on the current architecture. +/// +/// It acts on arrays of the form either `[Mersenne31::Packing; WIDTH]` or `[Mersenne31; WIDTH]`. For speed purposes, +/// wherever possible, input arrays should of the form `[Mersenne31::Packing; WIDTH]`. +pub type Poseidon2Mersenne31 = Poseidon2< + Mersenne31, + Poseidon2ExternalLayerMersenne31, + Poseidon2InternalLayerMersenne31, + WIDTH, + MERSENNE31_S_BOX_DEGREE, +>; + +/// An implementation of the matrix multiplications in the internal and external layers of Poseidon2. +/// +/// This can act on `[A; WIDTH]` for any ring implementing `Algebra`. +/// If you have either `[Mersenne31::Packing; WIDTH]` or `[Mersenne31; WIDTH]` it will be much faster +/// to use `Poseidon2Mersenne31` instead of building a Poseidon2 permutation using this. +pub struct GenericPoseidon2LinearLayersMersenne31 {} + +const POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS: [u8; 15] = + [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 13, 14, 15, 16]; + +const POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS: [u8; 23] = [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, +]; + +/// Multiply state by the matrix (1 + Diag(V)) +/// +/// Here V is the vector [-2] + 1 << shifts. This used delayed reduction to be slightly faster. +fn permute_mut(state: &mut [Mersenne31; N], shifts: &[u8]) { + debug_assert_eq!(shifts.len() + 1, N); + let part_sum: u64 = state[1..].iter().map(|x| x.value as u64).sum(); + let full_sum = part_sum + (state[0].value as u64); + let s0 = part_sum + (-state[0]).value as u64; + state[0] = from_u62(s0); + for i in 1..N { + let si = full_sum + ((state[i].value as u64) << shifts[i - 1]); + state[i] = from_u62(si); + } +} + +impl InternalLayer for Poseidon2InternalLayerMersenne31 { + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [Mersenne31; 16]) { + internal_permute_state( + state, + |x| permute_mut(x, &POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS), + &self.internal_constants, + ) + } +} + +impl InternalLayer for Poseidon2InternalLayerMersenne31 { + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [Mersenne31; 24]) { + internal_permute_state( + state, + |x| permute_mut(x, &POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS), + &self.internal_constants, + ) + } +} + +impl ExternalLayer + for Poseidon2ExternalLayerMersenne31 +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [Mersenne31; WIDTH]) { + external_initial_permute_state( + state, + self.external_constants.get_initial_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [Mersenne31; WIDTH]) { + external_terminal_permute_state( + state, + self.external_constants.get_terminal_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } +} + +impl> GenericPoseidon2LinearLayers + for GenericPoseidon2LinearLayersMersenne31 +{ + fn internal_linear_layer(state: &mut [A; 16]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use the mul_2exp_u64 method. + // We need state[1..] as POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS + // doesn't include the shift for the 0'th element as it is -2. + state[1..] + .iter_mut() + .zip(POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS) + .skip(2) + .for_each(|(val, diag_shift)| { + *val = full_sum.clone() + val.clone().mul_2exp_u64(diag_shift as u64); + }); + } +} + +impl> GenericPoseidon2LinearLayers + for GenericPoseidon2LinearLayersMersenne31 +{ + fn internal_linear_layer(state: &mut [A; 24]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use the mul_2exp_u64 method. + // We need state[1..] as POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS + // doesn't include the shift for the 0'th element as it is -2. + state[1..] + .iter_mut() + .zip(POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS) + .skip(2) + .for_each(|(val, diag_shift)| { + *val = full_sum.clone() + val.clone().mul_2exp_u64(diag_shift as u64); + }); + } +} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::SeedableRng; + use rand_xoshiro::Xoroshiro128Plus; + + use super::*; + + type F = Mersenne31; + + // We need to make some round constants. We use Xoroshiro128Plus for this as we can easily match this PRNG in sage. + // See: https://github.com/0xPolygonZero/hash-constants for the sage code used to create all these tests. + + /// Test on a roughly random input. + /// This random input is generated by the following sage code: + /// set_random_seed(16) + /// vector([M31.random_element() for t in range(16)]). + #[test] + fn test_poseidon2_width_16_random() { + let mut input: [F; 16] = Mersenne31::new_array([ + 894848333, 1437655012, 1200606629, 1690012884, 71131202, 1749206695, 1717947831, + 120589055, 19776022, 42382981, 1831865506, 724844064, 171220207, 1299207443, 227047920, + 1783754913, + ]); + + let expected: [F; 16] = Mersenne31::new_array([ + 1124552602, 2127602268, 1834113265, 1207687593, 1891161485, 245915620, 981277919, + 627265710, 1534924153, 1580826924, 887997842, 1526280482, 547791593, 1028672510, + 1803086471, 323071277, + ]); + + let mut rng = Xoroshiro128Plus::seed_from_u64(1); + let perm = Poseidon2Mersenne31::new_from_rng_128(&mut rng); + + perm.permute_mut(&mut input); + assert_eq!(input, expected); + } + + /// Test on a roughly random input. + /// This random input is generated by the following sage code: + /// set_random_seed(24) + /// vector([M31.random_element() for t in range(24)]). + #[test] + fn test_poseidon2_width_24_random() { + let mut input: [F; 24] = Mersenne31::new_array([ + 886409618, 1327899896, 1902407911, 591953491, 648428576, 1844789031, 1198336108, + 355597330, 1799586834, 59617783, 790334801, 1968791836, 559272107, 31054313, + 1042221543, 474748436, 135686258, 263665994, 1962340735, 1741539604, 2026927696, + 449439011, 1131357108, 50869465, + ]); + + let expected: [F; 24] = Mersenne31::new_array([ + 87189408, 212775836, 954807335, 1424761838, 1222521810, 1264950009, 1891204592, + 710452896, 957091834, 1776630156, 1091081383, 786687731, 1101902149, 1281649821, + 436070674, 313565599, 1961711763, 2002894460, 2040173120, 854107426, 25198245, + 1967213543, 604802266, 2086190331, + ]); + + let mut rng = Xoroshiro128Plus::seed_from_u64(1); + let perm = Poseidon2Mersenne31::new_from_rng_128(&mut rng); + + perm.permute_mut(&mut input); + assert_eq!(input, expected); + } +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/poseidon2.v b/CoqOfRust/plonky3/mersenne-31/src/poseidon2.v new file mode 100644 index 000000000..6695f0b0a --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/poseidon2.v @@ -0,0 +1,2393 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module poseidon2. + Definition value_MERSENNE31_S_BOX_DEGREE + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U64 5 |))). + + Global Instance Instance_IsConstant_value_MERSENNE31_S_BOX_DEGREE : + M.IsFunction.C + "p3_mersenne_31::poseidon2::MERSENNE31_S_BOX_DEGREE" + value_MERSENNE31_S_BOX_DEGREE. + Admitted. + Global Typeclasses Opaque value_MERSENNE31_S_BOX_DEGREE. + + Axiom Poseidon2Mersenne31 : + forall (WIDTH : Value.t), + (Ty.apply (Ty.path "p3_mersenne_31::poseidon2::Poseidon2Mersenne31") [ WIDTH ] []) = + (Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ + WIDTH; + M.unevaluated_const + (mk_str (| "p3_mersenne_31_poseidon2_Poseidon2Mersenne31_discriminant" |)) + ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.apply + (Ty.path "p3_mersenne_31::no_packing::poseidon2::Poseidon2ExternalLayerMersenne31") + [ WIDTH ] + []; + Ty.path "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31" + ]). + + (* StructTuple + { + name := "GenericPoseidon2LinearLayersMersenne31"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Definition value_POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 2; + Value.Integer IntegerKind.U8 3; + Value.Integer IntegerKind.U8 4; + Value.Integer IntegerKind.U8 5; + Value.Integer IntegerKind.U8 6; + Value.Integer IntegerKind.U8 7; + Value.Integer IntegerKind.U8 8; + Value.Integer IntegerKind.U8 10; + Value.Integer IntegerKind.U8 12; + Value.Integer IntegerKind.U8 13; + Value.Integer IntegerKind.U8 14; + Value.Integer IntegerKind.U8 15; + Value.Integer IntegerKind.U8 16 + ] + |))). + + Global Instance Instance_IsConstant_value_POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS : + M.IsFunction.C + "p3_mersenne_31::poseidon2::POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS" + value_POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS. + Admitted. + Global Typeclasses Opaque value_POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS. + + Definition value_POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 2; + Value.Integer IntegerKind.U8 3; + Value.Integer IntegerKind.U8 4; + Value.Integer IntegerKind.U8 5; + Value.Integer IntegerKind.U8 6; + Value.Integer IntegerKind.U8 7; + Value.Integer IntegerKind.U8 8; + Value.Integer IntegerKind.U8 9; + Value.Integer IntegerKind.U8 10; + Value.Integer IntegerKind.U8 11; + Value.Integer IntegerKind.U8 12; + Value.Integer IntegerKind.U8 13; + Value.Integer IntegerKind.U8 14; + Value.Integer IntegerKind.U8 15; + Value.Integer IntegerKind.U8 16; + Value.Integer IntegerKind.U8 17; + Value.Integer IntegerKind.U8 18; + Value.Integer IntegerKind.U8 19; + Value.Integer IntegerKind.U8 20; + Value.Integer IntegerKind.U8 21; + Value.Integer IntegerKind.U8 22 + ] + |))). + + Global Instance Instance_IsConstant_value_POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS : + M.IsFunction.C + "p3_mersenne_31::poseidon2::POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS" + value_POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS. + Admitted. + Global Typeclasses Opaque value_POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS. + + (* + fn permute_mut(state: &mut [Mersenne31; N], shifts: &[u8]) { + debug_assert_eq!(shifts.len() + 1, N); + let part_sum: u64 = state[1..].iter().map(|x| x.value as u64).sum(); + let full_sum = part_sum + (state[0].value as u64); + let s0 = part_sum + (-state[0]).value as u64; + state[0] = from_u62(s0); + for i in 1..N { + let si = full_sum + ((state[i].value as u64) << shifts[i - 1]); + state[i] = from_u62(si); + } + } + *) + Definition permute_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [ state; shifts ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let shifts := M.alloc (| shifts |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shifts |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ part_sum : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + (Ty.path "u64") + ], + [], + [], + "sum", + [], + [ Ty.path "u64" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + (Ty.path "u64") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + [], + [], + "map", + [], + [ + Ty.path "u64"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + (Ty.path "u64") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| state |) |) |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| x |) |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ full_sum : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ + M.read (| part_sum |); + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)) + ] + |) + |) in + let~ s0 : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ + M.read (| part_sum |); + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "core::ops::arith::Neg", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "neg", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_function (| "p3_mersenne_31::mersenne_31::from_u62", [], [] |), + [ M.read (| s0 |) ] + |) + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 1); ("end_", N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ si : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ + M.read (| full_sum |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + M.read (| i |) + |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| shifts |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + M.read (| i |) + |), + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_function (| + "p3_mersenne_31::mersenne_31::from_u62", + [], + [] + |), + [ M.read (| si |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_permute_mut : + M.IsFunction.C "p3_mersenne_31::poseidon2::permute_mut" permute_mut. + Admitted. + Global Typeclasses Opaque permute_mut. + + Module Impl_p3_poseidon2_internal_InternalLayer_Usize_16_expr_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2InternalLayerMersenne31. + Definition Self : Ty.t := + Ty.path "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31". + + (* + fn permute_state(&self, state: &mut [Mersenne31; 16]) { + internal_permute_state( + state, + |x| permute_mut(x, &POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS), + &self.internal_constants, + ) + } + *) + Definition permute_state (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::internal_permute_state", + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.U64 5 ], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + (* ClosureFnPointer(Safe) *) + M.pointer_coercion + (M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mersenne_31::poseidon2::permute_mut", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_mersenne_31::poseidon2::POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ Ty.path "u8" ] + |) + |) + |) + |)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end))); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31", + "internal_constants" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayer" + (* Trait polymorphic consts *) + [ + Value.Integer IntegerKind.Usize 16; + M.unevaluated_const (mk_str (| "p3_mersenne_31_poseidon2_discriminant" |)) + ] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("permute_state", InstanceField.Method permute_state) ]. + End Impl_p3_poseidon2_internal_InternalLayer_Usize_16_expr_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2InternalLayerMersenne31. + + Module Impl_p3_poseidon2_internal_InternalLayer_Usize_24_expr_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2InternalLayerMersenne31. + Definition Self : Ty.t := + Ty.path "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31". + + (* + fn permute_state(&self, state: &mut [Mersenne31; 24]) { + internal_permute_state( + state, + |x| permute_mut(x, &POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS), + &self.internal_constants, + ) + } + *) + Definition permute_state (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::internal::internal_permute_state", + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.U64 5 ], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + (* ClosureFnPointer(Safe) *) + M.pointer_coercion + (M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mersenne_31::poseidon2::permute_mut", + [ Value.Integer IntegerKind.Usize 24 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_mersenne_31::poseidon2::POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 23 ] + [ Ty.path "u8" ] + |) + |) + |) + |)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end))); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::no_packing::poseidon2::Poseidon2InternalLayerMersenne31", + "internal_constants" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayer" + (* Trait polymorphic consts *) + [ + Value.Integer IntegerKind.Usize 24; + M.unevaluated_const (mk_str (| "p3_mersenne_31_poseidon2_discriminant" |)) + ] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + Self + (* Instance *) [ ("permute_state", InstanceField.Method permute_state) ]. + End Impl_p3_poseidon2_internal_InternalLayer_Usize_24_expr_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2InternalLayerMersenne31. + + Module Impl_p3_poseidon2_external_ExternalLayer_WIDTH_expr_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2ExternalLayerMersenne31_WIDTH. + Definition Self (WIDTH : Value.t) : Ty.t := + Ty.apply + (Ty.path "p3_mersenne_31::no_packing::poseidon2::Poseidon2ExternalLayerMersenne31") + [ WIDTH ] + []. + + (* + fn permute_state_initial(&self, state: &mut [Mersenne31; WIDTH]) { + external_initial_permute_state( + state, + self.external_constants.get_initial_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + *) + Definition permute_state_initial + (WIDTH : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_initial_permute_state", + [ WIDTH ], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_poseidon2::external::MDSMat4" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "get_initial_constants", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::no_packing::poseidon2::Poseidon2ExternalLayerMersenne31", + "external_constants" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ Value.Integer IntegerKind.U64 5 ], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::MDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_state_terminal(&self, state: &mut [Mersenne31; WIDTH]) { + external_terminal_permute_state( + state, + self.external_constants.get_terminal_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + *) + Definition permute_state_terminal + (WIDTH : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_terminal_permute_state", + [ WIDTH ], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_poseidon2::external::MDSMat4" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "get_terminal_constants", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_mersenne_31::no_packing::poseidon2::Poseidon2ExternalLayerMersenne31", + "external_constants" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ Value.Integer IntegerKind.U64 5 ], + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::MDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t), + M.IsTraitInstance + "p3_poseidon2::external::ExternalLayer" + (* Trait polymorphic consts *) + [ WIDTH; M.unevaluated_const (mk_str (| "p3_mersenne_31_poseidon2_discriminant" |)) ] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + (Self WIDTH) + (* Instance *) + [ + ("permute_state_initial", InstanceField.Method (permute_state_initial WIDTH)); + ("permute_state_terminal", InstanceField.Method (permute_state_terminal WIDTH)) + ]. + End Impl_p3_poseidon2_external_ExternalLayer_WIDTH_expr_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_no_packing_poseidon2_Poseidon2ExternalLayerMersenne31_WIDTH. + + Module Impl_p3_poseidon2_generic_GenericPoseidon2LinearLayers_where_p3_field_field_Algebra_A_p3_mersenne_31_mersenne_31_Mersenne31_Usize_16_A_for_p3_mersenne_31_poseidon2_GenericPoseidon2LinearLayersMersenne31. + Definition Self (A : Ty.t) : Ty.t := + Ty.path "p3_mersenne_31::poseidon2::GenericPoseidon2LinearLayersMersenne31". + + (* + fn internal_linear_layer(state: &mut [A; 16]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use the mul_2exp_u64 method. + // We need state[1..] as POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS + // doesn't include the shift for the 0'th element as it is -2. + state[1..] + .iter_mut() + .zip(POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS) + .skip(2) + .for_each(|(val, diag_shift)| { + *val = full_sum.clone() + val.clone().mul_2exp_u64(diag_shift as u64); + }); + } + *) + Definition internal_linear_layer + (A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self A in + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ part_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + [], + [], + "sum", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + [], + [], + "cloned", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ A ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ A ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| state |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ full_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, part_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Sub", A, [], [ A ], "sub", [], [] |), + [ + M.read (| part_sum |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 15 ] + [ Ty.path "u8" ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ A ]; Ty.path "u8" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 15 ] + [ Ty.path "u8" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 15 ] + [ Ty.path "u8" ] + ], + [], + [], + "skip", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 15 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ Ty.path "u8" ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ A ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ A ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_mersenne_31::poseidon2::POSEIDON2_INTERNAL_MATRIX_DIAG_16_SHIFTS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 15 ] + [ Ty.path "u8" ] + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.apply (Ty.path "&mut") [] [ A ]; Ty.path "u8" ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let val := M.copy (| γ0_0 |) in + let diag_shift := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| val |) |), + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Add", + A, + [], + [ A ], + "add", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "mul_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| val |) |) + |) + ] + |) + |) + |); + M.cast + (Ty.path "u64") + (M.read (| diag_shift |)) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (A : Ty.t), + M.IsTraitInstance + "p3_poseidon2::generic::GenericPoseidon2LinearLayers" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 16 ] + (* Trait polymorphic types *) [ A ] + (Self A) + (* Instance *) + [ ("internal_linear_layer", InstanceField.Method (internal_linear_layer A)) ]. + End Impl_p3_poseidon2_generic_GenericPoseidon2LinearLayers_where_p3_field_field_Algebra_A_p3_mersenne_31_mersenne_31_Mersenne31_Usize_16_A_for_p3_mersenne_31_poseidon2_GenericPoseidon2LinearLayersMersenne31. + + Module Impl_p3_poseidon2_generic_GenericPoseidon2LinearLayers_where_p3_field_field_Algebra_A_p3_mersenne_31_mersenne_31_Mersenne31_Usize_24_A_for_p3_mersenne_31_poseidon2_GenericPoseidon2LinearLayersMersenne31. + Definition Self (A : Ty.t) : Ty.t := + Ty.path "p3_mersenne_31::poseidon2::GenericPoseidon2LinearLayersMersenne31". + + (* + fn internal_linear_layer(state: &mut [A; 24]) { + let part_sum: A = state[1..].iter().cloned().sum(); + let full_sum = part_sum.clone() + state[0].clone(); + + // The first three diagonal elements are -2, 1, 2 so we do something custom. + state[0] = part_sum - state[0].clone(); + state[1] = full_sum.clone() + state[1].clone(); + state[2] = full_sum.clone() + state[2].double(); + + // For the remaining elements we use the mul_2exp_u64 method. + // We need state[1..] as POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS + // doesn't include the shift for the 0'th element as it is -2. + state[1..] + .iter_mut() + .zip(POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS) + .skip(2) + .for_each(|(val, diag_shift)| { + *val = full_sum.clone() + val.clone().mul_2exp_u64(diag_shift as u64); + }); + } + *) + Definition internal_linear_layer + (A : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self A in + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ part_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + [], + [], + "sum", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + [], + [], + "cloned", + [], + [ A ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ A ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ A ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| state |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ full_sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, part_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Sub", A, [], [ A ], "sub", [], [] |), + [ + M.read (| part_sum |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + A, + M.get_trait_method (| "core::ops::arith::Add", A, [], [ A ], "add", [], [] |), + [ + M.call_closure (| + A, + M.get_trait_method (| "core::clone::Clone", A, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 23 ] + [ Ty.path "u8" ] + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ A ]; Ty.path "u8" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 23 ] + [ Ty.path "u8" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 23 ] + [ Ty.path "u8" ] + ], + [], + [], + "skip", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 23 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 23 ] + [ Ty.path "u8" ] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ A ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ A ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |); + M.read (| + get_constant (| + "p3_mersenne_31::poseidon2::POSEIDON2_INTERNAL_MATRIX_DIAG_24_SHIFTS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 23 ] + [ Ty.path "u8" ] + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ Ty.apply (Ty.path "&mut") [] [ A ]; Ty.path "u8" ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let val := M.copy (| γ0_0 |) in + let diag_shift := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| val |) |), + M.call_closure (| + A, + M.get_trait_method (| + "core::ops::arith::Add", + A, + [], + [ A ], + "add", + [], + [] + |), + [ + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, full_sum |) ] + |); + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "mul_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| val |) |) + |) + ] + |) + |) + |); + M.cast + (Ty.path "u64") + (M.read (| diag_shift |)) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (A : Ty.t), + M.IsTraitInstance + "p3_poseidon2::generic::GenericPoseidon2LinearLayers" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 24 ] + (* Trait polymorphic types *) [ A ] + (Self A) + (* Instance *) + [ ("internal_linear_layer", InstanceField.Method (internal_linear_layer A)) ]. + End Impl_p3_poseidon2_generic_GenericPoseidon2LinearLayers_where_p3_field_field_Algebra_A_p3_mersenne_31_mersenne_31_Mersenne31_Usize_24_A_for_p3_mersenne_31_poseidon2_GenericPoseidon2LinearLayersMersenne31. +End poseidon2. diff --git a/CoqOfRust/plonky3/mersenne-31/src/radix_2_dit.rs b/CoqOfRust/plonky3/mersenne-31/src/radix_2_dit.rs new file mode 100644 index 000000000..4b36dea78 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/radix_2_dit.rs @@ -0,0 +1,157 @@ +use alloc::vec::Vec; + +use p3_dft::TwoAdicSubgroupDft; +use p3_field::extension::Complex; +use p3_field::{PrimeCharacteristicRing, PrimeField64, TwoAdicField}; +use p3_matrix::Matrix; +use p3_matrix::dense::{RowMajorMatrix, RowMajorMatrixViewMut}; +use p3_matrix::util::reverse_matrix_index_bits; +use p3_util::log2_strict_usize; + +use crate::Mersenne31; + +type F = Mersenne31; +type C = Complex; + +#[derive(Debug, Default, Clone)] +pub struct Mersenne31ComplexRadix2Dit; + +impl TwoAdicSubgroupDft for Mersenne31ComplexRadix2Dit { + type Evaluations = RowMajorMatrix; + fn dft_batch(&self, mut mat: RowMajorMatrix) -> RowMajorMatrix { + let h = mat.height(); + let log_h = log2_strict_usize(h); + + let root = C::two_adic_generator(log_h); + let twiddles: Vec = root.powers().take(h / 2).collect(); + + // DIT butterfly + reverse_matrix_index_bits(&mut mat); + for layer in 0..log_h { + dit_layer(&mut mat.as_view_mut(), layer, &twiddles); + } + mat + } +} + +// NB: Most of what follows is copypasta from `dft/src/radix_2_dit.rs`. +// This is ugly, but the alternative is finding another way to "inject" +// the specialisation of the butterfly evaluation to Mersenne31Complex +// (in `dit_butterfly_inner()` below) into the existing structure. + +/// One layer of a DIT butterfly network. +fn dit_layer(mat: &mut RowMajorMatrixViewMut<'_, C>, layer: usize, twiddles: &[C]) { + let h = mat.height(); + let log_h = log2_strict_usize(h); + let layer_rev = log_h - 1 - layer; + + let half_block_size = 1 << layer; + let block_size = half_block_size * 2; + + for j in (0..h).step_by(block_size) { + // Unroll i=0 case + let butterfly_hi = j; + let butterfly_lo = butterfly_hi + half_block_size; + twiddle_free_butterfly(mat, butterfly_hi, butterfly_lo); + + for i in 1..half_block_size { + let butterfly_hi = j + i; + let butterfly_lo = butterfly_hi + half_block_size; + let twiddle = twiddles[i << layer_rev]; + dit_butterfly(mat, butterfly_hi, butterfly_lo, twiddle); + } + } +} + +#[inline] +fn twiddle_free_butterfly(mat: &mut RowMajorMatrixViewMut<'_, C>, row_1: usize, row_2: usize) { + let ((shorts_1, suffix_1), (shorts_2, suffix_2)) = mat.packed_row_pair_mut(row_1, row_2); + + // TODO: There's no special packing for Mersenne31Complex at the + // time of writing; when there is we'll want to expand this out + // into three separate loops. + let row_1 = shorts_1.iter_mut().chain(suffix_1); + let row_2 = shorts_2.iter_mut().chain(suffix_2); + + for (x, y) in row_1.zip(row_2) { + let sum = *x + *y; + let diff = *x - *y; + *x = sum; + *y = diff; + } +} + +#[inline] +fn dit_butterfly(mat: &mut RowMajorMatrixViewMut<'_, C>, row_1: usize, row_2: usize, twiddle: C) { + let ((shorts_1, suffix_1), (shorts_2, suffix_2)) = mat.packed_row_pair_mut(row_1, row_2); + + // TODO: There's no special packing for Mersenne31Complex at the + // time of writing; when there is we'll want to expand this out + // into three separate loops. + let row_1 = shorts_1.iter_mut().chain(suffix_1); + let row_2 = shorts_2.iter_mut().chain(suffix_2); + + for (x, y) in row_1.zip(row_2) { + dit_butterfly_inner(x, y, twiddle); + } +} + +/// Given x, y, and twiddle, return the "butterfly values" +/// x' = x + y*twiddle and y' = x - y*twiddle. +/// +/// NB: At the time of writing, replacing the straight-forward +/// implementation +/// +/// let sum = *x + *y * twiddle; +/// let diff = *x - *y * twiddle; +/// *x = sum; +/// *y = diff; +/// +/// with the one below approximately halved the runtime of a DFT over +/// `Mersenne31Complex`. +#[inline] +fn dit_butterfly_inner(x: &mut C, y: &mut C, twiddle: C) { + // Adding any multiple of P doesn't change the result modulo P; + // we use this to ensure that the inputs to `from_u64` + // below are non-negative. + const P_SQR: i64 = (F::ORDER_U64 * F::ORDER_U64) as i64; + const TWO_P_SQR: i64 = 2 * P_SQR; + + // Unpack the inputs; + // x = x1 + i*x2 + // y = y1 + i*y2 + // twiddle = w1 + i*w2 + let unpack = |x: C| (x.to_array()[0].value as i64, x.to_array()[1].value as i64); + let (x1, x2) = unpack(*x); + let (y1, y2) = unpack(*y); + let (w1, w2) = unpack(twiddle); + + // x ± y*twiddle + // = (x1 + i*x2) ± (y1 + i*y2)*(w1 + i*w2) + // = (x1 ± (y1*w1 - y2*w2)) + i*(x2 ± (y2*w1 + y1*w2)) + // = (x1 ± z1) + i*(x2 ± z2) + // where z1 + i*z2 = y*twiddle + + // SAFE: multiplying `u64` values within the range of `Mersennes31` doesn't overflow: + // (2^31 - 1) * (2^31 - 1) = 2^62 - 2^32 + 1 < 2^64 - 1 + let z1 = y1 * w1 - y2 * w2; // -P^2 <= z1 <= P^2 + + // NB: 2*P^2 + P < 2^63 + + // -P^2 <= x1 + z1 <= P^2 + P + let a1 = F::from_u64((P_SQR + x1 + z1) as u64); + // -P^2 <= x1 - z1 <= P^2 + P + let b1 = F::from_u64((P_SQR + x1 - z1) as u64); + + // SAFE: multiplying `u64` values within the range of `Mersennes31` doesn't overflow: + // 2 * (2^31 - 1) * (2^31 - 1) = 2 * (2^62 - 2^32 + 1) < 2^64 - 1 + let z2 = y2 * w1 + y1 * w2; // 0 <= z2 <= 2*P^2 + + // 0 <= x2 + z2 <= 2*P^2 + P + let a2 = F::from_u64((x2 + z2) as u64); + // -2*P^2 <= x2 - z2 <= P + let b2 = F::from_u64((TWO_P_SQR + x2 - z2) as u64); + + *x = C::new_complex(a1, a2); + *y = C::new_complex(b1, b2); +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/radix_2_dit.v b/CoqOfRust/plonky3/mersenne-31/src/radix_2_dit.v new file mode 100644 index 000000000..389ff495e --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/radix_2_dit.v @@ -0,0 +1,3936 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module radix_2_dit. + Axiom F : + (Ty.path "p3_mersenne_31::radix_2_dit::F") = + (Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"). + + Axiom C : + (Ty.path "p3_mersenne_31::radix_2_dit::C") = + (Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]). + + (* StructTuple + { + name := "Mersenne31ComplexRadix2Dit"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_fmt_Debug_for_p3_mersenne_31_radix_2_dit_Mersenne31ComplexRadix2Dit. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::radix_2_dit::Mersenne31ComplexRadix2Dit". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Mersenne31ComplexRadix2Dit" |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_mersenne_31_radix_2_dit_Mersenne31ComplexRadix2Dit. + + Module Impl_core_default_Default_for_p3_mersenne_31_radix_2_dit_Mersenne31ComplexRadix2Dit. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::radix_2_dit::Mersenne31ComplexRadix2Dit". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple "p3_mersenne_31::radix_2_dit::Mersenne31ComplexRadix2Dit" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_mersenne_31_radix_2_dit_Mersenne31ComplexRadix2Dit. + + Module Impl_core_clone_Clone_for_p3_mersenne_31_radix_2_dit_Mersenne31ComplexRadix2Dit. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::radix_2_dit::Mersenne31ComplexRadix2Dit". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_mersenne_31::radix_2_dit::Mersenne31ComplexRadix2Dit" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_mersenne_31_radix_2_dit_Mersenne31ComplexRadix2Dit. + + Module Impl_p3_dft_traits_TwoAdicSubgroupDft_p3_field_extension_binomial_extension_BinomialExtensionField_Usize_2_p3_mersenne_31_mersenne_31_Mersenne31_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_radix_2_dit_Mersenne31ComplexRadix2Dit. + Definition Self : Ty.t := Ty.path "p3_mersenne_31::radix_2_dit::Mersenne31ComplexRadix2Dit". + + (* type Evaluations = RowMajorMatrix; *) + Definition _Evaluations : Ty.t := + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ]. + + (* + fn dft_batch(&self, mut mat: RowMajorMatrix) -> RowMajorMatrix { + let h = mat.height(); + let log_h = log2_strict_usize(h); + + let root = C::two_adic_generator(log_h); + let twiddles: Vec = root.powers().take(h / 2).collect(); + + // DIT butterfly + reverse_matrix_index_bits(&mut mat); + for layer in 0..log_h { + dit_layer(&mut mat.as_view_mut(), layer, &twiddles); + } + mat + } + *) + Definition dft_batch (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.read (| + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ root : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| log_h |) ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, root |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| h |); Value.Integer IntegerKind.Usize 2 ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_matrix::util::reverse_matrix_index_bits", + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, mat |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| log_h |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let layer := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mersenne_31::radix_2_dit::dit_layer", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "as_view_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, mat |) ] + |) + |) + |) + |) + |); + M.read (| layer |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, twiddles |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + mat + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_dft::traits::TwoAdicSubgroupDft" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + Self + (* Instance *) + [ + ("Evaluations", InstanceField.Ty _Evaluations); + ("dft_batch", InstanceField.Method dft_batch) + ]. + End Impl_p3_dft_traits_TwoAdicSubgroupDft_p3_field_extension_binomial_extension_BinomialExtensionField_Usize_2_p3_mersenne_31_mersenne_31_Mersenne31_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_mersenne_31_radix_2_dit_Mersenne31ComplexRadix2Dit. + + (* + fn dit_layer(mat: &mut RowMajorMatrixViewMut<'_, C>, layer: usize, twiddles: &[C]) { + let h = mat.height(); + let log_h = log2_strict_usize(h); + let layer_rev = log_h - 1 - layer; + + let half_block_size = 1 << layer; + let block_size = half_block_size * 2; + + for j in (0..h).step_by(block_size) { + // Unroll i=0 case + let butterfly_hi = j; + let butterfly_lo = butterfly_hi + half_block_size; + twiddle_free_butterfly(mat, butterfly_hi, butterfly_lo); + + for i in 1..half_block_size { + let butterfly_hi = j + i; + let butterfly_lo = butterfly_hi + half_block_size; + let twiddle = twiddles[i << layer_rev]; + dit_butterfly(mat, butterfly_hi, butterfly_lo, twiddle); + } + } + } + *) + Definition dit_layer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ mat; layer; twiddles ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let layer := M.alloc (| layer |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + let~ h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |) ] + |) + |) in + let~ log_h : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| h |) ] + |) + |) in + let~ layer_rev : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| log_h |); Value.Integer IntegerKind.Usize 1 ] + |); + M.read (| layer |) + ] + |) + |) in + let~ half_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| layer |) ] + |) + |) in + let~ block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| half_block_size |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "step_by", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", M.read (| h |)) + ]; + M.read (| block_size |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let j := M.copy (| γ0_0 |) in + let~ butterfly_hi : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| j |) in + let~ butterfly_lo : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| butterfly_hi |); M.read (| half_block_size |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mersenne_31::radix_2_dit::twiddle_free_butterfly", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| mat |) |) + |); + M.read (| butterfly_hi |); + M.read (| butterfly_lo |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 1); + ("end_", M.read (| half_block_size |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ butterfly_hi : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| j |); M.read (| i |) ] + |) + |) in + let~ butterfly_lo : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| butterfly_hi |); + M.read (| half_block_size |) + ] + |) + |) in + let~ twiddle : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| twiddles |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.read (| i |); + M.read (| layer_rev |) + ] + |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mersenne_31::radix_2_dit::dit_butterfly", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| mat |) |) + |); + M.read (| butterfly_hi |); + M.read (| butterfly_lo |); + M.read (| twiddle |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dit_layer : + M.IsFunction.C "p3_mersenne_31::radix_2_dit::dit_layer" dit_layer. + Admitted. + Global Typeclasses Opaque dit_layer. + + (* + fn twiddle_free_butterfly(mat: &mut RowMajorMatrixViewMut<'_, C>, row_1: usize, row_2: usize) { + let ((shorts_1, suffix_1), (shorts_2, suffix_2)) = mat.packed_row_pair_mut(row_1, row_2); + + // TODO: There's no special packing for Mersenne31Complex at the + // time of writing; when there is we'll want to expand this out + // into three separate loops. + let row_1 = shorts_1.iter_mut().chain(suffix_1); + let row_2 = shorts_2.iter_mut().chain(suffix_2); + + for (x, y) in row_1.zip(row_2) { + let sum = *x + *y; + let diff = *x - *y; + *x = sum; + *y = diff; + } + } + *) + Definition twiddle_free_butterfly (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ mat; row_1; row_2 ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let row_1 := M.alloc (| row_1 |) in + let row_2 := M.alloc (| row_2 |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + "packed_row_pair_mut", + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.read (| row_1 |); + M.read (| row_2 |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let shorts_1 := M.copy (| γ1_0 |) in + let suffix_1 := M.copy (| γ1_1 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_1, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_1, 1 |) in + let shorts_2 := M.copy (| γ1_0 |) in + let suffix_2 := M.copy (| γ1_1 |) in + let~ row_1 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| shorts_1 |) |) + |) + ] + |); + M.read (| suffix_1 |) + ] + |) + |) in + let~ row_2 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| shorts_2 |) |) + |) + ] + |); + M.read (| suffix_2 |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + |), + [ M.read (| row_1 |); M.read (| row_2 |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let x := M.copy (| γ1_0 |) in + let y := M.copy (| γ1_1 |) in + let~ sum : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "add", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| x |) |) |); + M.read (| M.deref (| M.read (| y |) |) |) + ] + |) + |) in + let~ diff : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + [], + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "sub", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| x |) |) |); + M.read (| M.deref (| M.read (| y |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| x |) |), + M.read (| sum |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| y |) |), + M.read (| diff |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_twiddle_free_butterfly : + M.IsFunction.C "p3_mersenne_31::radix_2_dit::twiddle_free_butterfly" twiddle_free_butterfly. + Admitted. + Global Typeclasses Opaque twiddle_free_butterfly. + + (* + fn dit_butterfly(mat: &mut RowMajorMatrixViewMut<'_, C>, row_1: usize, row_2: usize, twiddle: C) { + let ((shorts_1, suffix_1), (shorts_2, suffix_2)) = mat.packed_row_pair_mut(row_1, row_2); + + // TODO: There's no special packing for Mersenne31Complex at the + // time of writing; when there is we'll want to expand this out + // into three separate loops. + let row_1 = shorts_1.iter_mut().chain(suffix_1); + let row_2 = shorts_2.iter_mut().chain(suffix_2); + + for (x, y) in row_1.zip(row_2) { + dit_butterfly_inner(x, y, twiddle); + } + } + *) + Definition dit_butterfly (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ mat; row_1; row_2; twiddle ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let row_1 := M.alloc (| row_1 |) in + let row_2 := M.alloc (| row_2 |) in + let twiddle := M.alloc (| twiddle |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ]; + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + "packed_row_pair_mut", + [], + [ + Ty.apply + (Ty.path "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.read (| row_1 |); + M.read (| row_2 |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let shorts_1 := M.copy (| γ1_0 |) in + let suffix_1 := M.copy (| γ1_1 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_1, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_1, 1 |) in + let shorts_2 := M.copy (| γ1_0 |) in + let suffix_2 := M.copy (| γ1_1 |) in + let~ row_1 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| shorts_1 |) |) + |) + ] + |); + M.read (| suffix_1 |) + ] + |) + |) in + let~ row_2 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| shorts_2 |) |) + |) + ] + |); + M.read (| suffix_2 |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ] + |), + [ M.read (| row_1 |); M.read (| row_2 |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ]; + Ty.apply + (Ty.path "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let x := M.copy (| γ1_0 |) in + let y := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_mersenne_31::radix_2_dit::dit_butterfly_inner", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| y |) |) + |); + M.read (| twiddle |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dit_butterfly : + M.IsFunction.C "p3_mersenne_31::radix_2_dit::dit_butterfly" dit_butterfly. + Admitted. + Global Typeclasses Opaque dit_butterfly. + + (* + fn dit_butterfly_inner(x: &mut C, y: &mut C, twiddle: C) { + // Adding any multiple of P doesn't change the result modulo P; + // we use this to ensure that the inputs to `from_u64` + // below are non-negative. + const P_SQR: i64 = (F::ORDER_U64 * F::ORDER_U64) as i64; + const TWO_P_SQR: i64 = 2 * P_SQR; + + // Unpack the inputs; + // x = x1 + i*x2 + // y = y1 + i*y2 + // twiddle = w1 + i*w2 + let unpack = |x: C| (x.to_array()[0].value as i64, x.to_array()[1].value as i64); + let (x1, x2) = unpack( *x); + let (y1, y2) = unpack( *y); + let (w1, w2) = unpack(twiddle); + + // x ± y*twiddle + // = (x1 + i*x2) ± (y1 + i*y2)*(w1 + i*w2) + // = (x1 ± (y1*w1 - y2*w2)) + i*(x2 ± (y2*w1 + y1*w2)) + // = (x1 ± z1) + i*(x2 ± z2) + // where z1 + i*z2 = y*twiddle + + // SAFE: multiplying `u64` values within the range of `Mersennes31` doesn't overflow: + // (2^31 - 1) * (2^31 - 1) = 2^62 - 2^32 + 1 < 2^64 - 1 + let z1 = y1 * w1 - y2 * w2; // -P^2 <= z1 <= P^2 + + // NB: 2*P^2 + P < 2^63 + + // -P^2 <= x1 + z1 <= P^2 + P + let a1 = F::from_u64((P_SQR + x1 + z1) as u64); + // -P^2 <= x1 - z1 <= P^2 + P + let b1 = F::from_u64((P_SQR + x1 - z1) as u64); + + // SAFE: multiplying `u64` values within the range of `Mersennes31` doesn't overflow: + // 2 * (2^31 - 1) * (2^31 - 1) = 2 * (2^62 - 2^32 + 1) < 2^64 - 1 + let z2 = y2 * w1 + y1 * w2; // 0 <= z2 <= 2*P^2 + + // 0 <= x2 + z2 <= 2*P^2 + P + let a2 = F::from_u64((x2 + z2) as u64); + // -2*P^2 <= x2 - z2 <= P + let b2 = F::from_u64((TWO_P_SQR + x2 - z2) as u64); + + *x = C::new_complex(a1, a2); + *y = C::new_complex(b1, b2); + } + *) + Definition dit_butterfly_inner (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x; y; twiddle ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + let twiddle := M.alloc (| twiddle |) in + M.read (| + let~ unpack : + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.tuple [ Ty.path "i64"; Ty.path "i64" ]) + ] := + M.alloc (| + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.tuple [ Ty.path "i64"; Ty.path "i64" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + Value.Tuple + [ + M.cast + (Ty.path "i64") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "to_array", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)); + M.cast + (Ty.path "i64") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "to_array", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + |), + Value.Integer IntegerKind.Usize 1 + |), + "p3_mersenne_31::mersenne_31::Mersenne31", + "value" + |) + |)) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "i64"; Ty.path "i64" ], + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.tuple [ Ty.path "i64"; Ty.path "i64" ]), + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, unpack |); + Value.Tuple [ M.read (| M.deref (| M.read (| x |) |) |) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x1 := M.copy (| γ0_0 |) in + let x2 := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "i64"; Ty.path "i64" ], + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.tuple [ Ty.path "i64"; Ty.path "i64" ]), + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, unpack |); + Value.Tuple [ M.read (| M.deref (| M.read (| y |) |) |) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let y1 := M.copy (| γ0_0 |) in + let y2 := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "i64"; Ty.path "i64" ], + M.get_trait_method (| + "core::ops::function::Fn", + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ] + (Ty.tuple [ Ty.path "i64"; Ty.path "i64" ]), + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + ], + "call", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, unpack |); + Value.Tuple [ M.read (| twiddle |) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let w1 := M.copy (| γ0_0 |) in + let w2 := M.copy (| γ0_1 |) in + let~ z1 : Ty.apply (Ty.path "*") [] [ Ty.path "i64" ] := + M.alloc (| + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.mul, + [ M.read (| y1 |); M.read (| w1 |) ] + |); + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.mul, + [ M.read (| y2 |); M.read (| w2 |) ] + |) + ] + |) + |) in + let~ a1 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "from_u64", + [], + [] + |), + [ + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "i64", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_mersenne_31::radix_2_dit::dit_butterfly_inner::P_SQR", + Ty.path "i64" + |) + |); + M.read (| x1 |) + ] + |); + M.read (| z1 |) + ] + |)) + ] + |) + |) in + let~ b1 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "from_u64", + [], + [] + |), + [ + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "i64", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_mersenne_31::radix_2_dit::dit_butterfly_inner::P_SQR", + Ty.path "i64" + |) + |); + M.read (| x1 |) + ] + |); + M.read (| z1 |) + ] + |)) + ] + |) + |) in + let~ z2 : Ty.apply (Ty.path "*") [] [ Ty.path "i64" ] := + M.alloc (| + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.mul, + [ M.read (| y2 |); M.read (| w1 |) ] + |); + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.mul, + [ M.read (| y1 |); M.read (| w2 |) ] + |) + ] + |) + |) in + let~ a2 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "from_u64", + [], + [] + |), + [ + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "i64", + BinOp.Wrap.add, + [ M.read (| x2 |); M.read (| z2 |) ] + |)) + ] + |) + |) in + let~ b2 : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] := + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "from_u64", + [], + [] + |), + [ + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "i64", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_mersenne_31::radix_2_dit::dit_butterfly_inner::TWO_P_SQR", + Ty.path "i64" + |) + |); + M.read (| x2 |) + ] + |); + M.read (| z2 |) + ] + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| x |) |), + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_complex", + [], + [] + |), + [ M.read (| a1 |); M.read (| a2 |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| y |) |), + M.call_closure (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_field::extension::binomial_extension::BinomialExtensionField") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"; + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ], + "new_complex", + [], + [] + |), + [ M.read (| b1 |); M.read (| b2 |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_dit_butterfly_inner : + M.IsFunction.C "p3_mersenne_31::radix_2_dit::dit_butterfly_inner" dit_butterfly_inner. + Admitted. + Global Typeclasses Opaque dit_butterfly_inner. + + Module dit_butterfly_inner. + Definition value_P_SQR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.cast + (Ty.path "i64") + (M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.read (| + get_constant (| "p3_field::field::PrimeField64::ORDER_U64", Ty.path "u64" |) + |); + M.read (| + get_constant (| "p3_field::field::PrimeField64::ORDER_U64", Ty.path "u64" |) + |) + ] + |)) + |))). + + Global Instance Instance_IsConstant_value_P_SQR : + M.IsFunction.C "p3_mersenne_31::radix_2_dit::dit_butterfly_inner::P_SQR" value_P_SQR. + Admitted. + Global Typeclasses Opaque value_P_SQR. + + Definition value_TWO_P_SQR (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.I64 2; + M.read (| + get_constant (| + "p3_mersenne_31::radix_2_dit::dit_butterfly_inner::P_SQR", + Ty.path "i64" + |) + |) + ] + |) + |))). + + Global Instance Instance_IsConstant_value_TWO_P_SQR : + M.IsFunction.C "p3_mersenne_31::radix_2_dit::dit_butterfly_inner::TWO_P_SQR" value_TWO_P_SQR. + Admitted. + Global Typeclasses Opaque value_TWO_P_SQR. + End dit_butterfly_inner. +End radix_2_dit. diff --git a/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx2/mod.rs b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx2/mod.rs new file mode 100644 index 000000000..30b9a1acb --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx2/mod.rs @@ -0,0 +1,5 @@ +mod packing; +mod poseidon2; + +pub use packing::*; +pub use poseidon2::*; diff --git a/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx2/packing.rs b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx2/packing.rs new file mode 100644 index 000000000..317f38321 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx2/packing.rs @@ -0,0 +1,751 @@ +use alloc::vec::Vec; +use core::arch::x86_64::{self, __m256i}; +use core::iter::{Product, Sum}; +use core::mem::transmute; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; + +use p3_field::exponentiation::exp_1717986917; +use p3_field::{ + Algebra, Field, InjectiveMonomial, PackedField, PackedFieldPow2, PackedValue, + PermutationMonomial, PrimeCharacteristicRing, +}; +use p3_util::reconstitute_from_base; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; + +use crate::Mersenne31; + +const WIDTH: usize = 8; +pub(crate) const P: __m256i = unsafe { transmute::<[u32; WIDTH], _>([0x7fffffff; WIDTH]) }; + +/// Vectorized AVX2 implementation of `Mersenne31` arithmetic. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(transparent)] // Needed to make `transmute`s safe. +pub struct PackedMersenne31AVX2(pub [Mersenne31; WIDTH]); + +impl PackedMersenne31AVX2 { + #[inline] + #[must_use] + /// Get an arch-specific vector representing the packed values. + pub(crate) fn to_vector(self) -> __m256i { + unsafe { + // Safety: `Mersenne31` is `repr(transparent)` so it can be transmuted to `u32`. It + // follows that `[Mersenne31; WIDTH]` can be transmuted to `[u32; WIDTH]`, which can be + // transmuted to `__m256i`, since arrays are guaranteed to be contiguous in memory. + // Finally `PackedMersenne31AVX2` is `repr(transparent)` so it can be transmuted to + // `[Mersenne31; WIDTH]`. + transmute(self) + } + } + + #[inline] + #[must_use] + /// Make a packed field vector from an arch-specific vector. + /// + /// SAFETY: The caller must ensure that each element of `vector` represents a valid + /// `Mersenne31`. In particular, each element of vector must be in `0..=P`. + pub(crate) unsafe fn from_vector(vector: __m256i) -> Self { + unsafe { + // Safety: It is up to the user to ensure that elements of `vector` represent valid + // `Mersenne31` values. We must only reason about memory representations. `__m256i` can be + // transmuted to `[u32; WIDTH]` (since arrays elements are contiguous in memory), which can + // be transmuted to `[Mersenne31; WIDTH]` (since `Mersenne31` is `repr(transparent)`), which + // in turn can be transmuted to `PackedMersenne31AVX2` (since `PackedMersenne31AVX2` is also + // `repr(transparent)`). + transmute(vector) + } + } + + /// Copy `value` to all positions in a packed vector. This is the same as + /// `From::from`, but `const`. + #[inline] + #[must_use] + const fn broadcast(value: Mersenne31) -> Self { + Self([value; WIDTH]) + } +} + +impl Add for PackedMersenne31AVX2 { + type Output = Self; + #[inline] + fn add(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = add(lhs, rhs); + unsafe { + // Safety: `add` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Mul for PackedMersenne31AVX2 { + type Output = Self; + #[inline] + fn mul(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = mul(lhs, rhs); + unsafe { + // Safety: `mul` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Neg for PackedMersenne31AVX2 { + type Output = Self; + #[inline] + fn neg(self) -> Self { + let val = self.to_vector(); + let res = neg(val); + unsafe { + // Safety: `neg` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Sub for PackedMersenne31AVX2 { + type Output = Self; + #[inline] + fn sub(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = sub(lhs, rhs); + unsafe { + // Safety: `sub` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +/// Add two vectors of Mersenne-31 field elements represented as values in {0, ..., P}. +/// If the inputs do not conform to this representation, the result is undefined. +#[inline] +#[must_use] +fn add(lhs: __m256i, rhs: __m256i) -> __m256i { + // We want this to compile to: + // vpaddd t, lhs, rhs + // vpsubd u, t, P + // vpminud res, t, u + // throughput: 1 cyc/vec (8 els/cyc) + // latency: 3 cyc + + // Let t := lhs + rhs. We want to return a value r in {0, ..., P} such that r = t (mod P). + // Define u := (t - P) mod 2^32 and r := min(t, u). t is in {0, ..., 2 P}. We argue by cases. + // If t is in {0, ..., P - 1}, then u is in {(P - 1 <) 2^32 - P, ..., 2^32 - 1}, so r = t is + // in the correct range. + // If t is in {P, ..., 2 P}, then u is in {0, ..., P} and r = u is in the correct range. + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + let t = x86_64::_mm256_add_epi32(lhs, rhs); + let u = x86_64::_mm256_sub_epi32(t, P); + x86_64::_mm256_min_epu32(t, u) + } +} + +#[inline] +#[must_use] +fn movehdup_epi32(x: __m256i) -> __m256i { + // The instruction is only available in the floating-point flavor; this distinction is only for + // historical reasons and no longer matters. We cast to floats, duplicate, and cast back. + unsafe { + x86_64::_mm256_castps_si256(x86_64::_mm256_movehdup_ps(x86_64::_mm256_castsi256_ps(x))) + } +} + +#[inline] +#[must_use] +fn moveldup_epi32(x: __m256i) -> __m256i { + // This instruction is only available in the floating-point flavor; this distinction is only for + // historical reasons and no longer matters. We cast to floats, duplicate, and cast back. + unsafe { + x86_64::_mm256_castps_si256(x86_64::_mm256_moveldup_ps(x86_64::_mm256_castsi256_ps(x))) + } +} + +/// Multiply vectors of Mersenne-31 field elements represented as values in {0, ..., P}. +/// If the inputs do not conform to this representation, the result is undefined. +#[inline] +#[must_use] +fn mul(lhs: __m256i, rhs: __m256i) -> __m256i { + // We want this to compile to: + // vpsrlq lhs_odd_dbl, lhs, 31 + // vmovshdup rhs_odd, rhs + // vpmuludq prod_odd_dbl, lhs_odd_dbl, rhs_odd + // vpmuludq prod_evn, lhs, rhs + // vpsllq prod_odd_lo_dirty, prod_odd_dbl, 31 + // vpsrlq prod_evn_hi, prod_evn, 31 + // vpblendd prod_lo_dirty, prod_evn, prod_odd_lo_dirty, aah + // vpblendd prod_hi, prod_evn_hi, prod_odd_dbl, aah + // vpand prod_lo, prod_lo_dirty, P + // vpaddd t, prod_lo, prod_hi + // vpsubd u, t, P + // vpminud res, t, u + // throughput: 4 cyc/vec (2 els/cyc) + // latency: 13 cyc + unsafe { + // vpmuludq only reads the bottom 32 bits of every 64-bit quadword. + // The even indices are already in the bottom 32 bits of a quadword, so we can leave them. + let lhs_evn = lhs; + let rhs_evn = rhs; + // Right shift by 31 is equivalent to moving the high 32 bits down to the low 32, and then + // doubling it. So these are the odd indices in lhs, but doubled. + let lhs_odd_dbl = x86_64::_mm256_srli_epi64::<31>(lhs); + // Copy the high 32 bits in each quadword of rhs down to the low 32. + let rhs_odd = movehdup_epi32(rhs); + + // Multiply odd indices; since lhs_odd_dbl is doubled, these products are also doubled. + // prod_odd_dbl.quadword[i] = 2 * lsh.doubleword[2 * i + 1] * rhs.doubleword[2 * i + 1] + let prod_odd_dbl = x86_64::_mm256_mul_epu32(rhs_odd, lhs_odd_dbl); + // Multiply even indices. + // prod_evn.quadword[i] = lsh.doubleword[2 * i] * rhs.doubleword[2 * i] + let prod_evn = x86_64::_mm256_mul_epu32(rhs_evn, lhs_evn); + + // We now need to extract the low 31 bits and the high 31 bits of each 62 bit product and + // prepare to add them. + // Put the low 31 bits of the product (recall that it is shifted left by 1) in an odd + // doubleword. (Notice that the high 31 bits are already in an odd doubleword in + // prod_odd_dbl.) We will still need to clear the sign bit, hence we mark it _dirty. + let prod_odd_lo_dirty = x86_64::_mm256_slli_epi64::<31>(prod_odd_dbl); + // Put the high 31 bits in an even doubleword, again noting that in prod_evn the even + // doublewords contain the low 31 bits (with a dirty sign bit). + let prod_evn_hi = x86_64::_mm256_srli_epi64::<31>(prod_evn); + + // Put all the low halves of all the products into one vector. Take the even values from + // prod_evn and odd values from prod_odd_lo_dirty. Note that the sign bits still need + // clearing. + let prod_lo_dirty = x86_64::_mm256_blend_epi32::<0b10101010>(prod_evn, prod_odd_lo_dirty); + // Now put all the high halves into one vector. The even values come from prod_evn_hi and + // the odd values come from prod_odd_dbl. + let prod_hi = x86_64::_mm256_blend_epi32::<0b10101010>(prod_evn_hi, prod_odd_dbl); + // Clear the most significant bit. + let prod_lo = x86_64::_mm256_and_si256(prod_lo_dirty, P); + + // Standard addition of two 31-bit values. + add(prod_lo, prod_hi) + } +} + +/// Negate a vector of Mersenne-31 field elements represented as values in {0, ..., P}. +/// If the input does not conform to this representation, the result is undefined. +#[inline] +#[must_use] +fn neg(val: __m256i) -> __m256i { + // We want this to compile to: + // vpxor res, val, P + // throughput: .33 cyc/vec (24 els/cyc) + // latency: 1 cyc + + // Since val is in {0, ..., P (= 2^31 - 1)}, res = val XOR P = P - val. Then res is in {0, + // ..., P}. + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + x86_64::_mm256_xor_si256(val, P) + } +} + +/// Subtract vectors of Mersenne-31 field elements represented as values in {0, ..., P}. +/// If the inputs do not conform to this representation, the result is undefined. +#[inline] +#[must_use] +fn sub(lhs: __m256i, rhs: __m256i) -> __m256i { + // We want this to compile to: + // vpsubd t, lhs, rhs + // vpaddd u, t, P + // vpminud res, t, u + // throughput: 1 cyc/vec (8 els/cyc) + // latency: 3 cyc + + // Let d := lhs - rhs and t := d mod 2^32. We want to return a value r in {0, ..., P} such + // that r = d (mod P). + // Define u := (t + P) mod 2^32 and r := min(t, u). d is in {-P, ..., P}. We argue by cases. + // If d is in {0, ..., P}, then t = d and u is in {P, ..., 2 P}. r = t is in the correct + // range. + // If d is in {-P, ..., -1}, then t is in {2^32 - P, ..., 2^32 - 1} and u is in + // {0, ..., P - 1}. r = u is in the correct range. + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + let t = x86_64::_mm256_sub_epi32(lhs, rhs); + let u = x86_64::_mm256_add_epi32(t, P); + x86_64::_mm256_min_epu32(t, u) + } +} + +/// Reduce a representative in {0, ..., P^2} +/// to a representative in [-P, P]. If the input is greater than P^2, the output will +/// still correspond to the same class but will instead lie in [-P, 2^34]. +#[inline(always)] +fn partial_reduce_neg(x: __m256i) -> __m256i { + unsafe { + // Get the top bits shifted down. + let hi = x86_64::_mm256_srli_epi64::<31>(x); + + const LOW31: __m256i = unsafe { transmute::<[u64; 4], _>([0x7fffffff; 4]) }; + // nand instead of and means this returns P - lo. + let neg_lo = x86_64::_mm256_andnot_si256(x, LOW31); + + // Compiling with sub_epi64 vs sub_epi32 both produce reasonable code so we use + // sub_epi64 for the slightly greater flexibility. + // See: https://godbolt.org/z/WPze9e3f3 + x86_64::_mm256_sub_epi64(hi, neg_lo) + } +} + +/// Compute the square of the Mersenne-31 field elements located in the even indices. +/// These field elements are represented as values in {-P, ..., P}. If the even inputs +/// do not conform to this representation, the result is undefined. +/// Values in odd indices are ignored. +/// Output will contain 0's in odd indices. +#[inline(always)] +fn square_unred(x: __m256i) -> __m256i { + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + let x2 = x86_64::_mm256_mul_epi32(x, x); + partial_reduce_neg(x2) + } +} + +/// Compute the permutation x -> x^5 on Mersenne-31 field elements +/// represented as values in {0, ..., P}. If the inputs do not conform +/// to this representation, the result is undefined. +#[inline(always)] +pub(crate) fn exp5(x: __m256i) -> __m256i { + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + let input_evn = x; + let input_odd = movehdup_epi32(x); + + let evn_sq = square_unred(input_evn); + let odd_sq = square_unred(input_odd); + + let evn_4 = square_unred(evn_sq); + let odd_4 = square_unred(odd_sq); + + let evn_5 = x86_64::_mm256_mul_epi32(evn_4, input_evn); + let odd_5 = x86_64::_mm256_mul_epi32(odd_4, input_odd); + + // Marked dirty as the top bit needs to be cleared. + let odd_5_lo_dirty = moveldup_epi32(odd_5); + let odd_5_hi = x86_64::_mm256_add_epi64(odd_5, odd_5); + let evn_5_hi = x86_64::_mm256_srli_epi64::<31>(evn_5); + + // Marked dirty as the top bit needs to be cleared. + let lo_dirty = x86_64::_mm256_blend_epi32::<0b10101010>(evn_5, odd_5_lo_dirty); + let hi = x86_64::_mm256_blend_epi32::<0b10101010>(evn_5_hi, odd_5_hi); + let lo = x86_64::_mm256_and_si256(lo_dirty, P); + let corr = x86_64::_mm256_sign_epi32(P, hi); + let t = x86_64::_mm256_add_epi32(hi, lo); + let u = x86_64::_mm256_sub_epi32(t, corr); + + x86_64::_mm256_min_epu32(t, u) + } +} + +impl From for PackedMersenne31AVX2 { + #[inline] + fn from(value: Mersenne31) -> Self { + Self::broadcast(value) + } +} + +impl Default for PackedMersenne31AVX2 { + #[inline] + fn default() -> Self { + Mersenne31::default().into() + } +} + +impl AddAssign for PackedMersenne31AVX2 { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} + +impl MulAssign for PackedMersenne31AVX2 { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} + +impl SubAssign for PackedMersenne31AVX2 { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} + +impl Sum for PackedMersenne31AVX2 { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs + rhs).unwrap_or(Self::ZERO) + } +} + +impl Product for PackedMersenne31AVX2 { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs * rhs).unwrap_or(Self::ONE) + } +} + +impl PrimeCharacteristicRing for PackedMersenne31AVX2 { + type PrimeSubfield = Mersenne31; + + const ZERO: Self = Self::broadcast(Mersenne31::ZERO); + const ONE: Self = Self::broadcast(Mersenne31::ONE); + const TWO: Self = Self::broadcast(Mersenne31::TWO); + const NEG_ONE: Self = Self::broadcast(Mersenne31::NEG_ONE); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f.into() + } + + #[inline(always)] + fn exp_const_u64(&self) -> Self { + // We provide specialised code for power 5 as this turns up regularly. + // The other powers could be specialised similarly but we ignore this for now. + // These ideas could also be used to speed up the more generic exp_u64. + match POWER { + 0 => Self::ONE, + 1 => *self, + 2 => self.square(), + 3 => self.cube(), + 4 => self.square().square(), + 5 => unsafe { + let val = self.to_vector(); + Self::from_vector(exp5(val)) + }, + 6 => self.square().cube(), + 7 => { + let x2 = self.square(); + let x3 = x2 * *self; + let x4 = x2.square(); + x3 * x4 + } + _ => self.exp_u64(POWER), + } + } + + #[inline(always)] + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(Mersenne31::zero_vec(len * WIDTH)) } + } +} + +// Degree of the smallest permutation polynomial for Mersenne31. +// +// As p - 1 = 2×3^2×7×11×... the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 5. +impl InjectiveMonomial<5> for PackedMersenne31AVX2 {} + +impl PermutationMonomial<5> for PackedMersenne31AVX2 { + /// In the field `Mersenne31`, `a^{1/5}` is equal to a^{1717986917}. + /// + /// This follows from the calculation `5 * 1717986917 = 4*(2^31 - 2) + 1 = 1 mod p - 1`. + fn injective_exp_root_n(&self) -> Self { + exp_1717986917(*self) + } +} + +impl Algebra for PackedMersenne31AVX2 {} + +impl Add for PackedMersenne31AVX2 { + type Output = Self; + #[inline] + fn add(self, rhs: Mersenne31) -> Self { + self + Self::from(rhs) + } +} + +impl Mul for PackedMersenne31AVX2 { + type Output = Self; + #[inline] + fn mul(self, rhs: Mersenne31) -> Self { + self * Self::from(rhs) + } +} + +impl Sub for PackedMersenne31AVX2 { + type Output = Self; + #[inline] + fn sub(self, rhs: Mersenne31) -> Self { + self - Self::from(rhs) + } +} + +impl AddAssign for PackedMersenne31AVX2 { + #[inline] + fn add_assign(&mut self, rhs: Mersenne31) { + *self += Self::from(rhs) + } +} + +impl MulAssign for PackedMersenne31AVX2 { + #[inline] + fn mul_assign(&mut self, rhs: Mersenne31) { + *self *= Self::from(rhs) + } +} + +impl SubAssign for PackedMersenne31AVX2 { + #[inline] + fn sub_assign(&mut self, rhs: Mersenne31) { + *self -= Self::from(rhs) + } +} + +impl Sum for PackedMersenne31AVX2 { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator, + { + iter.sum::().into() + } +} + +impl Product for PackedMersenne31AVX2 { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator, + { + iter.product::().into() + } +} + +impl Div for PackedMersenne31AVX2 { + type Output = Self; + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: Mersenne31) -> Self { + self * rhs.inverse() + } +} + +impl Add for Mersenne31 { + type Output = PackedMersenne31AVX2; + #[inline] + fn add(self, rhs: PackedMersenne31AVX2) -> PackedMersenne31AVX2 { + PackedMersenne31AVX2::from(self) + rhs + } +} + +impl Mul for Mersenne31 { + type Output = PackedMersenne31AVX2; + #[inline] + fn mul(self, rhs: PackedMersenne31AVX2) -> PackedMersenne31AVX2 { + PackedMersenne31AVX2::from(self) * rhs + } +} + +impl Sub for Mersenne31 { + type Output = PackedMersenne31AVX2; + #[inline] + fn sub(self, rhs: PackedMersenne31AVX2) -> PackedMersenne31AVX2 { + PackedMersenne31AVX2::from(self) - rhs + } +} + +impl Distribution for StandardUniform { + #[inline] + fn sample(&self, rng: &mut R) -> PackedMersenne31AVX2 { + PackedMersenne31AVX2(rng.random()) + } +} + +#[inline] +#[must_use] +fn interleave1(a: __m256i, b: __m256i) -> (__m256i, __m256i) { + // We want this to compile to: + // vpsllq t, a, 32 + // vpsrlq u, b, 32 + // vpblendd res0, a, u, aah + // vpblendd res1, t, b, aah + // throughput: 1.33 cyc/2 vec (12 els/cyc) + // latency: (1 -> 1) 1 cyc + // (1 -> 2) 2 cyc + // (2 -> 1) 2 cyc + // (2 -> 2) 1 cyc + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + + // We currently have: + // a = [ a0 a1 a2 a3 a4 a5 a6 a7 ], + // b = [ b0 b1 b2 b3 b4 b5 b6 b7 ]. + // First form + // t = [ a1 0 a3 0 a5 0 a7 0 ]. + // u = [ 0 b0 0 b2 0 b4 0 b6 ]. + let t = x86_64::_mm256_srli_epi64::<32>(a); + let u = x86_64::_mm256_slli_epi64::<32>(b); + + // Then + // res0 = [ a0 b0 a2 b2 a4 b4 a6 b6 ], + // res1 = [ a1 b1 a3 b3 a5 b5 a7 b7 ]. + ( + x86_64::_mm256_blend_epi32::<0b10101010>(a, u), + x86_64::_mm256_blend_epi32::<0b10101010>(t, b), + ) + } +} + +#[inline] +#[must_use] +fn interleave2(a: __m256i, b: __m256i) -> (__m256i, __m256i) { + // We want this to compile to: + // vpalignr t, b, a, 8 + // vpblendd res0, a, t, cch + // vpblendd res1, t, b, cch + // throughput: 1 cyc/2 vec (16 els/cyc) + // latency: 2 cyc + + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + + // We currently have: + // a = [ a0 a1 a2 a3 a4 a5 a6 a7 ], + // b = [ b0 b1 b2 b3 b4 b5 b6 b7 ]. + // First form + // t = [ a2 a3 b0 b1 a6 a7 b4 b5 ]. + let t = x86_64::_mm256_alignr_epi8::<8>(b, a); + + // Then + // res0 = [ a0 a1 b0 b1 a4 a5 b4 b5 ], + // res1 = [ a2 a3 b2 b3 a6 a7 b6 b7 ]. + ( + x86_64::_mm256_blend_epi32::<0b11001100>(a, t), + x86_64::_mm256_blend_epi32::<0b11001100>(t, b), + ) + } +} + +#[inline] +#[must_use] +fn interleave4(a: __m256i, b: __m256i) -> (__m256i, __m256i) { + // We want this to compile to: + // vperm2i128 t, a, b, 21h + // vpblendd res0, a, t, f0h + // vpblendd res1, t, b, f0h + // throughput: 1 cyc/2 vec (16 els/cyc) + // latency: 4 cyc + + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + + // We currently have: + // a = [ a0 a1 a2 a3 a4 a5 a6 a7 ], + // b = [ b0 b1 b2 b3 b4 b5 b6 b7 ]. + // First form + // t = [ a4 a5 a6 a7 b0 b1 b2 b3 ]. + let t = x86_64::_mm256_permute2x128_si256::<0x21>(a, b); + + // Then + // res0 = [ a0 a1 a2 a3 b0 b1 b2 b3 ], + // res1 = [ a4 a5 a6 a7 b4 b5 b6 b7 ]. + ( + x86_64::_mm256_blend_epi32::<0b11110000>(a, t), + x86_64::_mm256_blend_epi32::<0b11110000>(t, b), + ) + } +} + +unsafe impl PackedValue for PackedMersenne31AVX2 { + type Value = Mersenne31; + + const WIDTH: usize = WIDTH; + + #[inline] + fn from_slice(slice: &[Mersenne31]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[Mersenne31; WIDTH]` can be transmuted to `PackedMersenne31AVX2` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast is + // safe too. + &*slice.as_ptr().cast() + } + } + #[inline] + fn from_slice_mut(slice: &mut [Mersenne31]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[Mersenne31; WIDTH]` can be transmuted to `PackedMersenne31AVX2` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast is + // safe too. + &mut *slice.as_mut_ptr().cast() + } + } + + /// Similar to `core:array::from_fn`. + #[inline] + fn from_fn Mersenne31>(f: F) -> Self { + let vals_arr: [_; WIDTH] = core::array::from_fn(f); + Self(vals_arr) + } + + #[inline] + fn as_slice(&self) -> &[Mersenne31] { + &self.0[..] + } + #[inline] + fn as_slice_mut(&mut self) -> &mut [Mersenne31] { + &mut self.0[..] + } +} + +unsafe impl PackedField for PackedMersenne31AVX2 { + type Scalar = Mersenne31; +} + +unsafe impl PackedFieldPow2 for PackedMersenne31AVX2 { + #[inline] + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { + let (v0, v1) = (self.to_vector(), other.to_vector()); + let (res0, res1) = match block_len { + 1 => interleave1(v0, v1), + 2 => interleave2(v0, v1), + 4 => interleave4(v0, v1), + 8 => (v0, v1), + _ => panic!("unsupported block_len"), + }; + unsafe { + // Safety: all values are in canonical form (we haven't changed them). + (Self::from_vector(res0), Self::from_vector(res1)) + } + } +} + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::{Mersenne31, PackedMersenne31AVX2}; + + /// Zero has a redundant representation, so let's test both. + const ZEROS: PackedMersenne31AVX2 = PackedMersenne31AVX2(Mersenne31::new_array([ + 0x00000000, 0x7fffffff, 0x00000000, 0x7fffffff, 0x00000000, 0x7fffffff, 0x00000000, + 0x7fffffff, + ])); + + const SPECIAL_VALS: PackedMersenne31AVX2 = PackedMersenne31AVX2(Mersenne31::new_array([ + 0x00000000, 0x7fffffff, 0x00000001, 0x7ffffffe, 0x00000002, 0x7ffffffd, 0x40000000, + 0x3fffffff, + ])); + + test_packed_field!( + crate::PackedMersenne31AVX2, + &[super::ZEROS], + &[crate::PackedMersenne31AVX2::ONE], + super::SPECIAL_VALS + ); +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx2/poseidon2.rs b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx2/poseidon2.rs new file mode 100644 index 000000000..667c6bb77 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx2/poseidon2.rs @@ -0,0 +1,392 @@ +use alloc::vec::Vec; +use core::arch::x86_64::{self, __m256i}; +use core::mem::transmute; + +use p3_field::{PrimeCharacteristicRing, PrimeField32}; +use p3_poseidon2::{ + ExternalLayer, ExternalLayerConstants, ExternalLayerConstructor, InternalLayer, + InternalLayerConstructor, MDSMat4, external_initial_permute_state, + external_terminal_permute_state, +}; + +use crate::{Mersenne31, P, PackedMersenne31AVX2, exp5}; + +/// The internal layers of the Poseidon2 permutation for Mersenne31. +/// +/// The packed constants are stored in negative form as this allows some optimizations. +/// This means given a constant `x`, we treat it as an `i32` and +/// pack 8 copies of `x - P` into the corresponding `__m256i` packed constant. +#[derive(Debug, Clone)] +pub struct Poseidon2InternalLayerMersenne31 { + pub(crate) internal_constants: Vec, + packed_internal_constants: Vec<__m256i>, +} + +impl InternalLayerConstructor for Poseidon2InternalLayerMersenne31 { + /// We save the round constants in the {-P, ..., 0} representation instead of the standard + /// {0, ..., P} one. This saves several instructions later. + fn new_from_constants(internal_constants: Vec) -> Self { + Self::new_from_constants(internal_constants) + } +} + +/// The external layers of the Poseidon2 permutation for Mersenne31. +/// +/// The packed constants are stored in negative form as this allows some optimizations. +/// This means given a constant `x`, we treat it as an `i32` and +/// pack 8 copies of `x - P` into the corresponding `__m256i` packed constant. +#[derive(Clone)] +pub struct Poseidon2ExternalLayerMersenne31 { + pub(crate) external_constants: ExternalLayerConstants, + packed_initial_external_constants: Vec<[__m256i; WIDTH]>, + packed_terminal_external_constants: Vec<[__m256i; WIDTH]>, +} + +impl ExternalLayerConstructor + for Poseidon2ExternalLayerMersenne31 +{ + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + Self::new_from_constants(external_constants) + } +} + +/// Convert elements from the standard form {0, ..., P} to {-P, ..., 0} and copy into a vector +fn convert_to_vec_neg_form(input: i32) -> __m256i { + let input_sub_p = input - (Mersenne31::ORDER_U32 as i32); + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + x86_64::_mm256_set1_epi32(input_sub_p) + } +} + +impl Poseidon2InternalLayerMersenne31 { + /// Construct an instance of Poseidon2InternalLayerMersenne31 from a vector containing + /// the constants for each round. Internally, the constants are transformed into the + /// {-P, ..., 0} representation instead of the standard {0, ..., P} one. + fn new_from_constants(internal_constants: Vec) -> Self { + let packed_internal_constants = internal_constants + .iter() + .map(|constant| convert_to_vec_neg_form(constant.value as i32)) + .collect(); + Self { + internal_constants, + packed_internal_constants, + } + } +} + +impl Poseidon2ExternalLayerMersenne31 { + /// Construct an instance of Poseidon2ExternalLayerMersenne31 from an array of + /// vectors containing the constants for each round. Internally, the constants + /// are transformed into the {-P, ..., 0} representation instead of the standard {0, ..., P} one. + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + let packed_initial_external_constants = external_constants + .get_initial_constants() + .iter() + .map(|array| array.map(|constant| convert_to_vec_neg_form(constant.value as i32))) + .collect(); + let packed_terminal_external_constants = external_constants + .get_terminal_constants() + .iter() + .map(|array| array.map(|constant| convert_to_vec_neg_form(constant.value as i32))) + .collect(); + Self { + external_constants, + packed_initial_external_constants, + packed_terminal_external_constants, + } + } +} + +/// Compute the map `x -> 2^I x` on Mersenne-31 field elements. +/// +/// `x` must be represented as a value in `[0, P]`. +/// This requires 2 generic parameters, `I` and `I_PRIME` satisfying `I + I_PRIME = 31`. +/// If the inputs do not conform to this representations, the result is undefined. +#[inline(always)] +fn mul_2exp_i(val: PackedMersenne31AVX2) -> PackedMersenne31AVX2 { + /* + We want this to compile to: + vpslld hi_dirty, val, I + vpsrld lo, val, 31 - I + vpand hi, hi_dirty, P + vpor res, lo, hi + throughput: 1.33 cyc/vec + latency: 3 cyc + */ + assert_eq!(I + I_PRIME, 31); + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + let input = val.to_vector(); + + // In M31, multiplication by 2^n corresponds to a cyclic rotation which + // is much faster than the naive multiplication method. + + // Shift the low bits up. This also shifts something unwanted into + // the sign bit so we mark it dirty. + let hi_bits_dirty = x86_64::_mm256_slli_epi32::(input); + + // Shift the high bits down. + let lo_bits = x86_64::_mm256_srli_epi32::(input); + + // Clear the sign bit. + let hi_bits = x86_64::_mm256_and_si256(hi_bits_dirty, P); + + // Combine the lo and high bits. + let output = x86_64::_mm256_or_si256(lo_bits, hi_bits); + PackedMersenne31AVX2::from_vector(output) + } +} + +/// Compute the map `x -> 2^15 x` on Mersenne-31 field elements. +/// +/// `x` must be represented as a value in `[0, P]`. +/// If the input does not conform to this representations, the result is undefined. +/// This has higher throughput and higher latency than mul_2exp_i so should be used +/// in contexts where latency is less important. +#[inline(always)] +fn mul_2exp_15(val: PackedMersenne31AVX2) -> PackedMersenne31AVX2 { + /* + We want this to compile to: + vpmaddwd neg_madds, val, C + vpaddd dirty_neg_res, neg_madds, P + vpandn res, dirty_neg_res, P + throughput: 1 cyc/vec + latency: 7 cyc + + The following is a proof that this works: + Let our input be x which we can decompose as (x_lo + 2^{16}x_hi). + Additionally let x_n denote the n'th binary digit of x. + + Our goal is to output y = 2^15x = 2^15x_lo + 2^{31}x_hi = x_hi + 2^{15}x_lo + Note additionally that x_hi + 2^{15}x_lo < 2^31 as x_lo < 2^16 and x_hi < 2^15. + + On each 32 bit lane vpmaddwd signed multiplies matching 16 bit integers and adds the result. + Hence setting C = [[-2^{15}, -1]; 8], the first instruction outputs + + -x_hi - 2^{15}(x_lo - 2^{16}x_{16}) (The x_{16} appears as we interpret x_lo as a signed integer). + = -(x_hi + 2^{15}x_lo) + 2^{31}x_{16} + = -y + 2^{31}x_{16} + + Next, we add P = 2^31 - 1 to this, giving us: + -y + 2^{31}x_{16} + P = 2^31(1 + x_{16}) + (- y - 1) mod 2^32. + Note that -y-1 is exactly (NOT y) as y + (NOT y) = - 1 so we are left with: + + 2^31(1 + x_{16}) + (NOT y) + + As we know y < 2^31, we simply do a NOT followed by clearing the sign bit + this is exactly what vpandn accomplishes (with third argument equal to P.) + + */ + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + let input = val.to_vector(); + + const C: __m256i = unsafe { transmute([[(-1_i16) << 15, -1_i16]; 8]) }; + + let neg_madds = x86_64::_mm256_madd_epi16(input, C); + let dirty_neg_output = x86_64::_mm256_add_epi32(neg_madds, P); + let output = x86_64::_mm256_andnot_si256(dirty_neg_output, P); + + PackedMersenne31AVX2::from_vector(output) + } +} + +/// We hard code multiplication by the diagonal minus 1 of our internal matrix (1 + Diag(V)) +/// In the Mersenne31, WIDTH = 16 case, the diagonal minus 1 is: +/// [-2] + 1 << [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 13, 14, 15, 16] +/// i.e. The first entry is -2 and all other entries are powers of 2. +#[inline(always)] +fn diagonal_mul_16(state: &mut [PackedMersenne31AVX2; 16]) { + // The first three entries involve multiplication by -2, 1, 2 which are simple: + // state[0] -> -2*state[0] is handled by the calling code. + state[2] = state[2] + state[2]; // add is 3 instructions whereas shift is 4. + + // For the remaining entries we use our fast shift code. + state[3] = mul_2exp_i::<2, 29>(state[3]); + state[4] = mul_2exp_i::<3, 28>(state[4]); + state[5] = mul_2exp_i::<4, 27>(state[5]); + state[6] = mul_2exp_i::<5, 26>(state[6]); + state[7] = mul_2exp_i::<6, 25>(state[7]); + state[8] = mul_2exp_i::<7, 24>(state[8]); + state[9] = mul_2exp_i::<8, 23>(state[9]); + state[10] = mul_2exp_i::<10, 21>(state[10]); + state[11] = mul_2exp_i::<12, 19>(state[11]); + state[12] = mul_2exp_i::<13, 18>(state[12]); + state[13] = mul_2exp_i::<14, 17>(state[13]); + state[14] = mul_2exp_15(state[14]); + state[15] = mul_2exp_i::<16, 15>(state[15]); +} + +/// We hard code multiplication by the diagonal minus 1 of our internal matrix (1 + Diag(V)) +/// In the Mersenne31, WIDTH = 24 case, the diagonal minus 1 is: +/// [-2] + 1 << [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22] +/// i.e. The first entry is -2 and all other entries are powers of 2. +#[inline(always)] +fn diagonal_mul_24(state: &mut [PackedMersenne31AVX2; 24]) { + // The first three entries involve multiplication by -2, 1, 2 which are simple: + // state[0] -> -2*state[0] is handled by the calling code. + state[2] = state[2] + state[2]; // add is 3 instructions whereas shift is 4. + + // For the remaining entries we use our fast shift code. + state[3] = mul_2exp_i::<2, 29>(state[3]); + state[4] = mul_2exp_i::<3, 28>(state[4]); + state[5] = mul_2exp_i::<4, 27>(state[5]); + state[6] = mul_2exp_i::<5, 26>(state[6]); + state[7] = mul_2exp_i::<6, 25>(state[7]); + state[8] = mul_2exp_i::<7, 24>(state[8]); + state[9] = mul_2exp_i::<8, 23>(state[9]); + state[10] = mul_2exp_i::<9, 22>(state[10]); + state[11] = mul_2exp_i::<10, 21>(state[11]); + state[12] = mul_2exp_i::<11, 20>(state[12]); + state[13] = mul_2exp_i::<12, 19>(state[13]); + state[14] = mul_2exp_i::<13, 18>(state[14]); + state[15] = mul_2exp_i::<14, 17>(state[15]); + state[16] = mul_2exp_15(state[16]); + state[17] = mul_2exp_i::<16, 15>(state[17]); + state[18] = mul_2exp_i::<17, 14>(state[18]); + state[19] = mul_2exp_i::<18, 13>(state[19]); + state[20] = mul_2exp_i::<19, 12>(state[20]); + state[21] = mul_2exp_i::<20, 11>(state[21]); + state[22] = mul_2exp_i::<21, 10>(state[22]); + state[23] = mul_2exp_i::<22, 9>(state[23]); +} + +/// Compute the map x -> (x + rc)^5 on Mersenne-31 field elements. +/// x must be represented as a value in {0..P}. +/// rc must be represented as a value in {-P, ..., 0}. +/// If the inputs do not conform to these representations, the result is undefined. +/// The output will be represented as a value in {0..P}. +#[inline(always)] +fn add_rc_and_sbox(input: &mut PackedMersenne31AVX2, rc: __m256i) { + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + let input_vec = input.to_vector(); + let input_plus_rc = x86_64::_mm256_add_epi32(input_vec, rc); + + // Due to the representations of input and rc, input_plus_rc is in {-P, ..., P}. + // This is exactly the required bound to apply sbox. + let input_post_sbox = exp5(input_plus_rc); + *input = PackedMersenne31AVX2::from_vector(input_post_sbox); + } +} + +/// Compute a single Poseidon2 internal layer on a state of width 16. +#[inline(always)] +fn internal_16(state: &mut [PackedMersenne31AVX2; 16], rc: __m256i) { + add_rc_and_sbox(&mut state[0], rc); + let sum_tail = PackedMersenne31AVX2::sum_array::<15>(&state[1..]); + let sum = sum_tail + state[0]; + state[0] = sum_tail - state[0]; + diagonal_mul_16(state); + state[1..].iter_mut().for_each(|x| *x += sum); +} + +impl InternalLayer for Poseidon2InternalLayerMersenne31 { + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [PackedMersenne31AVX2; 16]) { + self.packed_internal_constants + .iter() + .for_each(|&rc| internal_16(state, rc)) + } +} + +/// Compute a single Poseidon2 internal layer on a state of width 24. +#[inline(always)] +fn internal_24(state: &mut [PackedMersenne31AVX2; 24], rc: __m256i) { + add_rc_and_sbox(&mut state[0], rc); + let sum_tail = PackedMersenne31AVX2::sum_array::<23>(&state[1..]); + let sum = sum_tail + state[0]; + state[0] = sum_tail - state[0]; + diagonal_mul_24(state); + state[1..].iter_mut().for_each(|x| *x += sum); +} + +impl InternalLayer for Poseidon2InternalLayerMersenne31 { + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [PackedMersenne31AVX2; 24]) { + self.packed_internal_constants + .iter() + .for_each(|&rc| internal_24(state, rc)) + } +} + +impl ExternalLayer + for Poseidon2ExternalLayerMersenne31 +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [PackedMersenne31AVX2; WIDTH]) { + external_initial_permute_state( + state, + &self.packed_initial_external_constants, + add_rc_and_sbox, + &MDSMat4, + ); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [PackedMersenne31AVX2; WIDTH]) { + external_terminal_permute_state( + state, + &self.packed_terminal_external_constants, + add_rc_and_sbox, + &MDSMat4, + ); + } +} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + use crate::Poseidon2Mersenne31; + + type F = Mersenne31; + type Perm16 = Poseidon2Mersenne31<16>; + type Perm24 = Poseidon2Mersenne31<24>; + + /// Test that the output is the same as the scalar version on a random input of length 16. + #[test] + fn test_avx2_poseidon2_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm16::new_from_rng_128(&mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + + assert_eq!(avx2_output, expected); + } + + /// Test that the output is the same as the scalar version on a random input of length 24. + #[test] + fn test_avx2_poseidon2_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm24::new_from_rng_128(&mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx2_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx2_input); + + let avx2_output = avx2_input.map(|x| x.0[0]); + + assert_eq!(avx2_output, expected); + } +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx512/mod.rs b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx512/mod.rs new file mode 100644 index 000000000..c0537721b --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx512/mod.rs @@ -0,0 +1,5 @@ +mod packing; +mod poseidon2; + +pub use packing::*; +pub(crate) use poseidon2::*; diff --git a/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx512/packing.rs b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx512/packing.rs new file mode 100644 index 000000000..0657bd0c3 --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx512/packing.rs @@ -0,0 +1,855 @@ +use alloc::vec::Vec; +use core::arch::x86_64::{self, __m512i, __mmask8, __mmask16}; +use core::iter::{Product, Sum}; +use core::mem::transmute; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; + +use p3_field::exponentiation::exp_1717986917; +use p3_field::{ + Algebra, Field, InjectiveMonomial, PackedField, PackedFieldPow2, PackedValue, + PermutationMonomial, PrimeCharacteristicRing, +}; +use p3_util::reconstitute_from_base; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; + +use crate::Mersenne31; + +const WIDTH: usize = 16; +pub(crate) const P: __m512i = unsafe { transmute::<[u32; WIDTH], _>([0x7fffffff; WIDTH]) }; +const EVENS: __mmask16 = 0b0101010101010101; +const ODDS: __mmask16 = 0b1010101010101010; +const EVENS4: __mmask16 = 0x0f0f; + +/// Vectorized AVX-512F implementation of `Mersenne31` arithmetic. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(transparent)] // Needed to make `transmute`s safe. +pub struct PackedMersenne31AVX512(pub [Mersenne31; WIDTH]); + +impl PackedMersenne31AVX512 { + #[inline] + #[must_use] + /// Get an arch-specific vector representing the packed values. + pub(crate) fn to_vector(self) -> __m512i { + unsafe { + // Safety: `Mersenne31` is `repr(transparent)` so it can be transmuted to `u32`. It + // follows that `[Mersenne31; WIDTH]` can be transmuted to `[u32; WIDTH]`, which can be + // transmuted to `__m512i`, since arrays are guaranteed to be contiguous in memory. + // Finally `PackedMersenne31AVX512` is `repr(transparent)` so it can be transmuted to + // `[Mersenne31; WIDTH]`. + transmute(self) + } + } + + #[inline] + #[must_use] + /// Make a packed field vector from an arch-specific vector. + /// + /// SAFETY: The caller must ensure that each element of `vector` represents a valid + /// `Mersenne31`. In particular, each element of vector must be in `0..=P`. + pub(crate) unsafe fn from_vector(vector: __m512i) -> Self { + unsafe { + // Safety: It is up to the user to ensure that elements of `vector` represent valid + // `Mersenne31` values. We must only reason about memory representations. `__m512i` can be + // transmuted to `[u32; WIDTH]` (since arrays elements are contiguous in memory), which can + // be transmuted to `[Mersenne31; WIDTH]` (since `Mersenne31` is `repr(transparent)`), which + // in turn can be transmuted to `PackedMersenne31AVX512` (since `PackedMersenne31AVX512` is also + // `repr(transparent)`). + transmute(vector) + } + } + + /// Copy `value` to all positions in a packed vector. This is the same as + /// `From::from`, but `const`. + #[inline] + #[must_use] + const fn broadcast(value: Mersenne31) -> Self { + Self([value; WIDTH]) + } +} + +impl Add for PackedMersenne31AVX512 { + type Output = Self; + #[inline] + fn add(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = add(lhs, rhs); + unsafe { + // Safety: `add` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Mul for PackedMersenne31AVX512 { + type Output = Self; + #[inline] + fn mul(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = mul(lhs, rhs); + unsafe { + // Safety: `mul` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Neg for PackedMersenne31AVX512 { + type Output = Self; + #[inline] + fn neg(self) -> Self { + let val = self.to_vector(); + let res = neg(val); + unsafe { + // Safety: `neg` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Sub for PackedMersenne31AVX512 { + type Output = Self; + #[inline] + fn sub(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = sub(lhs, rhs); + unsafe { + // Safety: `sub` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +/// Add two vectors of Mersenne-31 field elements represented as values in {0, ..., P}. +/// If the inputs do not conform to this representation, the result is undefined. +#[inline] +#[must_use] +fn add(lhs: __m512i, rhs: __m512i) -> __m512i { + // We want this to compile to: + // vpaddd t, lhs, rhs + // vpsubd u, t, P + // vpminud res, t, u + // throughput: 1.5 cyc/vec (10.67 els/cyc) + // latency: 3 cyc + + // Let t := lhs + rhs. We want to return a value r in {0, ..., P} such that r = t (mod P). + // Define u := (t - P) mod 2^32 and r := min(t, u). t is in {0, ..., 2 P}. We argue by cases. + // If t is in {0, ..., P - 1}, then u is in {(P - 1 <) 2^32 - P, ..., 2^32 - 1}, so r = t is + // in the correct range. + // If t is in {P, ..., 2 P}, then u is in {0, ..., P} and r = u is in the correct range. + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + let t = x86_64::_mm512_add_epi32(lhs, rhs); + let u = x86_64::_mm512_sub_epi32(t, P); + x86_64::_mm512_min_epu32(t, u) + } +} + +#[inline] +#[must_use] +fn movehdup_epi32(a: __m512i) -> __m512i { + // The instruction is only available in the floating-point flavor; this distinction is only for + // historical reasons and no longer matters. We cast to floats, do the thing, and cast back. + unsafe { + x86_64::_mm512_castps_si512(x86_64::_mm512_movehdup_ps(x86_64::_mm512_castsi512_ps(a))) + } +} + +#[inline] +#[must_use] +fn mask_movehdup_epi32(src: __m512i, k: __mmask16, a: __m512i) -> __m512i { + // The instruction is only available in the floating-point flavor; this distinction is only for + // historical reasons and no longer matters. We cast to floats, do the thing, and cast back. + unsafe { + let src = x86_64::_mm512_castsi512_ps(src); + let a = x86_64::_mm512_castsi512_ps(a); + x86_64::_mm512_castps_si512(x86_64::_mm512_mask_movehdup_ps(src, k, a)) + } +} + +#[inline] +#[must_use] +fn mask_moveldup_epi32(src: __m512i, k: __mmask16, a: __m512i) -> __m512i { + // The instruction is only available in the floating-point flavor; this distinction is only for + // historical reasons and no longer matters. We cast to floats, do the thing, and cast back. + unsafe { + let src = x86_64::_mm512_castsi512_ps(src); + let a = x86_64::_mm512_castsi512_ps(a); + x86_64::_mm512_castps_si512(x86_64::_mm512_mask_moveldup_ps(src, k, a)) + } +} + +/// Multiply vectors of Mersenne-31 field elements represented as values in {0, ..., P}. +/// If the inputs do not conform to this representation, the result is undefined. +#[inline] +#[must_use] +fn mul(lhs: __m512i, rhs: __m512i) -> __m512i { + // We want this to compile to: + // vpaddd lhs_evn_dbl, lhs, lhs + // vmovshdup rhs_odd, rhs + // vpsrlq lhs_odd_dbl, lhs, 31 + // vpmuludq prod_lo_dbl, lhs_evn_dbl, rhs + // vpmuludq prod_odd_dbl, lhs_odd_dbl, rhs_odd + // vmovdqa32 prod_hi, prod_odd_dbl + // vmovshdup prod_hi{EVENS}, prod_lo_dbl + // vmovsldup prod_lo_dbl{ODDS}, prod_odd_dbl + // vpsrld prod_lo, prod_lo_dbl, 1 + // vpaddd t, prod_lo, prod_hi + // vpsubd u, t, P + // vpminud res, t, u + // throughput: 5.5 cyc/vec (2.91 els/cyc) + // latency: (lhs->res) 15 cyc, (rhs->res) 14 cyc + unsafe { + // vpmuludq only reads the bottom 32 bits of every 64-bit quadword. + // The even indices are already in the bottom 32 bits of a quadword, so we can leave them. + let rhs_evn = rhs; + // Again, vpmuludq only reads the bottom 32 bits so we don't need to clear the top. But we + // do want to double the lhs. + let lhs_evn_dbl = x86_64::_mm512_add_epi32(lhs, lhs); + // Copy the high 32 bits in each quadword of rhs down to the low 32. + let rhs_odd = movehdup_epi32(rhs); + // Right shift by 31 is equivalent to moving the high 32 bits down to the low 32, and then + // doubling it. So these are the odd indices in lhs, but doubled. + let lhs_odd_dbl = x86_64::_mm512_srli_epi64::<31>(lhs); + + // Multiply odd indices; since lhs_odd_dbl is doubled, these products are also doubled. + // prod_odd_dbl.quadword[i] = 2 * lhs.doubleword[2 * i + 1] * rhs.doubleword[2 * i + 1] + let prod_odd_dbl = x86_64::_mm512_mul_epu32(lhs_odd_dbl, rhs_odd); + // Multiply even indices; these are also doubled. + // prod_evn_dbl.quadword[i] = 2 * lhs.doubleword[2 * i] * rhs.doubleword[2 * i] + let prod_evn_dbl = x86_64::_mm512_mul_epu32(lhs_evn_dbl, rhs_evn); + + // Move the low halves of odd products into odd positions; keep the low halves of even + // products in even positions (where they already are). Note that the products are doubled, + // so the result is a vector of all the low halves, but doubled. + let prod_lo_dbl = mask_moveldup_epi32(prod_evn_dbl, ODDS, prod_odd_dbl); + // Move the high halves of even products into even positions, keeping the high halves of odd + // products where they are. The products are doubled, but we are looking at (prod >> 32), + // which cancels out the doubling, so this result is _not_ doubled. + let prod_hi = mask_movehdup_epi32(prod_odd_dbl, EVENS, prod_evn_dbl); + // Right shift to undo the doubling. + let prod_lo = x86_64::_mm512_srli_epi32::<1>(prod_lo_dbl); + + // Standard addition of two 31-bit values. + add(prod_lo, prod_hi) + } +} + +/// Negate a vector of Mersenne-31 field elements represented as values in {0, ..., P}. +/// If the input does not conform to this representation, the result is undefined. +#[inline] +#[must_use] +fn neg(val: __m512i) -> __m512i { + // We want this to compile to: + // vpxord res, val, P + // throughput: .5 cyc/vec (32 els/cyc) + // latency: 1 cyc + + // Since val is in {0, ..., P (= 2^31 - 1)}, res = val XOR P = P - val. Then res is in {0, + // ..., P}. + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + x86_64::_mm512_xor_epi32(val, P) + } +} + +/// Subtract vectors of Mersenne-31 field elements represented as values in {0, ..., P}. +/// If the inputs do not conform to this representation, the result is undefined. +#[inline] +#[must_use] +fn sub(lhs: __m512i, rhs: __m512i) -> __m512i { + // We want this to compile to: + // vpsubd t, lhs, rhs + // vpaddd u, t, P + // vpminud res, t, u + // throughput: 1.5 cyc/vec (10.67 els/cyc) + // latency: 3 cyc + + // Let d := lhs - rhs and t := d mod 2^32. We want to return a value r in {0, ..., P} such + // that r = d (mod P). + // Define u := (t + P) mod 2^32 and r := min(t, u). d is in {-P, ..., P}. We argue by cases. + // If d is in {0, ..., P}, then t = d and u is in {P, ..., 2 P}. r = t is in the correct + // range. + // If d is in {-P, ..., -1}, then t is in {2^32 - P, ..., 2^32 - 1} and u is in + // {0, ..., P - 1}. r = u is in the correct range. + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + let t = x86_64::_mm512_sub_epi32(lhs, rhs); + let u = x86_64::_mm512_add_epi32(t, P); + x86_64::_mm512_min_epu32(t, u) + } +} + +/// Reduce a representative in {0, ..., P^2} +/// to a representative in [-P, P]. If the input is greater than P^2, the output will +/// still correspond to the same class but will instead lie in [-P, 2^34]. +#[inline(always)] +fn partial_reduce_neg(x: __m512i) -> __m512i { + unsafe { + // Get the top bits shifted down. + let hi = x86_64::_mm512_srli_epi64::<31>(x); + + const LOW31: __m512i = unsafe { transmute::<[u64; 8], _>([0x7fffffff; 8]) }; + + // nand instead of and means this returns P - lo. + let neg_lo = x86_64::_mm512_andnot_si512(x, LOW31); + + // we could also try: + // let neg_lo = x86_64::_mm512_maskz_andnot_epi32(EVENS, x, P); + // but this seems to get compiled badly and likes outputting vpternlogd. + // See: https://godbolt.org/z/WPze9e3f3 + + // Compiling with sub_epi64 vs sub_epi32 both produce reasonable code so we use + // sub_epi64 for the slightly greater flexibility. + x86_64::_mm512_sub_epi64(hi, neg_lo) + } +} + +/// Compute the square of the Mersenne-31 field elements located in the even indices. +/// These field elements are represented as values in {-P, ..., P}. If the even inputs +/// do not conform to this representation, the result is undefined. +/// The top half of each 64-bit lane is ignored. +/// The top half of each 64-bit lane in the result is 0. +#[inline(always)] +fn square_unred(x: __m512i) -> __m512i { + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + let x2 = x86_64::_mm512_mul_epi32(x, x); + partial_reduce_neg(x2) + } +} + +/// Compute the permutation x -> x^5 on Mersenne-31 field elements +/// represented as values in {0, ..., P}. If the inputs do not conform +/// to this representation, the result is undefined. +#[inline(always)] +pub(crate) fn exp5(x: __m512i) -> __m512i { + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + let input_evn = x; + let input_odd = movehdup_epi32(x); + + let evn_sq = square_unred(input_evn); + let odd_sq = square_unred(input_odd); + + let evn_4 = square_unred(evn_sq); + let odd_4 = square_unred(odd_sq); + + let evn_5 = x86_64::_mm512_mul_epi32(evn_4, input_evn); + let odd_5 = x86_64::_mm512_mul_epi32(odd_4, input_odd); + + // Marked dirty as the top bit needs to be cleared. + let lo_dirty = mask_moveldup_epi32(evn_5, ODDS, odd_5); + + // We could use 2 adds and mask_movehdup_epi32. + // instead of an add, a shift and a blend. + let odd_5_hi = x86_64::_mm512_add_epi64(odd_5, odd_5); + let evn_5_hi = x86_64::_mm512_srli_epi64::<31>(evn_5); + let hi = x86_64::_mm512_mask_blend_epi32(ODDS, evn_5_hi, odd_5_hi); + + let zero = x86_64::_mm512_setzero_si512(); + let signs = x86_64::_mm512_movepi32_mask(hi); + let corr = x86_64::_mm512_mask_sub_epi32(P, signs, zero, P); + + let lo = x86_64::_mm512_and_si512(lo_dirty, P); + + let t = x86_64::_mm512_add_epi32(hi, lo); + let u = x86_64::_mm512_sub_epi32(t, corr); + + x86_64::_mm512_min_epu32(t, u) + } +} + +impl From for PackedMersenne31AVX512 { + #[inline] + fn from(value: Mersenne31) -> Self { + Self::broadcast(value) + } +} + +impl Default for PackedMersenne31AVX512 { + #[inline] + fn default() -> Self { + Mersenne31::default().into() + } +} + +impl AddAssign for PackedMersenne31AVX512 { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} + +impl MulAssign for PackedMersenne31AVX512 { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} + +impl SubAssign for PackedMersenne31AVX512 { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} + +impl Sum for PackedMersenne31AVX512 { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs + rhs).unwrap_or(Self::ZERO) + } +} + +impl Product for PackedMersenne31AVX512 { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs * rhs).unwrap_or(Self::ONE) + } +} + +impl PrimeCharacteristicRing for PackedMersenne31AVX512 { + type PrimeSubfield = Mersenne31; + + const ZERO: Self = Self::broadcast(Mersenne31::ZERO); + const ONE: Self = Self::broadcast(Mersenne31::ONE); + const TWO: Self = Self::broadcast(Mersenne31::TWO); + const NEG_ONE: Self = Self::broadcast(Mersenne31::NEG_ONE); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f.into() + } + + #[inline(always)] + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(Mersenne31::zero_vec(len * WIDTH)) } + } + + #[must_use] + #[inline(always)] + fn exp_const_u64(&self) -> Self { + // We provide specialised code for power 5 as this turns up regularly. + // The other powers could be specialised similarly but we ignore this for now. + // These ideas could also be used to speed up the more generic exp_u64. + match POWER { + 0 => Self::ONE, + 1 => *self, + 2 => self.square(), + 3 => self.cube(), + 4 => self.square().square(), + 5 => unsafe { + let val = self.to_vector(); + Self::from_vector(exp5(val)) + }, + 6 => self.square().cube(), + 7 => { + let x2 = self.square(); + let x3 = x2 * *self; + let x4 = x2.square(); + x3 * x4 + } + _ => self.exp_u64(POWER), + } + } +} + +impl Algebra for PackedMersenne31AVX512 {} + +// Degree of the smallest permutation polynomial for Mersenne31. +// +// As p - 1 = 2×3^2×7×11×... the smallest choice for a degree D satisfying gcd(p - 1, D) = 1 is 5. +impl InjectiveMonomial<5> for PackedMersenne31AVX512 {} + +impl PermutationMonomial<5> for PackedMersenne31AVX512 { + /// In the field `Mersenne31`, `a^{1/5}` is equal to a^{1717986917}. + /// + /// This follows from the calculation `5 * 1717986917 = 4*(2^31 - 2) + 1 = 1 mod p - 1`. + fn injective_exp_root_n(&self) -> Self { + exp_1717986917(*self) + } +} + +impl Add for PackedMersenne31AVX512 { + type Output = Self; + #[inline] + fn add(self, rhs: Mersenne31) -> Self { + self + Self::from(rhs) + } +} + +impl Mul for PackedMersenne31AVX512 { + type Output = Self; + #[inline] + fn mul(self, rhs: Mersenne31) -> Self { + self * Self::from(rhs) + } +} + +impl Sub for PackedMersenne31AVX512 { + type Output = Self; + #[inline] + fn sub(self, rhs: Mersenne31) -> Self { + self - Self::from(rhs) + } +} + +impl AddAssign for PackedMersenne31AVX512 { + #[inline] + fn add_assign(&mut self, rhs: Mersenne31) { + *self += Self::from(rhs) + } +} + +impl MulAssign for PackedMersenne31AVX512 { + #[inline] + fn mul_assign(&mut self, rhs: Mersenne31) { + *self *= Self::from(rhs) + } +} + +impl SubAssign for PackedMersenne31AVX512 { + #[inline] + fn sub_assign(&mut self, rhs: Mersenne31) { + *self -= Self::from(rhs) + } +} + +impl Sum for PackedMersenne31AVX512 { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator, + { + iter.sum::().into() + } +} + +impl Product for PackedMersenne31AVX512 { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator, + { + iter.product::().into() + } +} + +impl Div for PackedMersenne31AVX512 { + type Output = Self; + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: Mersenne31) -> Self { + self * rhs.inverse() + } +} + +impl Add for Mersenne31 { + type Output = PackedMersenne31AVX512; + #[inline] + fn add(self, rhs: PackedMersenne31AVX512) -> PackedMersenne31AVX512 { + PackedMersenne31AVX512::from(self) + rhs + } +} + +impl Mul for Mersenne31 { + type Output = PackedMersenne31AVX512; + #[inline] + fn mul(self, rhs: PackedMersenne31AVX512) -> PackedMersenne31AVX512 { + PackedMersenne31AVX512::from(self) * rhs + } +} + +impl Sub for Mersenne31 { + type Output = PackedMersenne31AVX512; + #[inline] + fn sub(self, rhs: PackedMersenne31AVX512) -> PackedMersenne31AVX512 { + PackedMersenne31AVX512::from(self) - rhs + } +} + +impl Distribution for StandardUniform { + #[inline] + fn sample(&self, rng: &mut R) -> PackedMersenne31AVX512 { + PackedMersenne31AVX512(rng.random()) + } +} + +// vpshrdq requires AVX-512VBMI2. +#[cfg(target_feature = "avx512vbmi2")] +#[inline] +#[must_use] +fn interleave1_antidiagonal(x: __m512i, y: __m512i) -> __m512i { + unsafe { + // Safety: If this code got compiled then AVX-512VBMI2 intrinsics are available. + x86_64::_mm512_shrdi_epi64::<32>(x, y) + } +} + +// If we can't use vpshrdq, then do a vpermi2d, but we waste a register and double the latency. +#[cfg(not(target_feature = "avx512vbmi2"))] +#[inline] +#[must_use] +fn interleave1_antidiagonal(x: __m512i, y: __m512i) -> __m512i { + const INTERLEAVE1_INDICES: __m512i = unsafe { + // Safety: `[u32; 16]` is trivially transmutable to `__m512i`. + transmute::<[u32; WIDTH], _>([ + 0x01, 0x10, 0x03, 0x12, 0x05, 0x14, 0x07, 0x16, 0x09, 0x18, 0x0b, 0x1a, 0x0d, 0x1c, + 0x0f, 0x1e, + ]) + }; + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + x86_64::_mm512_permutex2var_epi32(x, INTERLEAVE1_INDICES, y) + } +} + +#[inline] +#[must_use] +fn interleave1(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + // If we have AVX-512VBMI2, we want this to compile to: + // vpshrdq t, x, y, 32 + // vpblendmd res0 {EVENS}, t, x + // vpblendmd res1 {EVENS}, y, t + // throughput: 1.5 cyc/2 vec (21.33 els/cyc) + // latency: 2 cyc + // + // Otherwise, we want it to compile to: + // vmovdqa32 t, INTERLEAVE1_INDICES + // vpermi2d t, x, y + // vpblendmd res0 {EVENS}, t, x + // vpblendmd res1 {EVENS}, y, t + // throughput: 1.5 cyc/2 vec (21.33 els/cyc) + // latency: 4 cyc + + // We currently have: + // x = [ x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf ], + // y = [ y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 ya yb yc yd ye yf ]. + // First form + // t = [ x1 y0 x3 y2 x5 y4 x7 y6 x9 y8 xb ya xd yc xf ye ]. + let t = interleave1_antidiagonal(x, y); + + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + + // Then + // res0 = [ x0 y0 x2 y2 x4 y4 x6 y6 x8 y8 xa ya xc yc xe ye ], + // res1 = [ x1 y1 x3 y3 x5 y5 x7 y7 x9 y9 xb yb xd yd xf yf ]. + ( + x86_64::_mm512_mask_blend_epi32(EVENS, t, x), + x86_64::_mm512_mask_blend_epi32(EVENS, y, t), + ) + } +} + +#[inline] +#[must_use] +fn shuffle_epi64(a: __m512i, b: __m512i) -> __m512i { + // The instruction is only available in the floating-point flavor; this distinction is only for + // historical reasons and no longer matters. We cast to floats, do the thing, and cast back. + unsafe { + let a = x86_64::_mm512_castsi512_pd(a); + let b = x86_64::_mm512_castsi512_pd(b); + x86_64::_mm512_castpd_si512(x86_64::_mm512_shuffle_pd::(a, b)) + } +} + +#[inline] +#[must_use] +fn interleave2(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + // We want this to compile to: + // vshufpd t, x, y, 55h + // vpblendmq res0 {EVENS}, t, x + // vpblendmq res1 {EVENS}, y, t + // throughput: 1.5 cyc/2 vec (21.33 els/cyc) + // latency: 2 cyc + + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + + // We currently have: + // x = [ x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf ], + // y = [ y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 ya yb yc yd ye yf ]. + // First form + // t = [ x2 x3 y0 y1 x6 x7 y4 y5 xa xb y8 y9 xe xf yc yd ]. + let t = shuffle_epi64::<0b01010101>(x, y); + + // Then + // res0 = [ x0 x1 y0 y1 x4 x5 y4 y5 x8 x9 y8 y9 xc xd yc yd ], + // res1 = [ x2 x3 y2 y3 x6 x7 y6 y7 xa xb ya yb xe xf ye yf ]. + ( + x86_64::_mm512_mask_blend_epi64(EVENS as __mmask8, t, x), + x86_64::_mm512_mask_blend_epi64(EVENS as __mmask8, y, t), + ) + } +} + +#[inline] +#[must_use] +fn interleave4(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + // We want this to compile to: + // vmovdqa64 t, INTERLEAVE4_INDICES + // vpermi2q t, x, y + // vpblendmd res0 {EVENS4}, t, x + // vpblendmd res1 {EVENS4}, y, t + // throughput: 1.5 cyc/2 vec (21.33 els/cyc) + // latency: 4 cyc + + const INTERLEAVE4_INDICES: __m512i = unsafe { + // Safety: `[u64; 8]` is trivially transmutable to `__m512i`. + transmute::<[u64; WIDTH / 2], _>([0o02, 0o03, 0o10, 0o11, 0o06, 0o07, 0o14, 0o15]) + }; + + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + + // We currently have: + // x = [ x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf ], + // y = [ y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 ya yb yc yd ye yf ]. + // First form + // t = [ x4 x5 x6 x7 y0 y1 y2 y3 xc xd xe xf y8 y9 ya yb ]. + let t = x86_64::_mm512_permutex2var_epi64(x, INTERLEAVE4_INDICES, y); + + // Then + // res0 = [ x0 x1 x2 x3 y0 y1 y2 y3 x8 x9 xa xb y8 y9 ya yb ], + // res1 = [ x4 x5 x6 x7 y4 y5 y6 y7 xc xd xe xf yc yd ye yf ]. + ( + x86_64::_mm512_mask_blend_epi32(EVENS4, t, x), + x86_64::_mm512_mask_blend_epi32(EVENS4, y, t), + ) + } +} + +#[inline] +#[must_use] +fn interleave8(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + // We want this to compile to: + // vshufi64x2 t, x, b, 4eh + // vpblendmq res0 {EVENS4}, t, x + // vpblendmq res1 {EVENS4}, y, t + // throughput: 1.5 cyc/2 vec (21.33 els/cyc) + // latency: 4 cyc + + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + + // We currently have: + // x = [ x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf ], + // y = [ y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 ya yb yc yd ye yf ]. + // First form + // t = [ x8 x9 xa xb xc xd xe xf y0 y1 y2 y3 y4 y5 y6 y7 ]. + let t = x86_64::_mm512_shuffle_i64x2::<0b01_00_11_10>(x, y); + + // Then + // res0 = [ x0 x1 x2 x3 x4 x5 x6 x7 y0 y1 y2 y3 y4 y5 y6 y7 ], + // res1 = [ x8 x9 xa xb xc xd xe xf y8 y9 ya yb yc yd ye yf ]. + ( + x86_64::_mm512_mask_blend_epi64(EVENS4 as __mmask8, t, x), + x86_64::_mm512_mask_blend_epi64(EVENS4 as __mmask8, y, t), + ) + } +} + +unsafe impl PackedValue for PackedMersenne31AVX512 { + type Value = Mersenne31; + + const WIDTH: usize = WIDTH; + + #[inline] + fn from_slice(slice: &[Mersenne31]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[Mersenne31; WIDTH]` can be transmuted to `PackedMersenne31AVX512` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast is + // safe too. + &*slice.as_ptr().cast() + } + } + #[inline] + fn from_slice_mut(slice: &mut [Mersenne31]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[Mersenne31; WIDTH]` can be transmuted to `PackedMersenne31AVX512` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast is + // safe too. + &mut *slice.as_mut_ptr().cast() + } + } + + /// Similar to `core:array::from_fn`. + #[inline] + fn from_fn Mersenne31>(f: F) -> Self { + let vals_arr: [_; WIDTH] = core::array::from_fn(f); + Self(vals_arr) + } + + #[inline] + fn as_slice(&self) -> &[Mersenne31] { + &self.0[..] + } + #[inline] + fn as_slice_mut(&mut self) -> &mut [Mersenne31] { + &mut self.0[..] + } +} + +unsafe impl PackedField for PackedMersenne31AVX512 { + type Scalar = Mersenne31; +} + +unsafe impl PackedFieldPow2 for PackedMersenne31AVX512 { + #[inline] + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { + let (v0, v1) = (self.to_vector(), other.to_vector()); + let (res0, res1) = match block_len { + 1 => interleave1(v0, v1), + 2 => interleave2(v0, v1), + 4 => interleave4(v0, v1), + 8 => interleave8(v0, v1), + 16 => (v0, v1), + _ => panic!("unsupported block_len"), + }; + unsafe { + // Safety: all values are in canonical form (we haven't changed them). + (Self::from_vector(res0), Self::from_vector(res1)) + } + } +} + +#[cfg(test)] +mod tests { + use p3_field_testing::test_packed_field; + + use super::{Mersenne31, PackedMersenne31AVX512}; + + /// Zero has a redundant representation, so let's test both. + const ZEROS: PackedMersenne31AVX512 = PackedMersenne31AVX512(Mersenne31::new_array([ + 0x00000000, 0x7fffffff, 0x00000000, 0x7fffffff, 0x00000000, 0x7fffffff, 0x00000000, + 0x7fffffff, 0x00000000, 0x7fffffff, 0x00000000, 0x7fffffff, 0x00000000, 0x7fffffff, + 0x00000000, 0x7fffffff, + ])); + + const SPECIAL_VALS: PackedMersenne31AVX512 = PackedMersenne31AVX512(Mersenne31::new_array([ + 0x00000000, 0x7fffffff, 0x00000001, 0x7ffffffe, 0x00000002, 0x7ffffffd, 0x40000000, + 0x3fffffff, 0x00000000, 0x7fffffff, 0x00000001, 0x7ffffffe, 0x00000002, 0x7ffffffd, + 0x40000000, 0x3fffffff, + ])); + + test_packed_field!( + crate::PackedMersenne31AVX512, + &[super::ZEROS], + &[crate::PackedMersenne31AVX512::ONE], + super::SPECIAL_VALS + ); +} diff --git a/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx512/poseidon2.rs b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx512/poseidon2.rs new file mode 100644 index 000000000..32f5d466e --- /dev/null +++ b/CoqOfRust/plonky3/mersenne-31/src/x86_64_avx512/poseidon2.rs @@ -0,0 +1,339 @@ +use alloc::vec::Vec; +use core::arch::x86_64::{self, __m512i}; + +use p3_field::{PrimeCharacteristicRing, PrimeField32}; +use p3_poseidon2::{ + ExternalLayer, ExternalLayerConstants, ExternalLayerConstructor, InternalLayer, + InternalLayerConstructor, MDSMat4, mds_light_permutation, +}; + +use crate::{Mersenne31, P, PackedMersenne31AVX512, exp5}; + +/// The internal layers of the Poseidon2 permutation for Mersenne31. +/// +/// The packed constants are stored in negative form as this allows some optimizations. +/// This means given a constant `x`, we treat it as an `i32` and +/// pack 16 copies of `x - P` into the corresponding `__m512i` packed constant. +#[derive(Debug, Clone)] +pub struct Poseidon2InternalLayerMersenne31 { + pub(crate) internal_constants: Vec, + packed_internal_constants: Vec<__m512i>, +} + +impl InternalLayerConstructor for Poseidon2InternalLayerMersenne31 { + /// We save the round constants in the {-P, ..., 0} representation instead of the standard + /// {0, ..., P} one. This saves several instructions later. + fn new_from_constants(internal_constants: Vec) -> Self { + Self::new_from_constants(internal_constants) + } +} + +/// The external layers of the Poseidon2 permutation for Mersenne31. +/// +/// The packed constants are stored in negative form as this allows some optimizations. +/// This means given a constant `x`, we treat it as an `i32` and +/// pack 16 copies of `x - P` into the corresponding `__m512i` packed constant. +#[derive(Clone)] +pub struct Poseidon2ExternalLayerMersenne31 { + pub(crate) external_constants: ExternalLayerConstants, + packed_initial_external_constants: Vec<[__m512i; WIDTH]>, + packed_terminal_external_constants: Vec<[__m512i; WIDTH]>, +} + +impl ExternalLayerConstructor + for Poseidon2ExternalLayerMersenne31 +{ + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + Self::new_from_constants(external_constants) + } +} + +/// Convert elements from the standard form {0, ..., P} to {-P, ..., 0} and copy into a vector +fn convert_to_vec_neg_form(input: i32) -> __m512i { + let input_sub_p = input - (Mersenne31::ORDER_U32 as i32); + unsafe { + // Safety: If this code got compiled then AVX512-F intrinsics are available. + x86_64::_mm512_set1_epi32(input_sub_p) + } +} + +impl Poseidon2InternalLayerMersenne31 { + /// Construct an instance of Poseidon2InternalLayerMersenne31 from a vector containing + /// the constants for each round. Internally, the constants are transformed into the + /// {-P, ..., 0} representation instead of the standard {0, ..., P} one. + fn new_from_constants(internal_constants: Vec) -> Self { + let packed_internal_constants = internal_constants + .iter() + .map(|constant| convert_to_vec_neg_form(constant.value as i32)) + .collect(); + Self { + internal_constants, + packed_internal_constants, + } + } +} + +impl Poseidon2ExternalLayerMersenne31 { + /// Construct an instance of Poseidon2ExternalLayerMersenne31 from an array of + /// vectors containing the constants for each round. Internally, the constants + /// are transformed into the {-P, ..., 0} representation instead of the standard {0, ..., P} one. + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self { + let packed_initial_external_constants = external_constants + .get_initial_constants() + .iter() + .map(|array| array.map(|constant| convert_to_vec_neg_form(constant.value as i32))) + .collect(); + let packed_terminal_external_constants = external_constants + .get_terminal_constants() + .iter() + .map(|array| array.map(|constant| convert_to_vec_neg_form(constant.value as i32))) + .collect(); + Self { + external_constants, + packed_initial_external_constants, + packed_terminal_external_constants, + } + } +} + +/// Compute the map x -> 2^I x on Mersenne-31 field elements. +/// x must be represented as a value in {0..P}. +/// This requires 2 generic parameters, I and I_PRIME satisfying I + I_PRIME = 31. +/// If the inputs do not conform to this representations, the result is undefined. +#[inline(always)] +fn mul_2exp_i( + val: PackedMersenne31AVX512, +) -> PackedMersenne31AVX512 { + assert_eq!(I + I_PRIME, 31); + unsafe { + // Safety: If this code got compiled then AVX512-F intrinsics are available. + let input = val.to_vector(); + + // In M31, multiplication by 2^n corresponds to a cyclic rotation which + // is much faster than the naive multiplication method. + + // Shift the low bits up. This also shifts something unwanted into + // the sign bit so we mark it dirty. + let hi_bits_dirty = x86_64::_mm512_slli_epi32::(input); + + // Shift the high bits down. + let lo_bits = x86_64::_mm512_srli_epi32::(input); + + // Clear the sign bit and combine the lo and high bits. + // The simplest description of the operation we want is lo OR (hi_dirty AND P) which has bit pattern: + // 111 => 1, 110 => 1, 101 => 1, 100 => 1, 011 => 1, 010 => 0, 001 => 0, 000 => 0 + // Note that the input patterns: 111, 110, 100 cannot occur so any constant of the form **1*1000 should work. + let output = x86_64::_mm512_ternarylogic_epi32::<0b11111000>(lo_bits, hi_bits_dirty, P); + PackedMersenne31AVX512::from_vector(output) + } +} + +/// We hard code multiplication by the diagonal minus 1 of our internal matrix (1 + Diag(V)) +/// In the Mersenne31, WIDTH = 16 case, the diagonal minus 1 is: +/// [-2] + 1 << [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 13, 14, 15, 16] +/// i.e. The first entry is -2 and all other entries are powers of 2. +#[inline(always)] +fn diagonal_mul_16(state: &mut [PackedMersenne31AVX512; 16]) { + // The first three entries involve multiplication by -2, 1, 2 which are simple: + // state[0] -> -2*state[0] is handled by the calling code. + + // We could use mul_2exp_i here as it is also 3 instructions but add should have better throughput as its instructions work on more ports. + state[2] = state[2] + state[2]; + + // For the remaining entries we use our fast shift code. + state[3] = mul_2exp_i::<2, 29>(state[3]); + state[4] = mul_2exp_i::<3, 28>(state[4]); + state[5] = mul_2exp_i::<4, 27>(state[5]); + state[6] = mul_2exp_i::<5, 26>(state[6]); + state[7] = mul_2exp_i::<6, 25>(state[7]); + state[8] = mul_2exp_i::<7, 24>(state[8]); + state[9] = mul_2exp_i::<8, 23>(state[9]); + state[10] = mul_2exp_i::<10, 21>(state[10]); + state[11] = mul_2exp_i::<12, 19>(state[11]); + state[12] = mul_2exp_i::<13, 18>(state[12]); + state[13] = mul_2exp_i::<14, 17>(state[13]); + state[14] = mul_2exp_i::<15, 16>(state[14]); + state[15] = mul_2exp_i::<16, 15>(state[15]); +} + +/// We hard code multiplication by the diagonal minus 1 of our internal matrix (1 + Diag(V)) +/// In the Mersenne31, WIDTH = 24 case, the diagonal minus 1 is: +/// [-2] + 1 << [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22] +/// i.e. The first entry is -2 and all other entries a power of 2. +#[inline(always)] +fn diagonal_mul_24(state: &mut [PackedMersenne31AVX512; 24]) { + // The first three entries involve multiplication by -2, 1, 2 which are simple: + // state[0] -> -2*state[0] is handled by the calling code. + + // We could use mul_2exp_i here as it is also 3 instructions but add should have better throughput as its instructions work on more ports. + state[2] = state[2] + state[2]; + + // For the remaining entries we use our fast shift code. + state[3] = mul_2exp_i::<2, 29>(state[3]); + state[4] = mul_2exp_i::<3, 28>(state[4]); + state[5] = mul_2exp_i::<4, 27>(state[5]); + state[6] = mul_2exp_i::<5, 26>(state[6]); + state[7] = mul_2exp_i::<6, 25>(state[7]); + state[8] = mul_2exp_i::<7, 24>(state[8]); + state[9] = mul_2exp_i::<8, 23>(state[9]); + state[10] = mul_2exp_i::<9, 22>(state[10]); + state[11] = mul_2exp_i::<10, 21>(state[11]); + state[12] = mul_2exp_i::<11, 20>(state[12]); + state[13] = mul_2exp_i::<12, 19>(state[13]); + state[14] = mul_2exp_i::<13, 18>(state[14]); + state[15] = mul_2exp_i::<14, 17>(state[15]); + state[16] = mul_2exp_i::<15, 16>(state[16]); + state[17] = mul_2exp_i::<16, 15>(state[17]); + state[18] = mul_2exp_i::<17, 14>(state[18]); + state[19] = mul_2exp_i::<18, 13>(state[19]); + state[20] = mul_2exp_i::<19, 12>(state[20]); + state[21] = mul_2exp_i::<20, 11>(state[21]); + state[22] = mul_2exp_i::<21, 10>(state[22]); + state[23] = mul_2exp_i::<22, 9>(state[23]); +} + +/// Compute the map x -> (x + rc)^5 on Mersenne-31 field elements. +/// x must be represented as a value in {0..P}. +/// rc must be represented as a value in {-P, ..., 0}. +/// If the inputs do not conform to these representations, the result is undefined. +/// The output will be represented as a value in {0..P}. +#[inline(always)] +fn add_rc_and_sbox(input: PackedMersenne31AVX512, rc: __m512i) -> PackedMersenne31AVX512 { + unsafe { + // Safety: If this code got compiled then AVX512-F intrinsics are available. + let input_vec = input.to_vector(); + let input_plus_rc = x86_64::_mm512_add_epi32(input_vec, rc); + + // Due to the representations of input and rc, input_plus_rc is in {-P, ..., P}. + // This is exactly the required bound to apply sbox. + let input_post_sbox = exp5(input_plus_rc); + PackedMersenne31AVX512::from_vector(input_post_sbox) + } +} + +/// Compute a single Poseidon2 internal layer on a state of width 16. +#[inline(always)] +fn internal_16(state: &mut [PackedMersenne31AVX512; 16], rc: __m512i) { + state[0] = add_rc_and_sbox(state[0], rc); + let sum_tail = PackedMersenne31AVX512::sum_array::<15>(&state[1..]); + let sum = sum_tail + state[0]; + state[0] = sum_tail - state[0]; + diagonal_mul_16(state); + state[1..].iter_mut().for_each(|x| *x += sum); +} + +impl InternalLayer for Poseidon2InternalLayerMersenne31 { + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [PackedMersenne31AVX512; 16]) { + self.packed_internal_constants + .iter() + .for_each(|&rc| internal_16(state, rc)) + } +} + +/// Compute a single Poseidon2 internal layer on a state of width 24. +#[inline(always)] +fn internal_24(state: &mut [PackedMersenne31AVX512; 24], rc: __m512i) { + state[0] = add_rc_and_sbox(state[0], rc); + let sum_tail = PackedMersenne31AVX512::sum_array::<23>(&state[1..]); + let sum = sum_tail + state[0]; + state[0] = sum_tail - state[0]; + diagonal_mul_24(state); + state[1..].iter_mut().for_each(|x| *x += sum); +} + +impl InternalLayer for Poseidon2InternalLayerMersenne31 { + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [PackedMersenne31AVX512; 24]) { + self.packed_internal_constants + .iter() + .for_each(|&rc| internal_24(state, rc)) + } +} + +/// Compute a collection of Poseidon2 external layers. +/// One layer for every constant supplied. +#[inline] +fn external_rounds( + state: &mut [PackedMersenne31AVX512; WIDTH], + packed_external_constants: &[[__m512i; WIDTH]], +) { + packed_external_constants.iter().for_each(|round_consts| { + state + .iter_mut() + .zip(round_consts.iter()) + .for_each(|(val, &rc)| *val = add_rc_and_sbox(*val, rc)); + mds_light_permutation(state, &MDSMat4); + }); +} + +impl ExternalLayer + for Poseidon2ExternalLayerMersenne31 +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [PackedMersenne31AVX512; WIDTH]) { + mds_light_permutation(state, &MDSMat4); + external_rounds(state, &self.packed_initial_external_constants); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [PackedMersenne31AVX512; WIDTH]) { + external_rounds(state, &self.packed_terminal_external_constants); + } +} + +#[cfg(test)] +mod tests { + use p3_symmetric::Permutation; + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + use crate::Poseidon2Mersenne31; + + type F = Mersenne31; + type Perm16 = Poseidon2Mersenne31<16>; + type Perm24 = Poseidon2Mersenne31<24>; + + /// Test that the output is the same as the scalar version on a random input of length 16. + #[test] + fn test_avx512_poseidon2_width_16() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm16::new_from_rng_128(&mut rng); + + let input: [F; 16] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx512_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx512_input); + + let avx512_output = avx512_input.map(|x| x.0[0]); + + assert_eq!(avx512_output, expected); + } + + /// Test that the output is the same as the scalar version on a random input of length 24. + #[test] + fn test_avx512_poseidon2_width_24() { + let mut rng = SmallRng::seed_from_u64(1); + + // Our Poseidon2 implementation. + let poseidon2 = Perm24::new_from_rng_128(&mut rng); + + let input: [F; 24] = rng.random(); + + let mut expected = input; + poseidon2.permute_mut(&mut expected); + + let mut avx512_input = input.map(Into::::into); + poseidon2.permute_mut(&mut avx512_input); + + let avx512_output = avx512_input.map(|x| x.0[0]); + + assert_eq!(avx512_output, expected); + } +} diff --git a/CoqOfRust/plonky3/monolith/src/lib.rs b/CoqOfRust/plonky3/monolith/src/lib.rs new file mode 100644 index 000000000..6e8c55048 --- /dev/null +++ b/CoqOfRust/plonky3/monolith/src/lib.rs @@ -0,0 +1,12 @@ +//! The Monolith permutation, and hash functions built from it. + +#![no_std] + +extern crate alloc; + +mod monolith; +mod monolith_mds; +mod util; + +pub use monolith::MonolithMersenne31; +pub use monolith_mds::MonolithMdsMatrixMersenne31; diff --git a/CoqOfRust/plonky3/monolith/src/monolith.rs b/CoqOfRust/plonky3/monolith/src/monolith.rs new file mode 100644 index 000000000..ff064a78b --- /dev/null +++ b/CoqOfRust/plonky3/monolith/src/monolith.rs @@ -0,0 +1,216 @@ +//! The Monolith-31 permutation. +//! With significant inspiration from https://extgit.iaik.tugraz.at/krypto/zkfriendlyhashzoo/ + +extern crate alloc; + +use alloc::borrow::ToOwned; +use alloc::vec::Vec; + +use p3_field::integers::QuotientMap; +use p3_field::{PrimeCharacteristicRing, PrimeField32}; +use p3_mds::MdsPermutation; +use p3_mersenne_31::Mersenne31; +use sha3::digest::{ExtendableOutput, Update}; +use sha3::{Shake128, Shake128Reader}; + +use crate::util::get_random_u32; + +// The Monolith-31 permutation over Mersenne31. +// NUM_FULL_ROUNDS is the number of rounds - 1 +// (used to avoid const generics because we need an array of length NUM_FULL_ROUNDS) +#[derive(Debug)] +pub struct MonolithMersenne31 +where + Mds: MdsPermutation, +{ + pub round_constants: [[Mersenne31; WIDTH]; NUM_FULL_ROUNDS], + pub lookup1: Vec, + pub lookup2: Vec, + pub mds: Mds, +} + +impl + MonolithMersenne31 +where + Mds: MdsPermutation, +{ + pub const NUM_BARS: usize = 8; + + pub fn new(mds: Mds) -> Self { + assert!(WIDTH >= 8); + assert!(WIDTH <= 24); + assert_eq!(WIDTH % 4, 0); + + let round_constants = Self::instantiate_round_constants(); + let lookup1 = Self::instantiate_lookup1(); + let lookup2 = Self::instantiate_lookup2(); + + Self { + round_constants, + lookup1, + lookup2, + mds, + } + } + + const fn s_box(y: u8) -> u8 { + let tmp = y ^ !y.rotate_left(1) & y.rotate_left(2) & y.rotate_left(3); + tmp.rotate_left(1) + } + + pub fn final_s_box(y: u8) -> u8 { + debug_assert_eq!(y >> 7, 0); // must be a 7-bit value + + let y_rot_1 = (y >> 6) | (y << 1); + let y_rot_2 = (y >> 5) | (y << 2); + + let tmp = (y ^ !y_rot_1 & y_rot_2) & 0x7F; + ((tmp >> 6) | (tmp << 1)) & 0x7F + } + + fn instantiate_lookup1() -> Vec { + (0..=u16::MAX) + .map(|i| { + let hi = (i >> 8) as u8; + let lo = i as u8; + ((Self::s_box(hi) as u16) << 8) | Self::s_box(lo) as u16 + }) + .collect() + } + + fn instantiate_lookup2() -> Vec { + (0..(1 << 15)) + .map(|i| { + let hi = (i >> 8) as u8; + let lo: u8 = i as u8; + ((Self::final_s_box(hi) as u16) << 8) | Self::s_box(lo) as u16 + }) + .collect() + } + + fn random_field_element(shake: &mut Shake128Reader) -> Mersenne31 { + let mut val = get_random_u32(shake); + while val >= Mersenne31::ORDER_U32 { + val = get_random_u32(shake); + } + + unsafe { + // Safety: By construction, val is now < 2^31 - 1. + Mersenne31::from_canonical_unchecked(val) + } + } + + fn init_shake() -> Shake128Reader { + let num_rounds = (NUM_FULL_ROUNDS + 1) as u8; + + let mut shake = Shake128::default(); + shake.update(b"Monolith"); + shake.update(&[WIDTH as u8, num_rounds]); + shake.update(&Mersenne31::ORDER_U32.to_le_bytes()); + shake.update(&[8, 8, 8, 7]); + shake.finalize_xof() + } + + fn instantiate_round_constants() -> [[Mersenne31; WIDTH]; NUM_FULL_ROUNDS] { + let mut shake = Self::init_shake(); + + [[Mersenne31::ZERO; WIDTH]; NUM_FULL_ROUNDS] + .map(|arr| arr.map(|_| Self::random_field_element(&mut shake))) + } + + #[inline] + pub fn concrete(&self, state: &mut [Mersenne31; WIDTH]) { + self.mds.permute_mut(state); + } + + #[inline] + pub fn add_round_constants( + &self, + state: &mut [Mersenne31; WIDTH], + round_constants: &[Mersenne31; WIDTH], + ) { + // TODO: vectorize? + for (x, rc) in state.iter_mut().zip(round_constants) { + *x += *rc; + } + } + + #[inline] + pub fn bricks(state: &mut [Mersenne31; WIDTH]) { + // Feistel Type-3 + for (x, x_mut) in state.to_owned().iter().zip(state.iter_mut().skip(1)) { + *x_mut += x.square(); + } + } + + #[inline] + pub fn bar(&self, el: Mersenne31) -> Mersenne31 { + let val = &mut el.as_canonical_u32(); + + unsafe { + // get_unchecked here is safe because lookup table 1 contains 2^16 elements + let low = *self.lookup1.get_unchecked(*val as u16 as usize); + + // get_unchecked here is safe because lookup table 2 contains 2^15 elements, + // and el >> 16 < 2^15 (since el < Mersenne31::ORDER_U32 < 2^31) + let high = *self.lookup2.get_unchecked((*val >> 16) as u16 as usize); + *val = ((high as u32) << 16) | low as u32 + } + + unsafe { + // Safety: low + high < 2^31 as low < 2^16 and high < 2^15. + Mersenne31::from_canonical_unchecked(*val) + } + } + + #[inline] + pub fn bars(&self, state: &mut [Mersenne31; WIDTH]) { + state + .iter_mut() + .take(Self::NUM_BARS) + .for_each(|el| *el = self.bar(*el)); + } + + pub fn permutation(&self, state: &mut [Mersenne31; WIDTH]) { + self.concrete(state); + for rc in self.round_constants { + self.bars(state); + Self::bricks(state); + self.concrete(state); + self.add_round_constants(state, &rc); + } + self.bars(state); + Self::bricks(state); + self.concrete(state); + } +} + +#[cfg(test)] +mod tests { + use core::array; + + use p3_field::PrimeCharacteristicRing; + use p3_mersenne_31::Mersenne31; + + use crate::monolith::MonolithMersenne31; + use crate::monolith_mds::MonolithMdsMatrixMersenne31; + + #[test] + fn test_monolith_31() { + let mds = MonolithMdsMatrixMersenne31::<6>; + let monolith: MonolithMersenne31<_, 16, 5> = MonolithMersenne31::new(mds); + + let mut input = array::from_fn(Mersenne31::from_usize); + + let expected = [ + 609156607, 290107110, 1900746598, 1734707571, 2050994835, 1648553244, 1307647296, + 1941164548, 1707113065, 1477714255, 1170160793, 93800695, 769879348, 375548503, + 1989726444, 1349325635, + ] + .map(Mersenne31::from_u32); + + monolith.permutation(&mut input); + + assert_eq!(input, expected); + } +} diff --git a/CoqOfRust/plonky3/monolith/src/monolith.v b/CoqOfRust/plonky3/monolith/src/monolith.v new file mode 100644 index 000000000..475996b55 --- /dev/null +++ b/CoqOfRust/plonky3/monolith/src/monolith.v @@ -0,0 +1,3184 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module monolith. + (* StructRecord + { + name := "MonolithMersenne31"; + const_params := [ "WIDTH"; "NUM_FULL_ROUNDS" ]; + ty_params := [ "Mds" ]; + fields := + [ + ("round_constants", + Ty.apply + (Ty.path "array") + [ NUM_FULL_ROUNDS ] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ]); + ("lookup1", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ]); + ("lookup2", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ]); + ("mds", Mds) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Mds_where_p3_mds_MdsPermutation_Mds_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_monolith_monolith_MonolithMersenne31_WIDTH_NUM_FULL_ROUNDS_Mds. + Definition Self (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ]. + + (* Debug *) + Definition fmt + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field4_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "MonolithMersenne31" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "round_constants" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monolith::monolith::MonolithMersenne31", + "round_constants" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "lookup1" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monolith::monolith::MonolithMersenne31", + "lookup1" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "lookup2" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monolith::monolith::MonolithMersenne31", + "lookup2" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "mds" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monolith::monolith::MonolithMersenne31", + "mds" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH NUM_FULL_ROUNDS Mds) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH NUM_FULL_ROUNDS Mds)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Mds_where_p3_mds_MdsPermutation_Mds_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_monolith_monolith_MonolithMersenne31_WIDTH_NUM_FULL_ROUNDS_Mds. + + Module Impl_p3_monolith_monolith_MonolithMersenne31_WIDTH_NUM_FULL_ROUNDS_Mds. + Definition Self (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ]. + + (* pub const NUM_BARS: usize = 8; *) + (* Ty.path "usize" *) + Definition value_NUM_BARS + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 8 |))). + + Global Instance AssociatedConstant_value_NUM_BARS : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "NUM_BARS" + (value_NUM_BARS WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque value_NUM_BARS. + + (* + pub fn new(mds: Mds) -> Self { + assert!(WIDTH >= 8); + assert!(WIDTH <= 24); + assert_eq!(WIDTH % 4, 0); + + let round_constants = Self::instantiate_round_constants(); + let lookup1 = Self::instantiate_lookup1(); + let lookup2 = Self::instantiate_lookup2(); + + Self { + round_constants, + lookup1, + lookup2, + mds, + } + } + *) + Definition new + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ mds ] => + ltac:(M.monadic + (let mds := M.alloc (| mds |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ WIDTH; Value.Integer IntegerKind.Usize 8 ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: WIDTH >= 8" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ WIDTH; Value.Integer IntegerKind.Usize 24 ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: WIDTH <= 24" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ WIDTH; Value.Integer IntegerKind.Usize 4 ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 0 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ round_constants : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ NUM_FULL_ROUNDS ] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ NUM_FULL_ROUNDS ] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "instantiate_round_constants", + [], + [] + |), + [] + |) + |) in + let~ lookup1 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "instantiate_lookup1", + [], + [] + |), + [] + |) + |) in + let~ lookup2 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "instantiate_lookup2", + [], + [] + |), + [] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_monolith::monolith::MonolithMersenne31" + [ + ("round_constants", M.read (| round_constants |)); + ("lookup1", M.read (| lookup1 |)); + ("lookup2", M.read (| lookup2 |)); + ("mds", M.read (| mds |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "new" + (new WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque new. + + (* + const fn s_box(y: u8) -> u8 { + let tmp = y ^ !y.rotate_left(1) & y.rotate_left(2) & y.rotate_left(3); + tmp.rotate_left(1) + } + *) + Definition s_box + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ y ] => + ltac:(M.monadic + (let y := M.alloc (| y |) in + M.read (| + let~ tmp : Ty.apply (Ty.path "*") [] [ Ty.path "u8" ] := + M.alloc (| + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_xor, + [ + M.read (| y |); + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_and, + [ + UnOp.not (| + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| Ty.path "u8", "rotate_left", [], [] |), + [ M.read (| y |); Value.Integer IntegerKind.U32 1 ] + |) + |); + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| Ty.path "u8", "rotate_left", [], [] |), + [ M.read (| y |); Value.Integer IntegerKind.U32 2 ] + |) + ] + |); + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| Ty.path "u8", "rotate_left", [], [] |), + [ M.read (| y |); Value.Integer IntegerKind.U32 3 ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| Ty.path "u8", "rotate_left", [], [] |), + [ M.read (| tmp |); Value.Integer IntegerKind.U32 1 ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_s_box : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "s_box" + (s_box WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque s_box. + + (* + pub fn final_s_box(y: u8) -> u8 { + debug_assert_eq!(y >> 7, 0); // must be a 7-bit value + + let y_rot_1 = (y >> 6) | (y << 1); + let y_rot_2 = (y >> 5) | (y << 2); + + let tmp = (y ^ !y_rot_1 & y_rot_2) & 0x7F; + ((tmp >> 6) | (tmp << 1)) & 0x7F + } + *) + Definition final_s_box + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ y ] => + ltac:(M.monadic + (let y := M.alloc (| y |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.shr, + [ M.read (| y |); Value.Integer IntegerKind.I32 7 ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.U8 0 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "u8"; Ty.path "u8" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ y_rot_1 : Ty.apply (Ty.path "*") [] [ Ty.path "u8" ] := + M.alloc (| + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_or, + [ + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.shr, + [ M.read (| y |); Value.Integer IntegerKind.I32 6 ] + |); + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.shl, + [ M.read (| y |); Value.Integer IntegerKind.I32 1 ] + |) + ] + |) + |) in + let~ y_rot_2 : Ty.apply (Ty.path "*") [] [ Ty.path "u8" ] := + M.alloc (| + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_or, + [ + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.shr, + [ M.read (| y |); Value.Integer IntegerKind.I32 5 ] + |); + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.shl, + [ M.read (| y |); Value.Integer IntegerKind.I32 2 ] + |) + ] + |) + |) in + let~ tmp : Ty.apply (Ty.path "*") [] [ Ty.path "u8" ] := + M.alloc (| + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_xor, + [ + M.read (| y |); + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_and, + [ UnOp.not (| M.read (| y_rot_1 |) |); M.read (| y_rot_2 |) ] + |) + ] + |); + Value.Integer IntegerKind.U8 127 + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.bit_or, + [ + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.shr, + [ M.read (| tmp |); Value.Integer IntegerKind.I32 6 ] + |); + M.call_closure (| + Ty.path "u8", + BinOp.Wrap.shl, + [ M.read (| tmp |); Value.Integer IntegerKind.I32 1 ] + |) + ] + |); + Value.Integer IntegerKind.U8 127 + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_final_s_box : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "final_s_box" + (final_s_box WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque final_s_box. + + (* + fn instantiate_lookup1() -> Vec { + (0..=u16::MAX) + .map(|i| { + let hi = (i >> 8) as u8; + let lo = i as u8; + ((Self::s_box(hi) as u16) << 8) | Self::s_box(lo) as u16 + }) + .collect() + } + *) + Definition instantiate_lookup1 + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "u16" ]; + Ty.function [ Ty.tuple [ Ty.path "u16" ] ] (Ty.path "u16") + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "u16" ]; + Ty.function [ Ty.tuple [ Ty.path "u16" ] ] (Ty.path "u16") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "u16" ], + [], + [], + "map", + [], + [ Ty.path "u16"; Ty.function [ Ty.tuple [ Ty.path "u16" ] ] (Ty.path "u16") ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "u16" ], + M.get_associated_function (| + Ty.apply (Ty.path "core::ops::range::RangeInclusive") [] [ Ty.path "u16" ], + "new", + [], + [] + |), + [ + Value.Integer IntegerKind.U16 0; + M.read (| get_associated_constant (| Ty.path "u16", "MAX", Ty.path "u16" |) |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "u16" ] ] (Ty.path "u16") ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + let~ hi : Ty.apply (Ty.path "*") [] [ Ty.path "u8" ] := + M.alloc (| + M.cast + (Ty.path "u8") + (M.call_closure (| + Ty.path "u16", + BinOp.Wrap.shr, + [ M.read (| i |); Value.Integer IntegerKind.I32 8 ] + |)) + |) in + let~ lo : Ty.apply (Ty.path "*") [] [ Ty.path "u8" ] := + M.alloc (| M.cast (Ty.path "u8") (M.read (| i |)) |) in + M.alloc (| + M.call_closure (| + Ty.path "u16", + BinOp.Wrap.bit_or, + [ + M.call_closure (| + Ty.path "u16", + BinOp.Wrap.shl, + [ + M.cast + (Ty.path "u16") + (M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "s_box", + [], + [] + |), + [ M.read (| hi |) ] + |)); + Value.Integer IntegerKind.I32 8 + ] + |); + M.cast + (Ty.path "u16") + (M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "s_box", + [], + [] + |), + [ M.read (| lo |) ] + |)) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_instantiate_lookup1 : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "instantiate_lookup1" + (instantiate_lookup1 WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque instantiate_lookup1. + + (* + fn instantiate_lookup2() -> Vec { + (0..(1 << 15)) + .map(|i| { + let hi = (i >> 8) as u8; + let lo: u8 = i as u8; + ((Self::final_s_box(hi) as u16) << 8) | Self::s_box(lo) as u16 + }) + .collect() + } + *) + Definition instantiate_lookup2 + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ]; + Ty.function [ Ty.tuple [ Ty.path "i32" ] ] (Ty.path "u16") + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ]; + Ty.function [ Ty.tuple [ Ty.path "i32" ] ] (Ty.path "u16") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "map", + [], + [ Ty.path "u16"; Ty.function [ Ty.tuple [ Ty.path "i32" ] ] (Ty.path "u16") ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", + M.call_closure (| + Ty.path "i32", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.I32 1; Value.Integer IntegerKind.I32 15 ] + |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "i32" ] ] (Ty.path "u16") ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + let~ hi : Ty.apply (Ty.path "*") [] [ Ty.path "u8" ] := + M.alloc (| + M.cast + (Ty.path "u8") + (M.call_closure (| + Ty.path "i32", + BinOp.Wrap.shr, + [ M.read (| i |); Value.Integer IntegerKind.I32 8 ] + |)) + |) in + let~ lo : Ty.apply (Ty.path "*") [] [ Ty.path "u8" ] := + M.alloc (| M.cast (Ty.path "u8") (M.read (| i |)) |) in + M.alloc (| + M.call_closure (| + Ty.path "u16", + BinOp.Wrap.bit_or, + [ + M.call_closure (| + Ty.path "u16", + BinOp.Wrap.shl, + [ + M.cast + (Ty.path "u16") + (M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "final_s_box", + [], + [] + |), + [ M.read (| hi |) ] + |)); + Value.Integer IntegerKind.I32 8 + ] + |); + M.cast + (Ty.path "u16") + (M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "s_box", + [], + [] + |), + [ M.read (| lo |) ] + |)) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_instantiate_lookup2 : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "instantiate_lookup2" + (instantiate_lookup2 WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque instantiate_lookup2. + + (* + fn random_field_element(shake: &mut Shake128Reader) -> Mersenne31 { + let mut val = get_random_u32(shake); + while val >= Mersenne31::ORDER_U32 { + val = get_random_u32(shake); + } + + unsafe { + // Safety: By construction, val is now < 2^31 - 1. + Mersenne31::from_canonical_unchecked(val) + } + } + *) + Definition random_field_element + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ shake ] => + ltac:(M.monadic + (let shake := M.alloc (| shake |) in + M.read (| + let~ val : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monolith::util::get_random_u32", [], [] |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| shake |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| val |); + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + val, + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monolith::util::get_random_u32", [], [] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| shake |) |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "u32" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.read (| val |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_random_field_element : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "random_field_element" + (random_field_element WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque random_field_element. + + (* + fn init_shake() -> Shake128Reader { + let num_rounds = (NUM_FULL_ROUNDS + 1) as u8; + + let mut shake = Shake128::default(); + shake.update(b"Monolith"); + shake.update(&[WIDTH as u8, num_rounds]); + shake.update(&Mersenne31::ORDER_U32.to_le_bytes()); + shake.update(&[8, 8, 8, 7]); + shake.finalize_xof() + } + *) + Definition init_shake + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.read (| + let~ num_rounds : Ty.apply (Ty.path "*") [] [ Ty.path "u8" ] := + M.alloc (| + M.cast + (Ty.path "u8") + (M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ NUM_FULL_ROUNDS; Value.Integer IntegerKind.Usize 1 ] + |)) + |) in + let~ shake : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::Update", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, shake |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| UnsupportedLiteral |) |) + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::Update", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, shake |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ M.cast (Ty.path "u8") WIDTH; M.read (| num_rounds |) ] + |) + |) + |) + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::Update", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, shake |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "u32", + "to_le_bytes", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + |) + |) + |) + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::Update", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, shake |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U8 8; + Value.Integer IntegerKind.U8 8; + Value.Integer IntegerKind.U8 8; + Value.Integer IntegerKind.U8 7 + ] + |) + |) + |) + |)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "digest::core_api::xof_reader::XofReaderCoreWrapper") + [] + [ Ty.path "sha3::Shake128ReaderCore" ], + M.get_trait_method (| + "digest::ExtendableOutput", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "finalize_xof", + [], + [] + |), + [ M.read (| shake |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_init_shake : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "init_shake" + (init_shake WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque init_shake. + + (* + fn instantiate_round_constants() -> [[Mersenne31; WIDTH]; NUM_FULL_ROUNDS] { + let mut shake = Self::init_shake(); + + [[Mersenne31::ZERO; WIDTH]; NUM_FULL_ROUNDS] + .map(|arr| arr.map(|_| Self::random_field_element(&mut shake))) + } + *) + Definition instantiate_round_constants + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.read (| + let~ shake : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "digest::core_api::xof_reader::XofReaderCoreWrapper") + [] + [ Ty.path "sha3::Shake128ReaderCore" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "digest::core_api::xof_reader::XofReaderCoreWrapper") + [] + [ Ty.path "sha3::Shake128ReaderCore" ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "init_shake", + [], + [] + |), + [] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ NUM_FULL_ROUNDS ] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "array") + [ NUM_FULL_ROUNDS ] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + "map", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + (Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]); + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + |), + [ + repeat (| + repeat (| + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + |) + |), + WIDTH + |), + NUM_FULL_ROUNDS + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + (Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let arr := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_associated_function (| + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "map", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + (Ty.path "p3_mersenne_31::mersenne_31::Mersenne31"); + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" + ] + |), + [ + M.read (| arr |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31" + ] + ] + (Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.path + "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "random_field_element", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + shake + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_instantiate_round_constants : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "instantiate_round_constants" + (instantiate_round_constants WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque instantiate_round_constants. + + (* + pub fn concrete(&self, state: &mut [Mersenne31; WIDTH]) { + self.mds.permute_mut(state); + } + *) + Definition concrete + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Mds, + [], + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monolith::monolith::MonolithMersenne31", + "mds" + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_concrete : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "concrete" + (concrete WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque concrete. + + (* + pub fn add_round_constants( + &self, + state: &mut [Mersenne31; WIDTH], + round_constants: &[Mersenne31; WIDTH], + ) { + // TODO: vectorize? + for (x, rc) in state.iter_mut().zip(round_constants) { + *x += *rc; + } + } + *) + Definition add_round_constants + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ self; state; round_constants ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + let round_constants := M.alloc (| round_constants |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.read (| round_constants |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let x := M.copy (| γ1_0 |) in + let rc := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| M.deref (| M.read (| rc |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_add_round_constants : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "add_round_constants" + (add_round_constants WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque add_round_constants. + + (* + pub fn bricks(state: &mut [Mersenne31; WIDTH]) { + // Feistel Type-3 + for (x, x_mut) in state.to_owned().iter().zip(state.iter_mut().skip(1)) { + *x_mut += x.square(); + } + } + *) + Definition bricks + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "alloc::borrow::ToOwned", + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + [], + [], + "to_owned", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) + |)) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + [], + [], + "skip", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ]; + Ty.apply + (Ty.path "core::iter::adapters::skip::Skip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let x := M.copy (| γ1_0 |) in + let x_mut := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x_mut |) |) + |); + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "square", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x |) |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bricks : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "bricks" + (bricks WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque bricks. + + (* + pub fn bar(&self, el: Mersenne31) -> Mersenne31 { + let val = &mut el.as_canonical_u32(); + + unsafe { + // get_unchecked here is safe because lookup table 1 contains 2^16 elements + let low = *self.lookup1.get_unchecked( *val as u16 as usize); + + // get_unchecked here is safe because lookup table 2 contains 2^15 elements, + // and el >> 16 < 2^15 (since el < Mersenne31::ORDER_U32 < 2^31) + let high = *self.lookup2.get_unchecked(( *val >> 16) as u16 as usize); + *val = ((high as u32) << 16) | low as u32 + } + + unsafe { + // Safety: low + high < 2^31 as low < 2^16 and high < 2^15. + Mersenne31::from_canonical_unchecked( *val) + } + } + *) + Definition bar + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ self; el ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let el := M.alloc (| el |) in + M.read (| + let~ val : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&mut") [] [ Ty.path "u32" ] ] := + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, el |) ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + let~ low : Ty.apply (Ty.path "*") [] [ Ty.path "u16" ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "u16" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u16" ], + "get_unchecked", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u16" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monolith::monolith::MonolithMersenne31", + "lookup1" + |) + |) + ] + |) + |) + |); + M.cast + (Ty.path "usize") + (M.cast (Ty.path "u16") (M.read (| M.deref (| M.read (| val |) |) |))) + ] + |) + |) + |) in + let~ high : Ty.apply (Ty.path "*") [] [ Ty.path "u16" ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "u16" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u16" ], + "get_unchecked", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u16" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u16"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monolith::monolith::MonolithMersenne31", + "lookup2" + |) + |) + ] + |) + |) + |); + M.cast + (Ty.path "usize") + (M.cast + (Ty.path "u16") + (M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.read (| M.deref (| M.read (| val |) |) |); + Value.Integer IntegerKind.I32 16 + ] + |))) + ] + |) + |) + |) in + M.alloc (| + M.write (| + M.deref (| M.read (| val |) |), + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_or, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ + M.cast (Ty.path "u32") (M.read (| high |)); + Value.Integer IntegerKind.I32 16 + ] + |); + M.cast (Ty.path "u32") (M.read (| low |)) + ] + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_trait_method (| + "p3_field::integers::QuotientMap", + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + [], + [ Ty.path "u32" ], + "from_canonical_unchecked", + [], + [] + |), + [ M.read (| M.deref (| M.read (| val |) |) |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bar : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "bar" + (bar WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque bar. + + (* + pub fn bars(&self, state: &mut [Mersenne31; WIDTH]) { + state + .iter_mut() + .take(Self::NUM_BARS) + .for_each(|el| *el = self.bar( *el)); + } + *) + Definition bars + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |)) + ] + |); + M.read (| + get_associated_constant (| + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "NUM_BARS", + Ty.path "usize" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let el := M.copy (| γ |) in + M.write (| + M.deref (| M.read (| el |) |), + M.call_closure (| + Ty.path "p3_mersenne_31::mersenne_31::Mersenne31", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "bar", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.read (| M.deref (| M.read (| el |) |) |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bars : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "bars" + (bars WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque bars. + + (* + pub fn permutation(&self, state: &mut [Mersenne31; WIDTH]) { + self.concrete(state); + for rc in self.round_constants { + self.bars(state); + Self::bricks(state); + self.concrete(state); + self.add_round_constants(state, &rc); + } + self.bars(state); + Self::bricks(state); + self.concrete(state); + } + *) + Definition permutation + (WIDTH NUM_FULL_ROUNDS : Value.t) + (Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_FULL_ROUNDS Mds in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "concrete", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ NUM_FULL_ROUNDS ] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ NUM_FULL_ROUNDS ] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monolith::monolith::MonolithMersenne31", + "round_constants" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ NUM_FULL_ROUNDS ] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let rc := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "bars", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "bricks", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "concrete", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "add_round_constants", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, rc |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "bars", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "bricks", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monolith::monolith::MonolithMersenne31") + [ WIDTH; NUM_FULL_ROUNDS ] + [ Mds ], + "concrete", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_permutation : + forall (WIDTH NUM_FULL_ROUNDS : Value.t) (Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH NUM_FULL_ROUNDS Mds) + "permutation" + (permutation WIDTH NUM_FULL_ROUNDS Mds). + Admitted. + Global Typeclasses Opaque permutation. + End Impl_p3_monolith_monolith_MonolithMersenne31_WIDTH_NUM_FULL_ROUNDS_Mds. +End monolith. diff --git a/CoqOfRust/plonky3/monolith/src/monolith_mds.rs b/CoqOfRust/plonky3/monolith/src/monolith_mds.rs new file mode 100644 index 000000000..b186ee48e --- /dev/null +++ b/CoqOfRust/plonky3/monolith/src/monolith_mds.rs @@ -0,0 +1,103 @@ +//! Monolith-31's default MDS permutation. +//! With significant inspiration from https://extgit.iaik.tugraz.at/krypto/zkfriendlyhashzoo/ + +use p3_field::PrimeField32; +use p3_mds::MdsPermutation; +use p3_mds::util::apply_circulant; +use p3_mersenne_31::Mersenne31; +use p3_symmetric::Permutation; +use sha3::digest::{ExtendableOutput, Update}; +use sha3::{Shake128, Shake128Reader}; + +use crate::util::get_random_u32; + +#[derive(Clone, Debug)] +pub struct MonolithMdsMatrixMersenne31; + +const MATRIX_CIRC_MDS_16_MERSENNE31_MONOLITH: [u64; 16] = [ + 61402, 17845, 26798, 59689, 12021, 40901, 41351, 27521, 56951, 12034, 53865, 43244, 7454, + 33823, 28750, 1108, +]; + +impl Permutation<[Mersenne31; WIDTH]> + for MonolithMdsMatrixMersenne31 +{ + fn permute(&self, input: [Mersenne31; WIDTH]) -> [Mersenne31; WIDTH] { + if WIDTH == 16 { + let matrix: [u64; WIDTH] = MATRIX_CIRC_MDS_16_MERSENNE31_MONOLITH[..] + .try_into() + .unwrap(); + apply_circulant(&matrix, input) + } else { + let mut shake = Shake128::default(); + shake.update(b"Monolith"); + shake.update(&[WIDTH as u8, NUM_ROUNDS as u8]); + shake.update(&Mersenne31::ORDER_U32.to_le_bytes()); + shake.update(&[16, 15]); + shake.update(b"MDS"); + let mut shake_finalized = shake.finalize_xof(); + apply_cauchy_mds_matrix(&mut shake_finalized, input) + } + } + + fn permute_mut(&self, input: &mut [Mersenne31; WIDTH]) { + *input = self.permute(*input); + } +} + +impl MdsPermutation + for MonolithMdsMatrixMersenne31 +{ +} + +fn apply_cauchy_mds_matrix( + shake: &mut Shake128Reader, + to_multiply: [F; WIDTH], +) -> [F; WIDTH] { + let mut output: [F; WIDTH] = [F::ZERO; WIDTH]; + + // As F is a PrimeField, it's order is equal to its characteristic. + // Thus 2|F| > 2^bits > |F|. + let bits = F::bits(); + let x_mask = (1 << (bits - 9)) - 1; + let y_mask = ((1 << bits) - 1) >> 2; + + let y = get_random_y_i::(shake, x_mask, y_mask); + let mut x = y; + x.iter_mut().for_each(|x_i| *x_i &= x_mask); + + for (i, x_i) in x.iter().enumerate() { + for (j, y_j) in y.iter().enumerate() { + let val = unsafe { + // Safety: + // x_i < x_mask < 2^{-8}|F| + // y_j < y_mask < 2^{-1}|F| + // Hence x_i + y_j < |F|. + F::from_canonical_unchecked(x_i + y_j).inverse() + }; + output[i] += val * to_multiply[j]; + } + } + + output +} + +fn get_random_y_i( + shake: &mut Shake128Reader, + x_mask: u32, + y_mask: u32, +) -> [u32; WIDTH] { + let mut res = [0; WIDTH]; + + for i in 0..WIDTH { + let mut y_i = get_random_u32(shake) & y_mask; + let mut x_i = y_i & x_mask; + while res.iter().take(i).any(|r| r & x_mask == x_i) { + y_i = get_random_u32(shake) & y_mask; + x_i = y_i & x_mask; + } + res[i] = y_i; + } + + res +} diff --git a/CoqOfRust/plonky3/monolith/src/monolith_mds.v b/CoqOfRust/plonky3/monolith/src/monolith_mds.v new file mode 100644 index 000000000..5f761de4b --- /dev/null +++ b/CoqOfRust/plonky3/monolith/src/monolith_mds.v @@ -0,0 +1,1666 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module monolith_mds. + (* StructTuple + { + name := "MonolithMdsMatrixMersenne31"; + const_params := [ "NUM_ROUNDS" ]; + ty_params := []; + fields := []; + } *) + + Module Impl_core_clone_Clone_for_p3_monolith_monolith_mds_MonolithMdsMatrixMersenne31_NUM_ROUNDS. + Definition Self (NUM_ROUNDS : Value.t) : Ty.t := + Ty.apply (Ty.path "p3_monolith::monolith_mds::MonolithMdsMatrixMersenne31") [ NUM_ROUNDS ] []. + + (* Clone *) + Definition clone + (NUM_ROUNDS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self NUM_ROUNDS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_monolith::monolith_mds::MonolithMdsMatrixMersenne31" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (NUM_ROUNDS : Value.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self NUM_ROUNDS) + (* Instance *) [ ("clone", InstanceField.Method (clone NUM_ROUNDS)) ]. + End Impl_core_clone_Clone_for_p3_monolith_monolith_mds_MonolithMdsMatrixMersenne31_NUM_ROUNDS. + + Module Impl_core_fmt_Debug_for_p3_monolith_monolith_mds_MonolithMdsMatrixMersenne31_NUM_ROUNDS. + Definition Self (NUM_ROUNDS : Value.t) : Ty.t := + Ty.apply (Ty.path "p3_monolith::monolith_mds::MonolithMdsMatrixMersenne31") [ NUM_ROUNDS ] []. + + (* Debug *) + Definition fmt + (NUM_ROUNDS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self NUM_ROUNDS in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "MonolithMdsMatrixMersenne31" |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (NUM_ROUNDS : Value.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self NUM_ROUNDS) + (* Instance *) [ ("fmt", InstanceField.Method (fmt NUM_ROUNDS)) ]. + End Impl_core_fmt_Debug_for_p3_monolith_monolith_mds_MonolithMdsMatrixMersenne31_NUM_ROUNDS. + + Definition value_MATRIX_CIRC_MDS_16_MERSENNE31_MONOLITH + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U64 61402; + Value.Integer IntegerKind.U64 17845; + Value.Integer IntegerKind.U64 26798; + Value.Integer IntegerKind.U64 59689; + Value.Integer IntegerKind.U64 12021; + Value.Integer IntegerKind.U64 40901; + Value.Integer IntegerKind.U64 41351; + Value.Integer IntegerKind.U64 27521; + Value.Integer IntegerKind.U64 56951; + Value.Integer IntegerKind.U64 12034; + Value.Integer IntegerKind.U64 53865; + Value.Integer IntegerKind.U64 43244; + Value.Integer IntegerKind.U64 7454; + Value.Integer IntegerKind.U64 33823; + Value.Integer IntegerKind.U64 28750; + Value.Integer IntegerKind.U64 1108 + ] + |))). + + Global Instance Instance_IsConstant_value_MATRIX_CIRC_MDS_16_MERSENNE31_MONOLITH : + M.IsFunction.C + "p3_monolith::monolith_mds::MATRIX_CIRC_MDS_16_MERSENNE31_MONOLITH" + value_MATRIX_CIRC_MDS_16_MERSENNE31_MONOLITH. + Admitted. + Global Typeclasses Opaque value_MATRIX_CIRC_MDS_16_MERSENNE31_MONOLITH. + + Module Impl_p3_symmetric_permutation_Permutation_array_WIDTH_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_monolith_monolith_mds_MonolithMdsMatrixMersenne31_NUM_ROUNDS. + Definition Self (WIDTH NUM_ROUNDS : Value.t) : Ty.t := + Ty.apply (Ty.path "p3_monolith::monolith_mds::MonolithMdsMatrixMersenne31") [ NUM_ROUNDS ] []. + + (* + fn permute(&self, input: [Mersenne31; WIDTH]) -> [Mersenne31; WIDTH] { + if WIDTH == 16 { + let matrix: [u64; WIDTH] = MATRIX_CIRC_MDS_16_MERSENNE31_MONOLITH[..] + .try_into() + .unwrap(); + apply_circulant(&matrix, input) + } else { + let mut shake = Shake128::default(); + shake.update(b"Monolith"); + shake.update(&[WIDTH as u8, NUM_ROUNDS as u8]); + shake.update(&Mersenne31::ORDER_U32.to_le_bytes()); + shake.update(&[16, 15]); + shake.update(b"MDS"); + let mut shake_finalized = shake.finalize_xof(); + apply_cauchy_mds_matrix(&mut shake_finalized, input) + } + } + *) + Definition permute + (WIDTH NUM_ROUNDS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_ROUNDS in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ WIDTH; Value.Integer IntegerKind.Usize 16 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ matrix : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ Ty.path "u64" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ Ty.path "u64" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ Ty.path "u64" ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ Ty.path "u64" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u64" ] ], + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ Ty.path "u64" ] ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u64" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "u64" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monolith::monolith_mds::MATRIX_CIRC_MDS_16_MERSENNE31_MONOLITH", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "u64" ] + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_function (| + "p3_mds::util::apply_circulant", + [ WIDTH ], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, matrix |) |) + |); + M.read (| input |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ shake : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::Update", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, shake |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| UnsupportedLiteral |) |) + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::Update", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, shake |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.cast (Ty.path "u8") WIDTH; + M.cast (Ty.path "u8") NUM_ROUNDS + ] + |) + |) + |) + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::Update", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, shake |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "u32", + "to_le_bytes", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField32::ORDER_U32", + Ty.path "u32" + |) + |) + ] + |) + |) + |) + |) + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::Update", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, shake |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U8 16; + Value.Integer IntegerKind.U8 15 + ] + |) + |) + |) + |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::Update", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, shake |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| UnsupportedLiteral |) |) + |)) + ] + |) + |) in + let~ shake_finalized : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "digest::core_api::xof_reader::XofReaderCoreWrapper") + [] + [ Ty.path "sha3::Shake128ReaderCore" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "digest::core_api::xof_reader::XofReaderCoreWrapper") + [] + [ Ty.path "sha3::Shake128ReaderCore" ], + M.get_trait_method (| + "digest::ExtendableOutput", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake128Core" ], + [], + [], + "finalize_xof", + [], + [] + |), + [ M.read (| shake |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_function (| + "p3_monolith::monolith_mds::apply_cauchy_mds_matrix", + [ WIDTH ], + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, shake_finalized |) |) + |); + M.read (| input |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [Mersenne31; WIDTH]) { + *input = self.permute( *input); + } + *) + Definition permute_mut + (WIDTH NUM_ROUNDS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH NUM_ROUNDS in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.apply + (Ty.path "p3_monolith::monolith_mds::MonolithMdsMatrixMersenne31") + [ NUM_ROUNDS ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH NUM_ROUNDS : Value.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ WIDTH ] [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + ] + (Self WIDTH NUM_ROUNDS) + (* Instance *) + [ + ("permute", InstanceField.Method (permute WIDTH NUM_ROUNDS)); + ("permute_mut", InstanceField.Method (permute_mut WIDTH NUM_ROUNDS)) + ]. + End Impl_p3_symmetric_permutation_Permutation_array_WIDTH_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_monolith_monolith_mds_MonolithMdsMatrixMersenne31_NUM_ROUNDS. + + Module Impl_p3_mds_MdsPermutation_WIDTH_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_monolith_monolith_mds_MonolithMdsMatrixMersenne31_NUM_ROUNDS. + Definition Self (WIDTH NUM_ROUNDS : Value.t) : Ty.t := + Ty.apply (Ty.path "p3_monolith::monolith_mds::MonolithMdsMatrixMersenne31") [ NUM_ROUNDS ] []. + + Axiom Implements : + forall (WIDTH NUM_ROUNDS : Value.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ WIDTH ] + (* Trait polymorphic types *) [ Ty.path "p3_mersenne_31::mersenne_31::Mersenne31" ] + (Self WIDTH NUM_ROUNDS) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_WIDTH_p3_mersenne_31_mersenne_31_Mersenne31_for_p3_monolith_monolith_mds_MonolithMdsMatrixMersenne31_NUM_ROUNDS. + + (* + fn apply_cauchy_mds_matrix( + shake: &mut Shake128Reader, + to_multiply: [F; WIDTH], + ) -> [F; WIDTH] { + let mut output: [F; WIDTH] = [F::ZERO; WIDTH]; + + // As F is a PrimeField, it's order is equal to its characteristic. + // Thus 2|F| > 2^bits > |F|. + let bits = F::bits(); + let x_mask = (1 << (bits - 9)) - 1; + let y_mask = ((1 << bits) - 1) >> 2; + + let y = get_random_y_i::(shake, x_mask, y_mask); + let mut x = y; + x.iter_mut().for_each(|x_i| *x_i &= x_mask); + + for (i, x_i) in x.iter().enumerate() { + for (j, y_j) in y.iter().enumerate() { + let val = unsafe { + // Safety: + // x_i < x_mask < 2^{-8}|F| + // y_j < y_mask < 2^{-1}|F| + // Hence x_i + y_j < |F|. + F::from_canonical_unchecked(x_i + y_j).inverse() + }; + output[i] += val * to_multiply[j]; + } + } + + output + } + *) + Definition apply_cauchy_mds_matrix (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH ], [ F ], [ shake; to_multiply ] => + ltac:(M.monadic + (let shake := M.alloc (| shake |) in + let to_multiply := M.alloc (| to_multiply |) in + M.read (| + let~ output : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] := + M.alloc (| + repeat (| + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) |), + WIDTH + |) + |) in + let~ bits : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| "p3_field::field::Field", F, [], [], "bits", [], [] |), + [] + |) + |) in + let~ x_mask : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.U32 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| bits |); Value.Integer IntegerKind.Usize 9 ] + |) + ] + |); + Value.Integer IntegerKind.U32 1 + ] + |) + |) in + let~ y_mask : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U32 1; M.read (| bits |) ] + |); + Value.Integer IntegerKind.U32 1 + ] + |); + Value.Integer IntegerKind.I32 2 + ] + |) + |) in + let~ y : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ Ty.path "u32" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ Ty.path "u32" ], + M.get_function (| "p3_monolith::monolith_mds::get_random_y_i", [ WIDTH ], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| shake |) |) |); + M.read (| x_mask |); + M.read (| y_mask |) + ] + |) + |) in + let~ x : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ Ty.path "u32" ] ] := + M.copy (| y |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u32" ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Ty.path "u32" ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u32" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u32" ], + "iter_mut", + [], + [] + |), + [ (* Unsize *) M.pointer_coercion (M.borrow (| Pointer.Kind.MutRef, x |)) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Ty.path "u32" ] ] ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x_i := M.copy (| γ |) in + let β := M.deref (| M.read (| x_i |) |) in + M.write (| + β, + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ M.read (| β |); M.read (| x_mask |) ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u32" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u32" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u32" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u32" ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u32" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u32" ], + "iter", + [], + [] + |), + [ (* Unsize *) M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, x |)) ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&") [] [ Ty.path "u32" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u32" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let i := M.copy (| γ1_0 |) in + let x_i := M.copy (| γ1_1 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u32" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u32" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u32" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u32" ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u32" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u32" ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, y |)) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u32" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "u32" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let j := M.copy (| γ1_0 |) in + let y_j := M.copy (| γ1_1 |) in + let~ val : + Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::integers::QuotientMap", + F, + [], + [ Ty.path "u32" ], + "from_canonical_unchecked", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u32" ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u32" + ] + ], + "add", + [], + [] + |), + [ + M.read (| x_i |); + M.read (| y_j |) + ] + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + output, + M.read (| i |) + |) + |); + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| val |); + M.read (| + M.SubPointer.get_array_field (| + to_multiply, + M.read (| j |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_apply_cauchy_mds_matrix : + M.IsFunction.C "p3_monolith::monolith_mds::apply_cauchy_mds_matrix" apply_cauchy_mds_matrix. + Admitted. + Global Typeclasses Opaque apply_cauchy_mds_matrix. + + (* + fn get_random_y_i( + shake: &mut Shake128Reader, + x_mask: u32, + y_mask: u32, + ) -> [u32; WIDTH] { + let mut res = [0; WIDTH]; + + for i in 0..WIDTH { + let mut y_i = get_random_u32(shake) & y_mask; + let mut x_i = y_i & x_mask; + while res.iter().take(i).any(|r| r & x_mask == x_i) { + y_i = get_random_u32(shake) & y_mask; + x_i = y_i & x_mask; + } + res[i] = y_i; + } + + res + } + *) + Definition get_random_y_i (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH ], [], [ shake; x_mask; y_mask ] => + ltac:(M.monadic + (let shake := M.alloc (| shake |) in + let x_mask := M.alloc (| x_mask |) in + let y_mask := M.alloc (| y_mask |) in + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ Ty.path "u32" ] ] := + M.alloc (| repeat (| Value.Integer IntegerKind.U32 0, WIDTH |) |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", WIDTH) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ y_i : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| + "p3_monolith::util::get_random_u32", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| shake |) |) + |) + ] + |); + M.read (| y_mask |) + ] + |) + |) in + let~ x_i : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ M.read (| y_i |); M.read (| x_mask |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "u32" ] + ], + [], + [], + "any", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u32" ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "u32" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "u32" ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "u32" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u32" ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + res + |)) + ] + |); + M.read (| i |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "u32" + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let r := + M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "core::ops::bit::BitAnd", + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "u32" + ], + [], + [ + Ty.path + "u32" + ], + "bitand", + [], + [] + |), + [ + M.read (| + r + |); + M.read (| + x_mask + |) + ] + |); + M.read (| x_i |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + y_i, + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| + "p3_monolith::util::get_random_u32", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| shake |) |) + |) + ] + |); + M.read (| y_mask |) + ] + |) + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + x_i, + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ M.read (| y_i |); M.read (| x_mask |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| res, M.read (| i |) |), + M.read (| y_i |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + res + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_get_random_y_i : + M.IsFunction.C "p3_monolith::monolith_mds::get_random_y_i" get_random_y_i. + Admitted. + Global Typeclasses Opaque get_random_y_i. +End monolith_mds. diff --git a/CoqOfRust/plonky3/monolith/src/util.rs b/CoqOfRust/plonky3/monolith/src/util.rs new file mode 100644 index 000000000..8c432870a --- /dev/null +++ b/CoqOfRust/plonky3/monolith/src/util.rs @@ -0,0 +1,8 @@ +use sha3::Shake128Reader; +use sha3::digest::XofReader; + +pub(crate) fn get_random_u32(shake: &mut Shake128Reader) -> u32 { + let mut rand = [0u8; 4]; + shake.read(&mut rand); + u32::from_le_bytes(rand) +} diff --git a/CoqOfRust/plonky3/monolith/src/util.v b/CoqOfRust/plonky3/monolith/src/util.v new file mode 100644 index 000000000..804381bc6 --- /dev/null +++ b/CoqOfRust/plonky3/monolith/src/util.v @@ -0,0 +1,69 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module util. + (* + pub(crate) fn get_random_u32(shake: &mut Shake128Reader) -> u32 { + let mut rand = [0u8; 4]; + shake.read(&mut rand); + u32::from_le_bytes(rand) + } + *) + Definition get_random_u32 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ shake ] => + ltac:(M.monadic + (let shake := M.alloc (| shake |) in + M.read (| + let~ rand : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ Ty.path "u8" ] + ] := + M.alloc (| + repeat (| Value.Integer IntegerKind.U8 0, Value.Integer IntegerKind.Usize 4 |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::XofReader", + Ty.apply + (Ty.path "digest::core_api::xof_reader::XofReaderCoreWrapper") + [] + [ Ty.path "sha3::Shake128ReaderCore" ], + [], + [], + "read", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| shake |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, rand |) |) + |)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "from_le_bytes", [], [] |), + [ M.read (| rand |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_get_random_u32 : + M.IsFunction.C "p3_monolith::util::get_random_u32" get_random_u32. + Admitted. + Global Typeclasses Opaque get_random_u32. +End util. diff --git a/CoqOfRust/plonky3/monty-31/src/aarch64_neon/mod.rs b/CoqOfRust/plonky3/monty-31/src/aarch64_neon/mod.rs new file mode 100644 index 000000000..30b9a1acb --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/aarch64_neon/mod.rs @@ -0,0 +1,5 @@ +mod packing; +mod poseidon2; + +pub use packing::*; +pub use poseidon2::*; diff --git a/CoqOfRust/plonky3/monty-31/src/aarch64_neon/packing.rs b/CoqOfRust/plonky3/monty-31/src/aarch64_neon/packing.rs new file mode 100644 index 000000000..e1ca39045 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/aarch64_neon/packing.rs @@ -0,0 +1,696 @@ +use alloc::vec::Vec; +use core::arch::aarch64::{self, int32x4_t, uint32x4_t}; +use core::arch::asm; +use core::hint::unreachable_unchecked; +use core::iter::{Product, Sum}; +use core::mem::transmute; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; + +use p3_field::{ + Algebra, Field, InjectiveMonomial, PackedField, PackedFieldPow2, PackedValue, + PermutationMonomial, PrimeCharacteristicRing, +}; +use p3_util::reconstitute_from_base; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; + +use crate::{FieldParameters, MontyField31, PackedMontyParameters, RelativelyPrimePower}; + +const WIDTH: usize = 4; + +pub trait MontyParametersNeon { + const PACKED_P: uint32x4_t; + const PACKED_MU: int32x4_t; +} + +/// Vectorized NEON implementation of `MontyField31` arithmetic. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(transparent)] // Needed to make `transmute`s safe. +pub struct PackedMontyField31Neon(pub [MontyField31; WIDTH]); + +impl PackedMontyField31Neon { + #[inline] + #[must_use] + /// Get an arch-specific vector representing the packed values. + fn to_vector(self) -> uint32x4_t { + unsafe { + // Safety: `MontyField31` is `repr(transparent)` so it can be transmuted to `u32`. It + // follows that `[MontyField31; WIDTH]` can be transmuted to `[u32; WIDTH]`, which can be + // transmuted to `uint32x4_t`, since arrays are guaranteed to be contiguous in memory. + // Finally `PackedMontyField31Neon` is `repr(transparent)` so it can be transmuted to + // `[MontyField31; WIDTH]`. + transmute(self) + } + } + + #[inline] + #[must_use] + /// Make a packed field vector from an arch-specific vector. + /// + /// SAFETY: The caller must ensure that each element of `vector` represents a valid `MontyField31`. + /// In particular, each element of vector must be in `0..P` (canonical form). + unsafe fn from_vector(vector: uint32x4_t) -> Self { + unsafe { + // Safety: It is up to the user to ensure that elements of `vector` represent valid + // `MontyField31` values. We must only reason about memory representations. `uint32x4_t` can be + // transmuted to `[u32; WIDTH]` (since arrays elements are contiguous in memory), which can + // be transmuted to `[MontyField31; WIDTH]` (since `MontyField31` is `repr(transparent)`), which in + // turn can be transmuted to `PackedMontyField31Neon` (since `PackedMontyField31Neon` is also + // `repr(transparent)`). + transmute(vector) + } + } + + /// Copy `value` to all positions in a packed vector. This is the same as + /// `From::from`, but `const`. + #[inline] + #[must_use] + const fn broadcast(value: MontyField31) -> Self { + Self([value; WIDTH]) + } +} + +impl Add for PackedMontyField31Neon { + type Output = Self; + #[inline] + fn add(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = add::(lhs, rhs); + unsafe { + // Safety: `add` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Mul for PackedMontyField31Neon { + type Output = Self; + #[inline] + fn mul(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = mul::(lhs, rhs); + unsafe { + // Safety: `mul` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Neg for PackedMontyField31Neon { + type Output = Self; + #[inline] + fn neg(self) -> Self { + let val = self.to_vector(); + let res = neg::(val); + unsafe { + // Safety: `neg` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Sub for PackedMontyField31Neon { + type Output = Self; + #[inline] + fn sub(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = sub::(lhs, rhs); + unsafe { + // Safety: `sub` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +/// No-op. Prevents the compiler from deducing the value of the vector. +/// +/// Similar to `core::hint::black_box`, it can be used to stop the compiler applying undesirable +/// "optimizations". Unlike the built-in `black_box`, it does not force the value to be written to +/// and then read from the stack. +#[inline] +#[must_use] +fn confuse_compiler(x: uint32x4_t) -> uint32x4_t { + let y; + unsafe { + asm!( + "/*{0:v}*/", + inlateout(vreg) x => y, + options(nomem, nostack, preserves_flags, pure), + ); + // Below tells the compiler the semantics of this so it can still do constant folding, etc. + // You may ask, doesn't it defeat the point of the inline asm block to tell the compiler + // what it does? The answer is that we still inhibit the transform we want to avoid, so + // apparently not. Idk, LLVM works in mysterious ways. + if transmute::(x) != transmute::(y) { + unreachable_unchecked(); + } + } + y +} + +/// Add two vectors of Monty31 field elements in canonical form. +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn add(lhs: uint32x4_t, rhs: uint32x4_t) -> uint32x4_t { + // We want this to compile to: + // add t.4s, lhs.4s, rhs.4s + // sub u.4s, t.4s, P.4s + // umin res.4s, t.4s, u.4s + // throughput: .75 cyc/vec (5.33 els/cyc) + // latency: 6 cyc + + // Let `t := lhs + rhs`. We want to return `t mod P`. Recall that `lhs` and `rhs` are in + // `0, ..., P - 1`, so `t` is in `0, ..., 2 P - 2 (< 2^32)`. It suffices to return `t` if + // `t < P` and `t - P` otherwise. + // Let `u := (t - P) mod 2^32` and `r := unsigned_min(t, u)`. + // If `t` is in `0, ..., P - 1`, then `u` is in `(P - 1 <) 2^32 - P, ..., 2^32 - 1` and + // `r = t`. Otherwise `t` is in `P, ..., 2 P - 2`, `u` is in `0, ..., P - 2 (< P)` and `r = u`. + // Hence, `r` is `t` if `t < P` and `t - P` otherwise, as desired. + + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + let t = aarch64::vaddq_u32(lhs, rhs); + let u = aarch64::vsubq_u32(t, MPNeon::PACKED_P); + aarch64::vminq_u32(t, u) + } +} + +// MONTGOMERY MULTIPLICATION +// This implementation is based on [1] but with changes. The reduction is as follows: +// +// Constants: P < 2^31 +// B = 2^32 +// μ = P^-1 mod B +// Input: -P^2 <= C <= P^2 +// Output: -P < D < P such that D = C B^-1 (mod P) +// Define: +// smod_B(a) = r, where -B/2 <= r <= B/2 - 1 and r = a (mod B). +// Algorithm: +// 1. Q := smod_B(μ C) +// 2. D := (C - Q P) / B +// +// We first show that the division in step 2. is exact. It suffices to show that C = Q P (mod B). By +// definition of Q, smod_B, and μ, we have Q P = smod_B(μ C) P = μ C P = P^-1 C P = C (mod B). +// +// We also have C - Q P = C (mod P), so thus D = C B^-1 (mod P). +// +// It remains to show that D is in the correct range. It suffices to show that -P B < C - Q P < P B. +// We know that -P^2 <= C <= P^2 and (-B / 2) P <= Q P <= (B/2 - 1) P. Then +// (1 - B/2) P - P^2 <= C - Q P <= (B/2) P + P^2. Now, P < B/2, so B/2 + P < B and +// (B/2) P + P^2 < P B; also B/2 - 1 + P < B, so -P B < (1 - B/2) P - P^2. +// Hence, -P B < C - Q P < P B as desired. +// +// [1] Modern Computer Arithmetic, Richard Brent and Paul Zimmermann, Cambridge University Press, +// 2010, algorithm 2.7. + +#[inline] +#[must_use] +fn mulby_mu(val: int32x4_t) -> int32x4_t { + // We want this to compile to: + // mul res.4s, val.4s, MU.4s + // throughput: .25 cyc/vec (16 els/cyc) + // latency: 3 cyc + + unsafe { aarch64::vmulq_s32(val, MPNeon::PACKED_MU) } +} + +#[inline] +#[must_use] +fn get_c_hi(lhs: int32x4_t, rhs: int32x4_t) -> int32x4_t { + // We want this to compile to: + // sqdmulh c_hi.4s, lhs.4s, rhs.4s + // throughput: .25 cyc/vec (16 els/cyc) + // latency: 3 cyc + + unsafe { + // Get bits 31, ..., 62 of C. Note that `sqdmulh` saturates when the product doesn't fit in + // an `i63`, but this cannot happen here due to our bounds on `lhs` and `rhs`. + aarch64::vqdmulhq_s32(lhs, rhs) + } +} + +#[inline] +#[must_use] +fn get_qp_hi(lhs: int32x4_t, mu_rhs: int32x4_t) -> int32x4_t { + // We want this to compile to: + // mul q.4s, lhs.4s, mu_rhs.4s + // sqdmulh qp_hi.4s, q.4s, P.4s + // throughput: .5 cyc/vec (8 els/cyc) + // latency: 6 cyc + + unsafe { + // Form `Q`. + let q = aarch64::vmulq_s32(lhs, mu_rhs); + + // Gets bits 31, ..., 62 of Q P. Again, saturation is not an issue because `P` is not + // -2**31. + aarch64::vqdmulhq_s32(q, aarch64::vreinterpretq_s32_u32(MPNeon::PACKED_P)) + } +} + +#[inline] +#[must_use] +fn get_d(c_hi: int32x4_t, qp_hi: int32x4_t) -> int32x4_t { + // We want this to compile to: + // shsub res.4s, c_hi.4s, qp_hi.4s + // throughput: .25 cyc/vec (16 els/cyc) + // latency: 2 cyc + + unsafe { + // Form D. Note that `c_hi` is C >> 31 and `qp_hi` is (Q P) >> 31, whereas we want + // (C - Q P) >> 32, so we need to subtract and divide by 2. Luckily NEON has an instruction + // for that! The lowest bit of `c_hi` and `qp_hi` is the same, so the division is exact. + aarch64::vhsubq_s32(c_hi, qp_hi) + } +} + +#[inline] +#[must_use] +fn get_reduced_d(c_hi: int32x4_t, qp_hi: int32x4_t) -> uint32x4_t { + // We want this to compile to: + // shsub res.4s, c_hi.4s, qp_hi.4s + // cmgt underflow.4s, qp_hi.4s, c_hi.4s + // mls res.4s, underflow.4s, P.4s + // throughput: .75 cyc/vec (5.33 els/cyc) + // latency: 5 cyc + + unsafe { + let d = aarch64::vreinterpretq_u32_s32(get_d(c_hi, qp_hi)); + + // Finally, we reduce D to canonical form. D is negative iff `c_hi > qp_hi`, so if that's the + // case then we add P. Note that if `c_hi > qp_hi` then `underflow` is -1, so we must + // _subtract_ `underflow` * P. + let underflow = aarch64::vcltq_s32(c_hi, qp_hi); + aarch64::vmlsq_u32(d, confuse_compiler(underflow), MPNeon::PACKED_P) + } +} + +#[inline] +#[must_use] +fn mul(lhs: uint32x4_t, rhs: uint32x4_t) -> uint32x4_t { + // We want this to compile to: + // sqdmulh c_hi.4s, lhs.4s, rhs.4s + // mul mu_rhs.4s, rhs.4s, MU.4s + // mul q.4s, lhs.4s, mu_rhs.4s + // sqdmulh qp_hi.4s, q.4s, P.4s + // shsub res.4s, c_hi.4s, qp_hi.4s + // cmgt underflow.4s, qp_hi.4s, c_hi.4s + // mls res.4s, underflow.4s, P.4s + // throughput: 1.75 cyc/vec (2.29 els/cyc) + // latency: (lhs->) 11 cyc, (rhs->) 14 cyc + + unsafe { + // No-op. The inputs are non-negative so we're free to interpret them as signed numbers. + let lhs = aarch64::vreinterpretq_s32_u32(lhs); + let rhs = aarch64::vreinterpretq_s32_u32(rhs); + + let mu_rhs = mulby_mu::(rhs); + let c_hi = get_c_hi(lhs, rhs); + let qp_hi = get_qp_hi::(lhs, mu_rhs); + get_reduced_d::(c_hi, qp_hi) + } +} + +#[inline] +#[must_use] +fn cube(val: uint32x4_t) -> uint32x4_t { + // throughput: 2.75 cyc/vec (1.45 els/cyc) + // latency: 22 cyc + + unsafe { + let val = aarch64::vreinterpretq_s32_u32(val); + let mu_val = mulby_mu::(val); + + let c_hi_2 = get_c_hi(val, val); + let qp_hi_2 = get_qp_hi::(val, mu_val); + let val_2 = get_d(c_hi_2, qp_hi_2); + + let c_hi_3 = get_c_hi(val_2, val); + let qp_hi_3 = get_qp_hi::(val_2, mu_val); + get_reduced_d::(c_hi_3, qp_hi_3) + } +} + +/// Negate a vector of Monty31 field elements in canonical form. +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn neg(val: uint32x4_t) -> uint32x4_t { + // We want this to compile to: + // sub t.4s, P.4s, val.4s + // cmeq is_zero.4s, val.4s, #0 + // bic res.4s, t.4s, is_zero.4s + // throughput: .75 cyc/vec (5.33 els/cyc) + // latency: 4 cyc + + // This has the same throughput as `sub(0, val)` but slightly lower latency. + + // We want to return (-val) mod P. This is equivalent to returning `0` if `val = 0` and + // `P - val` otherwise, since `val` is in `0, ..., P - 1`. + // Let `t := P - val` and let `is_zero := (-1) mod 2^32` if `val = 0` and `0` otherwise. + // We return `r := t & ~is_zero`, which is `t` if `val > 0` and `0` otherwise, as desired. + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + let t = aarch64::vsubq_u32(MPNeon::PACKED_P, val); + let is_zero = aarch64::vceqzq_u32(val); + aarch64::vbicq_u32(t, is_zero) + } +} + +/// Subtract vectors of Monty31 field elements in canonical form. +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn sub(lhs: uint32x4_t, rhs: uint32x4_t) -> uint32x4_t { + // We want this to compile to: + // sub res.4s, lhs.4s, rhs.4s + // cmhi underflow.4s, rhs.4s, lhs.4s + // mls res.4s, underflow.4s, P.4s + // throughput: .75 cyc/vec (5.33 els/cyc) + // latency: 5 cyc + + // Let `d := lhs - rhs`. We want to return `d mod P`. + // Since `lhs` and `rhs` are both in `0, ..., P - 1`, `d` is in `-P + 1, ..., P - 1`. It + // suffices to return `d + P` if `d < 0` and `d` otherwise. + // Equivalently, we return `d + P` if `rhs > lhs` and `d` otherwise. Observe that this + // permits us to perform all calculations `mod 2^32`, so define `diff := d mod 2^32`. + // Let `underflow` be `-1 mod 2^32` if `rhs > lhs` and `0` otherwise. + // Finally, let `r := (diff - underflow * P) mod 2^32` and observe that + // `r = (diff + P) mod 2^32` if `rhs > lhs` and `diff` otherwise, as desired. + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + let diff = aarch64::vsubq_u32(lhs, rhs); + let underflow = aarch64::vcltq_u32(lhs, rhs); + // We really want to emit a `mls` instruction here. The compiler knows that `underflow` is + // either 0 or -1 and will try to do an `and` and `add` instead, which is slower on the M1. + // The `confuse_compiler` prevents this "optimization". + aarch64::vmlsq_u32(diff, confuse_compiler(underflow), MPNeon::PACKED_P) + } +} + +impl From> for PackedMontyField31Neon { + #[inline] + fn from(value: MontyField31) -> Self { + Self::broadcast(value) + } +} + +impl Default for PackedMontyField31Neon { + #[inline] + fn default() -> Self { + MontyField31::::default().into() + } +} + +impl AddAssign for PackedMontyField31Neon { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} + +impl MulAssign for PackedMontyField31Neon { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} + +impl SubAssign for PackedMontyField31Neon { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} + +impl Sum for PackedMontyField31Neon { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs + rhs).unwrap_or(Self::ZERO) + } +} + +impl Product for PackedMontyField31Neon { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs * rhs).unwrap_or(Self::ONE) + } +} + +impl PrimeCharacteristicRing for PackedMontyField31Neon { + type PrimeSubfield = MontyField31; + + const ZERO: Self = Self::broadcast(MontyField31::ZERO); + const ONE: Self = Self::broadcast(MontyField31::ONE); + const TWO: Self = Self::broadcast(MontyField31::TWO); + const NEG_ONE: Self = Self::broadcast(MontyField31::NEG_ONE); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f.into() + } + + #[inline] + fn cube(&self) -> Self { + let val = self.to_vector(); + let res = cube::(val); + unsafe { + // Safety: `cube` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } + + #[inline(always)] + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(MontyField31::::zero_vec(len * WIDTH)) } + } +} + +impl Algebra> for PackedMontyField31Neon {} + +impl, const D: u64> InjectiveMonomial + for PackedMontyField31Neon +{ +} + +impl, const D: u64> PermutationMonomial + for PackedMontyField31Neon +{ + fn injective_exp_root_n(&self) -> Self { + FP::exp_root_d(*self) + } +} + +impl Add> for PackedMontyField31Neon { + type Output = Self; + #[inline] + fn add(self, rhs: MontyField31) -> Self { + self + Self::from(rhs) + } +} + +impl Mul> for PackedMontyField31Neon { + type Output = Self; + #[inline] + fn mul(self, rhs: MontyField31) -> Self { + self * Self::from(rhs) + } +} + +impl Sub> for PackedMontyField31Neon { + type Output = Self; + #[inline] + fn sub(self, rhs: MontyField31) -> Self { + self - Self::from(rhs) + } +} + +impl AddAssign> for PackedMontyField31Neon { + #[inline] + fn add_assign(&mut self, rhs: MontyField31) { + *self += Self::from(rhs) + } +} + +impl MulAssign> for PackedMontyField31Neon { + #[inline] + fn mul_assign(&mut self, rhs: MontyField31) { + *self *= Self::from(rhs) + } +} + +impl SubAssign> for PackedMontyField31Neon { + #[inline] + fn sub_assign(&mut self, rhs: MontyField31) { + *self -= Self::from(rhs) + } +} + +impl Sum> for PackedMontyField31Neon { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator>, + { + iter.sum::>().into() + } +} + +impl Product> for PackedMontyField31Neon { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator>, + { + iter.product::>().into() + } +} + +impl Div> for PackedMontyField31Neon { + type Output = Self; + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: MontyField31) -> Self { + self * rhs.inverse() + } +} + +impl Add> for MontyField31 { + type Output = PackedMontyField31Neon; + #[inline] + fn add(self, rhs: PackedMontyField31Neon) -> PackedMontyField31Neon { + PackedMontyField31Neon::::from(self) + rhs + } +} + +impl Mul> for MontyField31 { + type Output = PackedMontyField31Neon; + #[inline] + fn mul(self, rhs: PackedMontyField31Neon) -> PackedMontyField31Neon { + PackedMontyField31Neon::::from(self) * rhs + } +} + +impl Sub> for MontyField31 { + type Output = PackedMontyField31Neon; + #[inline] + fn sub(self, rhs: PackedMontyField31Neon) -> PackedMontyField31Neon { + PackedMontyField31Neon::::from(self) - rhs + } +} + +impl Distribution> for StandardUniform { + #[inline] + fn sample(&self, rng: &mut R) -> PackedMontyField31Neon { + PackedMontyField31Neon::(rng.random()) + } +} + +#[inline] +#[must_use] +fn interleave1(v0: uint32x4_t, v1: uint32x4_t) -> (uint32x4_t, uint32x4_t) { + // We want this to compile to: + // trn1 res0.4s, v0.4s, v1.4s + // trn2 res1.4s, v0.4s, v1.4s + // throughput: .5 cyc/2 vec (16 els/cyc) + // latency: 2 cyc + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + (aarch64::vtrn1q_u32(v0, v1), aarch64::vtrn2q_u32(v0, v1)) + } +} + +#[inline] +#[must_use] +fn interleave2(v0: uint32x4_t, v1: uint32x4_t) -> (uint32x4_t, uint32x4_t) { + // We want this to compile to: + // trn1 res0.2d, v0.2d, v1.2d + // trn2 res1.2d, v0.2d, v1.2d + // throughput: .5 cyc/2 vec (16 els/cyc) + // latency: 2 cyc + + // To transpose 64-bit blocks, cast the [u32; 4] vectors to [u64; 2], transpose, and cast back. + unsafe { + // Safety: If this code got compiled then NEON intrinsics are available. + let v0 = aarch64::vreinterpretq_u64_u32(v0); + let v1 = aarch64::vreinterpretq_u64_u32(v1); + ( + aarch64::vreinterpretq_u32_u64(aarch64::vtrn1q_u64(v0, v1)), + aarch64::vreinterpretq_u32_u64(aarch64::vtrn2q_u64(v0, v1)), + ) + } +} + +unsafe impl PackedValue for PackedMontyField31Neon { + type Value = MontyField31; + const WIDTH: usize = WIDTH; + + #[inline] + fn from_slice(slice: &[MontyField31]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[MontyField31; WIDTH]` can be transmuted to `PackedMontyField31Neon` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast is + // safe too. + &*slice.as_ptr().cast() + } + } + #[inline] + fn from_slice_mut(slice: &mut [MontyField31]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[MontyField31; WIDTH]` can be transmuted to `PackedMontyField31Neon` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast is + // safe too. + &mut *slice.as_mut_ptr().cast() + } + } + + /// Similar to `core:array::from_fn`. + #[inline] + fn from_fn MontyField31>(f: F) -> Self { + let vals_arr: [_; WIDTH] = core::array::from_fn(f); + Self(vals_arr) + } + + #[inline] + fn as_slice(&self) -> &[MontyField31] { + &self.0[..] + } + #[inline] + fn as_slice_mut(&mut self) -> &mut [MontyField31] { + &mut self.0[..] + } +} + +unsafe impl PackedField for PackedMontyField31Neon { + type Scalar = MontyField31; +} + +unsafe impl PackedFieldPow2 for PackedMontyField31Neon { + #[inline] + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { + let (v0, v1) = (self.to_vector(), other.to_vector()); + let (res0, res1) = match block_len { + 1 => interleave1(v0, v1), + 2 => interleave2(v0, v1), + 4 => (v0, v1), + _ => panic!("unsupported block_len"), + }; + unsafe { + // Safety: all values are in canonical form (we haven't changed them). + (Self::from_vector(res0), Self::from_vector(res1)) + } + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/aarch64_neon/poseidon2.rs b/CoqOfRust/plonky3/monty-31/src/aarch64_neon/poseidon2.rs new file mode 100644 index 000000000..0a800a709 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/aarch64_neon/poseidon2.rs @@ -0,0 +1,101 @@ +//! Eventually this will hold a Vectorized Neon implementation of Poseidon2 for MontyField31 +//! Currently this is essentially a placeholder to allow compilation on Neon devices. +//! +//! Converting the AVX2/AVX512 code across to Neon is on the TODO list. + +use alloc::vec::Vec; +use core::marker::PhantomData; + +use p3_poseidon2::{ + ExternalLayer, ExternalLayerConstants, ExternalLayerConstructor, InternalLayer, + InternalLayerConstructor, MDSMat4, add_rc_and_sbox_generic, external_initial_permute_state, + external_terminal_permute_state, +}; + +use crate::{ + FieldParameters, InternalLayerBaseParameters, MontyField31, MontyParameters, + PackedMontyField31Neon, RelativelyPrimePower, +}; + +/// The internal layers of the Poseidon2 permutation for Monty31 fields. +/// +/// This is currently not optimized for the Neon architecture but this is on the TODO list. +#[derive(Debug, Clone)] +pub struct Poseidon2InternalLayerMonty31< + MP: MontyParameters, + const WIDTH: usize, + ILP: InternalLayerBaseParameters, +> { + pub(crate) internal_constants: Vec>, + _phantom: PhantomData, +} + +/// The external layers of the Poseidon2 permutation for Monty31 fields. +/// +/// This is currently not optimized for the Neon architecture but this is on the TODO list. +#[derive(Debug, Clone)] +pub struct Poseidon2ExternalLayerMonty31 { + pub(crate) external_constants: ExternalLayerConstants, WIDTH>, +} + +impl> + InternalLayerConstructor> for Poseidon2InternalLayerMonty31 +{ + fn new_from_constants(internal_constants: Vec>) -> Self { + Self { + internal_constants, + _phantom: PhantomData, + } + } +} + +impl ExternalLayerConstructor, WIDTH> + for Poseidon2ExternalLayerMonty31 +{ + fn new_from_constants( + external_constants: ExternalLayerConstants, WIDTH>, + ) -> Self { + Self { external_constants } + } +} + +impl InternalLayer, WIDTH, D> + for Poseidon2InternalLayerMonty31 +where + FP: FieldParameters + RelativelyPrimePower, + ILP: InternalLayerBaseParameters, +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [PackedMontyField31Neon; WIDTH]) { + self.internal_constants.iter().for_each(|&rc| { + add_rc_and_sbox_generic(&mut state[0], rc); + ILP::generic_internal_linear_layer(state); + }) + } +} + +impl ExternalLayer, WIDTH, D> + for Poseidon2ExternalLayerMonty31 +where + FP: FieldParameters + RelativelyPrimePower, +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [PackedMontyField31Neon; WIDTH]) { + external_initial_permute_state( + state, + self.external_constants.get_initial_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [PackedMontyField31Neon; WIDTH]) { + external_terminal_permute_state( + state, + self.external_constants.get_terminal_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/data_traits.rs b/CoqOfRust/plonky3/monty-31/src/data_traits.rs new file mode 100644 index 000000000..88bfa1323 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/data_traits.rs @@ -0,0 +1,143 @@ +use core::fmt::Debug; +use core::hash::Hash; + +use p3_field::{Field, PrimeCharacteristicRing}; + +use crate::MontyField31; + +/// MontyParameters contains the prime P along with constants needed to convert elements into and out of MONTY form. +/// The MONTY constant is assumed to be a power of 2. +pub trait MontyParameters: + Copy + Clone + Default + Debug + Eq + PartialEq + Sync + Send + Hash + 'static +{ + // A 31-bit prime. + const PRIME: u32; + + // The log_2 of our MONTY constant. + const MONTY_BITS: u32; + + // We define MONTY_MU = PRIME^-1 (mod 2^MONTY_BITS). This is different from the usual convention + // (MONTY_MU = -PRIME^-1 (mod 2^MONTY_BITS)) but it avoids a carry. + const MONTY_MU: u32; + + const MONTY_MASK: u32 = ((1u64 << Self::MONTY_BITS) - 1) as u32; +} + +/// PackedMontyParameters contains constants needed for MONTY operations for packings of Monty31 fields. +#[cfg(all(target_arch = "aarch64", target_feature = "neon"))] +pub trait PackedMontyParameters: crate::MontyParametersNeon + MontyParameters {} +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +/// PackedMontyParameters contains constants needed for MONTY operations for packings of Monty31 fields. +pub trait PackedMontyParameters: crate::MontyParametersAVX2 + MontyParameters {} +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +/// PackedMontyParameters contains constants needed for MONTY operations for packings of Monty31 fields. +pub trait PackedMontyParameters: crate::MontyParametersAVX512 + MontyParameters {} +#[cfg(not(any( + all(target_arch = "aarch64", target_feature = "neon"), + all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) + ), + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), +)))] +/// PackedMontyParameters contains constants needed for MONTY operations for packings of Monty31 fields. +pub trait PackedMontyParameters: MontyParameters {} + +/// BarrettParameters contains constants needed for the Barrett reduction used in the MDS code. +pub trait BarrettParameters: MontyParameters { + const N: usize = 40; // beta = 2^N, fixing N = 40 here + const PRIME_I128: i128 = Self::PRIME as i128; + const PSEUDO_INV: i64 = (((1_i128) << (2 * Self::N)) / Self::PRIME_I128) as i64; // I = 2^80 / P => I < 2**50 + const MASK: i64 = !((1 << 10) - 1); // Lets us 0 out the bottom 10 digits of an i64. +} + +/// FieldParameters contains constants and methods needed to imply PrimeCharacteristicRing, Field and PrimeField32 for MontyField31. +pub trait FieldParameters: PackedMontyParameters + Sized { + // Simple field constants. + const MONTY_ZERO: MontyField31 = MontyField31::new(0); + const MONTY_ONE: MontyField31 = MontyField31::new(1); + const MONTY_TWO: MontyField31 = MontyField31::new(2); + const MONTY_NEG_ONE: MontyField31 = MontyField31::new(Self::PRIME - 1); + + // A generator of the fields multiplicative group. Needs to be given in Monty Form. + const MONTY_GEN: MontyField31; + + const HALF_P_PLUS_1: u32 = (Self::PRIME + 1) >> 1; + + fn try_inverse(p1: F) -> Option; +} + +/// An integer `D` such that `gcd(D, p - 1) = 1`. +pub trait RelativelyPrimePower { + /// Compute `x -> x^{1/D}` using the modular inverse + /// of `D mod p - 1`. + fn exp_root_d(val: R) -> R; +} + +/// TwoAdicData contains constants needed to imply TwoAdicField for Monty31 fields. +pub trait TwoAdicData: MontyParameters { + /// Largest n such that 2^n divides p - 1. + const TWO_ADICITY: usize; + + /// The odd constant r such that p = r * 2^n + 1 + const ODD_FACTOR: i32 = (Self::PRIME >> Self::TWO_ADICITY) as i32; + + /// ArrayLike should usually be `&'static [MontyField31]`. + type ArrayLike: AsRef<[MontyField31]> + Sized; + + /// A list of generators of 2-adic subgroups. + /// The i'th element must be a 2^i root of unity and the i'th element squared must be the i-1'th element. + const TWO_ADIC_GENERATORS: Self::ArrayLike; + + /// Precomputation of the first 3 8th-roots of unity. + /// + /// Must agree with the 8th-root in TWO_ADIC_GENERATORS, i.e. + /// ROOTS_8[1] == TWO_ADIC_GENERATORS[3] + const ROOTS_8: Self::ArrayLike; + + /// Precomputation of the inverses of ROOTS_8. + const INV_ROOTS_8: Self::ArrayLike; + + /// Precomputation of the first 7 16th-roots of unity. + /// + /// Must agree with the 16th-root in TWO_ADIC_GENERATORS, i.e. + /// ROOTS_16[1] == TWO_ADIC_GENERATORS[4] + const ROOTS_16: Self::ArrayLike; + + /// Precomputation of the inverses of ROOTS_16. + const INV_ROOTS_16: Self::ArrayLike; +} + +/// TODO: This should be deleted long term once we have improved our API for defining extension fields. +/// This allows us to implement Binomial Extensions over Monty31 fields. +pub trait BinomialExtensionData: MontyParameters + Sized { + /// W is a value such that (x^DEG - W) is irreducible. + const W: MontyField31; + + /// DTH_ROOT = W^((p - 1)/DEG) + const DTH_ROOT: MontyField31; + + /// A generator of the extension fields multiplicative group. + const EXT_GENERATOR: [MontyField31; DEG]; + + const EXT_TWO_ADICITY: usize; + + /// ArrayLike should usually be [MontyField31; EXT_TWO_ADICITY - TWO_ADICITY]. + type ArrayLike: AsRef<[[MontyField31; DEG]]> + Sized; + + /// A list of generators of 2-adic subgroups not contained in the base field. + const TWO_ADIC_EXTENSION_GENERATORS: Self::ArrayLike; +} diff --git a/CoqOfRust/plonky3/monty-31/src/data_traits.v b/CoqOfRust/plonky3/monty-31/src/data_traits.v new file mode 100644 index 000000000..95acabf23 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/data_traits.v @@ -0,0 +1,25 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module data_traits. + (* Trait *) + (* Empty module 'MontyParameters' *) + + (* Trait *) + (* Empty module 'PackedMontyParameters' *) + + (* Trait *) + (* Empty module 'BarrettParameters' *) + + (* Trait *) + (* Empty module 'FieldParameters' *) + + (* Trait *) + (* Empty module 'RelativelyPrimePower' *) + + (* Trait *) + (* Empty module 'TwoAdicData' *) + + (* Trait *) + (* Empty module 'BinomialExtensionData' *) +End data_traits. diff --git a/CoqOfRust/plonky3/monty-31/src/dft/backward.rs b/CoqOfRust/plonky3/monty-31/src/dft/backward.rs new file mode 100644 index 000000000..d49f85442 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/dft/backward.rs @@ -0,0 +1,308 @@ +//! Discrete Fourier Transform, in-place, decimation-in-time +//! +//! Straightforward recursive algorithm, "unrolled" up to size 256. +//! +//! Inspired by Bernstein's djbfft: https://cr.yp.to/djbfft.html + +extern crate alloc; +use alloc::vec::Vec; + +use itertools::izip; +use p3_field::{Field, PackedFieldPow2, PackedValue, PrimeCharacteristicRing}; +use p3_util::log2_strict_usize; + +use crate::utils::monty_reduce; +use crate::{FieldParameters, MontyField31, TwoAdicData}; + +#[inline(always)] +fn backward_butterfly(x: T, y: T, roots: T) -> (T, T) { + let t = y * roots; + (x + t, x - t) +} + +#[inline(always)] +fn backward_butterfly_interleaved( + x: T, + y: T, + roots: T, +) -> (T, T) { + let (x, y) = x.interleave(y, HALF_RADIX); + let (x, y) = backward_butterfly(x, y, roots); + x.interleave(y, HALF_RADIX) +} + +#[inline] +fn backward_pass_packed(input: &mut [T], roots: &[T::Scalar]) { + let packed_roots = T::pack_slice(roots); + let n = input.len(); + let (xs, ys) = unsafe { input.split_at_mut_unchecked(n / 2) }; + + izip!(xs, ys, packed_roots) + .for_each(|(x, y, &roots)| (*x, *y) = backward_butterfly(*x, *y, roots)); +} + +#[inline] +fn backward_iterative_layer_1(input: &mut [T], roots: &[T::Scalar]) { + let packed_roots = T::pack_slice(roots); + let n = input.len(); + let (top_half, bottom_half) = unsafe { input.split_at_mut_unchecked(n / 2) }; + let (xs, ys) = unsafe { top_half.split_at_mut_unchecked(n / 4) }; + let (zs, ws) = unsafe { bottom_half.split_at_mut_unchecked(n / 4) }; + + izip!(xs, ys, zs, ws, packed_roots).for_each(|(x, y, z, w, &root)| { + (*x, *y) = backward_butterfly(*x, *y, root); + (*z, *w) = backward_butterfly(*z, *w, root); + }); +} + +#[inline] +fn backward_iterative_packed( + input: &mut [T], + roots: &[T::Scalar], +) { + // roots[0] == 1 + // roots <-- [1, roots[1], ..., roots[HALF_RADIX-1], 1, roots[1], ...] + let roots = T::from_fn(|i| roots[i % HALF_RADIX]); + + input.chunks_exact_mut(2).for_each(|pair| { + let (x, y) = backward_butterfly_interleaved::(pair[0], pair[1], roots); + pair[0] = x; + pair[1] = y; + }); +} + +#[inline] +fn backward_iterative_packed_radix_2(input: &mut [T]) { + input.chunks_exact_mut(2).for_each(|pair| { + let x = pair[0]; + let y = pair[1]; + let (mut x, y) = x.interleave(y, 1); + let t = x - y; // roots[0] == 1 + x += y; + let (x, y) = x.interleave(t, 1); + pair[0] = x; + pair[1] = y; + }); +} + +impl MontyField31 { + /// Breadth-first DIT FFT for smallish vectors (must be >= 64) + #[inline] + fn backward_iterative_layer( + packed_input: &mut [::Packing], + roots: &[Self], + m: usize, + ) { + debug_assert_eq!(roots.len(), m); + let packed_roots = ::Packing::pack_slice(roots); + + // lg_m >= 4, so m = 2^lg_m >= 2^4, hence packing_width divides m + let packed_m = m / ::Packing::WIDTH; + packed_input + .chunks_exact_mut(2 * packed_m) + .for_each(|layer_chunk| { + let (xs, ys) = unsafe { layer_chunk.split_at_mut_unchecked(packed_m) }; + + izip!(xs, ys, packed_roots) + .for_each(|(x, y, &root)| (*x, *y) = backward_butterfly(*x, *y, root)); + }); + } + + #[inline] + fn backward_iterative_packed_radix_16(input: &mut [::Packing]) { + // Rather surprisingly, a version similar where the separate + // loops in each call to backward_iterative_packed() are + // combined into one, was not only not faster, but was + // actually a bit slower. + + // Radix 2 + backward_iterative_packed_radix_2(input); + + // Radix 4 + let roots4 = [MP::INV_ROOTS_8.as_ref()[0], MP::INV_ROOTS_8.as_ref()[2]]; + if ::Packing::WIDTH >= 4 { + backward_iterative_packed::<2, _>(input, &roots4); + } else { + Self::backward_iterative_layer(input, &roots4, 2); + } + + // Radix 8 + if ::Packing::WIDTH >= 8 { + backward_iterative_packed::<4, _>(input, MP::INV_ROOTS_8.as_ref()); + } else { + Self::backward_iterative_layer(input, MP::INV_ROOTS_8.as_ref(), 4); + } + + // Radix 16 + if ::Packing::WIDTH >= 16 { + backward_iterative_packed::<8, _>(input, MP::INV_ROOTS_16.as_ref()); + } else { + Self::backward_iterative_layer(input, MP::INV_ROOTS_16.as_ref(), 8); + } + } + + fn backward_iterative(packed_input: &mut [::Packing], root_table: &[Vec]) { + assert!(packed_input.len() >= 2); + let packing_width = ::Packing::WIDTH; + let n = packed_input.len() * packing_width; + let lg_n = log2_strict_usize(n); + + // Start loop after doing radix 16 separately. This value is determined by the largest + // packing width we will encounter, which is 16 at the moment for AVX512. Specifically + // it is log_2(max{possible packing widths}) = lg(16) = 4. + const FIRST_LOOP_LAYER: usize = 4; + + // How many layers have we specialised after the main loop + const NUM_SPECIALISATIONS: usize = 2; + + // Needed to avoid overlap of the 2 specialisations at the start + // with the radix-16 specialisation at the end of the loop + assert!(lg_n >= FIRST_LOOP_LAYER + NUM_SPECIALISATIONS); + + Self::backward_iterative_packed_radix_16(packed_input); + + for lg_m in FIRST_LOOP_LAYER..(lg_n - NUM_SPECIALISATIONS) { + let s = lg_n - lg_m - 1; + let m = 1 << lg_m; + + let roots = &root_table[s]; + debug_assert_eq!(roots.len(), m); + + Self::backward_iterative_layer(packed_input, roots, m); + } + // Specialise the last few iterations; improves performance a little. + backward_iterative_layer_1(packed_input, &root_table[1]); // lg_m == lg_n - 2, s == 1 + backward_pass_packed(packed_input, &root_table[0]); // lg_m == lg_n - 1, s == 0 + } + + #[inline] + fn backward_pass(input: &mut [Self], roots: &[Self]) { + let half_n = input.len() / 2; + assert_eq!(roots.len(), half_n); + + // Safe because 0 <= half_n < input.len() + let (xs, ys) = unsafe { input.split_at_mut_unchecked(half_n) }; + + let s = xs[0] + ys[0]; + let t = xs[0] - ys[0]; + xs[0] = s; + ys[0] = t; + + izip!(&mut xs[1..], &mut ys[1..], &roots[1..]).for_each(|(x, y, &root)| { + (*x, *y) = backward_butterfly(*x, *y, root); + }); + } + + #[inline(always)] + fn backward_2(a: &mut [Self]) { + assert_eq!(a.len(), 2); + + let s = a[0] + a[1]; + let t = a[0] - a[1]; + a[0] = s; + a[1] = t; + } + + #[inline(always)] + fn backward_4(a: &mut [Self]) { + assert_eq!(a.len(), 4); + + // Read in bit-reversed order + let a0 = a[0]; + let a2 = a[1]; + let a1 = a[2]; + let a3 = a[3]; + + // Expanding the calculation of t3 saves one instruction + let t1 = MP::PRIME + a1.value - a3.value; + let t3 = Self::new_monty(monty_reduce::( + t1 as u64 * MP::INV_ROOTS_8.as_ref()[2].value as u64, + )); + let t5 = a1 + a3; + let t4 = a0 + a2; + let t2 = a0 - a2; + + a[0] = t4 + t5; + a[1] = t2 + t3; + a[2] = t4 - t5; + a[3] = t2 - t3; + } + + #[inline(always)] + fn backward_8(a: &mut [Self]) { + assert_eq!(a.len(), 8); + + // Safe because a.len() == 8 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::backward_4(a0); + Self::backward_4(a1); + + Self::backward_pass(a, MP::INV_ROOTS_8.as_ref()); + } + + #[inline(always)] + fn backward_16(a: &mut [Self]) { + assert_eq!(a.len(), 16); + + // Safe because a.len() == 16 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::backward_8(a0); + Self::backward_8(a1); + + Self::backward_pass(a, MP::INV_ROOTS_16.as_ref()); + } + + #[inline(always)] + fn backward_32(a: &mut [Self], root_table: &[Vec]) { + assert_eq!(a.len(), 32); + + // Safe because a.len() == 32 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::backward_16(a0); + Self::backward_16(a1); + + Self::backward_pass(a, &root_table[0]); + } + + /// Assumes `input.len() >= 64`. + /// current packing widths. + #[inline] + fn backward_fft_recur(input: &mut [::Packing], root_table: &[Vec]) { + const ITERATIVE_FFT_THRESHOLD: usize = 1024; + + let n = input.len() * ::Packing::WIDTH; + if n <= ITERATIVE_FFT_THRESHOLD { + Self::backward_iterative(input, root_table); + } else { + assert_eq!(n, 1 << (root_table.len() + 1)); + + // Safe because input.len() > ITERATIVE_FFT_THRESHOLD + let (a0, a1) = unsafe { input.split_at_mut_unchecked(input.len() / 2) }; + Self::backward_fft_recur(a0, &root_table[1..]); + Self::backward_fft_recur(a1, &root_table[1..]); + + backward_pass_packed(input, &root_table[0]); + } + } + + #[inline] + pub fn backward_fft(input: &mut [Self], root_table: &[Vec]) { + let n = input.len(); + if n == 1 { + return; + } + + assert_eq!(n, 1 << (root_table.len() + 1)); + match n { + 32 => Self::backward_32(input, root_table), + 16 => Self::backward_16(input), + 8 => Self::backward_8(input), + 4 => Self::backward_4(input), + 2 => Self::backward_2(input), + _ => { + let packed_input = ::Packing::pack_slice_mut(input); + Self::backward_fft_recur(packed_input, root_table) + } + } + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/dft/backward.v b/CoqOfRust/plonky3/monty-31/src/dft/backward.v new file mode 100644 index 000000000..c1b6a3487 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/dft/backward.v @@ -0,0 +1,9717 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module dft. + Module backward. + (* + fn backward_butterfly(x: T, y: T, roots: T) -> (T, T) { + let t = y * roots; + (x + t, x - t) + } + *) + Definition backward_butterfly (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ x; y; roots ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + let roots := M.alloc (| roots |) in + M.read (| + let~ t : Ty.apply (Ty.path "*") [] [ T ] := + M.alloc (| + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Mul", T, [], [ T ], "mul", [], [] |), + [ M.read (| y |); M.read (| roots |) ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Add", T, [], [ T ], "add", [], [] |), + [ M.read (| x |); M.read (| t |) ] + |); + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Sub", T, [], [ T ], "sub", [], [] |), + [ M.read (| x |); M.read (| t |) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_backward_butterfly : + M.IsFunction.C "p3_monty_31::dft::backward::backward_butterfly" backward_butterfly. + Admitted. + Global Typeclasses Opaque backward_butterfly. + + (* + fn backward_butterfly_interleaved( + x: T, + y: T, + roots: T, + ) -> (T, T) { + let (x, y) = x.interleave(y, HALF_RADIX); + let (x, y) = backward_butterfly(x, y, roots); + x.interleave(y, HALF_RADIX) + } + *) + Definition backward_butterfly_interleaved + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ HALF_RADIX ], [ T ], [ x; y; roots ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + let roots := M.alloc (| roots |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [ T; T ] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_trait_method (| + "p3_field::packed::PackedFieldPow2", + T, + [], + [], + "interleave", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); M.read (| y |); HALF_RADIX ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [ T; T ] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_function (| + "p3_monty_31::dft::backward::backward_butterfly", + [], + [ T ] + |), + [ M.read (| x |); M.read (| y |); M.read (| roots |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_trait_method (| + "p3_field::packed::PackedFieldPow2", + T, + [], + [], + "interleave", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); M.read (| y |); HALF_RADIX ] + |) + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_backward_butterfly_interleaved : + M.IsFunction.C + "p3_monty_31::dft::backward::backward_butterfly_interleaved" + backward_butterfly_interleaved. + Admitted. + Global Typeclasses Opaque backward_butterfly_interleaved. + + (* + fn backward_pass_packed(input: &mut [T], roots: &[T::Scalar]) { + let packed_roots = T::pack_slice(roots); + let n = input.len(); + let (xs, ys) = unsafe { input.split_at_mut_unchecked(n / 2) }; + + izip!(xs, ys, packed_roots) + .for_each(|(x, y, &roots)| ( *x, *y) = backward_butterfly( *x, *y, roots)); + } + *) + Definition backward_pass_packed (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ input; roots ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let roots := M.alloc (| roots |) in + M.read (| + let~ packed_roots : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + T, + [], + [], + "pack_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| roots |) |) |) ] + |) + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| n |); Value.Integer IntegerKind.Usize 2 ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let xs := M.copy (| γ0_0 |) in + let ys := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| xs |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| ys |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| packed_roots |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := M.copy (| γ1_0 |) in + let b := M.copy (| γ1_1 |) in + let b := M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let γ0_2 := M.read (| γ0_2 |) in + let roots := M.copy (| γ0_2 |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_function (| + "p3_monty_31::dft::backward::backward_butterfly", + [], + [ T ] + |), + [ + M.read (| M.deref (| M.read (| x |) |) |); + M.read (| M.deref (| M.read (| y |) |) |); + M.read (| roots |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let lhs := M.copy (| γ0_0 |) in + let lhs := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| x |) |), + M.read (| lhs |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| y |) |), + M.read (| lhs |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_backward_pass_packed : + M.IsFunction.C "p3_monty_31::dft::backward::backward_pass_packed" backward_pass_packed. + Admitted. + Global Typeclasses Opaque backward_pass_packed. + + (* + fn backward_iterative_layer_1(input: &mut [T], roots: &[T::Scalar]) { + let packed_roots = T::pack_slice(roots); + let n = input.len(); + let (top_half, bottom_half) = unsafe { input.split_at_mut_unchecked(n / 2) }; + let (xs, ys) = unsafe { top_half.split_at_mut_unchecked(n / 4) }; + let (zs, ws) = unsafe { bottom_half.split_at_mut_unchecked(n / 4) }; + + izip!(xs, ys, zs, ws, packed_roots).for_each(|(x, y, z, w, &root)| { + ( *x, *y) = backward_butterfly( *x, *y, root); + ( *z, *w) = backward_butterfly( *z, *w, root); + }); + } + *) + Definition backward_iterative_layer_1 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ T ], [ input; roots ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let roots := M.alloc (| roots |) in + M.read (| + let~ packed_roots : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + T, + [], + [], + "pack_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| roots |) |) |) ] + |) + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| n |); Value.Integer IntegerKind.Usize 2 ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let top_half := M.copy (| γ0_0 |) in + let bottom_half := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| top_half |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| n |); Value.Integer IntegerKind.Usize 4 ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let xs := M.copy (| γ0_0 |) in + let ys := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| bottom_half |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| n |); Value.Integer IntegerKind.Usize 4 ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let zs := M.copy (| γ0_0 |) in + let ws := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply (Ty.path "&mut") [] [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| xs |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| ys |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| zs |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| ws |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| packed_roots |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ T ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ T ]; + Ty.apply + (Ty.path + "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&") + [] + [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&") + [] + [ T ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ1_0, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ1_0, + 1 + |) in + let γ3_0 := + M.SubPointer.get_tuple_field (| + γ2_0, + 0 + |) in + let γ3_1 := + M.SubPointer.get_tuple_field (| + γ2_0, + 1 + |) in + let a := M.copy (| γ3_0 |) in + let b := M.copy (| γ3_1 |) in + let b := M.copy (| γ2_1 |) in + let b := M.copy (| γ1_1 |) in + let b := M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&") + [] + [ T ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let γ0_3 := + M.SubPointer.get_tuple_field (| + γ, + 3 + |) in + let γ0_4 := + M.SubPointer.get_tuple_field (| + γ, + 4 + |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let z := M.copy (| γ0_2 |) in + let w := M.copy (| γ0_3 |) in + let γ0_4 := M.read (| γ0_4 |) in + let root := M.copy (| γ0_4 |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_function (| + "p3_monty_31::dft::backward::backward_butterfly", + [], + [ T ] + |), + [ + M.read (| + M.deref (| + M.read (| x |) + |) + |); + M.read (| + M.deref (| + M.read (| y |) + |) + |); + M.read (| root |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lhs := + M.copy (| γ0_0 |) in + let lhs := + M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| x |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| y |) + |), + M.read (| lhs |) + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_function (| + "p3_monty_31::dft::backward::backward_butterfly", + [], + [ T ] + |), + [ + M.read (| + M.deref (| + M.read (| z |) + |) + |); + M.read (| + M.deref (| + M.read (| w |) + |) + |); + M.read (| root |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lhs := + M.copy (| γ0_0 |) in + let lhs := + M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| z |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| w |) + |), + M.read (| lhs |) + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_backward_iterative_layer_1 : + M.IsFunction.C + "p3_monty_31::dft::backward::backward_iterative_layer_1" + backward_iterative_layer_1. + Admitted. + Global Typeclasses Opaque backward_iterative_layer_1. + + (* + fn backward_iterative_packed( + input: &mut [T], + roots: &[T::Scalar], + ) { + // roots[0] == 1 + // roots <-- [1, roots[1], ..., roots[HALF_RADIX-1], 1, roots[1], ...] + let roots = T::from_fn(|i| roots[i % HALF_RADIX]); + + input.chunks_exact_mut(2).for_each(|pair| { + let (x, y) = backward_butterfly_interleaved::(pair[0], pair[1], roots); + pair[0] = x; + pair[1] = y; + }); + } + *) + Definition backward_iterative_packed + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ HALF_RADIX ], [ T ], [ input; roots ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let roots := M.alloc (| roots |) in + M.read (| + let~ roots : Ty.apply (Ty.path "*") [] [ T ] := + M.alloc (| + M.call_closure (| + T, + M.get_trait_method (| + "p3_field::packed::PackedValue", + T, + [], + [], + "from_fn", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait "p3_field::packed::PackedField" [] [] T "Scalar") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + T + "Scalar") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| roots |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| i |); HALF_RADIX ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ T ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + Value.Integer IntegerKind.Usize 2 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let pair_ := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_function (| + "p3_monty_31::dft::backward::backward_butterfly_interleaved", + [ HALF_RADIX ], + [ T ] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| roots |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| x |) + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| y |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_backward_iterative_packed : + M.IsFunction.C + "p3_monty_31::dft::backward::backward_iterative_packed" + backward_iterative_packed. + Admitted. + Global Typeclasses Opaque backward_iterative_packed. + + (* + fn backward_iterative_packed_radix_2(input: &mut [T]) { + input.chunks_exact_mut(2).for_each(|pair| { + let x = pair[0]; + let y = pair[1]; + let (mut x, y) = x.interleave(y, 1); + let t = x - y; // roots[0] == 1 + x += y; + let (x, y) = x.interleave(t, 1); + pair[0] = x; + pair[1] = y; + }); + } + *) + Definition backward_iterative_packed_radix_2 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ T ], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ T ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + Value.Integer IntegerKind.Usize 2 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let pair_ := M.copy (| γ |) in + M.read (| + let~ x : Ty.apply (Ty.path "*") [] [ T ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) in + let~ y : Ty.apply (Ty.path "*") [] [ T ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_trait_method (| + "p3_field::packed::PackedFieldPow2", + T, + [], + [], + "interleave", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.read (| y |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let~ t : Ty.apply (Ty.path "*") [] [ T ] := + M.alloc (| + M.call_closure (| + T, + M.get_trait_method (| + "core::ops::arith::Sub", + T, + [], + [ T ], + "sub", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + T, + [], + [ T ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, x |); + M.read (| y |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_trait_method (| + "p3_field::packed::PackedFieldPow2", + T, + [], + [], + "interleave", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.read (| t |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| x |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| y |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_backward_iterative_packed_radix_2 : + M.IsFunction.C + "p3_monty_31::dft::backward::backward_iterative_packed_radix_2" + backward_iterative_packed_radix_2. + Admitted. + Global Typeclasses Opaque backward_iterative_packed_radix_2. + + Module Impl_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]. + + (* + fn backward_iterative_layer( + packed_input: &mut [::Packing], + roots: &[Self], + m: usize, + ) { + debug_assert_eq!(roots.len(), m); + let packed_roots = ::Packing::pack_slice(roots); + + // lg_m >= 4, so m = 2^lg_m >= 2^4, hence packing_width divides m + let packed_m = m / ::Packing::WIDTH; + packed_input + .chunks_exact_mut(2 * packed_m) + .for_each(|layer_chunk| { + let (xs, ys) = unsafe { layer_chunk.split_at_mut_unchecked(packed_m) }; + + izip!(xs, ys, packed_roots) + .for_each(|(x, y, &root)| ( *x, *y) = backward_butterfly( *x, *y, root)); + }); + } + *) + Definition backward_iterative_layer + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ packed_input; roots; m ] => + ltac:(M.monadic + (let packed_input := M.alloc (| packed_input |) in + let roots := M.alloc (| roots |) in + let m := M.alloc (| m |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| roots |) |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, m |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ packed_roots : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [], + "pack_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| roots |) |) |) ] + |) + |) in + let~ packed_m : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.read (| m |); + M.read (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| packed_input |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| packed_m |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let layer_chunk := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| layer_chunk |) |) + |); + M.read (| packed_m |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let xs := M.copy (| γ0_0 |) in + let ys := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| xs |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| ys |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| packed_roots |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := + M.copy (| + γ1_0 + |) in + let b := + M.copy (| + γ1_1 + |) in + let b := + M.copy (| + γ0_1 + |) in + Value.Tuple + [ + M.read (| + a + |); + M.read (| + b + |); + M.read (| + b + |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let x := + M.copy (| γ0_0 |) in + let y := + M.copy (| γ0_1 |) in + let γ0_2 := + M.read (| γ0_2 |) in + let root := + M.copy (| γ0_2 |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_function (| + "p3_monty_31::dft::backward::backward_butterfly", + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.read (| + M.deref (| + M.read (| + x + |) + |) + |); + M.read (| + M.deref (| + M.read (| + y + |) + |) + |); + M.read (| + root + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lhs := + M.copy (| + γ0_0 + |) in + let lhs := + M.copy (| + γ0_1 + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| + x + |) + |), + M.read (| + lhs + |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| + y + |) + |), + M.read (| + lhs + |) + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_iterative_layer : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "backward_iterative_layer" (backward_iterative_layer MP). + Admitted. + Global Typeclasses Opaque backward_iterative_layer. + + (* + fn backward_iterative_packed_radix_16(input: &mut [::Packing]) { + // Rather surprisingly, a version similar where the separate + // loops in each call to backward_iterative_packed() are + // combined into one, was not only not faster, but was + // actually a bit slower. + + // Radix 2 + backward_iterative_packed_radix_2(input); + + // Radix 4 + let roots4 = [MP::INV_ROOTS_8.as_ref()[0], MP::INV_ROOTS_8.as_ref()[2]]; + if ::Packing::WIDTH >= 4 { + backward_iterative_packed::<2, _>(input, &roots4); + } else { + Self::backward_iterative_layer(input, &roots4, 2); + } + + // Radix 8 + if ::Packing::WIDTH >= 8 { + backward_iterative_packed::<4, _>(input, MP::INV_ROOTS_8.as_ref()); + } else { + Self::backward_iterative_layer(input, MP::INV_ROOTS_8.as_ref(), 4); + } + + // Radix 16 + if ::Packing::WIDTH >= 16 { + backward_iterative_packed::<8, _>(input, MP::INV_ROOTS_16.as_ref()); + } else { + Self::backward_iterative_layer(input, MP::INV_ROOTS_16.as_ref(), 8); + } + } + *) + Definition backward_iterative_packed_radix_16 + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::backward::backward_iterative_packed_radix_2", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) ] + |) + |) in + let~ roots4 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] := + M.alloc (| + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::INV_ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::INV_ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::backward::backward_iterative_packed", + [ Value.Integer IntegerKind.Usize 2 ], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, roots4 |) |) + |)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_iterative_layer", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, roots4 |) |) + |)); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |); + Value.Integer IntegerKind.Usize 8 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::backward::backward_iterative_packed", + [ Value.Integer IntegerKind.Usize 4 ], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::INV_ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_iterative_layer", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::INV_ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |); + Value.Integer IntegerKind.Usize 16 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::backward::backward_iterative_packed", + [ Value.Integer IntegerKind.Usize 8 ], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::INV_ROOTS_16", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_iterative_layer", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::INV_ROOTS_16", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |); + Value.Integer IntegerKind.Usize 8 + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_iterative_packed_radix_16 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C + (Self MP) + "backward_iterative_packed_radix_16" + (backward_iterative_packed_radix_16 MP). + Admitted. + Global Typeclasses Opaque backward_iterative_packed_radix_16. + + (* + fn backward_iterative(packed_input: &mut [::Packing], root_table: &[Vec]) { + assert!(packed_input.len() >= 2); + let packing_width = ::Packing::WIDTH; + let n = packed_input.len() * packing_width; + let lg_n = log2_strict_usize(n); + + // Start loop after doing radix 16 separately. This value is determined by the largest + // packing width we will encounter, which is 16 at the moment for AVX512. Specifically + // it is log_2(max{possible packing widths}) = lg(16) = 4. + const FIRST_LOOP_LAYER: usize = 4; + + // How many layers have we specialised after the main loop + const NUM_SPECIALISATIONS: usize = 2; + + // Needed to avoid overlap of the 2 specialisations at the start + // with the radix-16 specialisation at the end of the loop + assert!(lg_n >= FIRST_LOOP_LAYER + NUM_SPECIALISATIONS); + + Self::backward_iterative_packed_radix_16(packed_input); + + for lg_m in FIRST_LOOP_LAYER..(lg_n - NUM_SPECIALISATIONS) { + let s = lg_n - lg_m - 1; + let m = 1 << lg_m; + + let roots = &root_table[s]; + debug_assert_eq!(roots.len(), m); + + Self::backward_iterative_layer(packed_input, roots, m); + } + // Specialise the last few iterations; improves performance a little. + backward_iterative_layer_1(packed_input, &root_table[1]); // lg_m == lg_n - 2, s == 1 + backward_pass_packed(packed_input, &root_table[0]); // lg_m == lg_n - 1, s == 0 + } + *) + Definition backward_iterative + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ packed_input; root_table ] => + ltac:(M.monadic + (let packed_input := M.alloc (| packed_input |) in + let root_table := M.alloc (| root_table |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| packed_input |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: packed_input.len() >= 2" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ packing_width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| packed_input |) |) |) ] + |); + M.read (| packing_width |) + ] + |) + |) in + let~ lg_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| n |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| lg_n |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_monty_31::dft::backward::backward_iterative::FIRST_LOOP_LAYER", + Ty.path "usize" + |) + |); + M.read (| + get_constant (| + "p3_monty_31::dft::backward::backward_iterative::NUM_SPECIALISATIONS", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: lg_n >= FIRST_LOOP_LAYER + NUM_SPECIALISATIONS" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_iterative_packed_radix_16", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| packed_input |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.read (| + get_constant (| + "p3_monty_31::dft::backward::backward_iterative::FIRST_LOOP_LAYER", + Ty.path "usize" + |) + |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| lg_n |); + M.read (| + get_constant (| + "p3_monty_31::dft::backward::backward_iterative::NUM_SPECIALISATIONS", + Ty.path "usize" + |) + |) + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let lg_m := M.copy (| γ0_0 |) in + let~ s : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| lg_n |); M.read (| lg_m |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ m : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| lg_m |) + ] + |) + |) in + let~ roots : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| root_table |) |), + M.read (| s |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| roots |) + |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, m |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "backward_iterative_layer", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| packed_input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| roots |) |) + |) + ] + |) + |) + |); + M.read (| m |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::backward::backward_iterative_layer_1", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| packed_input |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| root_table |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::backward::backward_pass_packed", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| packed_input |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| root_table |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_iterative : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "backward_iterative" (backward_iterative MP). + Admitted. + Global Typeclasses Opaque backward_iterative. + + (* + fn backward_pass(input: &mut [Self], roots: &[Self]) { + let half_n = input.len() / 2; + assert_eq!(roots.len(), half_n); + + // Safe because 0 <= half_n < input.len() + let (xs, ys) = unsafe { input.split_at_mut_unchecked(half_n) }; + + let s = xs[0] + ys[0]; + let t = xs[0] - ys[0]; + xs[0] = s; + ys[0] = t; + + izip!(&mut xs[1..], &mut ys[1..], &roots[1..]).for_each(|(x, y, &root)| { + ( *x, *y) = backward_butterfly( *x, *y, root); + }); + } + *) + Definition backward_pass + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ input; roots ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let roots := M.alloc (| roots |) in + M.read (| + let~ half_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| roots |) |) |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, half_n |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.read (| half_n |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let xs := M.copy (| γ0_0 |) in + let ys := M.copy (| γ0_1 |) in + let~ s : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| xs |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| ys |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ t : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| xs |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| ys |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| xs |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| s |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| ys |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| t |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| xs |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| ys |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| roots |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := M.copy (| γ1_0 |) in + let b := M.copy (| γ1_1 |) in + let b := M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| γ, 2 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let γ0_2 := M.read (| γ0_2 |) in + let root := M.copy (| γ0_2 |) in + M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_function (| + "p3_monty_31::dft::backward::backward_butterfly", + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.read (| + M.deref (| M.read (| x |) |) + |); + M.read (| + M.deref (| M.read (| y |) |) + |); + M.read (| root |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lhs := M.copy (| γ0_0 |) in + let lhs := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| x |) |), + M.read (| lhs |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| y |) |), + M.read (| lhs |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_pass : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "backward_pass" (backward_pass MP). + Admitted. + Global Typeclasses Opaque backward_pass. + + (* + fn backward_2(a: &mut [Self]) { + assert_eq!(a.len(), 2); + + let s = a[0] + a[1]; + let t = a[0] - a[1]; + a[0] = s; + a[1] = t; + } + *) + Definition backward_2 (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 2 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ s : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ t : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| s |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| t |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_2 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "backward_2" (backward_2 MP). + Admitted. + Global Typeclasses Opaque backward_2. + + (* + fn backward_4(a: &mut [Self]) { + assert_eq!(a.len(), 4); + + // Read in bit-reversed order + let a0 = a[0]; + let a2 = a[1]; + let a1 = a[2]; + let a3 = a[3]; + + // Expanding the calculation of t3 saves one instruction + let t1 = MP::PRIME + a1.value - a3.value; + let t3 = Self::new_monty(monty_reduce::( + t1 as u64 * MP::INV_ROOTS_8.as_ref()[2].value as u64, + )); + let t5 = a1 + a3; + let t4 = a0 + a2; + let t2 = a0 - a2; + + a[0] = t4 + t5; + a[1] = t2 + t3; + a[2] = t4 - t5; + a[3] = t2 - t3; + } + *) + Definition backward_4 (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 4 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ a0 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) in + let~ a2 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) in + let~ a1 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) in + let~ a3 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) in + let~ t1 : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + a1, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + a3, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |) + |) in + let~ t3 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::monty_reduce", [], [ MP ] |), + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.cast (Ty.path "u64") (M.read (| t1 |)); + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::INV_ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 2 + |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |)) + ] + |) + ] + |) + ] + |) + |) in + let~ t5 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ M.read (| a1 |); M.read (| a3 |) ] + |) + |) in + let~ t4 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ M.read (| a0 |); M.read (| a2 |) ] + |) + |) in + let~ t2 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "sub", + [], + [] + |), + [ M.read (| a0 |); M.read (| a2 |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ M.read (| t4 |); M.read (| t5 |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ M.read (| t2 |); M.read (| t3 |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "sub", + [], + [] + |), + [ M.read (| t4 |); M.read (| t5 |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "sub", + [], + [] + |), + [ M.read (| t2 |); M.read (| t3 |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_4 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "backward_4" (backward_4 MP). + Admitted. + Global Typeclasses Opaque backward_4. + + (* + fn backward_8(a: &mut [Self]) { + assert_eq!(a.len(), 8); + + // Safe because a.len() == 8 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::backward_4(a0); + Self::backward_4(a1); + + Self::backward_pass(a, MP::INV_ROOTS_8.as_ref()); + } + *) + Definition backward_8 (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 8 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a0 := M.copy (| γ0_0 |) in + let a1 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_4", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a0 |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_4", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a1 |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_pass", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::INV_ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_8 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "backward_8" (backward_8 MP). + Admitted. + Global Typeclasses Opaque backward_8. + + (* + fn backward_16(a: &mut [Self]) { + assert_eq!(a.len(), 16); + + // Safe because a.len() == 16 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::backward_8(a0); + Self::backward_8(a1); + + Self::backward_pass(a, MP::INV_ROOTS_16.as_ref()); + } + *) + Definition backward_16 + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 16 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a0 := M.copy (| γ0_0 |) in + let a1 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_8", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a0 |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_8", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a1 |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_pass", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::INV_ROOTS_16", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_16 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "backward_16" (backward_16 MP). + Admitted. + Global Typeclasses Opaque backward_16. + + (* + fn backward_32(a: &mut [Self], root_table: &[Vec]) { + assert_eq!(a.len(), 32); + + // Safe because a.len() == 32 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::backward_16(a0); + Self::backward_16(a1); + + Self::backward_pass(a, &root_table[0]); + } + *) + Definition backward_32 + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ a; root_table ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let root_table := M.alloc (| root_table |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 32 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a0 := M.copy (| γ0_0 |) in + let a1 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_16", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a0 |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_16", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a1 |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_pass", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| root_table |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_32 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "backward_32" (backward_32 MP). + Admitted. + Global Typeclasses Opaque backward_32. + + (* + fn backward_fft_recur(input: &mut [::Packing], root_table: &[Vec]) { + const ITERATIVE_FFT_THRESHOLD: usize = 1024; + + let n = input.len() * ::Packing::WIDTH; + if n <= ITERATIVE_FFT_THRESHOLD { + Self::backward_iterative(input, root_table); + } else { + assert_eq!(n, 1 << (root_table.len() + 1)); + + // Safe because input.len() > ITERATIVE_FFT_THRESHOLD + let (a0, a1) = unsafe { input.split_at_mut_unchecked(input.len() / 2) }; + Self::backward_fft_recur(a0, &root_table[1..]); + Self::backward_fft_recur(a1, &root_table[1..]); + + backward_pass_packed(input, &root_table[0]); + } + } + *) + Definition backward_fft_recur + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ input; root_table ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let root_table := M.alloc (| root_table |) in + M.read (| + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |); + M.read (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| n |); + M.read (| + get_constant (| + "p3_monty_31::dft::backward::backward_fft_recur::ITERATIVE_FFT_THRESHOLD", + Ty.path "usize" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_iterative", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| root_table |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, n |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a0 := M.copy (| γ0_0 |) in + let a1 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "backward_fft_recur", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| a0 |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "backward_fft_recur", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| a1 |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::backward::backward_pass_packed", + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| root_table |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_fft_recur : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "backward_fft_recur" (backward_fft_recur MP). + Admitted. + Global Typeclasses Opaque backward_fft_recur. + + (* + pub fn backward_fft(input: &mut [Self], root_table: &[Vec]) { + let n = input.len(); + if n == 1 { + return; + } + + assert_eq!(n, 1 << (root_table.len() + 1)); + match n { + 32 => Self::backward_32(input, root_table), + 16 => Self::backward_16(input), + 8 => Self::backward_8(input), + 4 => Self::backward_4(input), + 2 => Self::backward_2(input), + _ => { + let packed_input = ::Packing::pack_slice_mut(input); + Self::backward_fft_recur(packed_input, root_table) + } + } + } + *) + Definition backward_fft + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ input; root_table ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let root_table := M.alloc (| root_table |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| n |); Value.Integer IntegerKind.Usize 1 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| Value.Tuple [] |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, n |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + n, + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 32 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_32", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 16 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_16", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 8 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_8", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 4 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_4", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ packed_input : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + [], + [], + "pack_slice_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "backward_fft_recur", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| packed_input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |) + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_backward_fft : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "backward_fft" (backward_fft MP). + Admitted. + Global Typeclasses Opaque backward_fft. + End Impl_p3_monty_31_monty_31_MontyField31_MP. + End backward. +End dft. diff --git a/CoqOfRust/plonky3/monty-31/src/dft/forward.rs b/CoqOfRust/plonky3/monty-31/src/dft/forward.rs new file mode 100644 index 000000000..c42d79e1a --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/dft/forward.rs @@ -0,0 +1,336 @@ +//! Discrete Fourier Transform, in-place, decimation-in-frequency +//! +//! Straightforward recursive algorithm, "unrolled" up to size 256. +//! +//! Inspired by Bernstein's djbfft: https://cr.yp.to/djbfft.html + +extern crate alloc; + +use alloc::vec::Vec; + +use itertools::izip; +use p3_field::{Field, PackedFieldPow2, PackedValue, PrimeCharacteristicRing, TwoAdicField}; +use p3_util::log2_strict_usize; + +use crate::utils::monty_reduce; +use crate::{FieldParameters, MontyField31, TwoAdicData}; + +impl MontyField31 { + /// Given a field element `gen` of order n where `n = 2^lg_n`, + /// return a vector of vectors `table` where table[i] is the + /// vector of twiddle factors for an fft of length n/2^i. The + /// values g_i^k for k >= i/2 are skipped as these are just the + /// negatives of the other roots (using g_i^{i/2} = -1). The + /// value gen^0 = 1 is included to aid consistency between the + /// packed and non-packed variants. + pub fn roots_of_unity_table(n: usize) -> Vec> { + let lg_n = log2_strict_usize(n); + let generator = Self::two_adic_generator(lg_n); + let half_n = 1 << (lg_n - 1); + // nth_roots = [1, g, g^2, g^3, ..., g^{n/2 - 1}] + let nth_roots: Vec<_> = generator.powers().take(half_n).collect(); + + (0..(lg_n - 1)) + .map(|i| nth_roots.iter().step_by(1 << i).copied().collect()) + .collect() + } +} + +#[inline(always)] +fn forward_butterfly(x: T, y: T, roots: T) -> (T, T) { + let t = x - y; + (x + y, t * roots) +} + +#[inline(always)] +fn forward_butterfly_interleaved( + x: T, + y: T, + roots: T, +) -> (T, T) { + let (x, y) = x.interleave(y, HALF_RADIX); + let (x, y) = forward_butterfly(x, y, roots); + x.interleave(y, HALF_RADIX) +} + +#[inline] +fn forward_pass_packed(input: &mut [T], roots: &[T::Scalar]) { + let packed_roots = T::pack_slice(roots); + let n = input.len(); + let (xs, ys) = unsafe { input.split_at_mut_unchecked(n / 2) }; + + izip!(xs, ys, packed_roots) + .for_each(|(x, y, &roots)| (*x, *y) = forward_butterfly(*x, *y, roots)); +} + +#[inline] +fn forward_iterative_layer_1(input: &mut [T], roots: &[T::Scalar]) { + let packed_roots = T::pack_slice(roots); + let n = input.len(); + let (top_half, bottom_half) = unsafe { input.split_at_mut_unchecked(n / 2) }; + let (xs, ys) = unsafe { top_half.split_at_mut_unchecked(n / 4) }; + let (zs, ws) = unsafe { bottom_half.split_at_mut_unchecked(n / 4) }; + + izip!(xs, ys, zs, ws, packed_roots).for_each(|(x, y, z, w, &root)| { + (*x, *y) = forward_butterfly(*x, *y, root); + (*z, *w) = forward_butterfly(*z, *w, root); + }); +} + +#[inline] +fn forward_iterative_packed( + input: &mut [T], + roots: &[T::Scalar], +) { + // roots[0] == 1 + // roots <-- [1, roots[1], ..., roots[HALF_RADIX-1], 1, roots[1], ...] + let roots = T::from_fn(|i| roots[i % HALF_RADIX]); + + input.chunks_exact_mut(2).for_each(|pair| { + let (x, y) = forward_butterfly_interleaved::(pair[0], pair[1], roots); + pair[0] = x; + pair[1] = y; + }); +} + +#[inline] +fn forward_iterative_packed_radix_2(input: &mut [T]) { + input.chunks_exact_mut(2).for_each(|pair| { + let x = pair[0]; + let y = pair[1]; + let (mut x, y) = x.interleave(y, 1); + let t = x - y; // roots[0] == 1 + x += y; + let (x, y) = x.interleave(t, 1); + pair[0] = x; + pair[1] = y; + }); +} + +impl MontyField31 { + #[inline] + fn forward_iterative_layer( + packed_input: &mut [::Packing], + roots: &[Self], + m: usize, + ) { + debug_assert_eq!(roots.len(), m); + let packed_roots = ::Packing::pack_slice(roots); + + // lg_m >= 4, so m = 2^lg_m >= 2^4, hence packing_width divides m + let packed_m = m / ::Packing::WIDTH; + packed_input + .chunks_exact_mut(2 * packed_m) + .for_each(|layer_chunk| { + let (xs, ys) = unsafe { layer_chunk.split_at_mut_unchecked(packed_m) }; + + izip!(xs, ys, packed_roots) + .for_each(|(x, y, &root)| (*x, *y) = forward_butterfly(*x, *y, root)); + }); + } + + #[inline] + fn forward_iterative_packed_radix_16(input: &mut [::Packing]) { + // Rather surprisingly, a version similar where the separate + // loops in each call to forward_iterative_packed() are + // combined into one, was not only not faster, but was + // actually a bit slower. + + // Radix 16 + if ::Packing::WIDTH >= 16 { + forward_iterative_packed::<8, _>(input, MP::ROOTS_16.as_ref()); + } else { + Self::forward_iterative_layer(input, MP::ROOTS_16.as_ref(), 8); + } + + // Radix 8 + if ::Packing::WIDTH >= 8 { + forward_iterative_packed::<4, _>(input, MP::ROOTS_8.as_ref()); + } else { + Self::forward_iterative_layer(input, MP::ROOTS_8.as_ref(), 4); + } + + // Radix 4 + let roots4 = [MP::ROOTS_8.as_ref()[0], MP::ROOTS_8.as_ref()[2]]; + if ::Packing::WIDTH >= 4 { + forward_iterative_packed::<2, _>(input, &roots4); + } else { + Self::forward_iterative_layer(input, &roots4, 2); + } + + // Radix 2 + forward_iterative_packed_radix_2(input); + } + + /// Breadth-first DIF FFT for smallish vectors (must be >= 64) + #[inline] + fn forward_iterative(packed_input: &mut [::Packing], root_table: &[Vec]) { + assert!(packed_input.len() >= 2); + let packing_width = ::Packing::WIDTH; + let n = packed_input.len() * packing_width; + let lg_n = log2_strict_usize(n); + + // Stop loop early to do radix 16 separately. This value is determined by the largest + // packing width we will encounter, which is 16 at the moment for AVX512. Specifically + // it is log_2(max{possible packing widths}) = lg(16) = 4. + const LAST_LOOP_LAYER: usize = 4; + + // How many layers have we specialised before the main loop + const NUM_SPECIALISATIONS: usize = 2; + + // Needed to avoid overlap of the 2 specialisations at the start + // with the radix-16 specialisation at the end of the loop + assert!(lg_n >= LAST_LOOP_LAYER + NUM_SPECIALISATIONS); + + // Specialise the first NUM_SPECIALISATIONS iterations; improves performance a little. + forward_pass_packed(packed_input, &root_table[0]); // lg_m == lg_n - 1, s == 0 + forward_iterative_layer_1(packed_input, &root_table[1]); // lg_m == lg_n - 2, s == 1 + + // loop from lg_n-2 down to 4. + for lg_m in (LAST_LOOP_LAYER..(lg_n - NUM_SPECIALISATIONS)).rev() { + let s = lg_n - lg_m - 1; + let m = 1 << lg_m; + + let roots = &root_table[s]; + debug_assert_eq!(roots.len(), m); + + Self::forward_iterative_layer(packed_input, roots, m); + } + + // Last 4 layers + Self::forward_iterative_packed_radix_16(packed_input); + } + + #[inline(always)] + fn forward_butterfly(x: Self, y: Self, w: Self) -> (Self, Self) { + let t = MP::PRIME + x.value - y.value; + ( + x + y, + Self::new_monty(monty_reduce::(t as u64 * w.value as u64)), + ) + } + + #[inline] + fn forward_pass(input: &mut [Self], roots: &[Self]) { + let half_n = input.len() / 2; + assert_eq!(roots.len(), half_n); + + // Safe because 0 <= half_n < a.len() + let (xs, ys) = unsafe { input.split_at_mut_unchecked(half_n) }; + + let s = xs[0] + ys[0]; + let t = xs[0] - ys[0]; + xs[0] = s; + ys[0] = t; + + izip!(&mut xs[1..], &mut ys[1..], &roots[1..]).for_each(|(x, y, &root)| { + (*x, *y) = Self::forward_butterfly(*x, *y, root); + }); + } + + #[inline(always)] + fn forward_2(a: &mut [Self]) { + assert_eq!(a.len(), 2); + + let s = a[0] + a[1]; + let t = a[0] - a[1]; + a[0] = s; + a[1] = t; + } + + #[inline(always)] + fn forward_4(a: &mut [Self]) { + assert_eq!(a.len(), 4); + + // Expanding the calculation of t3 saves one instruction + let t1 = MP::PRIME + a[1].value - a[3].value; + let t3 = Self::new_monty(monty_reduce::( + t1 as u64 * MP::ROOTS_8.as_ref()[2].value as u64, + )); + let t5 = a[1] + a[3]; + let t4 = a[0] + a[2]; + let t2 = a[0] - a[2]; + + // Return in bit-reversed order + a[0] = t4 + t5; + a[1] = t4 - t5; + a[2] = t2 + t3; + a[3] = t2 - t3; + } + + #[inline(always)] + fn forward_8(a: &mut [Self]) { + assert_eq!(a.len(), 8); + + Self::forward_pass(a, MP::ROOTS_8.as_ref()); + + // Safe because a.len() == 8 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::forward_4(a0); + Self::forward_4(a1); + } + + #[inline(always)] + fn forward_16(a: &mut [Self]) { + assert_eq!(a.len(), 16); + + Self::forward_pass(a, MP::ROOTS_16.as_ref()); + + // Safe because a.len() == 16 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::forward_8(a0); + Self::forward_8(a1); + } + + #[inline(always)] + fn forward_32(a: &mut [Self], root_table: &[Vec]) { + assert_eq!(a.len(), 32); + + Self::forward_pass(a, &root_table[0]); + + // Safe because a.len() == 32 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::forward_16(a0); + Self::forward_16(a1); + } + + /// Assumes `input.len() >= 64`. + #[inline] + fn forward_fft_recur(input: &mut [::Packing], root_table: &[Vec]) { + const ITERATIVE_FFT_THRESHOLD: usize = 1024; + + let n = input.len() * ::Packing::WIDTH; + if n <= ITERATIVE_FFT_THRESHOLD { + Self::forward_iterative(input, root_table); + } else { + assert_eq!(n, 1 << (root_table.len() + 1)); + forward_pass_packed(input, &root_table[0]); + + // Safe because input.len() > ITERATIVE_FFT_THRESHOLD + let (a0, a1) = unsafe { input.split_at_mut_unchecked(input.len() / 2) }; + + Self::forward_fft_recur(a0, &root_table[1..]); + Self::forward_fft_recur(a1, &root_table[1..]); + } + } + + #[inline] + pub fn forward_fft(input: &mut [Self], root_table: &[Vec]) { + let n = input.len(); + if n == 1 { + return; + } + assert_eq!(n, 1 << (root_table.len() + 1)); + match n { + 32 => Self::forward_32(input, root_table), + 16 => Self::forward_16(input), + 8 => Self::forward_8(input), + 4 => Self::forward_4(input), + 2 => Self::forward_2(input), + _ => { + let packed_input = ::Packing::pack_slice_mut(input); + Self::forward_fft_recur(packed_input, root_table) + } + } + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/dft/forward.v b/CoqOfRust/plonky3/monty-31/src/dft/forward.v new file mode 100644 index 000000000..ff392258f --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/dft/forward.v @@ -0,0 +1,10395 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module dft. + Module forward. + Module Impl_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]. + + (* + pub fn roots_of_unity_table(n: usize) -> Vec> { + let lg_n = log2_strict_usize(n); + let generator = Self::two_adic_generator(lg_n); + let half_n = 1 << (lg_n - 1); + // nth_roots = [1, g, g^2, g^3, ..., g^{n/2 - 1}] + let nth_roots: Vec<_> = generator.powers().take(half_n).collect(); + + (0..(lg_n - 1)) + .map(|i| nth_roots.iter().step_by(1 << i).copied().collect()) + .collect() + } + *) + Definition roots_of_unity_table + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ n ] => + ltac:(M.monadic + (let n := M.alloc (| n |) in + M.read (| + let~ lg_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| n |) ] + |) + |) in + let~ generator : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| lg_n |) ] + |) + |) in + let~ half_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| lg_n |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + |) in + let~ nth_roots : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, generator |) ] + |); + M.read (| half_n |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| lg_n |); Value.Integer IntegerKind.Usize 1 ] + |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "copied", + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [], + "step_by", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + nth_roots + |) + ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| i |) + ] + |) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_roots_of_unity_table : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "roots_of_unity_table" (roots_of_unity_table MP). + Admitted. + Global Typeclasses Opaque roots_of_unity_table. + (* + fn forward_iterative_layer( + packed_input: &mut [::Packing], + roots: &[Self], + m: usize, + ) { + debug_assert_eq!(roots.len(), m); + let packed_roots = ::Packing::pack_slice(roots); + + // lg_m >= 4, so m = 2^lg_m >= 2^4, hence packing_width divides m + let packed_m = m / ::Packing::WIDTH; + packed_input + .chunks_exact_mut(2 * packed_m) + .for_each(|layer_chunk| { + let (xs, ys) = unsafe { layer_chunk.split_at_mut_unchecked(packed_m) }; + + izip!(xs, ys, packed_roots) + .for_each(|(x, y, &root)| ( *x, *y) = forward_butterfly( *x, *y, root)); + }); + } + *) + Definition forward_iterative_layer + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ packed_input; roots; m ] => + ltac:(M.monadic + (let packed_input := M.alloc (| packed_input |) in + let roots := M.alloc (| roots |) in + let m := M.alloc (| m |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| roots |) |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, m |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ packed_roots : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [], + "pack_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| roots |) |) |) ] + |) + |) in + let~ packed_m : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.read (| m |); + M.read (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| packed_input |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| packed_m |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let layer_chunk := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| layer_chunk |) |) + |); + M.read (| packed_m |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let xs := M.copy (| γ0_0 |) in + let ys := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| xs |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| ys |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.read (| packed_roots |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ] + ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := + M.copy (| + γ1_0 + |) in + let b := + M.copy (| + γ1_1 + |) in + let b := + M.copy (| + γ0_1 + |) in + Value.Tuple + [ + M.read (| + a + |); + M.read (| + b + |); + M.read (| + b + |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let x := + M.copy (| γ0_0 |) in + let y := + M.copy (| γ0_1 |) in + let γ0_2 := + M.read (| γ0_2 |) in + let root := + M.copy (| γ0_2 |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_function (| + "p3_monty_31::dft::forward::forward_butterfly", + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.read (| + M.deref (| + M.read (| + x + |) + |) + |); + M.read (| + M.deref (| + M.read (| + y + |) + |) + |); + M.read (| + root + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lhs := + M.copy (| + γ0_0 + |) in + let lhs := + M.copy (| + γ0_1 + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| + x + |) + |), + M.read (| + lhs + |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path + "*") + [] + [ + Ty.tuple + [] + ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| + y + |) + |), + M.read (| + lhs + |) + |) + |) in + M.alloc (| + Value.Tuple + [] + |))) + ] + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_iterative_layer : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_iterative_layer" (forward_iterative_layer MP). + Admitted. + Global Typeclasses Opaque forward_iterative_layer. + + (* + fn forward_iterative_packed_radix_16(input: &mut [::Packing]) { + // Rather surprisingly, a version similar where the separate + // loops in each call to forward_iterative_packed() are + // combined into one, was not only not faster, but was + // actually a bit slower. + + // Radix 16 + if ::Packing::WIDTH >= 16 { + forward_iterative_packed::<8, _>(input, MP::ROOTS_16.as_ref()); + } else { + Self::forward_iterative_layer(input, MP::ROOTS_16.as_ref(), 8); + } + + // Radix 8 + if ::Packing::WIDTH >= 8 { + forward_iterative_packed::<4, _>(input, MP::ROOTS_8.as_ref()); + } else { + Self::forward_iterative_layer(input, MP::ROOTS_8.as_ref(), 4); + } + + // Radix 4 + let roots4 = [MP::ROOTS_8.as_ref()[0], MP::ROOTS_8.as_ref()[2]]; + if ::Packing::WIDTH >= 4 { + forward_iterative_packed::<2, _>(input, &roots4); + } else { + Self::forward_iterative_layer(input, &roots4, 2); + } + + // Radix 2 + forward_iterative_packed_radix_2(input); + } + *) + Definition forward_iterative_packed_radix_16 + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |); + Value.Integer IntegerKind.Usize 16 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::forward::forward_iterative_packed", + [ Value.Integer IntegerKind.Usize 8 ], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::ROOTS_16", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_iterative_layer", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::ROOTS_16", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |); + Value.Integer IntegerKind.Usize 8 + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |); + Value.Integer IntegerKind.Usize 8 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::forward::forward_iterative_packed", + [ Value.Integer IntegerKind.Usize 4 ], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_iterative_layer", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ roots4 : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] := + M.alloc (| + Value.Array + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::forward::forward_iterative_packed", + [ Value.Integer IntegerKind.Usize 2 ], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, roots4 |) |) + |)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_iterative_layer", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, roots4 |) |) + |)); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::forward::forward_iterative_packed_radix_2", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_iterative_packed_radix_16 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C + (Self MP) + "forward_iterative_packed_radix_16" + (forward_iterative_packed_radix_16 MP). + Admitted. + Global Typeclasses Opaque forward_iterative_packed_radix_16. + + (* + fn forward_iterative(packed_input: &mut [::Packing], root_table: &[Vec]) { + assert!(packed_input.len() >= 2); + let packing_width = ::Packing::WIDTH; + let n = packed_input.len() * packing_width; + let lg_n = log2_strict_usize(n); + + // Stop loop early to do radix 16 separately. This value is determined by the largest + // packing width we will encounter, which is 16 at the moment for AVX512. Specifically + // it is log_2(max{possible packing widths}) = lg(16) = 4. + const LAST_LOOP_LAYER: usize = 4; + + // How many layers have we specialised before the main loop + const NUM_SPECIALISATIONS: usize = 2; + + // Needed to avoid overlap of the 2 specialisations at the start + // with the radix-16 specialisation at the end of the loop + assert!(lg_n >= LAST_LOOP_LAYER + NUM_SPECIALISATIONS); + + // Specialise the first NUM_SPECIALISATIONS iterations; improves performance a little. + forward_pass_packed(packed_input, &root_table[0]); // lg_m == lg_n - 1, s == 0 + forward_iterative_layer_1(packed_input, &root_table[1]); // lg_m == lg_n - 2, s == 1 + + // loop from lg_n-2 down to 4. + for lg_m in (LAST_LOOP_LAYER..(lg_n - NUM_SPECIALISATIONS)).rev() { + let s = lg_n - lg_m - 1; + let m = 1 << lg_m; + + let roots = &root_table[s]; + debug_assert_eq!(roots.len(), m); + + Self::forward_iterative_layer(packed_input, roots, m); + } + + // Last 4 layers + Self::forward_iterative_packed_radix_16(packed_input); + } + *) + Definition forward_iterative + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ packed_input; root_table ] => + ltac:(M.monadic + (let packed_input := M.alloc (| packed_input |) in + let root_table := M.alloc (| root_table |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| packed_input |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: packed_input.len() >= 2" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ packing_width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| packed_input |) |) |) ] + |); + M.read (| packing_width |) + ] + |) + |) in + let~ lg_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| n |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| lg_n |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_monty_31::dft::forward::forward_iterative::LAST_LOOP_LAYER", + Ty.path "usize" + |) + |); + M.read (| + get_constant (| + "p3_monty_31::dft::forward::forward_iterative::NUM_SPECIALISATIONS", + Ty.path "usize" + |) + |) + ] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ + mk_str (| + "assertion failed: lg_n >= LAST_LOOP_LAYER + NUM_SPECIALISATIONS" + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::forward::forward_pass_packed", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| packed_input |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| root_table |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::forward::forward_iterative_layer_1", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| packed_input |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| root_table |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "rev", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.read (| + get_constant (| + "p3_monty_31::dft::forward::forward_iterative::LAST_LOOP_LAYER", + Ty.path "usize" + |) + |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| lg_n |); + M.read (| + get_constant (| + "p3_monty_31::dft::forward::forward_iterative::NUM_SPECIALISATIONS", + Ty.path "usize" + |) + |) + ] + |)) + ] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let lg_m := M.copy (| γ0_0 |) in + let~ s : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| lg_n |); M.read (| lg_m |) ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ m : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| lg_m |) + ] + |) + |) in + let~ roots : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| root_table |) |), + M.read (| s |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| roots |) + |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, m |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| + left_val + |) + |) + |); + M.read (| + M.deref (| + M.read (| + right_val + |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.path "usize"; + Ty.path "usize" + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + left_val + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + right_val + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "forward_iterative_layer", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| packed_input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| roots |) |) + |) + ] + |) + |) + |); + M.read (| m |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_iterative_packed_radix_16", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| packed_input |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_iterative : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_iterative" (forward_iterative MP). + Admitted. + Global Typeclasses Opaque forward_iterative. + + (* + fn forward_butterfly(x: Self, y: Self, w: Self) -> (Self, Self) { + let t = MP::PRIME + x.value - y.value; + ( + x + y, + Self::new_monty(monty_reduce::(t as u64 * w.value as u64)), + ) + } + *) + Definition forward_butterfly + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ x; y; w ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + let w := M.alloc (| w |) in + M.read (| + let~ t : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + x, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + y, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::monty_reduce", [], [ MP ] |), + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.cast (Ty.path "u64") (M.read (| t |)); + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + w, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |)) + ] + |) + ] + |) + ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_butterfly : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_butterfly" (forward_butterfly MP). + Admitted. + Global Typeclasses Opaque forward_butterfly. + + (* + fn forward_pass(input: &mut [Self], roots: &[Self]) { + let half_n = input.len() / 2; + assert_eq!(roots.len(), half_n); + + // Safe because 0 <= half_n < a.len() + let (xs, ys) = unsafe { input.split_at_mut_unchecked(half_n) }; + + let s = xs[0] + ys[0]; + let t = xs[0] - ys[0]; + xs[0] = s; + ys[0] = t; + + izip!(&mut xs[1..], &mut ys[1..], &roots[1..]).for_each(|(x, y, &root)| { + ( *x, *y) = Self::forward_butterfly( *x, *y, root); + }); + } + *) + Definition forward_pass + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ input; roots ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let roots := M.alloc (| roots |) in + M.read (| + let~ half_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| roots |) |) |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, half_n |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.read (| half_n |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let xs := M.copy (| γ0_0 |) in + let ys := M.copy (| γ0_1 |) in + let~ s : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| xs |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| ys |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ t : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| xs |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| ys |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| xs |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| s |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| ys |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| t |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| xs |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| ys |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + |), + [ + M.read (| iter |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| roots |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := M.copy (| γ1_0 |) in + let b := M.copy (| γ1_1 |) in + let b := M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| γ, 2 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let γ0_2 := M.read (| γ0_2 |) in + let root := M.copy (| γ0_2 |) in + M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "forward_butterfly", + [], + [] + |), + [ + M.read (| + M.deref (| M.read (| x |) |) + |); + M.read (| + M.deref (| M.read (| y |) |) + |); + M.read (| root |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lhs := M.copy (| γ0_0 |) in + let lhs := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| x |) |), + M.read (| lhs |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| y |) |), + M.read (| lhs |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_pass : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_pass" (forward_pass MP). + Admitted. + Global Typeclasses Opaque forward_pass. + + (* + fn forward_2(a: &mut [Self]) { + assert_eq!(a.len(), 2); + + let s = a[0] + a[1]; + let t = a[0] - a[1]; + a[0] = s; + a[1] = t; + } + *) + Definition forward_2 (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 2 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ s : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ t : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| s |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| t |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_2 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_2" (forward_2 MP). + Admitted. + Global Typeclasses Opaque forward_2. + + (* + fn forward_4(a: &mut [Self]) { + assert_eq!(a.len(), 4); + + // Expanding the calculation of t3 saves one instruction + let t1 = MP::PRIME + a[1].value - a[3].value; + let t3 = Self::new_monty(monty_reduce::( + t1 as u64 * MP::ROOTS_8.as_ref()[2].value as u64, + )); + let t5 = a[1] + a[3]; + let t4 = a[0] + a[2]; + let t2 = a[0] - a[2]; + + // Return in bit-reversed order + a[0] = t4 + t5; + a[1] = t4 - t5; + a[2] = t2 + t3; + a[3] = t2 - t3; + } + *) + Definition forward_4 (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 4 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ t1 : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 3 + |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |) + |) in + let~ t3 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::monty_reduce", [], [ MP ] |), + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.cast (Ty.path "u64") (M.read (| t1 |)); + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 2 + |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |)) + ] + |) + ] + |) + ] + |) + |) in + let~ t5 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + |) in + let~ t4 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |) in + let~ t2 : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ M.read (| t4 |); M.read (| t5 |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "sub", + [], + [] + |), + [ M.read (| t4 |); M.read (| t5 |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "add", + [], + [] + |), + [ M.read (| t2 |); M.read (| t3 |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| a |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "sub", + [], + [] + |), + [ M.read (| t2 |); M.read (| t3 |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_4 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_4" (forward_4 MP). + Admitted. + Global Typeclasses Opaque forward_4. + + (* + fn forward_8(a: &mut [Self]) { + assert_eq!(a.len(), 8); + + Self::forward_pass(a, MP::ROOTS_8.as_ref()); + + // Safe because a.len() == 8 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::forward_4(a0); + Self::forward_4(a1); + } + *) + Definition forward_8 (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 8 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_pass", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::ROOTS_8", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a0 := M.copy (| γ0_0 |) in + let a1 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_4", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a0 |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_4", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a1 |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_8 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_8" (forward_8 MP). + Admitted. + Global Typeclasses Opaque forward_8. + + (* + fn forward_16(a: &mut [Self]) { + assert_eq!(a.len(), 16); + + Self::forward_pass(a, MP::ROOTS_16.as_ref()); + + // Safe because a.len() == 16 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::forward_8(a0); + Self::forward_8(a1); + } + *) + Definition forward_16 (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ a ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 16 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_pass", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::ROOTS_16", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + MP + "ArrayLike" + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a0 := M.copy (| γ0_0 |) in + let a1 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_8", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a0 |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_8", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a1 |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_16 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_16" (forward_16 MP). + Admitted. + Global Typeclasses Opaque forward_16. + + (* + fn forward_32(a: &mut [Self], root_table: &[Vec]) { + assert_eq!(a.len(), 32); + + Self::forward_pass(a, &root_table[0]); + + // Safe because a.len() == 32 + let (a0, a1) = unsafe { a.split_at_mut_unchecked(a.len() / 2) }; + Self::forward_16(a0); + Self::forward_16(a1); + } + *) + Definition forward_32 (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ a; root_table ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let root_table := M.alloc (| root_table |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 32 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_pass", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| root_table |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| a |) |) |) ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a0 := M.copy (| γ0_0 |) in + let a1 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_16", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a0 |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_16", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| a1 |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_32 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_32" (forward_32 MP). + Admitted. + Global Typeclasses Opaque forward_32. + + (* + fn forward_fft_recur(input: &mut [::Packing], root_table: &[Vec]) { + const ITERATIVE_FFT_THRESHOLD: usize = 1024; + + let n = input.len() * ::Packing::WIDTH; + if n <= ITERATIVE_FFT_THRESHOLD { + Self::forward_iterative(input, root_table); + } else { + assert_eq!(n, 1 << (root_table.len() + 1)); + forward_pass_packed(input, &root_table[0]); + + // Safe because input.len() > ITERATIVE_FFT_THRESHOLD + let (a0, a1) = unsafe { input.split_at_mut_unchecked(input.len() / 2) }; + + Self::forward_fft_recur(a0, &root_table[1..]); + Self::forward_fft_recur(a1, &root_table[1..]); + } + } + *) + Definition forward_fft_recur + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ input; root_table ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let root_table := M.alloc (| root_table |) in + M.read (| + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |); + M.read (| + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| n |); + M.read (| + get_constant (| + "p3_monty_31::dft::forward::forward_fft_recur::ITERATIVE_FFT_THRESHOLD", + Ty.path "usize" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_iterative", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| root_table |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, n |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::forward::forward_pass_packed", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| root_table |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a0 := M.copy (| γ0_0 |) in + let a1 := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "forward_fft_recur", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| a0 |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "forward_fft_recur", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| a1 |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_fft_recur : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_fft_recur" (forward_fft_recur MP). + Admitted. + Global Typeclasses Opaque forward_fft_recur. + + (* + pub fn forward_fft(input: &mut [Self], root_table: &[Vec]) { + let n = input.len(); + if n == 1 { + return; + } + assert_eq!(n, 1 << (root_table.len() + 1)); + match n { + 32 => Self::forward_32(input, root_table), + 16 => Self::forward_16(input), + 8 => Self::forward_8(input), + 4 => Self::forward_4(input), + 2 => Self::forward_2(input), + _ => { + let packed_input = ::Packing::pack_slice_mut(input); + Self::forward_fft_recur(packed_input, root_table) + } + } + } + *) + Definition forward_fft + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ input; root_table ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let root_table := M.alloc (| root_table |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| n |); Value.Integer IntegerKind.Usize 1 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| Value.Tuple [] |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, n |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + n, + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 32 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_32", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 16 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_16", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 8 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_8", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 4 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_4", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_2", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ packed_input : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + [], + [], + "pack_slice_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "forward_fft_recur", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| packed_input |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| root_table |) |) + |) + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_forward_fft : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "forward_fft" (forward_fft MP). + Admitted. + Global Typeclasses Opaque forward_fft. + End Impl_p3_monty_31_monty_31_MontyField31_MP. + + (* + fn forward_butterfly(x: T, y: T, roots: T) -> (T, T) { + let t = x - y; + (x + y, t * roots) + } + *) + Definition forward_butterfly (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ x; y; roots ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + let roots := M.alloc (| roots |) in + M.read (| + let~ t : Ty.apply (Ty.path "*") [] [ T ] := + M.alloc (| + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Sub", T, [], [ T ], "sub", [], [] |), + [ M.read (| x |); M.read (| y |) ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Add", T, [], [ T ], "add", [], [] |), + [ M.read (| x |); M.read (| y |) ] + |); + M.call_closure (| + T, + M.get_trait_method (| "core::ops::arith::Mul", T, [], [ T ], "mul", [], [] |), + [ M.read (| t |); M.read (| roots |) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_forward_butterfly : + M.IsFunction.C "p3_monty_31::dft::forward::forward_butterfly" forward_butterfly. + Admitted. + Global Typeclasses Opaque forward_butterfly. + + (* + fn forward_butterfly_interleaved( + x: T, + y: T, + roots: T, + ) -> (T, T) { + let (x, y) = x.interleave(y, HALF_RADIX); + let (x, y) = forward_butterfly(x, y, roots); + x.interleave(y, HALF_RADIX) + } + *) + Definition forward_butterfly_interleaved + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ HALF_RADIX ], [ T ], [ x; y; roots ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + let roots := M.alloc (| roots |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [ T; T ] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_trait_method (| + "p3_field::packed::PackedFieldPow2", + T, + [], + [], + "interleave", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); M.read (| y |); HALF_RADIX ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [ T; T ] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_function (| + "p3_monty_31::dft::forward::forward_butterfly", + [], + [ T ] + |), + [ M.read (| x |); M.read (| y |); M.read (| roots |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_trait_method (| + "p3_field::packed::PackedFieldPow2", + T, + [], + [], + "interleave", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |); M.read (| y |); HALF_RADIX ] + |) + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_forward_butterfly_interleaved : + M.IsFunction.C + "p3_monty_31::dft::forward::forward_butterfly_interleaved" + forward_butterfly_interleaved. + Admitted. + Global Typeclasses Opaque forward_butterfly_interleaved. + + (* + fn forward_pass_packed(input: &mut [T], roots: &[T::Scalar]) { + let packed_roots = T::pack_slice(roots); + let n = input.len(); + let (xs, ys) = unsafe { input.split_at_mut_unchecked(n / 2) }; + + izip!(xs, ys, packed_roots) + .for_each(|(x, y, &roots)| ( *x, *y) = forward_butterfly( *x, *y, roots)); + } + *) + Definition forward_pass_packed (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ input; roots ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let roots := M.alloc (| roots |) in + M.read (| + let~ packed_roots : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + T, + [], + [], + "pack_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| roots |) |) |) ] + |) + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| n |); Value.Integer IntegerKind.Usize 2 ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let xs := M.copy (| γ0_0 |) in + let ys := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| xs |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| ys |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| packed_roots |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := M.copy (| γ1_0 |) in + let b := M.copy (| γ1_1 |) in + let b := M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let γ0_2 := M.read (| γ0_2 |) in + let roots := M.copy (| γ0_2 |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_function (| + "p3_monty_31::dft::forward::forward_butterfly", + [], + [ T ] + |), + [ + M.read (| M.deref (| M.read (| x |) |) |); + M.read (| M.deref (| M.read (| y |) |) |); + M.read (| roots |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let lhs := M.copy (| γ0_0 |) in + let lhs := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| x |) |), + M.read (| lhs |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| y |) |), + M.read (| lhs |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_forward_pass_packed : + M.IsFunction.C "p3_monty_31::dft::forward::forward_pass_packed" forward_pass_packed. + Admitted. + Global Typeclasses Opaque forward_pass_packed. + + (* + fn forward_iterative_layer_1(input: &mut [T], roots: &[T::Scalar]) { + let packed_roots = T::pack_slice(roots); + let n = input.len(); + let (top_half, bottom_half) = unsafe { input.split_at_mut_unchecked(n / 2) }; + let (xs, ys) = unsafe { top_half.split_at_mut_unchecked(n / 4) }; + let (zs, ws) = unsafe { bottom_half.split_at_mut_unchecked(n / 4) }; + + izip!(xs, ys, zs, ws, packed_roots).for_each(|(x, y, z, w, &root)| { + ( *x, *y) = forward_butterfly( *x, *y, root); + ( *z, *w) = forward_butterfly( *z, *w, root); + }); + } + *) + Definition forward_iterative_layer_1 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ T ], [ input; roots ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let roots := M.alloc (| roots |) in + M.read (| + let~ packed_roots : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + T, + [], + [], + "pack_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| roots |) |) |) ] + |) + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| n |); Value.Integer IntegerKind.Usize 2 ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let top_half := M.copy (| γ0_0 |) in + let bottom_half := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| top_half |) |) |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| n |); Value.Integer IntegerKind.Usize 4 ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let xs := M.copy (| γ0_0 |) in + let ys := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "split_at_mut_unchecked", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| bottom_half |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| n |); Value.Integer IntegerKind.Usize 4 ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let zs := M.copy (| γ0_0 |) in + let ws := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply (Ty.path "&mut") [] [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| xs |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| ys |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| zs |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| ws |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ T ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ T ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + |), + [ M.read (| iter |); M.read (| packed_roots |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ T ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ] + ]; + Ty.apply (Ty.path "&") [] [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&mut") [] [ T ]; + Ty.apply (Ty.path "&") [] [ T ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ T ]; + Ty.apply + (Ty.path + "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path + "&mut") + [] + [ T ] + ]; + Ty.apply + (Ty.path "&") + [] + [ T ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&") + [] + [ T ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let γ2_0 := + M.SubPointer.get_tuple_field (| + γ1_0, + 0 + |) in + let γ2_1 := + M.SubPointer.get_tuple_field (| + γ1_0, + 1 + |) in + let γ3_0 := + M.SubPointer.get_tuple_field (| + γ2_0, + 0 + |) in + let γ3_1 := + M.SubPointer.get_tuple_field (| + γ2_0, + 1 + |) in + let a := M.copy (| γ3_0 |) in + let b := M.copy (| γ3_1 |) in + let b := M.copy (| γ2_1 |) in + let b := M.copy (| γ1_1 |) in + let b := M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&mut") + [] + [ T ]; + Ty.apply + (Ty.path "&") + [] + [ T ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let γ0_3 := + M.SubPointer.get_tuple_field (| + γ, + 3 + |) in + let γ0_4 := + M.SubPointer.get_tuple_field (| + γ, + 4 + |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let z := M.copy (| γ0_2 |) in + let w := M.copy (| γ0_3 |) in + let γ0_4 := M.read (| γ0_4 |) in + let root := M.copy (| γ0_4 |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_function (| + "p3_monty_31::dft::forward::forward_butterfly", + [], + [ T ] + |), + [ + M.read (| + M.deref (| + M.read (| x |) + |) + |); + M.read (| + M.deref (| + M.read (| y |) + |) + |); + M.read (| root |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lhs := + M.copy (| γ0_0 |) in + let lhs := + M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| x |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| y |) + |), + M.read (| lhs |) + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_function (| + "p3_monty_31::dft::forward::forward_butterfly", + [], + [ T ] + |), + [ + M.read (| + M.deref (| + M.read (| z |) + |) + |); + M.read (| + M.deref (| + M.read (| w |) + |) + |); + M.read (| root |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let lhs := + M.copy (| γ0_0 |) in + let lhs := + M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| z |) + |), + M.read (| lhs |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| w |) + |), + M.read (| lhs |) + |) + |) in + M.alloc (| + Value.Tuple [] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_forward_iterative_layer_1 : + M.IsFunction.C + "p3_monty_31::dft::forward::forward_iterative_layer_1" + forward_iterative_layer_1. + Admitted. + Global Typeclasses Opaque forward_iterative_layer_1. + + (* + fn forward_iterative_packed( + input: &mut [T], + roots: &[T::Scalar], + ) { + // roots[0] == 1 + // roots <-- [1, roots[1], ..., roots[HALF_RADIX-1], 1, roots[1], ...] + let roots = T::from_fn(|i| roots[i % HALF_RADIX]); + + input.chunks_exact_mut(2).for_each(|pair| { + let (x, y) = forward_butterfly_interleaved::(pair[0], pair[1], roots); + pair[0] = x; + pair[1] = y; + }); + } + *) + Definition forward_iterative_packed (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ HALF_RADIX ], [ T ], [ input; roots ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let roots := M.alloc (| roots |) in + M.read (| + let~ roots : Ty.apply (Ty.path "*") [] [ T ] := + M.alloc (| + M.call_closure (| + T, + M.get_trait_method (| + "p3_field::packed::PackedValue", + T, + [], + [], + "from_fn", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait "p3_field::packed::PackedField" [] [] T "Scalar") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_field::packed::PackedField" + [] + [] + T + "Scalar") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| roots |) |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| i |); HALF_RADIX ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ T ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + Value.Integer IntegerKind.Usize 2 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let pair_ := M.copy (| γ |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_function (| + "p3_monty_31::dft::forward::forward_butterfly_interleaved", + [ HALF_RADIX ], + [ T ] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| roots |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| x |) + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| y |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_forward_iterative_packed : + M.IsFunction.C "p3_monty_31::dft::forward::forward_iterative_packed" forward_iterative_packed. + Admitted. + Global Typeclasses Opaque forward_iterative_packed. + + (* + fn forward_iterative_packed_radix_2(input: &mut [T]) { + input.chunks_exact_mut(2).for_each(|pair| { + let x = pair[0]; + let y = pair[1]; + let (mut x, y) = x.interleave(y, 1); + let t = x - y; // roots[0] == 1 + x += y; + let (x, y) = x.interleave(t, 1); + pair[0] = x; + pair[1] = y; + }); + } + *) + Definition forward_iterative_packed_radix_2 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ T ], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ T ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |); + Value.Integer IntegerKind.Usize 2 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let pair_ := M.copy (| γ |) in + M.read (| + let~ x : Ty.apply (Ty.path "*") [] [ T ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) in + let~ y : Ty.apply (Ty.path "*") [] [ T ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_trait_method (| + "p3_field::packed::PackedFieldPow2", + T, + [], + [], + "interleave", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.read (| y |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let~ t : Ty.apply (Ty.path "*") [] [ T ] := + M.alloc (| + M.call_closure (| + T, + M.get_trait_method (| + "core::ops::arith::Sub", + T, + [], + [ T ], + "sub", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + T, + [], + [ T ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, x |); + M.read (| y |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ T; T ], + M.get_trait_method (| + "p3_field::packed::PackedFieldPow2", + T, + [], + [], + "interleave", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, x |); + M.read (| t |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let x := M.copy (| γ0_0 |) in + let y := M.copy (| γ0_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| x |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| pair_ |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| y |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_forward_iterative_packed_radix_2 : + M.IsFunction.C + "p3_monty_31::dft::forward::forward_iterative_packed_radix_2" + forward_iterative_packed_radix_2. + Admitted. + Global Typeclasses Opaque forward_iterative_packed_radix_2. + + End forward. +End dft. diff --git a/CoqOfRust/plonky3/monty-31/src/dft/mod.rs b/CoqOfRust/plonky3/monty-31/src/dft/mod.rs new file mode 100644 index 000000000..7f08b9689 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/dft/mod.rs @@ -0,0 +1,300 @@ +//! An implementation of the FFT for `MontyField31` +extern crate alloc; + +use alloc::vec::Vec; +use core::cell::RefCell; +use core::iter; + +use itertools::izip; +use p3_dft::TwoAdicSubgroupDft; +use p3_field::{Field, PrimeCharacteristicRing}; +use p3_matrix::Matrix; +use p3_matrix::bitrev::{BitReversedMatrixView, BitReversibleMatrix}; +use p3_matrix::dense::RowMajorMatrix; +use p3_maybe_rayon::prelude::*; +use p3_util::log2_ceil_usize; +use tracing::{debug_span, instrument}; + +mod backward; +mod forward; + +use crate::{FieldParameters, MontyField31, MontyParameters, TwoAdicData}; + +/// Multiply each element of column `j` of `mat` by `shift**j`. +#[instrument(level = "debug", skip_all)] +fn coset_shift_and_scale_rows( + out: &mut [F], + out_ncols: usize, + mat: &[F], + ncols: usize, + shift: F, + scale: F, +) { + let powers = shift.shifted_powers(scale).take(ncols).collect::>(); + out.par_chunks_exact_mut(out_ncols) + .zip(mat.par_chunks_exact(ncols)) + .for_each(|(out_row, in_row)| { + izip!(out_row.iter_mut(), in_row, &powers).for_each(|(out, &coeff, &weight)| { + *out = coeff * weight; + }); + }); +} + +/// Recursive DFT, decimation-in-frequency in the forward direction, +/// decimation-in-time in the backward (inverse) direction. +#[derive(Clone, Debug, Default)] +pub struct RecursiveDft { + /// Memoized twiddle factors for each length log_n. + /// + /// TODO: The use of RefCell means this can't be shared across + /// threads; consider using RwLock or finding a better design + /// instead. + twiddles: RefCell>>, + inv_twiddles: RefCell>>, +} + +impl RecursiveDft> { + pub fn new(n: usize) -> Self { + let res = Self { + twiddles: RefCell::default(), + inv_twiddles: RefCell::default(), + }; + res.update_twiddles(n); + res + } + + #[inline] + fn decimation_in_freq_dft( + mat: &mut [MontyField31], + ncols: usize, + twiddles: &[Vec>], + ) { + if ncols > 1 { + let lg_fft_len = p3_util::log2_ceil_usize(ncols); + let roots_idx = (twiddles.len() + 1) - lg_fft_len; + let twiddles = &twiddles[roots_idx..]; + + mat.par_chunks_exact_mut(ncols) + .for_each(|v| MontyField31::forward_fft(v, twiddles)) + } + } + + #[inline] + fn decimation_in_time_dft( + mat: &mut [MontyField31], + ncols: usize, + twiddles: &[Vec>], + ) { + if ncols > 1 { + let lg_fft_len = p3_util::log2_ceil_usize(ncols); + let roots_idx = (twiddles.len() + 1) - lg_fft_len; + let twiddles = &twiddles[roots_idx..]; + + mat.par_chunks_exact_mut(ncols) + .for_each(|v| MontyField31::backward_fft(v, twiddles)) + } + } + + /// Compute twiddle factors, or take memoized ones if already available. + #[instrument(skip_all)] + fn update_twiddles(&self, fft_len: usize) { + // TODO: This recomputes the entire table from scratch if we + // need it to be bigger, which is wasteful. + + // As we don't save the twiddles for the final layer where + // the only twiddle is 1, roots_of_unity_table(fft_len) + // returns a vector of twiddles of length log_2(fft_len) - 1. + let curr_max_fft_len = 2 << self.twiddles.borrow().len(); + if fft_len > curr_max_fft_len { + let new_twiddles = MontyField31::roots_of_unity_table(fft_len); + // We can obtain the inverse twiddles by reversing and + // negating the twiddles. + let new_inv_twiddles = new_twiddles + .iter() + .map(|ts| { + // The first twiddle is still one, we reverse and negate the rest... + iter::once(MontyField31::ONE) + .chain( + ts[1..] + .iter() + .rev() + // A twiddle t is never zero, so negation simplifies + // to P - t. + .map(|&t| MontyField31::new_monty(MP::PRIME - t.value)), + ) + .collect() + }) + .collect(); + self.twiddles.replace(new_twiddles); + self.inv_twiddles.replace(new_inv_twiddles); + } + } +} + +/// DFT implementation that uses DIT for the inverse "backward" +/// direction and DIF for the "forward" direction. +/// +/// The API mandates that the LDE is applied column-wise on the +/// _row-major_ input. This is awkward for memory coherence, so the +/// algorithm here transposes the input and operates on the rows in +/// the typical way, then transposes back again for the output. Even +/// for modestly large inputs, the cost of the two transposes +/// outweighed by the improved performance from operating row-wise. +/// +/// The choice of DIT for inverse and DIF for "forward" transform mean +/// that a (coset) LDE +/// +/// - IDFT / zero extend / DFT +/// +/// expands to +/// +/// - bit-reverse input +/// - invDFT DIT +/// - result is in "correct" order +/// - coset shift and zero extend result +/// - DFT DIF on result +/// - output is bit-reversed, as required for FRI. +/// +/// Hence the only bit-reversal that needs to take place is on the input. +/// +impl TwoAdicSubgroupDft> + for RecursiveDft> +{ + type Evaluations = BitReversedMatrixView>>; + + #[instrument(skip_all, fields(dims = %mat.dimensions(), added_bits))] + fn dft_batch(&self, mut mat: RowMajorMatrix>) -> Self::Evaluations + where + MP: MontyParameters + FieldParameters + TwoAdicData, + { + let nrows = mat.height(); + let ncols = mat.width(); + if nrows <= 1 { + return mat.bit_reverse_rows(); + } + + let mut scratch = debug_span!("allocate scratch space") + .in_scope(|| RowMajorMatrix::default(nrows, ncols)); + + self.update_twiddles(nrows); + let twiddles = self.twiddles.borrow(); + + // transpose input + debug_span!("pre-transpose", nrows, ncols) + .in_scope(|| transpose::transpose(&mat.values, &mut scratch.values, ncols, nrows)); + + debug_span!("dft batch", n_dfts = ncols, fft_len = nrows) + .in_scope(|| Self::decimation_in_freq_dft(&mut scratch.values, nrows, &twiddles)); + + // transpose output + debug_span!("post-transpose", nrows = ncols, ncols = nrows) + .in_scope(|| transpose::transpose(&scratch.values, &mut mat.values, nrows, ncols)); + + mat.bit_reverse_rows() + } + + #[instrument(skip_all, fields(dims = %mat.dimensions(), added_bits))] + fn idft_batch(&self, mat: RowMajorMatrix>) -> RowMajorMatrix> + where + MP: MontyParameters + FieldParameters + TwoAdicData, + { + let nrows = mat.height(); + let ncols = mat.width(); + if nrows <= 1 { + return mat; + } + + let mut scratch = debug_span!("allocate scratch space") + .in_scope(|| RowMajorMatrix::default(nrows, ncols)); + + let mut mat = + debug_span!("initial bitrev").in_scope(|| mat.bit_reverse_rows().to_row_major_matrix()); + + self.update_twiddles(nrows); + let inv_twiddles = self.inv_twiddles.borrow(); + + // transpose input + debug_span!("pre-transpose", nrows, ncols) + .in_scope(|| transpose::transpose(&mat.values, &mut scratch.values, ncols, nrows)); + + debug_span!("idft", n_dfts = ncols, fft_len = nrows) + .in_scope(|| Self::decimation_in_time_dft(&mut scratch.values, nrows, &inv_twiddles)); + + // transpose output + debug_span!("post-transpose", nrows = ncols, ncols = nrows) + .in_scope(|| transpose::transpose(&scratch.values, &mut mat.values, nrows, ncols)); + + let log_rows = log2_ceil_usize(nrows); + let inv_len = MontyField31::ONE.div_2exp_u64(log_rows as u64); + debug_span!("scale").in_scope(|| mat.scale(inv_len)); + mat + } + + #[instrument(skip_all, fields(dims = %mat.dimensions(), added_bits))] + fn coset_lde_batch( + &self, + mat: RowMajorMatrix>, + added_bits: usize, + shift: MontyField31, + ) -> Self::Evaluations { + let nrows = mat.height(); + let ncols = mat.width(); + let result_nrows = nrows << added_bits; + + if nrows == 1 { + let dupd_rows = core::iter::repeat_n(mat.values, result_nrows) + .flatten() + .collect(); + return RowMajorMatrix::new(dupd_rows, ncols).bit_reverse_rows(); + } + + let input_size = nrows * ncols; + let output_size = result_nrows * ncols; + + let mat = mat.bit_reverse_rows().to_row_major_matrix(); + + // Allocate space for the output and the intermediate state. + let (mut output, mut padded) = debug_span!("allocate scratch space").in_scope(|| { + // Safety: These are pretty dodgy, but work because MontyField31 is #[repr(transparent)] + let output = MontyField31::::zero_vec(output_size); + let padded = MontyField31::::zero_vec(output_size); + (output, padded) + }); + + // `coeffs` will hold the result of the inverse FFT; use the + // output storage as scratch space. + let coeffs = &mut output[..input_size]; + + debug_span!("pre-transpose", nrows, ncols) + .in_scope(|| transpose::transpose(&mat.values, coeffs, ncols, nrows)); + + // Apply inverse DFT; result is not yet normalised. + self.update_twiddles(result_nrows); + let inv_twiddles = self.inv_twiddles.borrow(); + debug_span!("inverse dft batch", n_dfts = ncols, fft_len = nrows) + .in_scope(|| Self::decimation_in_time_dft(coeffs, nrows, &inv_twiddles)); + + // At this point the inverse FFT of each column of `mat` appears + // as a row in `coeffs`. + + // Normalise inverse DFT and coset shift in one go. + let log_rows = log2_ceil_usize(nrows); + let inv_len = MontyField31::ONE.div_2exp_u64(log_rows as u64); + coset_shift_and_scale_rows(&mut padded, result_nrows, coeffs, nrows, shift, inv_len); + + // `padded` is implicitly zero padded since it was initialised + // to zeros when declared above. + + let twiddles = self.twiddles.borrow(); + + // Apply DFT + debug_span!("dft batch", n_dfts = ncols, fft_len = result_nrows) + .in_scope(|| Self::decimation_in_freq_dft(&mut padded, result_nrows, &twiddles)); + + // transpose output + debug_span!("post-transpose", nrows = ncols, ncols = result_nrows) + .in_scope(|| transpose::transpose(&padded, &mut output, result_nrows, ncols)); + + RowMajorMatrix::new(output, ncols).bit_reverse_rows() + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/dft/mod.v b/CoqOfRust/plonky3/monty-31/src/dft/mod.v new file mode 100644 index 000000000..5e61d46ad --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/dft/mod.v @@ -0,0 +1,20882 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module dft. + (* #[instrument(level = "debug", skip_all)] *) + Definition coset_shift_and_scale_rows (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ out; out_ncols; mat; ncols; shift; scale ] => + ltac:(M.monadic + (let out := M.alloc (| out |) in + let out_ncols := M.alloc (| out_ncols |) in + let mat := M.alloc (| mat |) in + let ncols := M.alloc (| ncols |) in + let shift := M.alloc (| shift |) in + let scale := M.alloc (| scale |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_shift_and_scale_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_shift_and_scale_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_shift_and_scale_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_shift_and_scale_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ powers : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_field::field::Powers") [] [ F ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "shifted_powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, shift |); M.read (| scale |) ] + |); + M.read (| ncols |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::ChunksExact") [] [ F ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::ChunksExact") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "core::slice::iter::ChunksExact") [] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Ty.apply (Ty.path "slice") [] [ F ], + [], + [ F ], + "par_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| out |) |) |); + M.read (| out_ncols |) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::ChunksExact") [] [ F ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSlice", + Ty.apply (Ty.path "slice") [] [ F ], + [], + [ F ], + "par_chunks_exact", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat |) |) |); + M.read (| ncols |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let out_row := M.copy (| γ0_0 |) in + let in_row := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ]; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ] + ]) + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ F ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ F ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| out_row |) |) + |) + ] + |) + ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ F ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ] + ] + |), + [ M.read (| iter |); M.read (| in_row |) ] + |) + |) in + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + F; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.read (| iter |); + M.borrow (| Pointer.Kind.Ref, powers |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ F ]; + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ F ]; + Ty.apply (Ty.path "&") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ] + ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&mut") + [] + [ F ]; + Ty.apply + (Ty.path + "&") + [] + [ F ] + ]; + Ty.apply + (Ty.path + "&") + [] + [ F ] + ] + ] + ] + (Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let a := + M.copy (| γ1_0 |) in + let b := + M.copy (| γ1_1 |) in + let b := + M.copy (| γ0_1 |) in + Value.Tuple + [ + M.read (| a |); + M.read (| b |); + M.read (| b |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ]; + Ty.apply + (Ty.path "&") + [] + [ F ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let γ0_2 := + M.SubPointer.get_tuple_field (| + γ, + 2 + |) in + let out := M.copy (| γ0_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let coeff := + M.copy (| γ0_1 |) in + let γ0_2 := M.read (| γ0_2 |) in + let weight := + M.copy (| γ0_2 |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.read (| out |) + |), + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.read (| coeff |); + M.read (| weight |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_coset_shift_and_scale_rows : + M.IsFunction.C "p3_monty_31::dft::coset_shift_and_scale_rows" coset_shift_and_scale_rows. + Admitted. + Global Typeclasses Opaque coset_shift_and_scale_rows. + + (* StructRecord + { + name := "RecursiveDft"; + const_params := []; + ty_params := [ "F" ]; + fields := + [ + ("twiddles", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]); + ("inv_twiddles", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ]) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_monty_31_dft_RecursiveDft_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::dft::RecursiveDft") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_monty_31::dft::RecursiveDft" + [ + ("twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "twiddles" + |) + |) + |) + |) + ] + |)); + ("inv_twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "inv_twiddles" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_monty_31_dft_RecursiveDft_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_monty_31_dft_RecursiveDft_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::dft::RecursiveDft") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "RecursiveDft" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "twiddles" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inv_twiddles" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "inv_twiddles" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_monty_31_dft_RecursiveDft_F. + + Module Impl_core_default_Default_where_core_default_Default_F_for_p3_monty_31_dft_RecursiveDft_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::dft::RecursiveDft") [] [ F ]. + + (* Default *) + Definition default (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_monty_31::dft::RecursiveDft" + [ + ("twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "default", + [], + [] + |), + [] + |)); + ("inv_twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("default", InstanceField.Method (default F)) ]. + End Impl_core_default_Default_where_core_default_Default_F_for_p3_monty_31_dft_RecursiveDft_F. + + Module Impl_p3_monty_31_dft_RecursiveDft_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ]. + + (* + pub fn new(n: usize) -> Self { + let res = Self { + twiddles: RefCell::default(), + inv_twiddles: RefCell::default(), + }; + res.update_twiddles(n); + res + } + *) + Definition new (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ n ] => + ltac:(M.monadic + (let n := M.alloc (| n |) in + M.read (| + let~ res : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] := + M.alloc (| + Value.StructRecord + "p3_monty_31::dft::RecursiveDft" + [ + ("twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "default", + [], + [] + |), + [] + |)); + ("inv_twiddles", + M.call_closure (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "default", + [], + [] + |), + [] + |)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "update_twiddles", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, res |); M.read (| n |) ] + |) + |) in + res + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "new" (new MP). + Admitted. + Global Typeclasses Opaque new. + + (* + fn decimation_in_freq_dft( + mat: &mut [MontyField31], + ncols: usize, + twiddles: &[Vec>], + ) { + if ncols > 1 { + let lg_fft_len = p3_util::log2_ceil_usize(ncols); + let roots_idx = (twiddles.len() + 1) - lg_fft_len; + let twiddles = &twiddles[roots_idx..]; + + mat.par_chunks_exact_mut(ncols) + .for_each(|v| MontyField31::forward_fft(v, twiddles)) + } + } + *) + Definition decimation_in_freq_dft + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ mat; ncols; twiddles ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let ncols := M.alloc (| ncols |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ M.read (| ncols |); Value.Integer IntegerKind.Usize 1 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ lg_fft_len : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_ceil_usize", [], [] |), + [ M.read (| ncols |) ] + |) + |) in + let~ roots_idx : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + M.read (| lg_fft_len |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", M.read (| roots_idx |)) ] + ] + |) + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "par_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.read (| ncols |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let v := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "forward_fft", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| v |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_decimation_in_freq_dft : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "decimation_in_freq_dft" (decimation_in_freq_dft MP). + Admitted. + Global Typeclasses Opaque decimation_in_freq_dft. + + (* + fn decimation_in_time_dft( + mat: &mut [MontyField31], + ncols: usize, + twiddles: &[Vec>], + ) { + if ncols > 1 { + let lg_fft_len = p3_util::log2_ceil_usize(ncols); + let roots_idx = (twiddles.len() + 1) - lg_fft_len; + let twiddles = &twiddles[roots_idx..]; + + mat.par_chunks_exact_mut(ncols) + .for_each(|v| MontyField31::backward_fft(v, twiddles)) + } + } + *) + Definition decimation_in_time_dft + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ mat; ncols; twiddles ] => + ltac:(M.monadic + (let mat := M.alloc (| mat |) in + let ncols := M.alloc (| ncols |) in + let twiddles := M.alloc (| twiddles |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ M.read (| ncols |); Value.Integer IntegerKind.Usize 1 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ lg_fft_len : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_ceil_usize", [], [] |), + [ M.read (| ncols |) ] + |) + |) in + let~ roots_idx : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + M.read (| lg_fft_len |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", M.read (| roots_idx |)) ] + ] + |) + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParallelSliceMut", + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "par_chunks_exact_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| mat |) |) |); + M.read (| ncols |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let v := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "backward_fft", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| v |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| twiddles |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_decimation_in_time_dft : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "decimation_in_time_dft" (decimation_in_time_dft MP). + Admitted. + Global Typeclasses Opaque decimation_in_time_dft. + + (* #[instrument(skip_all)] *) + Definition update_twiddles + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ self; fft_len ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let fft_len := M.alloc (| fft_len |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::update_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::update_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::update_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::update_twiddles::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ curr_max_fft_len : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 2; + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "twiddles" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ M.read (| fft_len |); M.read (| curr_max_fft_len |) ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ new_twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "roots_of_unity_table", + [], + [] + |), + [ M.read (| fft_len |) ] + |) + |) in + let~ new_inv_twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, new_twiddles |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let ts := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path + "core::iter::sources::once::Once") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]) + ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::chain::Chain") + [] + [ + Ty.apply + (Ty.path + "core::iter::sources::once::Once") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ]; + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]) + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::sources::once::Once") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [], + "chain", + [], + [ + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]) + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::sources::once::Once") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_function (| + "core::iter::sources::once::once", + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + [], + [], + "rev", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ + Ty.path + "usize" + ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + ts + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + Value.Integer + IntegerKind.Usize + 1) + ] + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP + ] + ] + ] + ] + (Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.read (| + γ + |) in + let t := + M.copy (| + γ + |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path + "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path + "u32" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + t, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "replace", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "twiddles" + |) + |); + M.read (| new_twiddles |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "replace", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "inv_twiddles" + |) + |); + M.read (| new_inv_twiddles |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_update_twiddles : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "update_twiddles" (update_twiddles MP). + Admitted. + Global Typeclasses Opaque update_twiddles. + End Impl_p3_monty_31_dft_RecursiveDft_p3_monty_31_monty_31_MontyField31_MP. + + Module Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_monty_31_data_traits_MontyParameters_MP_where_p3_monty_31_data_traits_FieldParameters_MP_where_p3_monty_31_data_traits_TwoAdicData_MP_p3_monty_31_monty_31_MontyField31_MP_for_p3_monty_31_dft_RecursiveDft_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ]. + + (* type Evaluations = BitReversedMatrixView>>; *) + Definition _Evaluations (MP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]. + + (* #[instrument(skip_all, fields(dims = %mat.dimensions(), added_bits))] *) + Definition dft_batch (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.catch_return + (Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + (Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ]) + "Evaluations") (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ] + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + mat + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "tracing_core::field::Empty" + [] + |) + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ nrows : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ ncols : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ M.read (| nrows |); Value.Integer IntegerKind.Usize 1 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::bitrev::BitReversibleMatrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "bit_reverse_rows", + [], + [] + |), + [ M.read (| mat |) ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ scratch : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]); + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "default", + [], + [] + |), + [ M.read (| nrows |); M.read (| ncols |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "update_twiddles", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| nrows |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "twiddles" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + nrows + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ncols + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_function (| + "transpose::out_of_place::transpose", + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + scratch, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| ncols |); + M.read (| nrows |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ncols + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + nrows + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "decimation_in_freq_dft", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + scratch, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| nrows |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + twiddles + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ncols + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + nrows + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::dft_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_function (| + "transpose::out_of_place::transpose", + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + scratch, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| nrows |); + M.read (| ncols |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::bitrev::BitReversibleMatrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "bit_reverse_rows", + [], + [] + |), + [ M.read (| mat |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* #[instrument(skip_all, fields(dims = %mat.dimensions(), added_bits))] *) + Definition idft_batch (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ self; mat ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + M.catch_return + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ] + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + mat + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "tracing_core::field::Empty" + [] + |) + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ nrows : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ ncols : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ M.read (| nrows |); Value.Integer IntegerKind.Usize 1 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| M.read (| mat |) |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ scratch : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]); + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "default", + [], + [] + |), + [ M.read (| nrows |); M.read (| ncols |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]); + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::bitrev::BitReversibleMatrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "bit_reverse_rows", + [], + [] + |), + [ M.read (| mat |) ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "update_twiddles", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| nrows |) + ] + |) + |) in + let~ inv_twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "inv_twiddles" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + nrows + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ncols + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_function (| + "transpose::out_of_place::transpose", + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + scratch, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| ncols |); + M.read (| nrows |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ncols + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + nrows + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "decimation_in_time_dft", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + scratch, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| nrows |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + inv_twiddles + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'5", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'5", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'5", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ncols + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + nrows + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'5", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_function (| + "transpose::out_of_place::transpose", + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + scratch, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| nrows |); + M.read (| ncols |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ log_rows : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_ceil_usize", [], [] |), + [ M.read (| nrows |) ] + |) + |) in + let~ inv_len : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + |) + |); + M.cast (Ty.path "u64") (M.read (| log_rows |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'6", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'6", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'6", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::idft_batch::__CALLSITE'6", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "scale", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, mat |); + M.read (| inv_len |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + mat + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* #[instrument(skip_all, fields(dims = %mat.dimensions(), added_bits))] *) + Definition coset_lde_batch + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ self; mat; added_bits; shift ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let mat := M.alloc (| mat |) in + let added_bits := M.alloc (| added_bits |) in + let shift := M.alloc (| shift |) in + M.catch_return + (Ty.associated_in_trait + "p3_dft::traits::TwoAdicSubgroupDft" + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + (Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ]) + "Evaluations") (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "tracing_core::field::DisplayValue") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ], + M.get_function (| + "tracing_core::field::display", + [], + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "p3_matrix::Dimensions" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "p3_matrix::Dimensions", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ + MP + ] + ], + "dimensions", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + mat + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "tracing_core::field::Empty" + [] + |) + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ nrows : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ ncols : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, mat |) ] + |) + |) in + let~ result_nrows : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ M.read (| nrows |); M.read (| added_bits |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| nrows |); Value.Integer IntegerKind.Usize 1 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ dupd_rows : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::flatten::Flatten") + [] + [ + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::Flatten") + [] + [ + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "flatten", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::sources::repeat_n::RepeatN") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_function (| + "core::iter::sources::repeat_n::repeat_n", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |); + M.read (| result_nrows |) + ] + |) + ] + |) + ] + |) + |) in + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::bitrev::BitReversibleMatrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "bit_reverse_rows", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ M.read (| dupd_rows |); M.read (| ncols |) ] + |) + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ input_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| nrows |); M.read (| ncols |) ] + |) + |) in + let~ output_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| result_nrows |); M.read (| ncols |) ] + |) + |) in + let~ mat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "to_row_major_matrix", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::bitrev::BitReversibleMatrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + "bit_reverse_rows", + [], + [] + |), + [ M.read (| mat |) ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]); + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + [], + [], + "zero_vec", + [], + [] + |), + [ M.read (| output_size |) ] + |) + |) in + let~ padded : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + [], + [], + "zero_vec", + [], + [] + |), + [ M.read (| output_size |) ] + |) + |) in + M.alloc (| + Value.Tuple + [ M.read (| output |); M.read (| padded |) ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let output := M.copy (| γ0_0 |) in + let padded := M.copy (| γ0_1 |) in + let~ coeffs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, output |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", M.read (| input_size |)) ] + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + nrows + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ncols + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_function (| + "transpose::out_of_place::transpose", + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + mat, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| coeffs |) |) + |); + M.read (| ncols |); + M.read (| nrows |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "update_twiddles", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| result_nrows |) + ] + |) + |) in + let~ inv_twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "inv_twiddles" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ncols + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + nrows + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "decimation_in_time_dft", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| coeffs |) |) + |); + M.read (| nrows |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + inv_twiddles + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ log_rows : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_ceil_usize", [], [] |), + [ M.read (| nrows |) ] + |) + |) in + let~ inv_len : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + [], + [], + "div_2exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + |) + |); + M.cast (Ty.path "u64") (M.read (| log_rows |)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_monty_31::dft::coset_shift_and_scale_rows", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, padded |) |) + |) + ] + |) + |) + |); + M.read (| result_nrows |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| coeffs |) |) |); + M.read (| nrows |); + M.read (| shift |); + M.read (| inv_len |) + ] + |) + |) in + let~ twiddles : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::cell::RefCell") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::dft::RecursiveDft", + "twiddles" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ncols + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + result_nrows + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'4", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::dft::RecursiveDft") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + "decimation_in_freq_dft", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + padded + |) + |) + |) + ] + |) + |) + |); + M.read (| result_nrows |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "core::cell::Ref") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + twiddles + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []); Ty.tuple [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'5", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'5", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'5", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::field::Iter" + ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::Iter", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + ncols + |) + |) + |)) + |)) + |) + ] + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::Field", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.path + "tracing_core::field::Field" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.path + "tracing_core::field::Iter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "FieldSet corrupted (this is a bug)" + |) + |) + |) + ] + |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.use + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + result_nrows + |) + |) + |)) + |)) + |) + |) + |)) + ] + ] + ] + |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_monty_31::dft::coset_lde_batch::__CALLSITE'5", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple [], + M.get_function (| + "transpose::out_of_place::transpose", + [], + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + padded + |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + output + |) + |) + |) + ] + |) + |) + |); + M.read (| result_nrows |); + M.read (| ncols |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::row_index_mapped::RowIndexMappedView") + [] + [ + Ty.path "p3_matrix::bitrev::BitReversalPerm"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "p3_matrix::bitrev::BitReversibleMatrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] + ], + "bit_reverse_rows", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ]; + Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ M.read (| output |); M.read (| ncols |) ] + |) + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (MP : Ty.t), + M.IsTraitInstance + "p3_dft::traits::TwoAdicSubgroupDft" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + (Self MP) + (* Instance *) + [ + ("Evaluations", InstanceField.Ty (_Evaluations MP)); + ("dft_batch", InstanceField.Method (dft_batch MP)); + ("idft_batch", InstanceField.Method (idft_batch MP)); + ("coset_lde_batch", InstanceField.Method (coset_lde_batch MP)) + ]. + End Impl_p3_dft_traits_TwoAdicSubgroupDft_where_p3_monty_31_data_traits_MontyParameters_MP_where_p3_monty_31_data_traits_FieldParameters_MP_where_p3_monty_31_data_traits_TwoAdicData_MP_p3_monty_31_monty_31_MontyField31_MP_for_p3_monty_31_dft_RecursiveDft_p3_monty_31_monty_31_MontyField31_MP. +End dft. diff --git a/CoqOfRust/plonky3/monty-31/src/extension.rs b/CoqOfRust/plonky3/monty-31/src/extension.rs new file mode 100644 index 000000000..9b3b7abf1 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/extension.rs @@ -0,0 +1,36 @@ +use p3_field::extension::{BinomiallyExtendable, HasTwoAdicBinomialExtension}; +use p3_field::{TwoAdicField, field_to_array}; + +use crate::{BinomialExtensionData, FieldParameters, MontyField31, TwoAdicData}; + +// If a field implements BinomialExtensionData then there is a natural +// field extension of degree WIDTH we can define. +// We perform no checks to make sure the data given in BinomialExtensionData is valid and +// corresponds to an actual field extension. Ensuring that is left to the implementor. + +impl BinomiallyExtendable for MontyField31 +where + FP: BinomialExtensionData + FieldParameters, +{ + const W: Self = FP::W; + + const DTH_ROOT: Self = FP::DTH_ROOT; + + const EXT_GENERATOR: [Self; WIDTH] = FP::EXT_GENERATOR; +} + +impl HasTwoAdicBinomialExtension for MontyField31 +where + FP: BinomialExtensionData + TwoAdicData + FieldParameters, +{ + const EXT_TWO_ADICITY: usize = FP::EXT_TWO_ADICITY; + + fn ext_two_adic_generator(bits: usize) -> [Self; WIDTH] { + assert!(bits <= Self::EXT_TWO_ADICITY); + if bits <= FP::TWO_ADICITY { + field_to_array(Self::two_adic_generator(bits)) + } else { + FP::TWO_ADIC_EXTENSION_GENERATORS.as_ref()[bits - FP::TWO_ADICITY - 1] + } + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/extension.v b/CoqOfRust/plonky3/monty-31/src/extension.v new file mode 100644 index 000000000..1296441a9 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/extension.v @@ -0,0 +1,329 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module extension. + Module Impl_p3_field_extension_BinomiallyExtendable_where_p3_monty_31_data_traits_BinomialExtensionData_FP_where_p3_monty_31_data_traits_FieldParameters_FP_WIDTH_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (WIDTH : Value.t) (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* const W: Self = FP::W; *) + (* Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] *) + Definition value_W + (WIDTH : Value.t) + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH FP in + ltac:(M.monadic + (get_constant (| + "p3_monty_31::data_traits::BinomialExtensionData::W", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |))). + + (* const DTH_ROOT: Self = FP::DTH_ROOT; *) + (* Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] *) + Definition value_DTH_ROOT + (WIDTH : Value.t) + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH FP in + ltac:(M.monadic + (get_constant (| + "p3_monty_31::data_traits::BinomialExtensionData::DTH_ROOT", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |))). + + (* const EXT_GENERATOR: [Self; WIDTH] = FP::EXT_GENERATOR; *) + (* Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] *) + Definition value_EXT_GENERATOR + (WIDTH : Value.t) + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH FP in + ltac:(M.monadic + (get_constant (| + "p3_monty_31::data_traits::BinomialExtensionData::EXT_GENERATOR", + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + |))). + + Axiom Implements : + forall (WIDTH : Value.t) (FP : Ty.t), + M.IsTraitInstance + "p3_field::extension::BinomiallyExtendable" + (* Trait polymorphic consts *) [ WIDTH ] + (* Trait polymorphic types *) [] + (Self WIDTH FP) + (* Instance *) + [ + ("value_W", InstanceField.Method (value_W WIDTH FP)); + ("value_DTH_ROOT", InstanceField.Method (value_DTH_ROOT WIDTH FP)); + ("value_EXT_GENERATOR", InstanceField.Method (value_EXT_GENERATOR WIDTH FP)) + ]. + End Impl_p3_field_extension_BinomiallyExtendable_where_p3_monty_31_data_traits_BinomialExtensionData_FP_where_p3_monty_31_data_traits_FieldParameters_FP_WIDTH_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_extension_HasTwoAdicBinomialExtension_where_p3_monty_31_data_traits_BinomialExtensionData_FP_where_p3_monty_31_data_traits_TwoAdicData_FP_where_p3_monty_31_data_traits_FieldParameters_FP_WIDTH_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (WIDTH : Value.t) (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* const EXT_TWO_ADICITY: usize = FP::EXT_TWO_ADICITY; *) + (* Ty.path "usize" *) + Definition value_EXT_TWO_ADICITY + (WIDTH : Value.t) + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH FP in + ltac:(M.monadic + (get_constant (| + "p3_monty_31::data_traits::BinomialExtensionData::EXT_TWO_ADICITY", + Ty.path "usize" + |))). + + (* + fn ext_two_adic_generator(bits: usize) -> [Self; WIDTH] { + assert!(bits <= Self::EXT_TWO_ADICITY); + if bits <= FP::TWO_ADICITY { + field_to_array(Self::two_adic_generator(bits)) + } else { + FP::TWO_ADIC_EXTENSION_GENERATORS.as_ref()[bits - FP::TWO_ADICITY - 1] + } + } + *) + Definition ext_two_adic_generator + (WIDTH : Value.t) + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH FP in + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| bits |); + M.read (| + get_constant (| + "p3_field::extension::HasTwoAdicBinomialExtension::EXT_TWO_ADICITY", + Ty.path "usize" + |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits <= Self::EXT_TWO_ADICITY" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| bits |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::TWO_ADICITY", + Ty.path "usize" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_function (| + "p3_field::helpers::field_to_array", + [ WIDTH ], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_field::field::TwoAdicField", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "two_adic_generator", + [], + [] + |), + [ M.read (| bits |) ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::BinomialExtensionData" + [ WIDTH ] + [] + FP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::BinomialExtensionData::TWO_ADIC_EXTENSION_GENERATORS", + Ty.associated_in_trait + "p3_monty_31::data_traits::BinomialExtensionData" + [ WIDTH ] + [] + FP + "ArrayLike" + |) + |) + ] + |) + |), + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| bits |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::TWO_ADICITY", + Ty.path "usize" + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (FP : Ty.t), + M.IsTraitInstance + "p3_field::extension::HasTwoAdicBinomialExtension" + (* Trait polymorphic consts *) [ WIDTH ] + (* Trait polymorphic types *) [] + (Self WIDTH FP) + (* Instance *) + [ + ("value_EXT_TWO_ADICITY", InstanceField.Method (value_EXT_TWO_ADICITY WIDTH FP)); + ("ext_two_adic_generator", InstanceField.Method (ext_two_adic_generator WIDTH FP)) + ]. + End Impl_p3_field_extension_HasTwoAdicBinomialExtension_where_p3_monty_31_data_traits_BinomialExtensionData_FP_where_p3_monty_31_data_traits_TwoAdicData_FP_where_p3_monty_31_data_traits_FieldParameters_FP_WIDTH_for_p3_monty_31_monty_31_MontyField31_FP. +End extension. diff --git a/CoqOfRust/plonky3/monty-31/src/lib.rs b/CoqOfRust/plonky3/monty-31/src/lib.rs new file mode 100644 index 000000000..6ca4f3e33 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/lib.rs @@ -0,0 +1,65 @@ +#![no_std] +#![cfg_attr( + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), + feature(stdarch_x86_avx512) +)] + +extern crate alloc; + +mod data_traits; +pub mod dft; +mod extension; +mod mds; +mod monty_31; +mod poseidon2; +mod utils; +pub use data_traits::*; +pub use mds::*; +pub use monty_31::*; +pub use poseidon2::*; + +#[cfg(all(target_arch = "aarch64", target_feature = "neon"))] +mod aarch64_neon; +#[cfg(all(target_arch = "aarch64", target_feature = "neon"))] +pub use aarch64_neon::*; + +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +mod x86_64_avx2; +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +pub use x86_64_avx2::*; + +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +mod x86_64_avx512; +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +pub use x86_64_avx512::*; + +#[cfg(not(any( + all(target_arch = "aarch64", target_feature = "neon"), + all(target_arch = "x86_64", target_feature = "avx2",), +)))] +mod no_packing; +#[cfg(not(any( + all(target_arch = "aarch64", target_feature = "neon"), + all(target_arch = "x86_64", target_feature = "avx2",), +)))] +pub use no_packing::*; diff --git a/CoqOfRust/plonky3/monty-31/src/mds.rs b/CoqOfRust/plonky3/monty-31/src/mds.rs new file mode 100644 index 000000000..2c0975d78 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/mds.rs @@ -0,0 +1,386 @@ +use core::marker::PhantomData; + +use p3_mds::MdsPermutation; +use p3_mds::karatsuba_convolution::Convolve; +use p3_mds::util::dot_product; +use p3_symmetric::Permutation; + +use crate::{BarrettParameters, MontyField31, MontyParameters}; + +/// A collection of circulant MDS matrices saved using their left most column. +pub trait MDSUtils: Clone + Sync { + const MATRIX_CIRC_MDS_8_COL: [i64; 8]; + const MATRIX_CIRC_MDS_12_COL: [i64; 12]; + const MATRIX_CIRC_MDS_16_COL: [i64; 16]; + const MATRIX_CIRC_MDS_24_COL: [i64; 24]; + const MATRIX_CIRC_MDS_32_COL: [i64; 32]; + const MATRIX_CIRC_MDS_64_COL: [i64; 64]; +} + +#[derive(Clone, Debug, Default)] +pub struct MdsMatrixMontyField31 { + _phantom: PhantomData, +} + +/// Instantiate convolution for "small" RHS vectors over a 31-bit MONTY_FIELD. +/// +/// Here "small" means N = len(rhs) <= 16 and sum(r for r in rhs) < +/// 2^24 (roughly), though in practice the sum will be less than 2^9. +struct SmallConvolveMontyField31; + +impl Convolve, i64, i64, i64> for SmallConvolveMontyField31 { + /// Return the lift of a Monty31 element, satisfying 0 <= + /// input.value < P < 2^31. Note that Monty31 elements are + /// represented in Monty form. + #[inline(always)] + fn read(input: MontyField31) -> i64 { + input.value as i64 + } + + /// For a convolution of size N, |x| < N * 2^31 and (as per the + /// assumption above), |y| < 2^24. So the product is at most N * 2^55 + /// which will not overflow for N <= 16. + /// + /// Note that the LHS element is in Monty form, while the RHS + /// element is a "plain integer". This informs the implementation + /// of `reduce()` below. + #[inline(always)] + fn parity_dot(u: [i64; N], v: [i64; N]) -> i64 { + dot_product(u, v) + } + + /// The assumptions above mean z < N^2 * 2^55, which is at most + /// 2^63 when N <= 16. + /// + /// Because the LHS elements were in Monty form and the RHS + /// elements were plain integers, reduction is simply the usual + /// reduction modulo P, rather than "Monty reduction". + /// + /// NB: Even though intermediate values could be negative, the + /// output must be non-negative since the inputs were + /// non-negative. + #[inline(always)] + fn reduce(z: i64) -> MontyField31 { + debug_assert!(z >= 0); + + MontyField31::new_monty((z as u64 % FP::PRIME as u64) as u32) + } +} + +/// Given |x| < 2^80 compute x' such that: +/// |x'| < 2**50 +/// x' = x mod p +/// x' = x mod 2^10 +/// See Thm 1 (Below function) for a proof that this function is correct. +#[inline(always)] +const fn barrett_red_monty31(input: i128) -> i64 { + // input = input_low + beta*input_high + // So input_high < 2**63 and fits in an i64. + let input_high = (input >> BP::N) as i64; // input_high < input / beta < 2**{80 - N} + + // I, input_high are i64's so this multiplication can't overflow. + let quot = (((input_high as i128) * (BP::PSEUDO_INV as i128)) >> BP::N) as i64; + + // Replace quot by a close value which is divisible by 2^10. + let quot_2adic = quot & BP::MASK; + + // quot_2adic, P are i64's so this can't overflow. + // sub is by construction divisible by both P and 2^10. + let sub = (quot_2adic as i128) * BP::PRIME_I128; + + (input - sub) as i64 +} + +// Theorem 1: +// Given |x| < 2^80, barrett_red(x) computes an x' such that: +// x' = x mod p +// x' = x mod 2^10 +// |x'| < 2**50. +/////////////////////////////////////////////////////////////////////////////////////// +// PROOF: +// By construction P, 2**10 | sub and so we immediately see that +// x' = x mod p +// x' = x mod 2^10. +// +// It remains to prove that |x'| < 2**50. +// +// We start by introducing some simple inequalities and relations between our variables: +// +// First consider the relationship between bit-shift and division. +// It's easy to check that for all x: +// 1: (x >> N) <= x / 2**N <= 1 + (x >> N) +// +// Similarly, as our mask just 0's the last 10 bits, +// 2: x + 1 - 2^10 <= x & mask <= x +// +// Now if x, y are positive integers then +// (x / y) - 1 <= x // y <= x / y +// Where // denotes integer division. +// +// From this last inequality we immediately derive: +// 3: (2**{2N} / P) - 1 <= I <= (2**{2N} / P) +// 3a: 2**{2N} - P <= PI +// +// Finally, note that by definition: +// input = input_high*(2**N) + input_low +// Hence a simple rearrangement gets us +// 4: input_high*(2**N) = input - input_low +// +// +// We now need to split into cases depending on the sign of input. +// Note that if x = 0 then x' = 0 so that case is trivial. +/////////////////////////////////////////////////////////////////////////// +// CASE 1: input > 0 +// +// If input > 0 then: +// sub = Q*P = ((((input >> N) * I) >> N) & mask) * P <= P * (input / 2**{N}) * (2**{2N} / P) / 2**{N} = input +// So input - sub >= 0. +// +// We need to improve our bound on Q. Observe that: +// Q = (((input_high * I) >> N) & mask) +// --(2) => Q + (2^10 - 1) >= (input_high * I) >> N) +// --(1) => Q + 2^10 >= (I*x_high)/(2**N) +// => (2**N)*Q + 2^10*(2**N) >= I*x_high +// +// Hence we find that: +// (2**N)*Q*P + 2^10*(2**N)*P >= input_high*I*P +// --(3a) >= input_high*2**{2N} - P*input_high +// --(4) >= (2**N)*input - (2**N)*input_low - (2**N)*input_high (Assuming P < 2**N) +// +// Dividing by 2**N we get +// Q*P + 2^{10}*P >= input - input_low - input_high +// which rearranges to +// x' = input - Q*P <= 2^{10}*P + input_low + input_high +// +// Picking N = 40 we see that 2^{10}*P, input_low, input_high are all bounded by 2**40 +// Hence x' < 2**42 < 2**50 as desired. +// +// +// +/////////////////////////////////////////////////////////////////////////// +// CASE 2: input < 0 +// +// This case will be similar but all our inequalities will change slightly as negatives complicate things. +// First observe that: +// (input >> N) * I >= (input >> N) * 2**(2N) / P +// >= (1 + (input / 2**N)) * 2**(2N) / P +// >= (2**N + input) * 2**N / P +// +// Thus: +// Q = ((input >> N) * I) >> N >= ((2**N + input) * 2**N / P) >> N +// >= ((2**N + input) / P) - 1 +// +// And so sub = Q*P >= 2**N - P + input. +// Hence input - sub < 2**N - P. +// +// Thus if input - sub > 0 then |input - sub| < 2**50. +// Thus we are left with bounding -(input - sub) = (sub - input). +// Again we will proceed by improving our bound on Q. +// +// Q = (((input_high * I) >> N) & mask) +// --(2) => Q <= (input_high * I) >> N) <= (I*x_high)/(2**N) +// --(1) => Q <= (I*x_high)/(2**N) +// => (2**N)*Q <= I*x_high +// +// Hence we find that: +// (2**N)*Q*P <= input_high*I*P +// --(3a) <= input_high*2**{2N} - P*input_high +// --(4) <= (2**N)*input - (2**N)*input_low - (2**N)*input_high (Assuming P < 2**N) +// +// Dividing by 2**N we get +// Q*P <= input - input_low - input_high +// which rearranges to +// -x' = -input + Q*P <= -input_high - input_low < 2**50 +// +// This completes the proof. + +/// Instantiate convolution for "large" RHS vectors over BabyBear. +/// +/// Here "large" means the elements can be as big as the field +/// characteristic, and the size N of the RHS is <= 64. +#[derive(Debug, Clone, Default)] +struct LargeConvolveMontyField31; + +impl Convolve, i64, i64, i64> for LargeConvolveMontyField31 +where + FP: BarrettParameters, +{ + /// Return the lift of a MontyField31 element, satisfying + /// 0 <= input.value < P < 2^31. + /// Note that MontyField31 elements are represented in Monty form. + #[inline(always)] + fn read(input: MontyField31) -> i64 { + input.value as i64 + } + + #[inline(always)] + fn parity_dot(u: [i64; N], v: [i64; N]) -> i64 { + // For a convolution of size N, |x|, |y| < N * 2^31, so the + // product could be as much as N^2 * 2^62. This will overflow an + // i64, so we first widen to i128. Note that N^2 * 2^62 < 2^80 + // for N <= 64, as required by `barrett_red_monty31()`. + + let mut dp = 0i128; + for i in 0..N { + dp += u[i] as i128 * v[i] as i128; + } + barrett_red_monty31::(dp) + } + + #[inline(always)] + fn reduce(z: i64) -> MontyField31 { + // After the barrett reduction method, the output z of parity + // dot satisfies |z| < 2^50 (See Thm 1 above). + // + // In the recombining steps, conv_n maps (wo, w1) -> + // ((wo + w1)/2, (wo + w1)/2) which has no effect on the maximal + // size. (Indeed, it makes sizes almost strictly smaller). + // + // On the other hand, negacyclic_conv_n (ignoring the re-index) + // recombines as: (w0, w1, w2) -> (w0 + w1, w2 - w0 - w1). + // Hence if the input is <= K, the output is <= 3K. + // + // Thus the values appearing at the end are bounded by 3^n 2^50 + // where n is the maximal number of negacyclic_conv + // recombination steps. When N = 64, we need to recombine for + // signed_conv_32, signed_conv_16, signed_conv_8 so the + // overall bound will be 3^3 2^50 < 32 * 2^50 < 2^55. + debug_assert!(z > -(1i64 << 55)); + debug_assert!(z < (1i64 << 55)); + + // Note we do NOT move it into MONTY form. We assume it is already + // in this form. + let red = (z % (FP::PRIME as i64)) as u32; + + // If z >= 0: 0 <= red < P is the correct value and P + red will + // not overflow. + // If z < 0: -P < red < 0 and the value we want is P + red. + // On bits, + acts identically for i32 and u32. Hence we can use + // u32's and just check for overflow. + + let (corr, over) = red.overflowing_add(FP::PRIME); + let value = if over { corr } else { red }; + MontyField31::new_monty(value) + } +} + +impl Permutation<[MontyField31; 8]> + for MdsMatrixMontyField31 +{ + fn permute(&self, input: [MontyField31; 8]) -> [MontyField31; 8] { + SmallConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_8_COL, + , i64, i64, i64>>::conv8, + ) + } + + fn permute_mut(&self, input: &mut [MontyField31; 8]) { + *input = self.permute(*input); + } +} +impl MdsPermutation, 8> + for MdsMatrixMontyField31 +{ +} + +impl Permutation<[MontyField31; 12]> + for MdsMatrixMontyField31 +{ + fn permute(&self, input: [MontyField31; 12]) -> [MontyField31; 12] { + SmallConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_12_COL, + , i64, i64, i64>>::conv12, + ) + } + + fn permute_mut(&self, input: &mut [MontyField31; 12]) { + *input = self.permute(*input); + } +} +impl MdsPermutation, 12> + for MdsMatrixMontyField31 +{ +} + +impl Permutation<[MontyField31; 16]> + for MdsMatrixMontyField31 +{ + fn permute(&self, input: [MontyField31; 16]) -> [MontyField31; 16] { + SmallConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_16_COL, + , i64, i64, i64>>::conv16, + ) + } + + fn permute_mut(&self, input: &mut [MontyField31; 16]) { + *input = self.permute(*input); + } +} +impl MdsPermutation, 16> + for MdsMatrixMontyField31 +{ +} + +impl Permutation<[MontyField31; 24]> for MdsMatrixMontyField31 +where + FP: BarrettParameters, +{ + fn permute(&self, input: [MontyField31; 24]) -> [MontyField31; 24] { + LargeConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_24_COL, + , i64, i64, i64>>::conv24, + ) + } + + fn permute_mut(&self, input: &mut [MontyField31; 24]) { + *input = self.permute(*input); + } +} +impl MdsPermutation, 24> + for MdsMatrixMontyField31 +{ +} + +impl Permutation<[MontyField31; 32]> + for MdsMatrixMontyField31 +{ + fn permute(&self, input: [MontyField31; 32]) -> [MontyField31; 32] { + LargeConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_32_COL, + , i64, i64, i64>>::conv32, + ) + } + + fn permute_mut(&self, input: &mut [MontyField31; 32]) { + *input = self.permute(*input); + } +} +impl MdsPermutation, 32> + for MdsMatrixMontyField31 +{ +} + +impl Permutation<[MontyField31; 64]> + for MdsMatrixMontyField31 +{ + fn permute(&self, input: [MontyField31; 64]) -> [MontyField31; 64] { + LargeConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_64_COL, + , i64, i64, i64>>::conv64, + ) + } + + fn permute_mut(&self, input: &mut [MontyField31; 64]) { + *input = self.permute(*input); + } +} +impl MdsPermutation, 64> + for MdsMatrixMontyField31 +{ +} diff --git a/CoqOfRust/plonky3/monty-31/src/mds.v b/CoqOfRust/plonky3/monty-31/src/mds.v new file mode 100644 index 000000000..d347833c4 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/mds.v @@ -0,0 +1,2025 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module mds. + (* Trait *) + (* Empty module 'MDSUtils' *) + + (* StructRecord + { + name := "MdsMatrixMontyField31"; + const_params := []; + ty_params := [ "MU" ]; + fields := [ ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ MU ]) ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_MU_where_p3_monty_31_mds_MDSUtils_MU_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + (* Clone *) + Definition clone (MU : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MU in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_monty_31::mds::MdsMatrixMontyField31" + [ + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ MU ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ MU ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::mds::MdsMatrixMontyField31", + "_phantom" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (MU : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self MU) + (* Instance *) [ ("clone", InstanceField.Method (clone MU)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_MU_where_p3_monty_31_mds_MDSUtils_MU_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_MU_where_p3_monty_31_mds_MDSUtils_MU_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + (* Debug *) + Definition fmt (MU : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MU in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "MdsMatrixMontyField31" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::mds::MdsMatrixMontyField31", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (MU : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self MU) + (* Instance *) [ ("fmt", InstanceField.Method (fmt MU)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_MU_where_p3_monty_31_mds_MDSUtils_MU_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_core_default_Default_where_core_default_Default_MU_where_p3_monty_31_mds_MDSUtils_MU_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + (* Default *) + Definition default (MU : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MU in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_monty_31::mds::MdsMatrixMontyField31" + [ + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ MU ], + M.get_trait_method (| + "core::default::Default", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ MU ], + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (MU : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self MU) + (* Instance *) [ ("default", InstanceField.Method (default MU)) ]. + End Impl_core_default_Default_where_core_default_Default_MU_where_p3_monty_31_mds_MDSUtils_MU_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + (* StructTuple + { + name := "SmallConvolveMontyField31"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_p3_mds_karatsuba_convolution_Convolve_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_i64_i64_i64_for_p3_monty_31_mds_SmallConvolveMontyField31. + Definition Self (FP : Ty.t) : Ty.t := Ty.path "p3_monty_31::mds::SmallConvolveMontyField31". + + (* + fn read(input: MontyField31) -> i64 { + input.value as i64 + } + *) + Definition read (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.cast + (Ty.path "i64") + (M.read (| + M.SubPointer.get_struct_record_field (| + input, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn parity_dot(u: [i64; N], v: [i64; N]) -> i64 { + dot_product(u, v) + } + *) + Definition parity_dot (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [ N ], [], [ u; v ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + let v := M.alloc (| v |) in + M.call_closure (| + Ty.path "i64", + M.get_function (| "p3_mds::util::dot_product", [ N ], [ Ty.path "i64" ] |), + [ M.read (| u |); M.read (| v |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn reduce(z: i64) -> MontyField31 { + debug_assert!(z >= 0); + + MontyField31::new_monty((z as u64 % FP::PRIME as u64) as u32) + } + *) + Definition reduce (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ z ] => + ltac:(M.monadic + (let z := M.alloc (| z |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| z |); Value.Integer IntegerKind.I64 0 ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: z >= 0" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u64", + BinOp.Wrap.rem, + [ + M.cast (Ty.path "u64") (M.read (| z |)); + M.cast + (Ty.path "u64") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_mds::karatsuba_convolution::Convolve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ] + (Self FP) + (* Instance *) + [ + ("read", InstanceField.Method (read FP)); + ("parity_dot", InstanceField.Method (parity_dot FP)); + ("reduce", InstanceField.Method (reduce FP)) + ]. + End Impl_p3_mds_karatsuba_convolution_Convolve_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_i64_i64_i64_for_p3_monty_31_mds_SmallConvolveMontyField31. + + (* + const fn barrett_red_monty31(input: i128) -> i64 { + // input = input_low + beta*input_high + // So input_high < 2**63 and fits in an i64. + let input_high = (input >> BP::N) as i64; // input_high < input / beta < 2**{80 - N} + + // I, input_high are i64's so this multiplication can't overflow. + let quot = (((input_high as i128) * (BP::PSEUDO_INV as i128)) >> BP::N) as i64; + + // Replace quot by a close value which is divisible by 2^10. + let quot_2adic = quot & BP::MASK; + + // quot_2adic, P are i64's so this can't overflow. + // sub is by construction divisible by both P and 2^10. + let sub = (quot_2adic as i128) * BP::PRIME_I128; + + (input - sub) as i64 + } + *) + Definition barrett_red_monty31 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ BP ], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ input_high : Ty.apply (Ty.path "*") [] [ Ty.path "i64" ] := + M.alloc (| + M.cast + (Ty.path "i64") + (M.call_closure (| + Ty.path "i128", + BinOp.Wrap.shr, + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::BarrettParameters::N", + Ty.path "usize" + |) + |) + ] + |)) + |) in + let~ quot : Ty.apply (Ty.path "*") [] [ Ty.path "i64" ] := + M.alloc (| + M.cast + (Ty.path "i64") + (M.call_closure (| + Ty.path "i128", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "i128", + BinOp.Wrap.mul, + [ + M.cast (Ty.path "i128") (M.read (| input_high |)); + M.cast + (Ty.path "i128") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::BarrettParameters::PSEUDO_INV", + Ty.path "i64" + |) + |)) + ] + |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::BarrettParameters::N", + Ty.path "usize" + |) + |) + ] + |)) + |) in + let~ quot_2adic : Ty.apply (Ty.path "*") [] [ Ty.path "i64" ] := + M.alloc (| + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.bit_and, + [ + M.read (| quot |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::BarrettParameters::MASK", + Ty.path "i64" + |) + |) + ] + |) + |) in + let~ sub : Ty.apply (Ty.path "*") [] [ Ty.path "i128" ] := + M.alloc (| + M.call_closure (| + Ty.path "i128", + BinOp.Wrap.mul, + [ + M.cast (Ty.path "i128") (M.read (| quot_2adic |)); + M.read (| + get_constant (| + "p3_monty_31::data_traits::BarrettParameters::PRIME_I128", + Ty.path "i128" + |) + |) + ] + |) + |) in + M.alloc (| + M.cast + (Ty.path "i64") + (M.call_closure (| + Ty.path "i128", + BinOp.Wrap.sub, + [ M.read (| input |); M.read (| sub |) ] + |)) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_barrett_red_monty31 : + M.IsFunction.C "p3_monty_31::mds::barrett_red_monty31" barrett_red_monty31. + Admitted. + Global Typeclasses Opaque barrett_red_monty31. + + (* StructTuple + { + name := "LargeConvolveMontyField31"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_fmt_Debug_for_p3_monty_31_mds_LargeConvolveMontyField31. + Definition Self : Ty.t := Ty.path "p3_monty_31::mds::LargeConvolveMontyField31". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "LargeConvolveMontyField31" |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_monty_31_mds_LargeConvolveMontyField31. + + Module Impl_core_clone_Clone_for_p3_monty_31_mds_LargeConvolveMontyField31. + Definition Self : Ty.t := Ty.path "p3_monty_31::mds::LargeConvolveMontyField31". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_monty_31::mds::LargeConvolveMontyField31" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_monty_31_mds_LargeConvolveMontyField31. + + Module Impl_core_default_Default_for_p3_monty_31_mds_LargeConvolveMontyField31. + Definition Self : Ty.t := Ty.path "p3_monty_31::mds::LargeConvolveMontyField31". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic (Value.StructTuple "p3_monty_31::mds::LargeConvolveMontyField31" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_monty_31_mds_LargeConvolveMontyField31. + + Module Impl_p3_mds_karatsuba_convolution_Convolve_where_p3_monty_31_data_traits_BarrettParameters_FP_p3_monty_31_monty_31_MontyField31_FP_i64_i64_i64_for_p3_monty_31_mds_LargeConvolveMontyField31. + Definition Self (FP : Ty.t) : Ty.t := Ty.path "p3_monty_31::mds::LargeConvolveMontyField31". + + (* + fn read(input: MontyField31) -> i64 { + input.value as i64 + } + *) + Definition read (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.cast + (Ty.path "i64") + (M.read (| + M.SubPointer.get_struct_record_field (| + input, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn parity_dot(u: [i64; N], v: [i64; N]) -> i64 { + // For a convolution of size N, |x|, |y| < N * 2^31, so the + // product could be as much as N^2 * 2^62. This will overflow an + // i64, so we first widen to i128. Note that N^2 * 2^62 < 2^80 + // for N <= 64, as required by `barrett_red_monty31()`. + + let mut dp = 0i128; + for i in 0..N { + dp += u[i] as i128 * v[i] as i128; + } + barrett_red_monty31::(dp) + } + *) + Definition parity_dot (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [ N ], [], [ u; v ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + let v := M.alloc (| v |) in + M.read (| + let~ dp : Ty.apply (Ty.path "*") [] [ Ty.path "i128" ] := + M.alloc (| Value.Integer IntegerKind.I128 0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := dp in + M.write (| + β, + M.call_closure (| + Ty.path "i128", + BinOp.Wrap.add, + [ + M.read (| β |); + M.call_closure (| + Ty.path "i128", + BinOp.Wrap.mul, + [ + M.cast + (Ty.path "i128") + (M.read (| + M.SubPointer.get_array_field (| + u, + M.read (| i |) + |) + |)); + M.cast + (Ty.path "i128") + (M.read (| + M.SubPointer.get_array_field (| + v, + M.read (| i |) + |) + |)) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.path "i64", + M.get_function (| "p3_monty_31::mds::barrett_red_monty31", [], [ FP ] |), + [ M.read (| dp |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn reduce(z: i64) -> MontyField31 { + // After the barrett reduction method, the output z of parity + // dot satisfies |z| < 2^50 (See Thm 1 above). + // + // In the recombining steps, conv_n maps (wo, w1) -> + // ((wo + w1)/2, (wo + w1)/2) which has no effect on the maximal + // size. (Indeed, it makes sizes almost strictly smaller). + // + // On the other hand, negacyclic_conv_n (ignoring the re-index) + // recombines as: (w0, w1, w2) -> (w0 + w1, w2 - w0 - w1). + // Hence if the input is <= K, the output is <= 3K. + // + // Thus the values appearing at the end are bounded by 3^n 2^50 + // where n is the maximal number of negacyclic_conv + // recombination steps. When N = 64, we need to recombine for + // signed_conv_32, signed_conv_16, signed_conv_8 so the + // overall bound will be 3^3 2^50 < 32 * 2^50 < 2^55. + debug_assert!(z > -(1i64 << 55)); + debug_assert!(z < (1i64 << 55)); + + // Note we do NOT move it into MONTY form. We assume it is already + // in this form. + let red = (z % (FP::PRIME as i64)) as u32; + + // If z >= 0: 0 <= red < P is the correct value and P + red will + // not overflow. + // If z < 0: -P < red < 0 and the value we want is P + red. + // On bits, + acts identically for i32 and u32. Hence we can use + // u32's and just check for overflow. + + let (corr, over) = red.overflowing_add(FP::PRIME); + let value = if over { corr } else { red }; + MontyField31::new_monty(value) + } + *) + Definition reduce (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ z ] => + ltac:(M.monadic + (let z := M.alloc (| z |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.read (| z |); + UnOp.neg (| + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I32 55 + ] + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: z > -(1i64 << 55)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| z |); + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.I64 1; + Value.Integer IntegerKind.I32 55 + ] + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: z < (1i64 << 55)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ red : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "i64", + BinOp.Wrap.rem, + [ + M.read (| z |); + M.cast + (Ty.path "i64") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |)) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u32"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "u32", "overflowing_add", [], [] |), + [ + M.read (| red |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let corr := M.copy (| γ0_0 |) in + let over := M.copy (| γ0_1 |) in + let~ value : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use over in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + corr)); + fun γ => ltac:(M.monadic red) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ M.read (| value |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_mds::karatsuba_convolution::Convolve" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ] + (Self FP) + (* Instance *) + [ + ("read", InstanceField.Method (read FP)); + ("parity_dot", InstanceField.Method (parity_dot FP)); + ("reduce", InstanceField.Method (reduce FP)) + ]. + End Impl_p3_mds_karatsuba_convolution_Convolve_where_p3_monty_31_data_traits_BarrettParameters_FP_p3_monty_31_monty_31_MontyField31_FP_i64_i64_i64_for_p3_monty_31_mds_LargeConvolveMontyField31. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_array_Usize_8_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + (* + fn permute(&self, input: [MontyField31; 8]) -> [MontyField31; 8] { + SmallConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_8_COL, + , i64, i64, i64>>::conv8, + ) + } + *) + Definition permute (FP MU : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::SmallConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 8 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_monty_31::mds::MDSUtils::MATRIX_CIRC_MDS_8_COL", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::SmallConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv8", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [MontyField31; 8]) { + *input = self.permute( *input); + } + *) + Definition permute_mut + (FP MU : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ] + (Self FP MU) + (* Instance *) + [ + ("permute", InstanceField.Method (permute FP MU)); + ("permute_mut", InstanceField.Method (permute_mut FP MU)) + ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_array_Usize_8_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_8_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 8 ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP MU) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_8_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_array_Usize_12_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + (* + fn permute(&self, input: [MontyField31; 12]) -> [MontyField31; 12] { + SmallConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_12_COL, + , i64, i64, i64>>::conv12, + ) + } + *) + Definition permute (FP MU : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::SmallConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 12 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_monty_31::mds::MDSUtils::MATRIX_CIRC_MDS_12_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::SmallConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv12", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [MontyField31; 12]) { + *input = self.permute( *input); + } + *) + Definition permute_mut + (FP MU : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 12 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ] + (Self FP MU) + (* Instance *) + [ + ("permute", InstanceField.Method (permute FP MU)); + ("permute_mut", InstanceField.Method (permute_mut FP MU)) + ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_array_Usize_12_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_12_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 12 ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP MU) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_12_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_array_Usize_16_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + (* + fn permute(&self, input: [MontyField31; 16]) -> [MontyField31; 16] { + SmallConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_16_COL, + , i64, i64, i64>>::conv16, + ) + } + *) + Definition permute (FP MU : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::SmallConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 16 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_monty_31::mds::MDSUtils::MATRIX_CIRC_MDS_16_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::SmallConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv16", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [MontyField31; 16]) { + *input = self.permute( *input); + } + *) + Definition permute_mut + (FP MU : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ] + (Self FP MU) + (* Instance *) + [ + ("permute", InstanceField.Method (permute FP MU)); + ("permute_mut", InstanceField.Method (permute_mut FP MU)) + ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_array_Usize_16_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_16_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 16 ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP MU) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_MontyParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_16_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_mds_MDSUtils_MU_where_p3_monty_31_data_traits_BarrettParameters_FP_array_Usize_24_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + (* + fn permute(&self, input: [MontyField31; 24]) -> [MontyField31; 24] { + LargeConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_24_COL, + , i64, i64, i64>>::conv24, + ) + } + *) + Definition permute (FP MU : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::LargeConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 24 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_monty_31::mds::MDSUtils::MATRIX_CIRC_MDS_24_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::LargeConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv24", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [MontyField31; 24]) { + *input = self.permute( *input); + } + *) + Definition permute_mut + (FP MU : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ] + (Self FP MU) + (* Instance *) + [ + ("permute", InstanceField.Method (permute FP MU)); + ("permute_mut", InstanceField.Method (permute_mut FP MU)) + ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_mds_MDSUtils_MU_where_p3_monty_31_data_traits_BarrettParameters_FP_array_Usize_24_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_BarrettParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_24_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 24 ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP MU) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_BarrettParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_24_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_data_traits_BarrettParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_array_Usize_32_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + (* + fn permute(&self, input: [MontyField31; 32]) -> [MontyField31; 32] { + LargeConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_32_COL, + , i64, i64, i64>>::conv32, + ) + } + *) + Definition permute (FP MU : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::LargeConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 32 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_monty_31::mds::MDSUtils::MATRIX_CIRC_MDS_32_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::LargeConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv32", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [MontyField31; 32]) { + *input = self.permute( *input); + } + *) + Definition permute_mut + (FP MU : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ] + (Self FP MU) + (* Instance *) + [ + ("permute", InstanceField.Method (permute FP MU)); + ("permute_mut", InstanceField.Method (permute_mut FP MU)) + ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_data_traits_BarrettParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_array_Usize_32_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_BarrettParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_32_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 32 ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP MU) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_BarrettParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_32_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_data_traits_BarrettParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_array_Usize_64_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + (* + fn permute(&self, input: [MontyField31; 64]) -> [MontyField31; 64] { + LargeConvolveMontyField31::apply( + input, + MU::MATRIX_CIRC_MDS_64_COL, + , i64, i64, i64>>::conv64, + ) + } + *) + Definition permute (FP MU : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::LargeConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "apply", + [ Value.Integer IntegerKind.Usize 64 ], + [ + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "i64" ]; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "i64" ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "i64" ] ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.read (| + get_constant (| + "p3_monty_31::mds::MDSUtils::MATRIX_CIRC_MDS_64_COL", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "i64" ] + |) + |); + M.get_trait_method (| + "p3_mds::karatsuba_convolution::Convolve", + Ty.path "p3_monty_31::mds::LargeConvolveMontyField31", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "i64"; + Ty.path "i64"; + Ty.path "i64" + ], + "conv64", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_mut(&self, input: &mut [MontyField31; 64]) { + *input = self.permute( *input); + } + *) + Definition permute_mut + (FP MU : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP MU in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| input |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + "permute", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ] + (Self FP MU) + (* Instance *) + [ + ("permute", InstanceField.Method (permute FP MU)); + ("permute_mut", InstanceField.Method (permute_mut FP MU)) + ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_monty_31_data_traits_BarrettParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_array_Usize_64_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + + Module Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_BarrettParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_64_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. + Definition Self (FP MU : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::mds::MdsMatrixMontyField31") [] [ MU ]. + + Axiom Implements : + forall (FP MU : Ty.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 64 ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP MU) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_where_p3_monty_31_data_traits_BarrettParameters_FP_where_p3_monty_31_mds_MDSUtils_MU_Usize_64_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_mds_MdsMatrixMontyField31_MU. +End mds. diff --git a/CoqOfRust/plonky3/monty-31/src/monty_31.rs b/CoqOfRust/plonky3/monty-31/src/monty_31.rs new file mode 100644 index 000000000..64672cb3c --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/monty_31.rs @@ -0,0 +1,591 @@ +//! An abstraction of 31-bit fields which use a MONTY approach for faster multiplication. + +use alloc::vec; +use alloc::vec::Vec; +use core::fmt::{self, Debug, Display, Formatter}; +use core::hash::Hash; +use core::iter::{Product, Sum}; +use core::marker::PhantomData; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; + +use num_bigint::BigUint; +use p3_field::integers::QuotientMap; +use p3_field::{ + Field, InjectiveMonomial, Packable, PermutationMonomial, PrimeCharacteristicRing, PrimeField, + PrimeField32, PrimeField64, TwoAdicField, quotient_map_small_int, +}; +use p3_util::flatten_to_base; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; +use serde::{Deserialize, Deserializer, Serialize}; + +use crate::utils::{ + from_monty, halve_u32, monty_reduce, to_monty, to_monty_64, to_monty_64_signed, to_monty_signed, +}; +use crate::{FieldParameters, MontyParameters, RelativelyPrimePower, TwoAdicData}; + +#[derive(Clone, Copy, Default, Eq, Hash, PartialEq)] +#[repr(transparent)] // Important for reasoning about memory layout. +pub struct MontyField31 { + /// The MONTY form of the field element, saved as a positive integer less than `P`. + /// + /// This is `pub(crate)` for tests and delayed reduction strategies. If you're accessing `value` outside of those, you're + /// likely doing something fishy. + pub(crate) value: u32, + _phantom: PhantomData, +} + +impl MontyField31 { + /// The standard way to crate a new element. + /// Note that new converts the input into MONTY form so should be avoided in performance critical implementations. + #[inline(always)] + pub const fn new(value: u32) -> Self { + Self { + value: to_monty::(value), + _phantom: PhantomData, + } + } + + /// Create a new field element from something already in MONTY form. + /// This is `pub(crate)` for tests and delayed reduction strategies. If you're using it outside of those, you're + /// likely doing something fishy. + #[inline(always)] + pub(crate) const fn new_monty(value: u32) -> Self { + Self { + value, + _phantom: PhantomData, + } + } + + /// Produce a u32 in range [0, P) from a field element corresponding to the true value. + #[inline(always)] + pub(crate) const fn to_u32(elem: &Self) -> u32 { + from_monty::(elem.value) + } + + /// Convert a constant u32 array into a constant array of field elements. + /// Constant version of array.map(MontyField31::new). + #[inline] + pub const fn new_array(input: [u32; N]) -> [Self; N] { + let mut output = [Self::new_monty(0); N]; + let mut i = 0; + while i < N { + output[i] = Self::new(input[i]); + i += 1; + } + output + } + + /// Convert a constant 2d u32 array into a constant 2d array of field elements. + /// Constant version of array.map(MontyField31::new_array). + #[inline] + pub const fn new_2d_array( + input: [[u32; N]; M], + ) -> [[Self; N]; M] { + let mut output = [[Self::new_monty(0); N]; M]; + let mut i = 0; + while i < M { + output[i] = Self::new_array(input[i]); + i += 1; + } + output + } +} + +impl MontyField31 { + const MONTY_POWERS_OF_TWO: [Self; 64] = { + let mut powers_of_two = [FP::MONTY_ONE; 64]; + let mut i = 1; + while i < 64 { + powers_of_two[i] = Self::new_monty(to_monty_64::(1 << i)); + i += 1; + } + powers_of_two + }; + + const HALF: Self = MontyField31::new(FP::HALF_P_PLUS_1); +} + +impl Ord for MontyField31 { + #[inline] + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + Self::to_u32(self).cmp(&Self::to_u32(other)) + } +} + +impl PartialOrd for MontyField31 { + #[inline] + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Display for MontyField31 { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Display::fmt(&Self::to_u32(self), f) + } +} + +impl Debug for MontyField31 { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Debug::fmt(&Self::to_u32(self), f) + } +} + +impl Distribution> for StandardUniform { + #[inline] + fn sample(&self, rng: &mut R) -> MontyField31 { + loop { + let next_u31 = rng.next_u32() >> 1; + let is_canonical = next_u31 < FP::PRIME; + if is_canonical { + return MontyField31::new_monty(next_u31); + } + } + } +} + +impl Serialize for MontyField31 { + fn serialize(&self, serializer: S) -> Result { + // It's faster to Serialize and Deserialize in monty form. + serializer.serialize_u32(self.value) + } +} + +impl<'de, FP: FieldParameters> Deserialize<'de> for MontyField31 { + fn deserialize>(d: D) -> Result { + // It's faster to Serialize and Deserialize in monty form. + let val = u32::deserialize(d)?; + Ok(Self::new_monty(val)) + } +} + +impl Packable for MontyField31 {} + +impl PrimeCharacteristicRing for MontyField31 { + type PrimeSubfield = Self; + + const ZERO: Self = FP::MONTY_ZERO; + const ONE: Self = FP::MONTY_ONE; + const TWO: Self = FP::MONTY_TWO; + const NEG_ONE: Self = FP::MONTY_NEG_ONE; + + #[inline(always)] + fn from_prime_subfield(f: Self) -> Self { + f + } + + #[inline] + fn mul_2exp_u64(&self, exp: u64) -> Self { + // The array FP::MONTY_POWERS_OF_TWO contains the powers of 2 + // from 2^0 to 2^63 in monty form. We can use this to quickly + // compute 2^exp. + if exp < 64 { + *self * Self::MONTY_POWERS_OF_TWO[exp as usize] + } else { + // For larger values we use the default method. + *self * Self::TWO.exp_u64(exp) + } + } + + #[inline] + fn zero_vec(len: usize) -> Vec { + // SAFETY: + // Due to `#[repr(transparent)]`, MontyField31 and u32 have the same size, alignment + // and memory layout making `flatten_to_base` safe. This this will create + // a vector MontyField31 elements with value set to 0 which is the + // MONTY form of 0. + unsafe { flatten_to_base(vec![0u32; len]) } + } + + #[inline] + fn sum_array(input: &[Self]) -> Self { + assert_eq!(N, input.len()); + // Benchmarking shows that for N <= 7 it's faster to sum the elements directly + // but for N > 7 it's faster to use the .sum() methods which passes through u64's + // allowing for delayed reductions. + match N { + 0 => Self::ZERO, + 1 => input[0], + 2 => input[0] + input[1], + 3 => input[0] + input[1] + input[2], + 4 => (input[0] + input[1]) + (input[2] + input[3]), + 5 => Self::sum_array::<4>(&input[..4]) + Self::sum_array::<1>(&input[4..]), + 6 => Self::sum_array::<4>(&input[..4]) + Self::sum_array::<2>(&input[4..]), + 7 => Self::sum_array::<4>(&input[..4]) + Self::sum_array::<3>(&input[4..]), + _ => input.iter().copied().sum(), + } + } +} + +impl, const D: u64> InjectiveMonomial + for MontyField31 +{ +} + +impl, const D: u64> PermutationMonomial + for MontyField31 +{ + fn injective_exp_root_n(&self) -> Self { + FP::exp_root_d(*self) + } +} + +impl Field for MontyField31 { + #[cfg(all(target_arch = "aarch64", target_feature = "neon"))] + type Packing = crate::PackedMontyField31Neon; + #[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) + ))] + type Packing = crate::PackedMontyField31AVX2; + #[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ))] + type Packing = crate::PackedMontyField31AVX512; + #[cfg(not(any( + all(target_arch = "aarch64", target_feature = "neon"), + all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) + ), + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), + )))] + type Packing = Self; + + const GENERATOR: Self = FP::MONTY_GEN; + + fn try_inverse(&self) -> Option { + FP::try_inverse(*self) + } + + #[inline] + fn halve(&self) -> Self { + Self::new_monty(halve_u32::(self.value)) + } + + #[inline] + fn div_2exp_u64(&self, exp: u64) -> Self { + if exp <= 32 { + // As the monty form of 2^{-exp} is 2^{32 - exp} mod P, for + // 0 <= exp <= 32, we can multiply by 2^{-exp} by doing a shift + // followed by a monty reduction. + let long_prod = (self.value as u64) << (32 - exp); + Self::new_monty(monty_reduce::(long_prod)) + } else { + // For larger values we use a slower method though this is + // still much faster than the default method as it avoids the inverse(). + *self * Self::HALF.exp_u64(exp) + } + } + + #[inline] + fn order() -> BigUint { + FP::PRIME.into() + } +} + +quotient_map_small_int!(MontyField31, u32, FieldParameters, [u8, u16]); +quotient_map_small_int!(MontyField31, i32, FieldParameters, [i8, i16]); + +impl QuotientMap for MontyField31 { + /// Convert a given `u32` integer into an element of the `MontyField31` field. + #[inline] + fn from_int(int: u32) -> Self { + Self::new(int) + } + + /// Convert a given `u32` integer into an element of the `MontyField31` field. + /// + /// Returns `None` if the given integer is greater than the Prime. + #[inline] + fn from_canonical_checked(int: u32) -> Option { + (int < FP::PRIME).then(|| Self::new(int)) + } + + /// Convert a given `u32` integer into an element of the `MontyField31` field. + /// + /// # Safety + /// This is always safe as the conversion to monty form can accept any `u32`. + #[inline(always)] + unsafe fn from_canonical_unchecked(int: u32) -> Self { + Self::new(int) + } +} + +impl QuotientMap for MontyField31 { + /// Convert a given `i32` integer into an element of the `MontyField31` field. + #[inline] + fn from_int(int: i32) -> Self { + Self::new_monty(to_monty_signed::(int)) + } + + /// Convert a given `i32` integer into an element of the `MontyField31` field. + /// + /// Returns `None` if the given integer does not lie in the range `[(1 - P)/2, (P - 1)/2]`. + #[inline] + fn from_canonical_checked(int: i32) -> Option { + let bound = (FP::PRIME >> 1) as i32; + if int <= bound { + (int >= (-bound)).then(|| Self::new_monty(to_monty_signed::(int))) + } else { + None + } + } + + /// Convert a given `i32` integer into an element of the `MontyField31` field. + /// + /// # Safety + /// This is always safe as the conversion to monty form can accept any `i32`. + #[inline(always)] + unsafe fn from_canonical_unchecked(int: i32) -> Self { + Self::new_monty(to_monty_signed::(int)) + } +} + +impl QuotientMap for MontyField31 { + /// Convert a given `u64` integer into an element of the `MontyField31` field. + fn from_int(int: u64) -> Self { + Self::new_monty(to_monty_64::(int)) + } + + /// Convert a given `u64` integer into an element of the `MontyField31` field. + /// + /// Returns `None` if the given integer is greater than the Prime. + fn from_canonical_checked(int: u64) -> Option { + (int < FP::PRIME as u64).then(|| Self::new(int as u32)) + } + + /// Convert a given `u64` integer into an element of the `MontyField31` field. + /// + /// # Safety + /// This is always safe as the conversion to monty form can accept any `u64`. + unsafe fn from_canonical_unchecked(int: u64) -> Self { + Self::new_monty(to_monty_64::(int)) + } +} + +impl QuotientMap for MontyField31 { + /// Convert a given `i64` integer into an element of the `MontyField31` field. + fn from_int(int: i64) -> Self { + Self::new_monty(to_monty_64_signed::(int)) + } + + /// Convert a given `i64` integer into an element of the `MontyField31` field. + /// + /// Returns `None` if the given integer does not lie in the range `[(1 - P)/2, (P - 1)/2]`. + fn from_canonical_checked(int: i64) -> Option { + let bound = (FP::PRIME >> 1) as i64; + if int <= bound { + (int >= (-bound)).then(|| Self::new_monty(to_monty_signed::(int as i32))) + } else { + None + } + } + + /// Convert a given `i64` integer into an element of the `MontyField31` field. + /// + /// # Safety + /// This is always safe as the conversion to monty form can accept any `i64`. + unsafe fn from_canonical_unchecked(int: i64) -> Self { + Self::new_monty(to_monty_64_signed::(int)) + } +} + +impl QuotientMap for MontyField31 { + /// Convert a given `u128` integer into an element of the `MontyField31` field. + fn from_int(int: u128) -> Self { + Self::new_monty(to_monty::((int % (FP::PRIME as u128)) as u32)) + } + + /// Convert a given `u128` integer into an element of the `MontyField31` field. + /// + /// Returns `None` if the given integer is greater than the Prime. + fn from_canonical_checked(int: u128) -> Option { + (int < FP::PRIME as u128).then(|| Self::new(int as u32)) + } + + /// Convert a given `u128` integer into an element of the `MontyField31` field. + /// + /// # Safety + /// The input must be a valid `u64` element. + unsafe fn from_canonical_unchecked(int: u128) -> Self { + Self::new_monty(to_monty_64::(int as u64)) + } +} + +impl QuotientMap for MontyField31 { + /// Convert a given `i128` integer into an element of the `MontyField31` field. + fn from_int(int: i128) -> Self { + Self::new_monty(to_monty_signed::((int % (FP::PRIME as i128)) as i32)) + } + + /// Convert a given `i128` integer into an element of the `MontyField31` field. + /// + /// Returns `None` if the given integer does not lie in the range `[(1 - P)/2, (P - 1)/2]`. + fn from_canonical_checked(int: i128) -> Option { + let bound = (FP::PRIME >> 1) as i128; + if int <= bound { + (int >= (-bound)).then(|| Self::new_monty(to_monty_signed::(int as i32))) + } else { + None + } + } + + /// Convert a given `i128` integer into an element of the `MontyField31` field. + /// + /// # Safety + /// The input must be a valid `i64` element. + unsafe fn from_canonical_unchecked(int: i128) -> Self { + Self::new_monty(to_monty_64_signed::(int as i64)) + } +} + +impl PrimeField for MontyField31 { + fn as_canonical_biguint(&self) -> BigUint { + ::as_canonical_u32(self).into() + } +} + +impl PrimeField64 for MontyField31 { + const ORDER_U64: u64 = FP::PRIME as u64; + + #[inline] + fn as_canonical_u64(&self) -> u64 { + self.as_canonical_u32().into() + } + + #[inline] + fn to_unique_u64(&self) -> u64 { + // The internal representation is already a unique u32 for each field element. + // It's fine to hash things in monty form. + self.value as u64 + } +} + +impl PrimeField32 for MontyField31 { + const ORDER_U32: u32 = FP::PRIME; + + #[inline] + fn as_canonical_u32(&self) -> u32 { + Self::to_u32(self) + } + + #[inline] + fn to_unique_u32(&self) -> u32 { + // The internal representation is already a unique u32 for each field element. + // It's fine to hash things in monty form. + self.value + } +} + +impl TwoAdicField for MontyField31 { + const TWO_ADICITY: usize = FP::TWO_ADICITY; + fn two_adic_generator(bits: usize) -> Self { + assert!(bits <= Self::TWO_ADICITY); + FP::TWO_ADIC_GENERATORS.as_ref()[bits] + } +} + +impl Add for MontyField31 { + type Output = Self; + + #[inline] + fn add(self, rhs: Self) -> Self { + let mut sum = self.value + rhs.value; + let (corr_sum, over) = sum.overflowing_sub(FP::PRIME); + if !over { + sum = corr_sum; + } + Self::new_monty(sum) + } +} + +impl AddAssign for MontyField31 { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} + +impl Sum for MontyField31 { + #[inline] + fn sum>(iter: I) -> Self { + // This is faster than iter.reduce(|x, y| x + y).unwrap_or(Self::ZERO) for iterators of length > 2. + // There might be a faster reduction method possible for lengths <= 16 which avoids %. + + // This sum will not overflow so long as iter.len() < 2^33. + let sum = iter.map(|x| x.value as u64).sum::(); + Self::new_monty((sum % FP::PRIME as u64) as u32) + } +} + +impl Sub for MontyField31 { + type Output = Self; + + #[inline] + fn sub(self, rhs: Self) -> Self { + let (mut diff, over) = self.value.overflowing_sub(rhs.value); + let corr = if over { FP::PRIME } else { 0 }; + diff = diff.wrapping_add(corr); + Self::new_monty(diff) + } +} + +impl SubAssign for MontyField31 { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} + +impl Neg for MontyField31 { + type Output = Self; + + #[inline] + fn neg(self) -> Self::Output { + Self::ZERO - self + } +} + +impl Mul for MontyField31 { + type Output = Self; + + #[inline] + fn mul(self, rhs: Self) -> Self { + let long_prod = self.value as u64 * rhs.value as u64; + Self::new_monty(monty_reduce::(long_prod)) + } +} + +impl MulAssign for MontyField31 { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} + +impl Product for MontyField31 { + #[inline] + fn product>(iter: I) -> Self { + iter.reduce(|x, y| x * y).unwrap_or(Self::ONE) + } +} + +impl Div for MontyField31 { + type Output = Self; + + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: Self) -> Self { + self * rhs.inverse() + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/monty_31.v b/CoqOfRust/plonky3/monty-31/src/monty_31.v new file mode 100644 index 000000000..59415d8cb --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/monty_31.v @@ -0,0 +1,5666 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module monty_31. + (* StructRecord + { + name := "MontyField31"; + const_params := []; + ty_params := [ "MP" ]; + fields := + [ + ("value", Ty.path "u32"); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ MP ]) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]. + + (* Clone *) + Definition clone (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_monty_31::monty_31::MontyField31" + [ + ("value", + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "u32", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + |) + |) + ] + |)); + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ MP ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ MP ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "_phantom" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (MP : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self MP) + (* Instance *) [ ("clone", InstanceField.Method (clone MP)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + + Module Impl_core_marker_Copy_where_core_marker_Copy_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]. + + Axiom Implements : + forall (MP : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self MP) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + + Module Impl_core_default_Default_where_core_default_Default_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]. + + (* Default *) + Definition default (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "p3_monty_31::monty_31::MontyField31" + [ + ("value", + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "core::default::Default", + Ty.path "u32", + [], + [], + "default", + [], + [] + |), + [] + |)); + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ MP ], + M.get_trait_method (| + "core::default::Default", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ MP ], + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (MP : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self MP) + (* Instance *) [ ("default", InstanceField.Method (default MP)) ]. + End Impl_core_default_Default_where_core_default_Default_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + + Module Impl_core_cmp_Eq_where_core_cmp_Eq_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]. + + (* Eq *) + Definition assert_receiver_is_total_eq + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (MP : Ty.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self MP) + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method (assert_receiver_is_total_eq MP)) ]. + End Impl_core_cmp_Eq_where_core_cmp_Eq_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + + Module Impl_core_hash_Hash_where_core_hash_Hash_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]. + + (* Hash *) + Definition hash (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "u32", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ MP ], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "_phantom" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (MP : Ty.t), + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self MP) + (* Instance *) [ ("hash", InstanceField.Method (hash MP)) ]. + End Impl_core_hash_Hash_where_core_hash_Hash_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + + Module Impl_core_marker_StructuralPartialEq_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]. + + Axiom Implements : + forall (MP : Ty.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self MP) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_monty_31_MontyField31_MP. + + Module Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_MP_where_p3_monty_31_data_traits_MontyParameters_MP_p3_monty_31_monty_31_MontyField31_MP_for_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]. + + (* PartialEq *) + Definition eq (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ MP ], + [], + [ Ty.apply (Ty.path "core::marker::PhantomData") [] [ MP ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "_phantom" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_monty_31::monty_31::MontyField31", + "_phantom" + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (MP : Ty.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + (Self MP) + (* Instance *) [ ("eq", InstanceField.Method (eq MP)) ]. + End Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_MP_where_p3_monty_31_data_traits_MontyParameters_MP_p3_monty_31_monty_31_MontyField31_MP_for_p3_monty_31_monty_31_MontyField31_MP. + + Module Impl_p3_monty_31_monty_31_MontyField31_MP. + Definition Self (MP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]. + + (* + pub const fn new(value: u32) -> Self { + Self { + value: to_monty::(value), + _phantom: PhantomData, + } + } + *) + Definition new (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructRecord + "p3_monty_31::monty_31::MontyField31" + [ + ("value", + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty", [], [ MP ] |), + [ M.read (| value |) ] + |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "new" (new MP). + Admitted. + Global Typeclasses Opaque new. + + (* + pub(crate) const fn new_monty(value: u32) -> Self { + Self { + value, + _phantom: PhantomData, + } + } + *) + Definition new_monty (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructRecord + "p3_monty_31::monty_31::MontyField31" + [ + ("value", M.read (| value |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_monty : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "new_monty" (new_monty MP). + Admitted. + Global Typeclasses Opaque new_monty. + + (* + pub(crate) const fn to_u32(elem: &Self) -> u32 { + from_monty::(elem.value) + } + *) + Definition to_u32 (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [], [], [ elem ] => + ltac:(M.monadic + (let elem := M.alloc (| elem |) in + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::from_monty", [], [ MP ] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| elem |) |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_u32 : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "to_u32" (to_u32 MP). + Admitted. + Global Typeclasses Opaque to_u32. + + (* + pub const fn new_array(input: [u32; N]) -> [Self; N] { + let mut output = [Self::new_monty(0); N]; + let mut i = 0; + while i < N { + output[i] = Self::new(input[i]); + i += 1; + } + output + } + *) + Definition new_array (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [ N ], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] := + M.alloc (| + repeat (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "new_monty", + [], + [] + |), + [ Value.Integer IntegerKind.U32 0 ] + |), + N + |) + |) in + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| Ty.path "bool", BinOp.lt, [ M.read (| i |); N ] |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| output, M.read (| i |) |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "new", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| input, M.read (| i |) |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_array : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "new_array" (new_array MP). + Admitted. + Global Typeclasses Opaque new_array. + + (* + pub const fn new_2d_array( + input: [[u32; N]; M], + ) -> [[Self; N]; M] { + let mut output = [[Self::new_monty(0); N]; M]; + let mut i = 0; + while i < M { + output[i] = Self::new_array(input[i]); + i += 1; + } + output + } + *) + Definition new_2d_array (MP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self MP in + match ε, τ, α with + | [ N; M_ ], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ output : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ M ] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ] + ] + ] := + M.alloc (| + repeat (| + repeat (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ], + "new_monty", + [], + [] + |), + [ Value.Integer IntegerKind.U32 0 ] + |), + N + |), + M + |) + |) in + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| i |); M_ ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| output, M.read (| i |) |), + M.call_closure (| + Ty.apply + (Ty.path "array") + [ N ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ MP ], + "new_array", + [ N ], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| input, M.read (| i |) |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_2d_array : + forall (MP : Ty.t), + M.IsAssociatedFunction.C (Self MP) "new_2d_array" (new_2d_array MP). + Admitted. + Global Typeclasses Opaque new_2d_array. + End Impl_p3_monty_31_monty_31_MontyField31_MP. + + Module Impl_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + const MONTY_POWERS_OF_TWO: [Self; 64] = { + let mut powers_of_two = [FP::MONTY_ONE; 64]; + let mut i = 1; + while i < 64 { + powers_of_two[i] = Self::new_monty(to_monty_64::(1 << i)); + i += 1; + } + powers_of_two + }; + *) + (* Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] *) + Definition value_MONTY_POWERS_OF_TWO + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + ltac:(M.monadic + (let~ powers_of_two : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ] := + M.alloc (| + repeat (| + M.read (| + get_constant (| + "p3_monty_31::data_traits::FieldParameters::MONTY_ONE", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |) + |), + Value.Integer IntegerKind.Usize 64 + |) + |) in + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| i |); Value.Integer IntegerKind.Usize 64 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| powers_of_two, M.read (| i |) |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| + "p3_monty_31::utils::to_monty_64", + [], + [ FP ] + |), + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.U64 1; M.read (| i |) ] + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + powers_of_two)). + + Global Instance AssociatedConstant_value_MONTY_POWERS_OF_TWO : + forall (FP : Ty.t), + M.IsAssociatedFunction.C (Self FP) "MONTY_POWERS_OF_TWO" (value_MONTY_POWERS_OF_TWO FP). + Admitted. + Global Typeclasses Opaque value_MONTY_POWERS_OF_TWO. + + (* const HALF: Self = MontyField31::new(FP::HALF_P_PLUS_1); *) + (* Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] *) + Definition value_HALF (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_monty_31::data_traits::FieldParameters::HALF_P_PLUS_1", + Ty.path "u32" + |) + |) + ] + |) + |))). + + Global Instance AssociatedConstant_value_HALF : + forall (FP : Ty.t), + M.IsAssociatedFunction.C (Self FP) "HALF" (value_HALF FP). + Admitted. + Global Typeclasses Opaque value_HALF. + End Impl_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_cmp_Ord_where_p3_monty_31_data_traits_MontyParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + Self::to_u32(self).cmp(&Self::to_u32(other)) + } + *) + Definition cmp (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| "core::cmp::Ord", Ty.path "u32", [], [], "cmp", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "to_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "to_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) [ ("cmp", InstanceField.Method (cmp FP)) ]. + End Impl_core_cmp_Ord_where_p3_monty_31_data_traits_MontyParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_cmp_PartialOrd_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } + *) + Definition partial_cmp (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp FP)) ]. + End Impl_core_cmp_PartialOrd_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_fmt_Display_where_p3_monty_31_data_traits_MontyParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Display::fmt(&Self::to_u32(self), f) + } + *) + Definition fmt (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| "core::fmt::Display", Ty.path "u32", [], [], "fmt", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "to_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) [ ("fmt", InstanceField.Method (fmt FP)) ]. + End Impl_core_fmt_Display_where_p3_monty_31_data_traits_MontyParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_fmt_Debug_where_p3_monty_31_data_traits_MontyParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Debug::fmt(&Self::to_u32(self), f) + } + *) + Definition fmt (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| "core::fmt::Debug", Ty.path "u32", [], [], "fmt", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "to_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) [ ("fmt", InstanceField.Method (fmt FP)) ]. + End Impl_core_fmt_Debug_where_p3_monty_31_data_traits_MontyParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_rand_distr_distribution_Distribution_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_rand_distr_StandardUniform. + Definition Self (FP : Ty.t) : Ty.t := Ty.path "rand::distr::StandardUniform". + + (* + fn sample(&self, rng: &mut R) -> MontyField31 { + loop { + let next_u31 = rng.next_u32() >> 1; + let is_canonical = next_u31 < FP::PRIME; + if is_canonical { + return MontyField31::new_monty(next_u31); + } + } + } + *) + Definition sample (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [ R ], [ self; rng ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rng := M.alloc (| rng |) in + M.catch_return (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) (| + ltac:(M.monadic + (M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic + (let~ next_u31 : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "rand_core::RngCore", + R, + [], + [], + "next_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |) + ] + |); + Value.Integer IntegerKind.I32 1 + ] + |) + |) in + let~ is_canonical : Ty.apply (Ty.path "*") [] [ Ty.path "bool" ] := + M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| next_u31 |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use is_canonical in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + "new_monty", + [], + [] + |), + [ M.read (| next_u31 |) ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "rand::distr::distribution::Distribution" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) [ ("sample", InstanceField.Method (sample FP)) ]. + End Impl_rand_distr_distribution_Distribution_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_rand_distr_StandardUniform. + + Module Impl_serde_ser_Serialize_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn serialize(&self, serializer: S) -> Result { + // It's faster to Serialize and Deserialize in monty form. + serializer.serialize_u32(self.value) + } + *) + Definition serialize (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [ _ as S ], [ self; serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let serializer := M.alloc (| serializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Error" + ], + M.get_trait_method (| "serde::ser::Serializer", S, [], [], "serialize_u32", [], [] |), + [ + M.read (| serializer |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) [ ("serialize", InstanceField.Method (serialize FP)) ]. + End Impl_serde_ser_Serialize_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_serde_de_Deserialize_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn deserialize>(d: D) -> Result { + // It's faster to Serialize and Deserialize in monty form. + let val = u32::deserialize(d)?; + Ok(Self::new_monty(val)) + } + *) + Definition deserialize (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [ D ], [ d ] => + ltac:(M.monadic + (let d := M.alloc (| d |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ val : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ]; + Ty.path "u32" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u32"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u32"; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ], + M.get_trait_method (| + "serde::de::Deserialize", + Ty.path "u32", + [], + [], + "deserialize", + [], + [ D ] + |), + [ M.read (| d |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ]; + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ]; + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::de::Deserializer" + [] + [] + D + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ M.read (| val |) ] + |) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize FP)) ]. + End Impl_serde_de_Deserialize_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_packed_Packable_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::packed::Packable" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) []. + End Impl_p3_field_packed_Packable_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_field_PrimeCharacteristicRing_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* type PrimeSubfield = Self; *) + Definition _PrimeSubfield (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* const ZERO: Self = FP::MONTY_ZERO; *) + (* Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] *) + Definition value_ZERO (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + ltac:(M.monadic + (get_constant (| + "p3_monty_31::data_traits::FieldParameters::MONTY_ZERO", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |))). + + (* const ONE: Self = FP::MONTY_ONE; *) + (* Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] *) + Definition value_ONE (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + ltac:(M.monadic + (get_constant (| + "p3_monty_31::data_traits::FieldParameters::MONTY_ONE", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |))). + + (* const TWO: Self = FP::MONTY_TWO; *) + (* Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] *) + Definition value_TWO (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + ltac:(M.monadic + (get_constant (| + "p3_monty_31::data_traits::FieldParameters::MONTY_TWO", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |))). + + (* const NEG_ONE: Self = FP::MONTY_NEG_ONE; *) + (* Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] *) + Definition value_NEG_ONE + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + ltac:(M.monadic + (get_constant (| + "p3_monty_31::data_traits::FieldParameters::MONTY_NEG_ONE", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |))). + + (* + fn from_prime_subfield(f: Self) -> Self { + f + } + *) + Definition from_prime_subfield + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.read (| f |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn mul_2exp_u64(&self, exp: u64) -> Self { + // The array FP::MONTY_POWERS_OF_TWO contains the powers of 2 + // from 2^0 to 2^63 in monty form. We can use this to quickly + // compute 2^exp. + if exp < 64 { + *self * Self::MONTY_POWERS_OF_TWO[exp as usize] + } else { + // For larger values we use the default method. + *self * Self::TWO.exp_u64(exp) + } + } + *) + Definition mul_2exp_u64 (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| exp |); Value.Integer IntegerKind.U64 64 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "mul", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| self |) |) |); + M.read (| + M.SubPointer.get_array_field (| + get_associated_constant (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "MONTY_POWERS_OF_TWO", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + |), + M.cast (Ty.path "usize") (M.read (| exp |)) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "mul", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeCharacteristicRing::TWO", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |) + |); + M.read (| exp |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn zero_vec(len: usize) -> Vec { + // SAFETY: + // Due to `#[repr(transparent)]`, MontyField31 and u32 have the same size, alignment + // and memory layout making `flatten_to_base` safe. This this will create + // a vector MontyField31 elements with value set to 0 which is the + // MONTY form of 0. + unsafe { flatten_to_base(vec![0u32; len]) } + } + *) + Definition zero_vec (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ len ] => + ltac:(M.monadic + (let len := M.alloc (| len |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_util::flatten_to_base", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; Ty.path "u32" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u32"; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloc::vec::from_elem", [], [ Ty.path "u32" ] |), + [ Value.Integer IntegerKind.U32 0; M.read (| len |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn sum_array(input: &[Self]) -> Self { + assert_eq!(N, input.len()); + // Benchmarking shows that for N <= 7 it's faster to sum the elements directly + // but for N > 7 it's faster to use the .sum() methods which passes through u64's + // allowing for delayed reductions. + match N { + 0 => Self::ZERO, + 1 => input[0], + 2 => input[0] + input[1], + 3 => input[0] + input[1] + input[2], + 4 => (input[0] + input[1]) + (input[2] + input[3]), + 5 => Self::sum_array::<4>(&input[..4]) + Self::sum_array::<1>(&input[4..]), + 6 => Self::sum_array::<4>(&input[..4]) + Self::sum_array::<2>(&input[4..]), + 7 => Self::sum_array::<4>(&input[..4]) + Self::sum_array::<3>(&input[4..]), + _ => input.iter().copied().sum(), + } + } + *) + Definition sum_array (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [ N ], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.alloc (| N |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 0 + |) in + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 1 + |) in + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 3 + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 4 + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ], + "add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| input |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 5 + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 6 + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 7 + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "sum_array", + [ Value.Integer IntegerKind.Usize 3 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| input |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 4) ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ] + ], + [], + [], + "sum", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ], + [], + [], + "copied", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| input |) |) |) + ] + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::field::PrimeCharacteristicRing" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) + [ + ("PrimeSubfield", InstanceField.Ty (_PrimeSubfield FP)); + ("value_ZERO", InstanceField.Method (value_ZERO FP)); + ("value_ONE", InstanceField.Method (value_ONE FP)); + ("value_TWO", InstanceField.Method (value_TWO FP)); + ("value_NEG_ONE", InstanceField.Method (value_NEG_ONE FP)); + ("from_prime_subfield", InstanceField.Method (from_prime_subfield FP)); + ("mul_2exp_u64", InstanceField.Method (mul_2exp_u64 FP)); + ("zero_vec", InstanceField.Method (zero_vec FP)); + ("sum_array", InstanceField.Method (sum_array FP)) + ]. + End Impl_p3_field_field_PrimeCharacteristicRing_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_field_InjectiveMonomial_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_data_traits_RelativelyPrimePower_FP_D_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (D : Value.t) (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + Axiom Implements : + forall (D : Value.t) (FP : Ty.t), + M.IsTraitInstance + "p3_field::field::InjectiveMonomial" + (* Trait polymorphic consts *) [ D ] + (* Trait polymorphic types *) [] + (Self D FP) + (* Instance *) []. + End Impl_p3_field_field_InjectiveMonomial_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_data_traits_RelativelyPrimePower_FP_D_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_field_PermutationMonomial_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_data_traits_RelativelyPrimePower_FP_D_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (D : Value.t) (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn injective_exp_root_n(&self) -> Self { + FP::exp_root_d( *self) + } + *) + Definition injective_exp_root_n + (D : Value.t) + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self D FP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_monty_31::data_traits::RelativelyPrimePower", + FP, + [ D ], + [], + "exp_root_d", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (D : Value.t) (FP : Ty.t), + M.IsTraitInstance + "p3_field::field::PermutationMonomial" + (* Trait polymorphic consts *) [ D ] + (* Trait polymorphic types *) [] + (Self D FP) + (* Instance *) + [ ("injective_exp_root_n", InstanceField.Method (injective_exp_root_n D FP)) ]. + End Impl_p3_field_field_PermutationMonomial_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_data_traits_RelativelyPrimePower_FP_D_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_field_Field_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* type Packing = Self; *) + Definition _Packing (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* const GENERATOR: Self = FP::MONTY_GEN; *) + (* Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] *) + Definition value_GENERATOR + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + ltac:(M.monadic + (get_constant (| + "p3_monty_31::data_traits::FieldParameters::MONTY_GEN", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |))). + + (* + fn try_inverse(&self) -> Option { + FP::try_inverse( *self) + } + *) + Definition try_inverse (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "p3_monty_31::data_traits::FieldParameters", + FP, + [], + [], + "try_inverse", + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn halve(&self) -> Self { + Self::new_monty(halve_u32::(self.value)) + } + *) + Definition halve (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::halve_u32", [], [ FP ] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn div_2exp_u64(&self, exp: u64) -> Self { + if exp <= 32 { + // As the monty form of 2^{-exp} is 2^{32 - exp} mod P, for + // 0 <= exp <= 32, we can multiply by 2^{-exp} by doing a shift + // followed by a monty reduction. + let long_prod = (self.value as u64) << (32 - exp); + Self::new_monty(monty_reduce::(long_prod)) + } else { + // For larger values we use a slower method though this is + // still much faster than the default method as it avoids the inverse(). + *self * Self::HALF.exp_u64(exp) + } + } + *) + Definition div_2exp_u64 (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ M.read (| exp |); Value.Integer IntegerKind.U64 32 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ long_prod : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |)); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ Value.Integer IntegerKind.U64 32; M.read (| exp |) ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::monty_reduce", [], [ FP ] |), + [ M.read (| long_prod |) ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "mul", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "exp_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + "HALF", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |) + |); + M.read (| exp |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn order() -> BigUint { + FP::PRIME.into() + } + *) + Definition order (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "core::convert::Into", + Ty.path "u32", + [], + [ Ty.path "num_bigint::biguint::BigUint" ], + "into", + [], + [] + |), + [ + M.read (| + get_constant (| "p3_monty_31::data_traits::MontyParameters::PRIME", Ty.path "u32" |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::field::Field" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) + [ + ("Packing", InstanceField.Ty (_Packing FP)); + ("value_GENERATOR", InstanceField.Method (value_GENERATOR FP)); + ("try_inverse", InstanceField.Method (try_inverse FP)); + ("halve", InstanceField.Method (halve FP)); + ("div_2exp_u64", InstanceField.Method (div_2exp_u64 FP)); + ("order", InstanceField.Method (order FP)) + ]. + End Impl_p3_field_field_Field_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_u32_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn from_int(int: u32) -> Self { + Self::new(int) + } + *) + Definition from_int (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new", + [], + [] + |), + [ M.read (| int |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: u32) -> Option { + (int < FP::PRIME).then(|| Self::new(int)) + } + *) + Definition from_canonical_checked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) + ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| int |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + "new", + [], + [] + |), + [ M.read (| int |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: u32) -> Self { + Self::new(int) + } + *) + Definition from_canonical_unchecked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new", + [], + [] + |), + [ M.read (| int |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u32" ] + (Self FP) + (* Instance *) + [ + ("from_int", InstanceField.Method (from_int FP)); + ("from_canonical_checked", InstanceField.Method (from_canonical_checked FP)); + ("from_canonical_unchecked", InstanceField.Method (from_canonical_unchecked FP)) + ]. + End Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_u32_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_i32_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn from_int(int: i32) -> Self { + Self::new_monty(to_monty_signed::(int)) + } + *) + Definition from_int (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty_signed", [], [ FP ] |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: i32) -> Option { + let bound = (FP::PRIME >> 1) as i32; + if int <= bound { + (int >= (-bound)).then(|| Self::new_monty(to_monty_signed::(int))) + } else { + None + } + } + *) + Definition from_canonical_checked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ bound : Ty.apply (Ty.path "*") [] [ Ty.path "i32" ] := + M.alloc (| + M.cast + (Ty.path "i32") + (M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.I32 1 + ] + |)) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ M.read (| int |); M.read (| bound |) ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) + ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| int |); UnOp.neg (| M.read (| bound |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| + "p3_monty_31::utils::to_monty_signed", + [], + [ FP ] + |), + [ M.read (| int |) ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: i32) -> Self { + Self::new_monty(to_monty_signed::(int)) + } + *) + Definition from_canonical_unchecked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty_signed", [], [ FP ] |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i32" ] + (Self FP) + (* Instance *) + [ + ("from_int", InstanceField.Method (from_int FP)); + ("from_canonical_checked", InstanceField.Method (from_canonical_checked FP)); + ("from_canonical_unchecked", InstanceField.Method (from_canonical_unchecked FP)) + ]. + End Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_i32_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_u64_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn from_int(int: u64) -> Self { + Self::new_monty(to_monty_64::(int)) + } + *) + Definition from_int (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty_64", [], [ FP ] |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: u64) -> Option { + (int < FP::PRIME as u64).then(|| Self::new(int as u32)) + } + *) + Definition from_canonical_checked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) + ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| int |); + M.cast + (Ty.path "u64") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + "new", + [], + [] + |), + [ M.cast (Ty.path "u32") (M.read (| int |)) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: u64) -> Self { + Self::new_monty(to_monty_64::(int)) + } + *) + Definition from_canonical_unchecked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty_64", [], [ FP ] |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + (Self FP) + (* Instance *) + [ + ("from_int", InstanceField.Method (from_int FP)); + ("from_canonical_checked", InstanceField.Method (from_canonical_checked FP)); + ("from_canonical_unchecked", InstanceField.Method (from_canonical_unchecked FP)) + ]. + End Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_u64_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_i64_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn from_int(int: i64) -> Self { + Self::new_monty(to_monty_64_signed::(int)) + } + *) + Definition from_int (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty_64_signed", [], [ FP ] |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: i64) -> Option { + let bound = (FP::PRIME >> 1) as i64; + if int <= bound { + (int >= (-bound)).then(|| Self::new_monty(to_monty_signed::(int as i32))) + } else { + None + } + } + *) + Definition from_canonical_checked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ bound : Ty.apply (Ty.path "*") [] [ Ty.path "i64" ] := + M.alloc (| + M.cast + (Ty.path "i64") + (M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.I32 1 + ] + |)) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ M.read (| int |); M.read (| bound |) ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) + ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| int |); UnOp.neg (| M.read (| bound |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| + "p3_monty_31::utils::to_monty_signed", + [], + [ FP ] + |), + [ M.cast (Ty.path "i32") (M.read (| int |)) ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: i64) -> Self { + Self::new_monty(to_monty_64_signed::(int)) + } + *) + Definition from_canonical_unchecked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty_64_signed", [], [ FP ] |), + [ M.read (| int |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i64" ] + (Self FP) + (* Instance *) + [ + ("from_int", InstanceField.Method (from_int FP)); + ("from_canonical_checked", InstanceField.Method (from_canonical_checked FP)); + ("from_canonical_unchecked", InstanceField.Method (from_canonical_unchecked FP)) + ]. + End Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_i64_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_u128_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn from_int(int: u128) -> Self { + Self::new_monty(to_monty::((int % (FP::PRIME as u128)) as u32)) + } + *) + Definition from_int (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty", [], [ FP ] |), + [ + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u128", + BinOp.Wrap.rem, + [ + M.read (| int |); + M.cast + (Ty.path "u128") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: u128) -> Option { + (int < FP::PRIME as u128).then(|| Self::new(int as u32)) + } + *) + Definition from_canonical_checked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) + ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| int |); + M.cast + (Ty.path "u128") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + "new", + [], + [] + |), + [ M.cast (Ty.path "u32") (M.read (| int |)) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: u128) -> Self { + Self::new_monty(to_monty_64::(int as u64)) + } + *) + Definition from_canonical_unchecked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty_64", [], [ FP ] |), + [ M.cast (Ty.path "u64") (M.read (| int |)) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u128" ] + (Self FP) + (* Instance *) + [ + ("from_int", InstanceField.Method (from_int FP)); + ("from_canonical_checked", InstanceField.Method (from_canonical_checked FP)); + ("from_canonical_unchecked", InstanceField.Method (from_canonical_unchecked FP)) + ]. + End Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_u128_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_i128_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn from_int(int: i128) -> Self { + Self::new_monty(to_monty_signed::((int % (FP::PRIME as i128)) as i32)) + } + *) + Definition from_int (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty_signed", [], [ FP ] |), + [ + M.cast + (Ty.path "i32") + (M.call_closure (| + Ty.path "i128", + BinOp.Wrap.rem, + [ + M.read (| int |); + M.cast + (Ty.path "i128") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn from_canonical_checked(int: i128) -> Option { + let bound = (FP::PRIME >> 1) as i128; + if int <= bound { + (int >= (-bound)).then(|| Self::new_monty(to_monty_signed::(int as i32))) + } else { + None + } + } + *) + Definition from_canonical_checked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.read (| + let~ bound : Ty.apply (Ty.path "*") [] [ Ty.path "i128" ] := + M.alloc (| + M.cast + (Ty.path "i128") + (M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |); + Value.Integer IntegerKind.I32 1 + ] + |)) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ M.read (| int |); M.read (| bound |) ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_associated_function (| + Ty.path "bool", + "then", + [], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) + ] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| int |); UnOp.neg (| M.read (| bound |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| + "p3_monty_31::utils::to_monty_signed", + [], + [ FP ] + |), + [ M.cast (Ty.path "i32") (M.read (| int |)) ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + unsafe fn from_canonical_unchecked(int: i128) -> Self { + Self::new_monty(to_monty_64_signed::(int as i64)) + } + *) + Definition from_canonical_unchecked + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ int ] => + ltac:(M.monadic + (let int := M.alloc (| int |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::to_monty_64_signed", [], [ FP ] |), + [ M.cast (Ty.path "i64") (M.read (| int |)) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::integers::QuotientMap" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i128" ] + (Self FP) + (* Instance *) + [ + ("from_int", InstanceField.Method (from_int FP)); + ("from_canonical_checked", InstanceField.Method (from_canonical_checked FP)); + ("from_canonical_unchecked", InstanceField.Method (from_canonical_unchecked FP)) + ]. + End Impl_p3_field_integers_QuotientMap_where_p3_monty_31_data_traits_FieldParameters_FP_i128_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_field_PrimeField_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn as_canonical_biguint(&self) -> BigUint { + ::as_canonical_u32(self).into() + } + *) + Definition as_canonical_biguint + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "core::convert::Into", + Ty.path "u32", + [], + [ Ty.path "num_bigint::biguint::BigUint" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::field::PrimeField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) [ ("as_canonical_biguint", InstanceField.Method (as_canonical_biguint FP)) ]. + End Impl_p3_field_field_PrimeField_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_field_PrimeField64_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* const ORDER_U64: u64 = FP::PRIME as u64; *) + (* Ty.path "u64" *) + Definition value_ORDER_U64 + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + ltac:(M.monadic + (M.alloc (| + M.cast + (Ty.path "u64") + (M.read (| + get_constant (| "p3_monty_31::data_traits::MontyParameters::PRIME", Ty.path "u32" |) + |)) + |))). + + (* + fn as_canonical_u64(&self) -> u64 { + self.as_canonical_u32().into() + } + *) + Definition as_canonical_u64 + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::convert::Into", + Ty.path "u32", + [], + [ Ty.path "u64" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "as_canonical_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn to_unique_u64(&self) -> u64 { + // The internal representation is already a unique u32 for each field element. + // It's fine to hash things in monty form. + self.value as u64 + } + *) + Definition to_unique_u64 + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::field::PrimeField64" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) + [ + ("value_ORDER_U64", InstanceField.Method (value_ORDER_U64 FP)); + ("as_canonical_u64", InstanceField.Method (as_canonical_u64 FP)); + ("to_unique_u64", InstanceField.Method (to_unique_u64 FP)) + ]. + End Impl_p3_field_field_PrimeField64_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_field_PrimeField32_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* const ORDER_U32: u32 = FP::PRIME; *) + (* Ty.path "u32" *) + Definition value_ORDER_U32 + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + ltac:(M.monadic + (get_constant (| "p3_monty_31::data_traits::MontyParameters::PRIME", Ty.path "u32" |))). + + (* + fn as_canonical_u32(&self) -> u32 { + Self::to_u32(self) + } + *) + Definition as_canonical_u32 + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "to_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn to_unique_u32(&self) -> u32 { + // The internal representation is already a unique u32 for each field element. + // It's fine to hash things in monty form. + self.value + } + *) + Definition to_unique_u32 + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::field::PrimeField32" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) + [ + ("value_ORDER_U32", InstanceField.Method (value_ORDER_U32 FP)); + ("as_canonical_u32", InstanceField.Method (as_canonical_u32 FP)); + ("to_unique_u32", InstanceField.Method (to_unique_u32 FP)) + ]. + End Impl_p3_field_field_PrimeField32_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_p3_field_field_TwoAdicField_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_data_traits_TwoAdicData_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* const TWO_ADICITY: usize = FP::TWO_ADICITY; *) + (* Ty.path "usize" *) + Definition value_TWO_ADICITY + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + ltac:(M.monadic + (get_constant (| "p3_monty_31::data_traits::TwoAdicData::TWO_ADICITY", Ty.path "usize" |))). + + (* + fn two_adic_generator(bits: usize) -> Self { + assert!(bits <= Self::TWO_ADICITY); + FP::TWO_ADIC_GENERATORS.as_ref()[bits] + } + *) + Definition two_adic_generator + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| bits |); + M.read (| + get_constant (| + "p3_field::field::TwoAdicField::TWO_ADICITY", + Ty.path "usize" + |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bits <= Self::TWO_ADICITY" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + FP + "ArrayLike", + [], + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_monty_31::data_traits::TwoAdicData::TWO_ADIC_GENERATORS", + Ty.associated_in_trait + "p3_monty_31::data_traits::TwoAdicData" + [] + [] + FP + "ArrayLike" + |) + |) + ] + |) + |), + M.read (| bits |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "p3_field::field::TwoAdicField" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) + [ + ("value_TWO_ADICITY", InstanceField.Method (value_TWO_ADICITY FP)); + ("two_adic_generator", InstanceField.Method (two_adic_generator FP)) + ]. + End Impl_p3_field_field_TwoAdicField_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_data_traits_TwoAdicData_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_ops_arith_Add_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* type Output = Self; *) + Definition _Output (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn add(self, rhs: Self) -> Self { + let mut sum = self.value + rhs.value; + let (corr_sum, over) = sum.overflowing_sub(FP::PRIME); + if !over { + sum = corr_sum; + } + Self::new_monty(sum) + } + *) + Definition add (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ sum : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u32"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "u32", "overflowing_sub", [], [] |), + [ + M.read (| sum |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let corr_sum := M.copy (| γ0_0 |) in + let over := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| UnOp.not (| M.read (| over |) |) |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.write (| sum, M.read (| corr_sum |) |) |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ M.read (| sum |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output FP)); ("add", InstanceField.Method (add FP)) ]. + End Impl_core_ops_arith_Add_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_ops_arith_AddAssign_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } + *) + Definition add_assign (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "add", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign FP)) ]. + End Impl_core_ops_arith_AddAssign_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_iter_traits_accum_Sum_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn sum>(iter: I) -> Self { + // This is faster than iter.reduce(|x, y| x + y).unwrap_or(Self::ZERO) for iterators of length > 2. + // There might be a faster reduction method possible for lengths <= 16 which avoids %. + + // This sum will not overflow so long as iter.len() < 2^33. + let sum = iter.map(|x| x.value as u64).sum::(); + Self::new_monty((sum % FP::PRIME as u64) as u32) + } + *) + Definition sum (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.read (| + let~ sum : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + I; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ] + (Ty.path "u64") + ], + [], + [], + "sum", + [], + [ Ty.path "u64" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + I; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ] + ] + (Ty.path "u64") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "map", + [], + [ + Ty.path "u64"; + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ] + ] + (Ty.path "u64") + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + x, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |)))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u64", + BinOp.Wrap.rem, + [ + M.read (| sum |); + M.cast + (Ty.path "u64") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Sum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) [ ("sum", InstanceField.Method (sum FP)) ]. + End Impl_core_iter_traits_accum_Sum_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_ops_arith_Sub_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* type Output = Self; *) + Definition _Output (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn sub(self, rhs: Self) -> Self { + let (mut diff, over) = self.value.overflowing_sub(rhs.value); + let corr = if over { FP::PRIME } else { 0 }; + diff = diff.wrapping_add(corr); + Self::new_monty(diff) + } + *) + Definition sub (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u32"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "u32", "overflowing_sub", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let diff := M.copy (| γ0_0 |) in + let over := M.copy (| γ0_1 |) in + let~ corr : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use over in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U32 0 |))) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + diff, + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "wrapping_add", [], [] |), + [ M.read (| diff |); M.read (| corr |) ] + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ M.read (| diff |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output FP)); ("sub", InstanceField.Method (sub FP)) ]. + End Impl_core_ops_arith_Sub_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_ops_arith_SubAssign_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } + *) + Definition sub_assign (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "sub", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) [ ("sub_assign", InstanceField.Method (sub_assign FP)) ]. + End Impl_core_ops_arith_SubAssign_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_ops_arith_Neg_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* type Output = Self; *) + Definition _Output (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn neg(self) -> Self::Output { + Self::ZERO - self + } + *) + Definition neg (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "sub", + [], + [] + |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |) + |); + M.read (| self |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self FP) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output FP)); ("neg", InstanceField.Method (neg FP)) ]. + End Impl_core_ops_arith_Neg_where_p3_monty_31_data_traits_FieldParameters_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_ops_arith_Mul_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* type Output = Self; *) + Definition _Output (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn mul(self, rhs: Self) -> Self { + let long_prod = self.value as u64 * rhs.value as u64; + Self::new_monty(monty_reduce::(long_prod)) + } + *) + Definition mul (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ long_prod : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |)); + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_struct_record_field (| + rhs, + "p3_monty_31::monty_31::MontyField31", + "value" + |) + |)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + "new_monty", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::monty_reduce", [], [ FP ] |), + [ M.read (| long_prod |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output FP)); ("mul", InstanceField.Method (mul FP)) ]. + End Impl_core_ops_arith_Mul_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_ops_arith_MulAssign_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } + *) + Definition mul_assign (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "mul", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) [ ("mul_assign", InstanceField.Method (mul_assign FP)) ]. + End Impl_core_ops_arith_MulAssign_where_p3_monty_31_data_traits_MontyParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_iter_traits_accum_Product_where_p3_monty_31_data_traits_FieldParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn product>(iter: I) -> Self { + iter.reduce(|x, y| x * y).unwrap_or(Self::ONE) + } + *) + Definition product (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ] + ] + (Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]) + ] + |), + [ + M.read (| iter |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ]; + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ] + (Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ]; + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ] + (Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Product" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) [ ("product", InstanceField.Method (product FP)) ]. + End Impl_core_iter_traits_accum_Product_where_p3_monty_31_data_traits_FieldParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + + Module Impl_core_ops_arith_Div_where_p3_monty_31_data_traits_FieldParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. + Definition Self (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* type Output = Self; *) + Definition _Output (FP : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]. + + (* + fn div(self, rhs: Self) -> Self { + self * rhs.inverse() + } + *) + Definition div (FP : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self FP in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "mul", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + M.get_trait_method (| + "p3_field::field::Field", + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ], + [], + [], + "inverse", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (FP : Ty.t), + M.IsTraitInstance + "core::ops::arith::Div" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self FP) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output FP)); ("div", InstanceField.Method (div FP)) ]. + End Impl_core_ops_arith_Div_where_p3_monty_31_data_traits_FieldParameters_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_monty_31_MontyField31_FP. +End monty_31. diff --git a/CoqOfRust/plonky3/monty-31/src/no_packing/mod.rs b/CoqOfRust/plonky3/monty-31/src/no_packing/mod.rs new file mode 100644 index 000000000..e056e09f2 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/no_packing/mod.rs @@ -0,0 +1,5 @@ +//! A couple of simple functions needed in the case that this is compiled without architecture optimizations available. + +mod poseidon2; + +pub use poseidon2::*; diff --git a/CoqOfRust/plonky3/monty-31/src/no_packing/poseidon2.rs b/CoqOfRust/plonky3/monty-31/src/no_packing/poseidon2.rs new file mode 100644 index 000000000..add222773 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/no_packing/poseidon2.rs @@ -0,0 +1,48 @@ +//! These are just simple wrapper structs allowing us to implement Poseidon2 Internal/ExternalLayer on top of them. +//! +//! They are used only in the case that none of the vectorization architectures (AVX2/AVX512/NEON) are available. + +use alloc::vec::Vec; +use core::marker::PhantomData; + +use p3_poseidon2::{ExternalLayerConstants, ExternalLayerConstructor, InternalLayerConstructor}; + +use crate::{FieldParameters, InternalLayerBaseParameters, MontyField31, MontyParameters}; + +/// The internal layers of the Poseidon2 permutation for Monty31 fields. +#[derive(Debug, Clone)] +pub struct Poseidon2InternalLayerMonty31< + MP: MontyParameters, + const WIDTH: usize, + ILP: InternalLayerBaseParameters, +> { + pub(crate) internal_constants: Vec>, + _phantom: PhantomData, +} + +/// The external layers of the Poseidon2 permutation for Monty31 fields. +#[derive(Debug, Clone)] +pub struct Poseidon2ExternalLayerMonty31 { + pub(crate) external_constants: ExternalLayerConstants, WIDTH>, +} + +impl> + InternalLayerConstructor> for Poseidon2InternalLayerMonty31 +{ + fn new_from_constants(internal_constants: Vec>) -> Self { + Self { + internal_constants, + _phantom: PhantomData, + } + } +} + +impl ExternalLayerConstructor, WIDTH> + for Poseidon2ExternalLayerMonty31 +{ + fn new_from_constants( + external_constants: ExternalLayerConstants, WIDTH>, + ) -> Self { + Self { external_constants } + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/no_packing/poseidon2.v b/CoqOfRust/plonky3/monty-31/src/no_packing/poseidon2.v new file mode 100644 index 000000000..a7b61a354 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/no_packing/poseidon2.v @@ -0,0 +1,472 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module no_packing. + Module poseidon2. + (* StructRecord + { + name := "Poseidon2InternalLayerMonty31"; + const_params := [ "WIDTH" ]; + ty_params := [ "MP"; "ILP" ]; + fields := + [ + ("internal_constants", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ]); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ ILP ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_MP_where_p3_monty_31_data_traits_MontyParameters_MP_where_core_fmt_Debug_ILP_where_p3_monty_31_poseidon2_InternalLayerBaseParameters_ILP_MP_for_p3_monty_31_no_packing_poseidon2_Poseidon2InternalLayerMonty31_WIDTH_MP_ILP. + Definition Self (WIDTH : Value.t) (MP ILP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ WIDTH ] + [ MP; ILP ]. + + (* Debug *) + Definition fmt + (WIDTH : Value.t) + (MP ILP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH MP ILP in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Poseidon2InternalLayerMonty31" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "internal_constants" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31", + "internal_constants" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (MP ILP : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH MP ILP) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH MP ILP)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_MP_where_p3_monty_31_data_traits_MontyParameters_MP_where_core_fmt_Debug_ILP_where_p3_monty_31_poseidon2_InternalLayerBaseParameters_ILP_MP_for_p3_monty_31_no_packing_poseidon2_Poseidon2InternalLayerMonty31_WIDTH_MP_ILP. + + Module Impl_core_clone_Clone_where_core_clone_Clone_MP_where_p3_monty_31_data_traits_MontyParameters_MP_where_core_clone_Clone_ILP_where_p3_monty_31_poseidon2_InternalLayerBaseParameters_ILP_MP_for_p3_monty_31_no_packing_poseidon2_Poseidon2InternalLayerMonty31_WIDTH_MP_ILP. + Definition Self (WIDTH : Value.t) (MP ILP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ WIDTH ] + [ MP; ILP ]. + + (* Clone *) + Definition clone + (WIDTH : Value.t) + (MP ILP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH MP ILP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31" + [ + ("internal_constants", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31", + "internal_constants" + |) + |) + |) + |) + ] + |)); + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ ILP ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ ILP ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31", + "_phantom" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (MP ILP : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH MP ILP) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH MP ILP)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_MP_where_p3_monty_31_data_traits_MontyParameters_MP_where_core_clone_Clone_ILP_where_p3_monty_31_poseidon2_InternalLayerBaseParameters_ILP_MP_for_p3_monty_31_no_packing_poseidon2_Poseidon2InternalLayerMonty31_WIDTH_MP_ILP. + + (* StructRecord + { + name := "Poseidon2ExternalLayerMonty31"; + const_params := [ "WIDTH" ]; + ty_params := [ "MP" ]; + fields := + [ + ("external_constants", + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_no_packing_poseidon2_Poseidon2ExternalLayerMonty31_WIDTH_MP. + Definition Self (WIDTH : Value.t) (MP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ WIDTH ] + [ MP ]. + + (* Debug *) + Definition fmt + (WIDTH : Value.t) + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH MP in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Poseidon2ExternalLayerMonty31" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "external_constants" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31", + "external_constants" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (MP : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH MP) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH MP)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_no_packing_poseidon2_Poseidon2ExternalLayerMonty31_WIDTH_MP. + + Module Impl_core_clone_Clone_where_core_clone_Clone_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_no_packing_poseidon2_Poseidon2ExternalLayerMonty31_WIDTH_MP. + Definition Self (WIDTH : Value.t) (MP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ WIDTH ] + [ MP ]. + + (* Clone *) + Definition clone + (WIDTH : Value.t) + (MP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH MP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31" + [ + ("external_constants", + M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ MP ] ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31", + "external_constants" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (MP : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH MP) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH MP)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_MP_where_p3_monty_31_data_traits_MontyParameters_MP_for_p3_monty_31_no_packing_poseidon2_Poseidon2ExternalLayerMonty31_WIDTH_MP. + + Module Impl_p3_poseidon2_internal_InternalLayerConstructor_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_poseidon2_InternalLayerBaseParameters_ILP_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_no_packing_poseidon2_Poseidon2InternalLayerMonty31_WIDTH_FP_ILP. + Definition Self (WIDTH : Value.t) (FP ILP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ WIDTH ] + [ FP; ILP ]. + + (* + fn new_from_constants(internal_constants: Vec>) -> Self { + Self { + internal_constants, + _phantom: PhantomData, + } + } + *) + Definition new_from_constants + (WIDTH : Value.t) + (FP ILP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH FP ILP in + match ε, τ, α with + | [], [], [ internal_constants ] => + ltac:(M.monadic + (let internal_constants := M.alloc (| internal_constants |) in + Value.StructRecord + "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31" + [ + ("internal_constants", M.read (| internal_constants |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (FP ILP : Ty.t), + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayerConstructor" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self WIDTH FP ILP) + (* Instance *) + [ ("new_from_constants", InstanceField.Method (new_from_constants WIDTH FP ILP)) ]. + End Impl_p3_poseidon2_internal_InternalLayerConstructor_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_poseidon2_InternalLayerBaseParameters_ILP_FP_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_no_packing_poseidon2_Poseidon2InternalLayerMonty31_WIDTH_FP_ILP. + + Module Impl_p3_poseidon2_external_ExternalLayerConstructor_where_p3_monty_31_data_traits_FieldParameters_FP_WIDTH_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_no_packing_poseidon2_Poseidon2ExternalLayerMonty31_WIDTH_FP. + Definition Self (WIDTH : Value.t) (FP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ WIDTH ] + [ FP ]. + + (* + fn new_from_constants( + external_constants: ExternalLayerConstants, WIDTH>, + ) -> Self { + Self { external_constants } + } + *) + Definition new_from_constants + (WIDTH : Value.t) + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH FP in + match ε, τ, α with + | [], [], [ external_constants ] => + ltac:(M.monadic + (let external_constants := M.alloc (| external_constants |) in + Value.StructRecord + "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31" + [ ("external_constants", M.read (| external_constants |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (FP : Ty.t), + M.IsTraitInstance + "p3_poseidon2::external::ExternalLayerConstructor" + (* Trait polymorphic consts *) [ WIDTH ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self WIDTH FP) + (* Instance *) + [ ("new_from_constants", InstanceField.Method (new_from_constants WIDTH FP)) ]. + End Impl_p3_poseidon2_external_ExternalLayerConstructor_where_p3_monty_31_data_traits_FieldParameters_FP_WIDTH_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_no_packing_poseidon2_Poseidon2ExternalLayerMonty31_WIDTH_FP. + End poseidon2. +End no_packing. diff --git a/CoqOfRust/plonky3/monty-31/src/poseidon2.rs b/CoqOfRust/plonky3/monty-31/src/poseidon2.rs new file mode 100644 index 000000000..158bff396 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/poseidon2.rs @@ -0,0 +1,145 @@ +use core::marker::PhantomData; + +use p3_field::{Algebra, InjectiveMonomial}; +use p3_poseidon2::{ + ExternalLayer, GenericPoseidon2LinearLayers, InternalLayer, MDSMat4, add_rc_and_sbox_generic, + external_initial_permute_state, external_terminal_permute_state, +}; + +use crate::{ + FieldParameters, MontyField31, MontyParameters, Poseidon2ExternalLayerMonty31, + Poseidon2InternalLayerMonty31, RelativelyPrimePower, +}; + +/// Trait which handles the Poseidon2 internal layers. +/// +/// Everything needed to compute multiplication by a `WIDTH x WIDTH` diffusion matrix whose monty form is `1 + Diag(vec)`. +/// vec is assumed to be of the form `[-2, ...]` with all entries after the first being small powers of `2`. +pub trait InternalLayerBaseParameters: + Clone + Sync +{ + // Most of the time, ArrayLike will be `[u8; WIDTH - 1]`. + type ArrayLike: AsRef<[MontyField31]> + Sized; + + // Long term INTERNAL_DIAG_MONTY will be removed. + // Currently it is needed for the Packed field implementations. + const INTERNAL_DIAG_MONTY: [MontyField31; WIDTH]; + + /// Perform the internal matrix multiplication: s -> (1 + Diag(V))s. + /// We ignore `state[0]` as it is handled separately. + fn internal_layer_mat_mul(state: &mut [MontyField31; WIDTH], sum: MontyField31); + + /// Perform the internal matrix multiplication for any Abstract field + /// which implements multiplication by MontyField31 elements. + fn generic_internal_linear_layer>>(state: &mut [A; WIDTH]); +} + +#[cfg(all(target_arch = "aarch64", target_feature = "neon"))] +pub trait InternalLayerParameters: + InternalLayerBaseParameters +{ +} +#[cfg(all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) +))] +pub trait InternalLayerParameters: + InternalLayerBaseParameters + crate::InternalLayerParametersAVX2 +{ +} +#[cfg(all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" +))] +pub trait InternalLayerParameters: + InternalLayerBaseParameters + crate::InternalLayerParametersAVX512 +{ +} +#[cfg(not(any( + all(target_arch = "aarch64", target_feature = "neon"), + all( + target_arch = "x86_64", + target_feature = "avx2", + not(all(feature = "nightly-features", target_feature = "avx512f")) + ), + all( + feature = "nightly-features", + target_arch = "x86_64", + target_feature = "avx512f" + ), +)))] +pub trait InternalLayerParameters: + InternalLayerBaseParameters +{ +} + +impl InternalLayer, WIDTH, D> + for Poseidon2InternalLayerMonty31 +where + FP: FieldParameters + RelativelyPrimePower, + P2P: InternalLayerParameters, +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [MontyField31; WIDTH]) { + self.internal_constants.iter().for_each(|rc| { + state[0] += *rc; + state[0] = state[0].injective_exp_n(); + let part_sum: MontyField31 = state[1..].iter().copied().sum(); + let full_sum = part_sum + state[0]; + state[0] = part_sum - state[0]; + P2P::internal_layer_mat_mul(state, full_sum); + }) + } +} + +impl ExternalLayer, WIDTH, D> + for Poseidon2ExternalLayerMonty31 +where + FP: FieldParameters + RelativelyPrimePower, +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [MontyField31; WIDTH]) { + external_initial_permute_state( + state, + self.external_constants.get_initial_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [MontyField31; WIDTH]) { + external_terminal_permute_state( + state, + self.external_constants.get_terminal_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } +} + +/// An implementation of the matrix multiplications in the internal and external layers of Poseidon2. +/// +/// This can act on `[A; WIDTH]` for any ring implementing `Algebra>`. +/// This will usually be slower than the Poseidon2 permutation built from `Poseidon2InternalLayerMonty31` and +/// `Poseidon2ExternalLayerMonty31` but it does work in more cases. +pub struct GenericPoseidon2LinearLayersMonty31 { + _phantom1: PhantomData, + _phantom2: PhantomData, +} + +impl GenericPoseidon2LinearLayers + for GenericPoseidon2LinearLayersMonty31 +where + FP: FieldParameters, + A: Algebra>, + ILBP: InternalLayerBaseParameters, +{ + /// Perform the external matrix multiplication for any Abstract field + /// which implements multiplication by MontyField31 elements. + fn internal_linear_layer(state: &mut [A; WIDTH]) { + ILBP::generic_internal_linear_layer(state); + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/poseidon2.v b/CoqOfRust/plonky3/monty-31/src/poseidon2.v new file mode 100644 index 000000000..f64db684f --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/poseidon2.v @@ -0,0 +1,961 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module poseidon2. + (* Trait *) + (* Empty module 'InternalLayerBaseParameters' *) + + (* Trait *) + (* Empty module 'InternalLayerParameters' *) + + Module Impl_p3_poseidon2_internal_InternalLayer_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_data_traits_RelativelyPrimePower_FP_where_p3_monty_31_poseidon2_InternalLayerParameters_P2P_FP_WIDTH_D_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_no_packing_poseidon2_Poseidon2InternalLayerMonty31_WIDTH_FP_P2P. + Definition Self (WIDTH D : Value.t) (FP P2P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31") + [ WIDTH ] + [ FP; P2P ]. + + (* + fn permute_state(&self, state: &mut [MontyField31; WIDTH]) { + self.internal_constants.iter().for_each(|rc| { + state[0] += *rc; + state[0] = state[0].injective_exp_n(); + let part_sum: MontyField31 = state[1..].iter().copied().sum(); + let full_sum = part_sum + state[0]; + state[0] = part_sum - state[0]; + P2P::internal_layer_mat_mul(state, full_sum); + }) + } + *) + Definition permute_state + (WIDTH D : Value.t) + (FP P2P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH D FP P2P in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::no_packing::poseidon2::Poseidon2InternalLayerMonty31", + "internal_constants" + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let rc := M.copy (| γ |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| M.deref (| M.read (| rc |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_trait_method (| + "p3_field::field::InjectiveMonomial", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + [ D ], + [], + "injective_exp_n", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) + |) in + let~ part_sum : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ], + [], + [], + "sum", + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + [], + [], + "copied", + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ + Ty.apply + (Ty.path + "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| state |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + Value.Integer IntegerKind.Usize 1) + ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + let~ full_sum : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + "add", + [], + [] + |), + [ + M.read (| part_sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ], + [], + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + "sub", + [], + [] + |), + [ + M.read (| part_sum |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_monty_31::poseidon2::InternalLayerBaseParameters", + P2P, + [ WIDTH ], + [ FP ], + "internal_layer_mat_mul", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |); + M.read (| full_sum |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH D : Value.t) (FP P2P : Ty.t), + M.IsTraitInstance + "p3_poseidon2::internal::InternalLayer" + (* Trait polymorphic consts *) [ WIDTH; D ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self WIDTH D FP P2P) + (* Instance *) [ ("permute_state", InstanceField.Method (permute_state WIDTH D FP P2P)) ]. + End Impl_p3_poseidon2_internal_InternalLayer_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_data_traits_RelativelyPrimePower_FP_where_p3_monty_31_poseidon2_InternalLayerParameters_P2P_FP_WIDTH_D_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_no_packing_poseidon2_Poseidon2InternalLayerMonty31_WIDTH_FP_P2P. + + Module Impl_p3_poseidon2_external_ExternalLayer_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_data_traits_RelativelyPrimePower_FP_WIDTH_D_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_no_packing_poseidon2_Poseidon2ExternalLayerMonty31_WIDTH_FP. + Definition Self (WIDTH D : Value.t) (FP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31") + [ WIDTH ] + [ FP ]. + + (* + fn permute_state_initial(&self, state: &mut [MontyField31; WIDTH]) { + external_initial_permute_state( + state, + self.external_constants.get_initial_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + *) + Definition permute_state_initial + (WIDTH D : Value.t) + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH D FP in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_initial_permute_state", + [ WIDTH ], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "p3_poseidon2::external::MDSMat4" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + "get_initial_constants", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31", + "external_constants" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ D ], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ] + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::MDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn permute_state_terminal(&self, state: &mut [MontyField31; WIDTH]) { + external_terminal_permute_state( + state, + self.external_constants.get_terminal_constants(), + add_rc_and_sbox_generic, + &MDSMat4, + ); + } + *) + Definition permute_state_terminal + (WIDTH D : Value.t) + (FP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH D FP in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_terminal_permute_state", + [ WIDTH ], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.path "p3_poseidon2::external::MDSMat4" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_monty_31::monty_31::MontyField31") + [] + [ FP ] + ], + "get_terminal_constants", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_monty_31::no_packing::poseidon2::Poseidon2ExternalLayerMonty31", + "external_constants" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + (* ReifyFnPointer *) + M.pointer_coercion + (M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ D ], + [ + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ]; + Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] + ] + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::MDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH D : Value.t) (FP : Ty.t), + M.IsTraitInstance + "p3_poseidon2::external::ExternalLayer" + (* Trait polymorphic consts *) [ WIDTH; D ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_monty_31::monty_31::MontyField31") [] [ FP ] ] + (Self WIDTH D FP) + (* Instance *) + [ + ("permute_state_initial", InstanceField.Method (permute_state_initial WIDTH D FP)); + ("permute_state_terminal", InstanceField.Method (permute_state_terminal WIDTH D FP)) + ]. + End Impl_p3_poseidon2_external_ExternalLayer_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_monty_31_data_traits_RelativelyPrimePower_FP_WIDTH_D_p3_monty_31_monty_31_MontyField31_FP_for_p3_monty_31_no_packing_poseidon2_Poseidon2ExternalLayerMonty31_WIDTH_FP. + + (* StructRecord + { + name := "GenericPoseidon2LinearLayersMonty31"; + const_params := []; + ty_params := [ "FP"; "ILBP" ]; + fields := + [ + ("_phantom1", Ty.apply (Ty.path "core::marker::PhantomData") [] [ FP ]); + ("_phantom2", Ty.apply (Ty.path "core::marker::PhantomData") [] [ ILBP ]) + ]; + } *) + + Module Impl_p3_poseidon2_generic_GenericPoseidon2LinearLayers_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_field_field_Algebra_A_p3_monty_31_monty_31_MontyField31_FP_where_p3_monty_31_poseidon2_InternalLayerBaseParameters_ILBP_FP_WIDTH_A_for_p3_monty_31_poseidon2_GenericPoseidon2LinearLayersMonty31_FP_ILBP. + Definition Self (WIDTH : Value.t) (FP A ILBP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_monty_31::poseidon2::GenericPoseidon2LinearLayersMonty31") + [] + [ FP; ILBP ]. + + (* + fn internal_linear_layer(state: &mut [A; WIDTH]) { + ILBP::generic_internal_linear_layer(state); + } + *) + Definition internal_linear_layer + (WIDTH : Value.t) + (FP A ILBP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH FP A ILBP in + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_monty_31::poseidon2::InternalLayerBaseParameters", + ILBP, + [ WIDTH ], + [ FP ], + "generic_internal_linear_layer", + [], + [ A ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (FP A ILBP : Ty.t), + M.IsTraitInstance + "p3_poseidon2::generic::GenericPoseidon2LinearLayers" + (* Trait polymorphic consts *) [ WIDTH ] + (* Trait polymorphic types *) [ A ] + (Self WIDTH FP A ILBP) + (* Instance *) + [ ("internal_linear_layer", InstanceField.Method (internal_linear_layer WIDTH FP A ILBP)) ]. + End Impl_p3_poseidon2_generic_GenericPoseidon2LinearLayers_where_p3_monty_31_data_traits_FieldParameters_FP_where_p3_field_field_Algebra_A_p3_monty_31_monty_31_MontyField31_FP_where_p3_monty_31_poseidon2_InternalLayerBaseParameters_ILBP_FP_WIDTH_A_for_p3_monty_31_poseidon2_GenericPoseidon2LinearLayersMonty31_FP_ILBP. +End poseidon2. diff --git a/CoqOfRust/plonky3/monty-31/src/utils.rs b/CoqOfRust/plonky3/monty-31/src/utils.rs new file mode 100644 index 000000000..0fc736e39 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/utils.rs @@ -0,0 +1,78 @@ +use crate::{FieldParameters, MontyParameters}; + +/// Convert a u32 into MONTY form. +/// There are no constraints on the input. +/// The output will be a u32 in range [0, P). +#[inline] +pub(crate) const fn to_monty(x: u32) -> u32 { + (((x as u64) << MP::MONTY_BITS) % MP::PRIME as u64) as u32 +} + +/// Convert an i32 into MONTY form. +/// There are no constraints on the input. +/// The output will be a u32 in range [0, P). +#[inline] +pub(crate) const fn to_monty_signed(x: i32) -> u32 { + let red = (((x as i64) << MP::MONTY_BITS) % MP::PRIME as i64) as i32; + if red >= 0 { + red as u32 + } else { + MP::PRIME.wrapping_add_signed(red) + } +} + +/// Convert a u64 into MONTY form. +/// There are no constraints on the input. +/// The output will be a u32 in range [0, P). +#[inline] +pub(crate) const fn to_monty_64(x: u64) -> u32 { + (((x as u128) << MP::MONTY_BITS) % MP::PRIME as u128) as u32 +} + +/// Convert an i64 into MONTY form. +/// There are no constraints on the input. +/// The output will be a u32 in range [0, P). +#[inline] +pub(crate) const fn to_monty_64_signed(x: i64) -> u32 { + let red = (((x as i128) << MP::MONTY_BITS) % MP::PRIME as i128) as i32; + if red >= 0 { + red as u32 + } else { + MP::PRIME.wrapping_add_signed(red) + } +} + +/// Convert a u32 out of MONTY form. +/// There are no constraints on the input. +/// The output will be a u32 in range [0, P). +#[inline] +#[must_use] +pub(crate) const fn from_monty(x: u32) -> u32 { + monty_reduce::(x as u64) +} + +/// Given an element x from a 31 bit field F_P compute x/2. +/// The input must be in [0, P). +/// The output will also be in [0, P). +#[inline] +pub(crate) const fn halve_u32(input: u32) -> u32 { + let shr = input >> 1; + let lo_bit = input & 1; + let shr_corr = shr + FP::HALF_P_PLUS_1; + if lo_bit == 0 { shr } else { shr_corr } +} + +/// Montgomery reduction of a value in `0..P << MONTY_BITS`. +/// the input must be in [0, MONTY * P). +/// the output will be in [0, P). +#[inline] +#[must_use] +pub(crate) const fn monty_reduce(x: u64) -> u32 { + let t = x.wrapping_mul(MP::MONTY_MU as u64) & (MP::MONTY_MASK as u64); + let u = t * (MP::PRIME as u64); + + let (x_sub_u, over) = x.overflowing_sub(u); + let x_sub_u_hi = (x_sub_u >> MP::MONTY_BITS) as u32; + let corr = if over { MP::PRIME } else { 0 }; + x_sub_u_hi.wrapping_add(corr) +} diff --git a/CoqOfRust/plonky3/monty-31/src/utils.v b/CoqOfRust/plonky3/monty-31/src/utils.v new file mode 100644 index 000000000..0bc3642ef --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/utils.v @@ -0,0 +1,520 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module utils. + (* + pub(crate) const fn to_monty(x: u32) -> u32 { + (((x as u64) << MP::MONTY_BITS) % MP::PRIME as u64) as u32 + } + *) + Definition to_monty (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ MP ], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u64", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ + M.cast (Ty.path "u64") (M.read (| x |)); + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::MONTY_BITS", + Ty.path "u32" + |) + |) + ] + |); + M.cast + (Ty.path "u64") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_to_monty : + M.IsFunction.C "p3_monty_31::utils::to_monty" to_monty. + Admitted. + Global Typeclasses Opaque to_monty. + + (* + pub(crate) const fn to_monty_signed(x: i32) -> u32 { + let red = (((x as i64) << MP::MONTY_BITS) % MP::PRIME as i64) as i32; + if red >= 0 { + red as u32 + } else { + MP::PRIME.wrapping_add_signed(red) + } + } + *) + Definition to_monty_signed (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ MP ], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + let~ red : Ty.apply (Ty.path "*") [] [ Ty.path "i32" ] := + M.alloc (| + M.cast + (Ty.path "i32") + (M.call_closure (| + Ty.path "i64", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "i64", + BinOp.Wrap.shl, + [ + M.cast (Ty.path "i64") (M.read (| x |)); + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::MONTY_BITS", + Ty.path "u32" + |) + |) + ] + |); + M.cast + (Ty.path "i64") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |)) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| red |); Value.Integer IntegerKind.I32 0 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| M.cast (Ty.path "u32") (M.read (| red |)) |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "wrapping_add_signed", [], [] |), + [ + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |); + M.read (| red |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_to_monty_signed : + M.IsFunction.C "p3_monty_31::utils::to_monty_signed" to_monty_signed. + Admitted. + Global Typeclasses Opaque to_monty_signed. + + (* + pub(crate) const fn to_monty_64(x: u64) -> u32 { + (((x as u128) << MP::MONTY_BITS) % MP::PRIME as u128) as u32 + } + *) + Definition to_monty_64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ MP ], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u128", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "u128", + BinOp.Wrap.shl, + [ + M.cast (Ty.path "u128") (M.read (| x |)); + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::MONTY_BITS", + Ty.path "u32" + |) + |) + ] + |); + M.cast + (Ty.path "u128") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_to_monty_64 : + M.IsFunction.C "p3_monty_31::utils::to_monty_64" to_monty_64. + Admitted. + Global Typeclasses Opaque to_monty_64. + + (* + pub(crate) const fn to_monty_64_signed(x: i64) -> u32 { + let red = (((x as i128) << MP::MONTY_BITS) % MP::PRIME as i128) as i32; + if red >= 0 { + red as u32 + } else { + MP::PRIME.wrapping_add_signed(red) + } + } + *) + Definition to_monty_64_signed (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ MP ], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + let~ red : Ty.apply (Ty.path "*") [] [ Ty.path "i32" ] := + M.alloc (| + M.cast + (Ty.path "i32") + (M.call_closure (| + Ty.path "i128", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "i128", + BinOp.Wrap.shl, + [ + M.cast (Ty.path "i128") (M.read (| x |)); + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::MONTY_BITS", + Ty.path "u32" + |) + |) + ] + |); + M.cast + (Ty.path "i128") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |)) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ M.read (| red |); Value.Integer IntegerKind.I32 0 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| M.cast (Ty.path "u32") (M.read (| red |)) |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "wrapping_add_signed", [], [] |), + [ + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |); + M.read (| red |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_to_monty_64_signed : + M.IsFunction.C "p3_monty_31::utils::to_monty_64_signed" to_monty_64_signed. + Admitted. + Global Typeclasses Opaque to_monty_64_signed. + + (* + pub(crate) const fn from_monty(x: u32) -> u32 { + monty_reduce::(x as u64) + } + *) + Definition from_monty (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ MP ], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.call_closure (| + Ty.path "u32", + M.get_function (| "p3_monty_31::utils::monty_reduce", [], [ MP ] |), + [ M.cast (Ty.path "u64") (M.read (| x |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_from_monty : + M.IsFunction.C "p3_monty_31::utils::from_monty" from_monty. + Admitted. + Global Typeclasses Opaque from_monty. + + (* + pub(crate) const fn halve_u32(input: u32) -> u32 { + let shr = input >> 1; + let lo_bit = input & 1; + let shr_corr = shr + FP::HALF_P_PLUS_1; + if lo_bit == 0 { shr } else { shr_corr } + } + *) + Definition halve_u32 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ FP ], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ shr : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.shr, + [ M.read (| input |); Value.Integer IntegerKind.I32 1 ] + |) + |) in + let~ lo_bit : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.bit_and, + [ M.read (| input |); Value.Integer IntegerKind.U32 1 ] + |) + |) in + let~ shr_corr : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.read (| shr |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::FieldParameters::HALF_P_PLUS_1", + Ty.path "u32" + |) + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| lo_bit |); Value.Integer IntegerKind.U32 0 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + shr)); + fun γ => ltac:(M.monadic shr_corr) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_halve_u32 : + M.IsFunction.C "p3_monty_31::utils::halve_u32" halve_u32. + Admitted. + Global Typeclasses Opaque halve_u32. + + (* + pub(crate) const fn monty_reduce(x: u64) -> u32 { + let t = x.wrapping_mul(MP::MONTY_MU as u64) & (MP::MONTY_MASK as u64); + let u = t * (MP::PRIME as u64); + + let (x_sub_u, over) = x.overflowing_sub(u); + let x_sub_u_hi = (x_sub_u >> MP::MONTY_BITS) as u32; + let corr = if over { MP::PRIME } else { 0 }; + x_sub_u_hi.wrapping_add(corr) + } + *) + Definition monty_reduce (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ MP ], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + let~ t : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| Ty.path "u64", "wrapping_mul", [], [] |), + [ + M.read (| x |); + M.cast + (Ty.path "u64") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::MONTY_MU", + Ty.path "u32" + |) + |)) + ] + |); + M.cast + (Ty.path "u64") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::MONTY_MASK", + Ty.path "u32" + |) + |)) + ] + |) + |) in + let~ u : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.read (| t |); + M.cast + (Ty.path "u64") + (M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |) + |)) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "u64"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "u64", "overflowing_sub", [], [] |), + [ M.read (| x |); M.read (| u |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let x_sub_u := M.copy (| γ0_0 |) in + let over := M.copy (| γ0_1 |) in + let~ x_sub_u_hi : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shr, + [ + M.read (| x_sub_u |); + M.read (| + get_constant (| + "p3_monty_31::data_traits::MontyParameters::MONTY_BITS", + Ty.path "u32" + |) + |) + ] + |)) + |) in + let~ corr : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.copy (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "u32" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use over in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + get_constant (| + "p3_monty_31::data_traits::MontyParameters::PRIME", + Ty.path "u32" + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U32 0 |))) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "wrapping_add", [], [] |), + [ M.read (| x_sub_u_hi |); M.read (| corr |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_monty_reduce : + M.IsFunction.C "p3_monty_31::utils::monty_reduce" monty_reduce. + Admitted. + Global Typeclasses Opaque monty_reduce. +End utils. diff --git a/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/mod.rs b/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/mod.rs new file mode 100644 index 000000000..697898094 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/mod.rs @@ -0,0 +1,7 @@ +mod packing; +mod poseidon2; +mod utils; + +pub use packing::*; +pub use poseidon2::*; +pub use utils::*; diff --git a/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/packing.rs b/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/packing.rs new file mode 100644 index 000000000..13a6b5b1c --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/packing.rs @@ -0,0 +1,1309 @@ +use alloc::vec::Vec; +use core::arch::x86_64::{self, __m256i}; +use core::array; +use core::iter::{Product, Sum}; +use core::mem::transmute; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; + +use p3_field::{ + Algebra, Field, InjectiveMonomial, PackedField, PackedFieldPow2, PackedValue, + PermutationMonomial, PrimeCharacteristicRing, +}; +use p3_util::reconstitute_from_base; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; + +use crate::{ + FieldParameters, MontyField31, PackedMontyParameters, RelativelyPrimePower, signed_add_avx2, +}; + +const WIDTH: usize = 8; + +pub trait MontyParametersAVX2 { + const PACKED_P: __m256i; + const PACKED_MU: __m256i; +} + +/// Vectorized AVX2 implementation of `MontyField31` arithmetic. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(transparent)] // This is needed to make `transmute`s safe. +pub struct PackedMontyField31AVX2(pub [MontyField31; WIDTH]); + +impl PackedMontyField31AVX2 { + #[inline] + #[must_use] + /// Get an arch-specific vector representing the packed values. + pub(crate) fn to_vector(self) -> __m256i { + unsafe { + // Safety: `MontyField31` is `repr(transparent)` so it can be transmuted to `u32`. It + // follows that `[MontyField31; WIDTH]` can be transmuted to `[u32; WIDTH]`, which can be + // transmuted to `__m256i`, since arrays are guaranteed to be contiguous in memory. + // Finally `PackedMontyField31AVX2` is `repr(transparent)` so it can be transmuted to + // `[MontyField31; WIDTH]`. + transmute(self) + } + } + + #[inline] + #[must_use] + /// Make a packed field vector from an arch-specific vector. + /// + /// SAFETY: The caller must ensure that each element of `vector` represents a valid `MontyField31`. + /// In particular, each element of vector must be in `0..P` (canonical form). + pub(crate) unsafe fn from_vector(vector: __m256i) -> Self { + unsafe { + // Safety: It is up to the user to ensure that elements of `vector` represent valid + // `MontyField31` values. We must only reason about memory representations. `__m256i` can be + // transmuted to `[u32; WIDTH]` (since arrays elements are contiguous in memory), which can + // be transmuted to `[MontyField31; WIDTH]` (since `MontyField31` is `repr(transparent)`), which in + // turn can be transmuted to `PackedMontyField31AVX2` (since `PackedMontyField31AVX2` is also + // `repr(transparent)`). + transmute(vector) + } + } + + /// Copy `value` to all positions in a packed vector. This is the same as + /// `From>::from`, but `const`. + #[inline] + #[must_use] + const fn broadcast(value: MontyField31) -> Self { + Self([value; WIDTH]) + } +} + +impl Add for PackedMontyField31AVX2 { + type Output = Self; + #[inline] + fn add(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = add::(lhs, rhs); + unsafe { + // Safety: `add` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Mul for PackedMontyField31AVX2 { + type Output = Self; + #[inline] + fn mul(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let t = mul::(lhs, rhs); + let res = red_signed_to_canonical::(t); + unsafe { + // Safety: `mul` returns values in signed form when given values in canonical form. + // Then `red_signed_to_canonical` reduces values from signed form to canonical form. + Self::from_vector(res) + } + } +} + +impl Neg for PackedMontyField31AVX2 { + type Output = Self; + #[inline] + fn neg(self) -> Self { + let val = self.to_vector(); + let res = neg::(val); + unsafe { + // Safety: `neg` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Sub for PackedMontyField31AVX2 { + type Output = Self; + #[inline] + fn sub(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = sub::(lhs, rhs); + unsafe { + // Safety: `sub` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +/// Add two vectors of Monty31 field elements in canonical form. +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +pub(crate) fn add(lhs: __m256i, rhs: __m256i) -> __m256i { + // We want this to compile to: + // vpaddd t, lhs, rhs + // vpsubd u, t, P + // vpminud res, t, u + // throughput: 1 cyc/vec (8 els/cyc) + // latency: 3 cyc + + // Let t := lhs + rhs. We want to return t mod P. Recall that lhs and rhs are in + // 0, ..., P - 1, so t is in 0, ..., 2 P - 2 (< 2^32). It suffices to return t if t < P and + // t - P otherwise. + // Let u := (t - P) mod 2^32 and r := unsigned_min(t, u). + // If t is in 0, ..., P - 1, then u is in (P - 1 <) 2^32 - P, ..., 2^32 - 1 and r = t. + // Otherwise, t is in P, ..., 2 P - 2, u is in 0, ..., P - 2 (< P) and r = u. Hence, r is t if + // t < P and t - P otherwise, as desired. + + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + let t = x86_64::_mm256_add_epi32(lhs, rhs); + let u = x86_64::_mm256_sub_epi32(t, MPAVX2::PACKED_P); + x86_64::_mm256_min_epu32(t, u) + } +} + +// MONTGOMERY MULTIPLICATION +// This implementation is based on [1] but with minor changes. The reduction is as follows: +// +// Constants: P < 2^31, prime +// B = 2^32 +// μ = P^-1 mod B +// Input: 0 <= C < P B +// Output: 0 <= R < P such that R = C B^-1 (mod P) +// 1. Q := μ C mod B +// 2. D := (C - Q P) / B +// 3. R := if D < 0 then D + P else D +// +// We first show that the division in step 2. is exact. It suffices to show that C = Q P (mod B). By +// definition of Q and μ, we have Q P = μ C P = P^-1 C P = C (mod B). We also have +// C - Q P = C (mod P), so thus D = C B^-1 (mod P). +// +// It remains to show that R is in the correct range. It suffices to show that -P < D < P. We know +// that 0 <= C < P B and 0 <= Q P < P B. Then -P B < C - QP < P B and -P < D < P, as desired. +// +// [1] Modern Computer Arithmetic, Richard Brent and Paul Zimmermann, Cambridge University Press, +// 2010, algorithm 2.7. + +// We provide 2 variants of Montgomery reduction depending on if the inputs are unsigned or signed. +// The unsigned variant follows steps 1 and 2 in the above protocol to produce D in (-P, ..., P). +// For the signed variant we assume -PB/2 < C < PB/2 and let Q := μ C mod B be the unique +// representative in [-B/2, ..., B/2 - 1]. The division in step 2 is clearly still exact and +// |C - Q P| <= |C| + |Q||P| < PB so D still lies in (-P, ..., P). + +/// Perform a partial Montgomery reduction on each 64 bit element. +/// Input must lie in {0, ..., 2^32P}. +/// The output will lie in {-P, ..., P} and be stored in the upper 32 bits. +#[inline] +#[must_use] +fn partial_monty_red_unsigned_to_signed(input: __m256i) -> __m256i { + unsafe { + let q = x86_64::_mm256_mul_epu32(input, MPAVX2::PACKED_MU); + let q_p = x86_64::_mm256_mul_epu32(q, MPAVX2::PACKED_P); + + // By construction, the bottom 32 bits of input and q_p are equal. + // Thus _mm256_sub_epi32 and _mm256_sub_epi64 should act identically. + // However for some reason, the compiler gets confused if we use _mm256_sub_epi64 + // and outputs a load of nonsense, see: https://godbolt.org/z/3W8M7Tv84. + x86_64::_mm256_sub_epi32(input, q_p) + } +} + +/// Perform a partial Montgomery reduction on each 64 bit element. +/// Input must lie in {-2^{31}P, ..., 2^31P}. +/// The output will lie in {-P, ..., P} and be stored in the upper 32 bits. +#[inline] +#[must_use] +fn partial_monty_red_signed_to_signed(input: __m256i) -> __m256i { + unsafe { + let q = x86_64::_mm256_mul_epi32(input, MPAVX2::PACKED_MU); + let q_p = x86_64::_mm256_mul_epi32(q, MPAVX2::PACKED_P); + + // Unlike the previous case the compiler output is essentially identical + // between _mm256_sub_epi32 and _mm256_sub_epi64. We use _mm256_sub_epi32 + // again just for consistency. + x86_64::_mm256_sub_epi32(input, q_p) + } +} + +/// Blend together in two vectors interleaving the 32-bit elements stored in the odd components. +/// +/// This ignores whatever is stored in even positions. +#[inline(always)] +#[must_use] +fn blend_evn_odd(evn: __m256i, odd: __m256i) -> __m256i { + // We want this to compile to: + // vmovshdup evn_hi, evn + // vpblendd t, evn_hi, odd, aah + // throughput: 0.67 cyc/vec (12 els/cyc) + // latency: 2 cyc + unsafe { + // We start with: + // evn = [ e0 e1 e2 e3 e4 e5 e6 e7 ], + // odd = [ o0 o1 o2 o3 o4 o5 o6 o7 ]. + let evn_hi = movehdup_epi32(evn); + x86_64::_mm256_blend_epi32::<0b10101010>(evn_hi, odd) + // res = [e1, o1, e3, o3, e5, o5, e7, o7] + } +} + +/// Given a vector of signed field elements, return a vector of elements in canonical form. +/// +/// Inputs must be signed 32-bit integers lying in (-P, ..., P). If they do not lie in +/// this range, the output is undefined. +#[inline(always)] +#[must_use] +fn red_signed_to_canonical(input: __m256i) -> __m256i { + unsafe { + // We want this to compile to: + // vpaddd corr, input, P + // vpminud res, input, corr + // throughput: 0.67 cyc/vec (12 els/cyc) + // latency: 2 cyc + + // We want to return input mod P where input lies in (-2^31 <) -P + 1, ..., P - 1 (< 2^31). + // It suffices to return input if input >= 0 and input + P otherwise. + // + // Let corr := (input + P) mod 2^32 and res := unsigned_min(input, corr). + // If input is in 0, ..., P - 1, then corr is in P, ..., 2 P - 1 and res = input. + // Otherwise, input is in -P + 1, ..., -1; corr is in 1, ..., P - 1 (< P) and res = corr. + // Hence, res is input if input < P and input + P otherwise, as desired. + let corr = x86_64::_mm256_add_epi32(input, MPAVX2::PACKED_P); + x86_64::_mm256_min_epu32(input, corr) + } +} + +/// Multiply the MontyField31 field elements in the even index entries. +/// lhs[2i], rhs[2i] must be unsigned 32-bit integers such that +/// lhs[2i] * rhs[2i] lies in {0, ..., 2^32P}. +/// The output will lie in {-P, ..., P} and be stored in output[2i + 1]. +#[inline] +#[must_use] +fn monty_mul(lhs: __m256i, rhs: __m256i) -> __m256i { + unsafe { + let prod = x86_64::_mm256_mul_epu32(lhs, rhs); + partial_monty_red_unsigned_to_signed::(prod) + } +} + +/// Multiply the MontyField31 field elements in the even index entries. +/// lhs[2i], rhs[2i] must be signed 32-bit integers such that +/// lhs[2i] * rhs[2i] lies in {-2^31P, ..., 2^31P}. +/// The output will lie in {-P, ..., P} stored in output[2i + 1]. +#[inline] +#[must_use] +fn monty_mul_signed(lhs: __m256i, rhs: __m256i) -> __m256i { + unsafe { + let prod = x86_64::_mm256_mul_epi32(lhs, rhs); + partial_monty_red_signed_to_signed::(prod) + } +} + +#[inline] +#[must_use] +fn movehdup_epi32(x: __m256i) -> __m256i { + // This instruction is only available in the floating-point flavor; this distinction is only for + // historical reasons and no longer matters. We cast to floats, duplicate, and cast back. + unsafe { + x86_64::_mm256_castps_si256(x86_64::_mm256_movehdup_ps(x86_64::_mm256_castsi256_ps(x))) + } +} + +/// Multiply unsigned vectors of field elements returning a vector of signed integers lying in (-P, P). +/// +/// Inputs are allowed to not be in canonical form however they must obey the bound `lhs*rhs < 2^32P`. If this bound +/// is broken, the output is undefined. +#[inline] +#[must_use] +fn mul(lhs: __m256i, rhs: __m256i) -> __m256i { + // We want this to compile to: + // vmovshdup lhs_odd, lhs + // vmovshdup rhs_odd, rhs + // vpmuludq prod_evn, lhs, rhs + // vpmuludq prod_odd, lhs_odd, rhs_odd + // vpmuludq q_evn, prod_evn, MU + // vpmuludq q_odd, prod_odd, MU + // vpmuludq q_P_evn, q_evn, P + // vpmuludq q_P_odd, q_odd, P + // vpsubq d_evn, prod_evn, q_P_evn + // vpsubq d_odd, prod_odd, q_P_odd + // vmovshdup d_evn_hi, d_evn + // vpblendd t, d_evn_hi, d_odd, aah + // throughput: 4 cyc/vec (2 els/cyc) + // latency: 19 cyc + let lhs_evn = lhs; + let rhs_evn = rhs; + let lhs_odd = movehdup_epi32(lhs); + let rhs_odd = movehdup_epi32(rhs); + + let d_evn = monty_mul::(lhs_evn, rhs_evn); + let d_odd = monty_mul::(lhs_odd, rhs_odd); + + blend_evn_odd(d_evn, d_odd) +} + +/// Lets us combine some code for MontyField31 and PackedMontyField31AVX2 elements. +/// +/// Provides methods to convert an element into a __m256i element and then shift this __m256i +/// element so that the odd elements now lie in the even positions. Depending on the type of input, +/// the shift might be a no-op. +trait IntoM256: Copy + Into> { + /// Convert the input into a __m256i element. + fn as_m256i(&self) -> __m256i; + + /// Convert the input to a __m256i element and shift so that all elements in odd positions + /// now lie in even positions. + /// + /// The values lying in the even positions are undefined. + #[inline(always)] + fn as_shifted_m256i(&self) -> __m256i { + let vec = self.as_m256i(); + movehdup_epi32(vec) + } +} + +impl IntoM256 for PackedMontyField31AVX2 { + #[inline(always)] + fn as_m256i(&self) -> __m256i { + self.to_vector() + } +} + +impl IntoM256 for MontyField31 { + #[inline(always)] + fn as_m256i(&self) -> __m256i { + unsafe { x86_64::_mm256_set1_epi32(self.value as i32) } + } + + #[inline(always)] + fn as_shifted_m256i(&self) -> __m256i { + unsafe { x86_64::_mm256_set1_epi32(self.value as i32) } + } +} + +/// Compute the elementary function `l0*r0 + l1*r1` given four inputs +/// in canonical form. +/// +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn dot_product_2, RHS: IntoM256>( + lhs: [LHS; 2], + rhs: [RHS; 2], +) -> __m256i { + // The following analysis treats all input arrays as being arrays of PackedMontyField31AVX2. + // If one of the arrays contains MontyField31, we get to avoid the initial vmovshdup. + // + // We improve the throughput by combining the monty reductions together. As all inputs are + // `< P < 2^{31}`, `l0*r0 + l1*r1 < 2P^2 < 2^{32}P` so the montgomery reduction + // algorithm can be applied to the sum of the products instead of to each product individually. + // + // We want this to compile to: + // vmovshdup lhs_odd0, lhs0 + // vmovshdup rhs_odd0, rhs0 + // vmovshdup lhs_odd1, lhs1 + // vmovshdup rhs_odd1, rhs1 + // vpmuludq prod_evn0, lhs0, rhs0 + // vpmuludq prod_odd0, lhs_odd0, rhs_odd0 + // vpmuludq prod_evn1, lhs1, rhs1 + // vpmuludq prod_odd1, lhs_odd1, rhs_odd1 + // vpaddq prod_evn, prod_evn0, prod_evn1 + // vpaddq prod_odd, prod_odd0, prod_odd1 + // vpmuludq q_evn, prod_evn, MU + // vpmuludq q_odd, prod_odd, MU + // vpmuludq q_P_evn, q_evn, P + // vpmuludq q_P_odd, q_odd, P + // vpsubq d_evn, prod_evn, q_P_evn + // vpsubq d_odd, prod_odd, q_P_odd + // vmovshdup d_evn_hi, d_evn + // vpblendd t, d_evn_hi, d_odd, aah + // vpaddd u, t, P + // vpminud res, t, u + // throughput: 6.67 cyc/vec (1.20 els/cyc) + // latency: 21 cyc + unsafe { + let lhs_evn0 = lhs[0].as_m256i(); + let lhs_odd0 = lhs[0].as_shifted_m256i(); + let lhs_evn1 = lhs[1].as_m256i(); + let lhs_odd1 = lhs[1].as_shifted_m256i(); + + let rhs_evn0 = rhs[0].as_m256i(); + let rhs_odd0 = rhs[0].as_shifted_m256i(); + let rhs_evn1 = rhs[1].as_m256i(); + let rhs_odd1 = rhs[1].as_shifted_m256i(); + + let mul_evn0 = x86_64::_mm256_mul_epu32(lhs_evn0, rhs_evn0); + let mul_evn1 = x86_64::_mm256_mul_epu32(lhs_evn1, rhs_evn1); + let mul_odd0 = x86_64::_mm256_mul_epu32(lhs_odd0, rhs_odd0); + let mul_odd1 = x86_64::_mm256_mul_epu32(lhs_odd1, rhs_odd1); + + let dot_evn = x86_64::_mm256_add_epi64(mul_evn0, mul_evn1); + let dot_odd = x86_64::_mm256_add_epi64(mul_odd0, mul_odd1); + + let red_evn = partial_monty_red_unsigned_to_signed::(dot_evn); + let red_odd = partial_monty_red_unsigned_to_signed::(dot_odd); + + let t = blend_evn_odd(red_evn, red_odd); + red_signed_to_canonical::(t) + } +} + +/// Compute the elementary function `l0*r0 + l1*r1 + l2*r2 + l3*r3` given eight inputs +/// in canonical form. +/// +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn dot_product_4, RHS: IntoM256>( + lhs: [LHS; 4], + rhs: [RHS; 4], +) -> __m256i { + // The following analysis treats all input arrays as being arrays of PackedMontyField31AVX2. + // If one of the arrays contains MontyField31, we get to avoid the initial vmovshdup. + // + // Similarly to dot_product_2, we improve throughput by combining monty reductions however in this case + // we will need to slightly adjust the reduction algorithm. + // + // As all inputs are `< P < 2^{31}`, the sum satisfies: `C = l0*r0 + l1*r1 + l2*r2 + l3*r3 < 4P^2 < 2*2^{32}P`. + // Start by computing Q := μ C mod B as usual. + // We can't proceed as normal however as 2*2^{32}P > C - QP > -2^{32}P which doesn't fit into an i64. + // Instead we do a reduction on C, defining C' = if C < 2^{32}P: {C} else {C - 2^{32}P} + // From here we proceed with the standard montgomery reduction with C replaced by C'. It works identically + // with the Q we already computed as C = C' mod B. + // + // We want this to compile to: + // vmovshdup lhs_odd0, lhs0 + // vmovshdup rhs_odd0, rhs0 + // vmovshdup lhs_odd1, lhs1 + // vmovshdup rhs_odd1, rhs1 + // vmovshdup lhs_odd2, lhs2 + // vmovshdup rhs_odd2, rhs2 + // vmovshdup lhs_odd3, lhs3 + // vmovshdup rhs_odd3, rhs3 + // vpmuludq prod_evn0, lhs0, rhs0 + // vpmuludq prod_odd0, lhs_odd0, rhs_odd0 + // vpmuludq prod_evn1, lhs1, rhs1 + // vpmuludq prod_odd1, lhs_odd1, rhs_odd1 + // vpmuludq prod_evn2, lhs2, rhs2 + // vpmuludq prod_odd2, lhs_odd2, rhs_odd2 + // vpmuludq prod_evn3, lhs3, rhs3 + // vpmuludq prod_odd3, lhs_odd3, rhs_odd3 + // vpaddq prod_evn01, prod_evn0, prod_evn1 + // vpaddq prod_odd01, prod_odd0, prod_odd1 + // vpaddq prod_evn23, prod_evn2, prod_evn3 + // vpaddq prod_odd23, prod_odd2, prod_odd3 + // vpaddq dot_evn, prod_evn01, prod_evn23 + // vpaddq dot_odd, prod_odd01, prod_odd23 + // vmovshdup dot_evn_hi, dot_evn + // vpblendd dot, dot_evn_hi, dot_odd, aah + // vpmuludq q_evn, dot_evn, MU + // vpmuludq q_odd, dot_odd, MU + // vpmuludq q_P_evn, q_evn, P + // vpmuludq q_P_odd, q_odd, P + // vmovshdup q_P_evn_hi, q_P_evn + // vpblendd q_P, q_P_evn_hi, q_P_odd, aah + // vpsubq dot_sub, dot, P + // vpminud dot_prime, dot, dot_sub + // vpsubq t, dot_prime, q_P + // vpaddd u, t, P + // vpminud res, t, u + // throughput: 11.67 cyc/vec (0.69 els/cyc) + // latency: 22 cyc + unsafe { + let lhs_evn0 = lhs[0].as_m256i(); + let lhs_odd0 = lhs[0].as_shifted_m256i(); + let lhs_evn1 = lhs[1].as_m256i(); + let lhs_odd1 = lhs[1].as_shifted_m256i(); + let lhs_evn2 = lhs[2].as_m256i(); + let lhs_odd2 = lhs[2].as_shifted_m256i(); + let lhs_evn3 = lhs[3].as_m256i(); + let lhs_odd3 = lhs[3].as_shifted_m256i(); + + let rhs_evn0 = rhs[0].as_m256i(); + let rhs_odd0 = rhs[0].as_shifted_m256i(); + let rhs_evn1 = rhs[1].as_m256i(); + let rhs_odd1 = rhs[1].as_shifted_m256i(); + let rhs_evn2 = rhs[2].as_m256i(); + let rhs_odd2 = rhs[2].as_shifted_m256i(); + let rhs_evn3 = rhs[3].as_m256i(); + let rhs_odd3 = rhs[3].as_shifted_m256i(); + + let mul_evn0 = x86_64::_mm256_mul_epu32(lhs_evn0, rhs_evn0); + let mul_evn1 = x86_64::_mm256_mul_epu32(lhs_evn1, rhs_evn1); + let mul_evn2 = x86_64::_mm256_mul_epu32(lhs_evn2, rhs_evn2); + let mul_evn3 = x86_64::_mm256_mul_epu32(lhs_evn3, rhs_evn3); + let mul_odd0 = x86_64::_mm256_mul_epu32(lhs_odd0, rhs_odd0); + let mul_odd1 = x86_64::_mm256_mul_epu32(lhs_odd1, rhs_odd1); + let mul_odd2 = x86_64::_mm256_mul_epu32(lhs_odd2, rhs_odd2); + let mul_odd3 = x86_64::_mm256_mul_epu32(lhs_odd3, rhs_odd3); + + let dot_evn01 = x86_64::_mm256_add_epi64(mul_evn0, mul_evn1); + let dot_odd01 = x86_64::_mm256_add_epi64(mul_odd0, mul_odd1); + let dot_evn23 = x86_64::_mm256_add_epi64(mul_evn2, mul_evn3); + let dot_odd23 = x86_64::_mm256_add_epi64(mul_odd2, mul_odd3); + + let dot_evn = x86_64::_mm256_add_epi64(dot_evn01, dot_evn23); + let dot_odd = x86_64::_mm256_add_epi64(dot_odd01, dot_odd23); + + // We only care about the top 32 bits of dot_evn/odd. + // They currently lie in [0, 2P] so we reduce them to [0, P) + let dot = blend_evn_odd(dot_evn, dot_odd); + let dot_sub = x86_64::_mm256_sub_epi32(dot, PMP::PACKED_P); + let dot_prime = x86_64::_mm256_min_epu32(dot, dot_sub); + + let q_evn = x86_64::_mm256_mul_epu32(dot_evn, PMP::PACKED_MU); + let q_p_evn = x86_64::_mm256_mul_epu32(q_evn, PMP::PACKED_P); + let q_odd = x86_64::_mm256_mul_epu32(dot_odd, PMP::PACKED_MU); + let q_p_odd = x86_64::_mm256_mul_epu32(q_odd, PMP::PACKED_P); + + // Similarly we only need to care about the top 32 bits of q_p_odd/evn + let q_p = blend_evn_odd(q_p_evn, q_p_odd); + + let t = x86_64::_mm256_sub_epi32(dot_prime, q_p); + red_signed_to_canonical::(t) + } +} + +/// A general fast dot product implementation. +/// +/// Maximises the number of calls to `dot_product_4` for dot products involving vectors of length +/// more than 4. The length 64 occurs commonly enough it's useful to have a custom implementation +/// which lets it use a slightly better summation algorithm with lower latency. +#[inline(always)] +fn general_dot_product< + FP: FieldParameters, + LHS: IntoM256, + RHS: IntoM256, + const N: usize, +>( + lhs: &[LHS], + rhs: &[RHS], +) -> PackedMontyField31AVX2 { + assert_eq!(lhs.len(), N); + assert_eq!(rhs.len(), N); + match N { + 0 => PackedMontyField31AVX2::::ZERO, + 1 => (lhs[0]).into() * (rhs[0]).into(), + 2 => { + let res = dot_product_2([lhs[0], lhs[1]], [rhs[0], rhs[1]]); + unsafe { + // Safety: `dot_product_2` returns values in canonical form when given values in canonical form. + PackedMontyField31AVX2::::from_vector(res) + } + } + 3 => { + let lhs2 = lhs[2]; + let rhs2 = rhs[2]; + let res = dot_product_2([lhs[0], lhs[1]], [rhs[0], rhs[1]]); + unsafe { + // Safety: `dot_product_2` returns values in canonical form when given values in canonical form. + PackedMontyField31AVX2::::from_vector(res) + (lhs2.into() * rhs2.into()) + } + } + 4 => { + let res = dot_product_4( + [lhs[0], lhs[1], lhs[2], lhs[3]], + [rhs[0], rhs[1], rhs[2], rhs[3]], + ); + unsafe { + // Safety: `dot_product_4` returns values in canonical form when given values in canonical form. + PackedMontyField31AVX2::::from_vector(res) + } + } + 64 => { + let sum_4s: [PackedMontyField31AVX2; 16] = array::from_fn(|i| { + let res = dot_product_4( + [lhs[4 * i], lhs[4 * i + 1], lhs[4 * i + 2], lhs[4 * i + 3]], + [rhs[4 * i], rhs[4 * i + 1], rhs[4 * i + 2], rhs[4 * i + 3]], + ); + unsafe { + // Safety: `dot_product_4` returns values in canonical form when given values in canonical form. + PackedMontyField31AVX2::::from_vector(res) + } + }); + PackedMontyField31AVX2::::sum_array::<16>(&sum_4s) + } + _ => { + let mut acc = { + let res = dot_product_4( + [lhs[0], lhs[1], lhs[2], lhs[3]], + [rhs[0], rhs[1], rhs[2], rhs[3]], + ); + unsafe { + // Safety: `dot_product_4` returns values in canonical form when given values in canonical form. + PackedMontyField31AVX2::::from_vector(res) + } + }; + for i in (4..(N - 3)).step_by(4) { + let res = dot_product_4( + [lhs[i], lhs[i + 1], lhs[i + 2], lhs[i + 3]], + [rhs[i], rhs[i + 1], rhs[i + 2], rhs[i + 3]], + ); + unsafe { + // Safety: `dot_product_4` returns values in canonical form when given values in canonical form. + acc += PackedMontyField31AVX2::::from_vector(res) + } + } + match N & 3 { + 0 => acc, + 1 => { + acc + general_dot_product::<_, _, _, 1>( + &lhs[(4 * (N / 4))..], + &rhs[(4 * (N / 4))..], + ) + } + 2 => { + acc + general_dot_product::<_, _, _, 2>( + &lhs[(4 * (N / 4))..], + &rhs[(4 * (N / 4))..], + ) + } + 3 => { + acc + general_dot_product::<_, _, _, 3>( + &lhs[(4 * (N / 4))..], + &rhs[(4 * (N / 4))..], + ) + } + _ => unreachable!(), + } + } + } +} + +/// Square the MontyField31 field elements in the even index entries. +/// Inputs must be signed 32-bit integers. +/// Outputs will be a signed integer in (-P, ..., P) copied into both the even and odd indices. +#[inline] +#[must_use] +fn shifted_square(input: __m256i) -> __m256i { + // Note that we do not need a restriction on the size of input[i]^2 as + // 2^30 < P and |i32| <= 2^31 and so => input[i]^2 <= 2^62 < 2^32P. + unsafe { + let square = x86_64::_mm256_mul_epi32(input, input); + let square_red = partial_monty_red_unsigned_to_signed::(square); + movehdup_epi32(square_red) + } +} + +/// Compute the elementary arithmetic generalization of `xor`, namely `xor(l, r) = l + r - 2lr` of +/// vectors in canonical form. +/// +/// Inputs are assumed to be in canonical form, if the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn xor(lhs: __m256i, rhs: __m256i) -> __m256i { + // Refactor the expression as r + 2l(1/2 - r). As MONTY_CONSTANT = 2^32, the internal + // representation 1/2 is 2^31 mod P so the product in the above expression is represented + // as 2l(2^31 - r). As 0 < 2l, 2^31 - r < 2^32 and 2l(2^31 - r) < 2^32P, we can compute + // the factors as 32 bit integers and then multiply and monty reduce as usual. + // + // We want this to compile to: + // vpaddd lhs_double, lhs, lhs + // vpsubd sub_rhs, rhs, (1 << 31) + // vmovshdup lhs_odd, lhs_double + // vmovshdup rhs_odd, sub_rhs + // vpmuludq prod_evn, lhs_double, sub_rhs + // vpmuludq prod_odd, lhs_odd, rhs_odd + // vpmuludq q_evn, prod_evn, MU + // vpmuludq q_odd, prod_odd, MU + // vpmuludq q_P_evn, q_evn, P + // vpmuludq q_P_odd, q_odd, P + // vpsubq d_evn, prod_evn, q_P_evn + // vpsubq d_odd, prod_odd, q_P_odd + // vmovshdup d_evn_hi, d_evn + // vpblendd t, d_evn_hi, d_odd, aah + // vpsignd pos_neg_P, P, t + // vpaddd sum, rhs, t + // vpsubd sum_corr, sum, pos_neg_P + // vpminud res, sum, sum_corr + // throughput: 6 cyc/vec (1.33 els/cyc) + // latency: 22 cyc + unsafe { + // 0 <= 2*lhs < 2P + let double_lhs = x86_64::_mm256_add_epi32(lhs, lhs); + + // Note that 2^31 is represented as an i32 as (-2^31). + // Compiler should realise this is a constant. + let half = x86_64::_mm256_set1_epi32(-1 << 31); + + // 0 < 2^31 - rhs < 2^31 + let half_sub_rhs = x86_64::_mm256_sub_epi32(half, rhs); + + // 2*lhs (2^31 - rhs) < 2P 2^31 < 2^32P so we can use the multiplication function. + let mul_res = mul::(double_lhs, half_sub_rhs); + + // As -P < mul_res < P and 0 <= rhs < P, we can use signed add + // which saves an instruction over reducing mul_res and adding in the usual way. + signed_add_avx2::(rhs, mul_res) + } +} + +/// Compute the elementary arithmetic generalization of `andnot`, namely `andn(l, r) = (1 - l)r` of +/// vectors in canonical form. +/// +/// Inputs are assumed to be in canonical form, if the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn andn(lhs: __m256i, rhs: __m256i) -> __m256i { + // As we are working with MONTY_CONSTANT = 2^32, the internal representation + // of 1 is 2^32 mod P = 2^32 - P mod P. Hence we compute (2^32 - P - l)r. + // This product is less than 2^32P so we can apply our monty reduction to this. + // + // We want this to compile to: + // vpsubd neg_lhs, -P, lhs + // vmovshdup lhs_odd, neg_lhs + // vmovshdup rhs_odd, rhs + // vpmuludq prod_evn, neg_lhs, rhs + // vpmuludq prod_odd, lhs_odd, rhs_odd + // vpmuludq q_evn, prod_evn, MU + // vpmuludq q_odd, prod_odd, MU + // vpmuludq q_P_evn, q_evn, P + // vpmuludq q_P_odd, q_odd, P + // vpsubq d_evn, prod_evn, q_P_evn + // vpsubq d_odd, prod_odd, q_P_odd + // vmovshdup d_evn_hi, d_evn + // vpblendd t, d_evn_hi, d_odd, aah + // vpaddd corr, t, P + // vpminud res, t, corr + // throughput: 5 cyc/vec (1.6 els/cyc) + // latency: 20 cyc + unsafe { + // We use 2^32 - P instead of 2^32 to avoid having to worry about 0's in lhs. + + // Compiler should realise that this is a constant. + let neg_p = x86_64::_mm256_sub_epi32(x86_64::_mm256_setzero_si256(), MPAVX2::PACKED_P); + let neg_lhs = x86_64::_mm256_sub_epi32(neg_p, lhs); + + // 2*lhs (2^31 - rhs) < 2P 2^31 < 2^32P so we can use the multiplication function. + let mul_res = mul::(neg_lhs, rhs); + + // As -P < mul_res < P we just need to reduce elements to canonical form. + red_signed_to_canonical::(mul_res) + } +} + +/// Cube the MontyField31 field elements in the even index entries. +/// Inputs must be signed 32-bit integers in [-P, ..., P]. +/// Outputs will be a signed integer in (-P, ..., P) stored in the odd indices. +#[inline] +#[must_use] +pub(crate) fn packed_exp_3(input: __m256i) -> __m256i { + let square = shifted_square::(input); + monty_mul_signed::(square, input) +} + +/// Take the fifth power of the MontyField31 field elements in the even index entries. +/// Inputs must be signed 32-bit integers in [-P, ..., P]. +/// Outputs will be a signed integer in (-P, ..., P) stored in the odd indices. +#[inline] +#[must_use] +pub(crate) fn packed_exp_5(input: __m256i) -> __m256i { + let square = shifted_square::(input); + let quad = shifted_square::(square); + monty_mul_signed::(quad, input) +} + +/// Take the seventh power of the MontyField31 field elements in the even index entries. +/// Inputs must lie in [-P, ..., P]. +/// Outputs will also lie in (-P, ..., P) stored in the odd indices. +#[inline] +#[must_use] +pub(crate) fn packed_exp_7(input: __m256i) -> __m256i { + let square = shifted_square::(input); + let cube = monty_mul_signed::(square, input); + let cube_shifted = movehdup_epi32(cube); + let quad = shifted_square::(square); + + monty_mul_signed::(quad, cube_shifted) +} + +/// Apply func to the even and odd indices of the input vector. +/// func should only depend in the 32 bit entries in the even indices. +/// The output of func must lie in (-P, ..., P) and be stored in the odd indices. +/// The even indices of the output of func will not be read. +/// The input should conform to the requirements of `func`. +#[inline] +#[must_use] +pub(crate) unsafe fn apply_func_to_even_odd( + input: __m256i, + func: fn(__m256i) -> __m256i, +) -> __m256i { + let input_evn = input; + let input_odd = movehdup_epi32(input); + + let d_evn = func(input_evn); + let d_odd = func(input_odd); + + let t = blend_evn_odd(d_evn, d_odd); + red_signed_to_canonical::(t) +} + +/// Negate a vector of MontyField31 field elements in canonical form. +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn neg(val: __m256i) -> __m256i { + // We want this to compile to: + // vpsubd t, P, val + // vpsignd res, t, val + // throughput: .67 cyc/vec (12 els/cyc) + // latency: 2 cyc + + // The vpsignd instruction is poorly named, because it doesn't _return_ or _copy_ the sign of + // anything, but _multiplies_ x by the sign of y (treating both as signed integers). In other + // words, + // { x if y >s 0, + // vpsignd(x, y) := { 0 if y = 0, + // { -x mod 2^32 if y s 0. If val = 0, then res = vpsignd(t, 0) = 0, as desired. Otherwise, + // res = vpsignd(t, val) = t passes t through. + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + let t = x86_64::_mm256_sub_epi32(MPAVX2::PACKED_P, val); + x86_64::_mm256_sign_epi32(t, val) + } +} + +/// Subtract vectors of MontyField31 field elements in canonical form. +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +pub(crate) fn sub(lhs: __m256i, rhs: __m256i) -> __m256i { + // We want this to compile to: + // vpsubd t, lhs, rhs + // vpaddd u, t, P + // vpminud res, t, u + // throughput: 1 cyc/vec (8 els/cyc) + // latency: 3 cyc + + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + let t = x86_64::_mm256_sub_epi32(lhs, rhs); + red_signed_to_canonical::(t) + } +} + +impl From> for PackedMontyField31AVX2 { + #[inline] + fn from(value: MontyField31) -> Self { + Self::broadcast(value) + } +} + +impl Default for PackedMontyField31AVX2 { + #[inline] + fn default() -> Self { + MontyField31::::default().into() + } +} + +impl AddAssign for PackedMontyField31AVX2 { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} + +impl MulAssign for PackedMontyField31AVX2 { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} + +impl SubAssign for PackedMontyField31AVX2 { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} + +impl Sum for PackedMontyField31AVX2 { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs + rhs).unwrap_or(Self::ZERO) + } +} + +impl Product for PackedMontyField31AVX2 { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs * rhs).unwrap_or(Self::ONE) + } +} + +impl PrimeCharacteristicRing for PackedMontyField31AVX2 { + type PrimeSubfield = MontyField31; + + const ZERO: Self = Self::broadcast(MontyField31::ZERO); + const ONE: Self = Self::broadcast(MontyField31::ONE); + const TWO: Self = Self::broadcast(MontyField31::TWO); + const NEG_ONE: Self = Self::broadcast(MontyField31::NEG_ONE); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f.into() + } + + #[inline] + fn cube(&self) -> Self { + let val = self.to_vector(); + unsafe { + // Safety: `apply_func_to_even_odd` returns values in canonical form when given values in canonical form. + let res = apply_func_to_even_odd::(val, packed_exp_3::); + Self::from_vector(res) + } + } + + #[inline] + fn xor(&self, rhs: &Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = xor::(lhs, rhs); + unsafe { + // Safety: `xor` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } + + #[inline] + fn andn(&self, rhs: &Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = andn::(lhs, rhs); + unsafe { + // Safety: `andn` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } + + #[inline(always)] + fn exp_const_u64(&self) -> Self { + // We provide specialised code for the powers 3, 5, 7 as these turn up regularly. + // The other powers could be specialised similarly but we ignore this for now. + // These ideas could also be used to speed up the more generic exp_u64. + match POWER { + 0 => Self::ONE, + 1 => *self, + 2 => self.square(), + 3 => self.cube(), + 4 => self.square().square(), + 5 => { + let val = self.to_vector(); + unsafe { + // Safety: `apply_func_to_even_odd` returns values in canonical form when given values in canonical form. + let res = apply_func_to_even_odd::(val, packed_exp_5::); + Self::from_vector(res) + } + } + 6 => self.square().cube(), + 7 => { + let val = self.to_vector(); + unsafe { + // Safety: `apply_func_to_even_odd` returns values in canonical form when given values in canonical form. + let res = apply_func_to_even_odd::(val, packed_exp_7::); + Self::from_vector(res) + } + } + _ => self.exp_u64(POWER), + } + } + + #[inline(always)] + fn dot_product(u: &[Self; N], v: &[Self; N]) -> Self { + general_dot_product::<_, _, _, N>(u, v) + } + + #[inline(always)] + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(MontyField31::::zero_vec(len * WIDTH)) } + } +} + +impl Algebra> for PackedMontyField31AVX2 {} + +impl, const D: u64> InjectiveMonomial + for PackedMontyField31AVX2 +{ +} + +impl, const D: u64> PermutationMonomial + for PackedMontyField31AVX2 +{ + fn injective_exp_root_n(&self) -> Self { + FP::exp_root_d(*self) + } +} + +impl Add> for PackedMontyField31AVX2 { + type Output = Self; + #[inline] + fn add(self, rhs: MontyField31) -> Self { + self + Self::from(rhs) + } +} + +impl Mul> for PackedMontyField31AVX2 { + type Output = Self; + #[inline] + fn mul(self, rhs: MontyField31) -> Self { + self * Self::from(rhs) + } +} + +impl Sub> for PackedMontyField31AVX2 { + type Output = Self; + #[inline] + fn sub(self, rhs: MontyField31) -> Self { + self - Self::from(rhs) + } +} + +impl AddAssign> for PackedMontyField31AVX2 { + #[inline] + fn add_assign(&mut self, rhs: MontyField31) { + *self += Self::from(rhs) + } +} + +impl MulAssign> for PackedMontyField31AVX2 { + #[inline] + fn mul_assign(&mut self, rhs: MontyField31) { + *self *= Self::from(rhs) + } +} + +impl SubAssign> for PackedMontyField31AVX2 { + #[inline] + fn sub_assign(&mut self, rhs: MontyField31) { + *self -= Self::from(rhs) + } +} + +impl Sum> for PackedMontyField31AVX2 { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator>, + { + iter.sum::>().into() + } +} + +impl Product> for PackedMontyField31AVX2 { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator>, + { + iter.product::>().into() + } +} + +impl Div> for PackedMontyField31AVX2 { + type Output = Self; + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: MontyField31) -> Self { + self * rhs.inverse() + } +} + +impl Add> for MontyField31 { + type Output = PackedMontyField31AVX2; + #[inline] + fn add(self, rhs: PackedMontyField31AVX2) -> PackedMontyField31AVX2 { + PackedMontyField31AVX2::::from(self) + rhs + } +} + +impl Mul> for MontyField31 { + type Output = PackedMontyField31AVX2; + #[inline] + fn mul(self, rhs: PackedMontyField31AVX2) -> PackedMontyField31AVX2 { + PackedMontyField31AVX2::::from(self) * rhs + } +} + +impl Sub> for MontyField31 { + type Output = PackedMontyField31AVX2; + #[inline] + fn sub(self, rhs: PackedMontyField31AVX2) -> PackedMontyField31AVX2 { + PackedMontyField31AVX2::::from(self) - rhs + } +} + +impl Distribution> for StandardUniform { + #[inline] + fn sample(&self, rng: &mut R) -> PackedMontyField31AVX2 { + PackedMontyField31AVX2::(rng.random()) + } +} + +#[inline] +#[must_use] +fn interleave1(a: __m256i, b: __m256i) -> (__m256i, __m256i) { + // We want this to compile to: + // vpsllq t, a, 32 + // vpsrlq u, b, 32 + // vpblendd res0, a, u, aah + // vpblendd res1, t, b, aah + // throughput: 1.33 cyc/2 vec (12 els/cyc) + // latency: (1 -> 1) 1 cyc + // (1 -> 2) 2 cyc + // (2 -> 1) 2 cyc + // (2 -> 2) 1 cyc + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + + // We currently have: + // a = [ a0 a1 a2 a3 a4 a5 a6 a7 ], + // b = [ b0 b1 b2 b3 b4 b5 b6 b7 ]. + // First form + // t = [ a1 0 a3 0 a5 0 a7 0 ]. + // u = [ 0 b0 0 b2 0 b4 0 b6 ]. + let t = x86_64::_mm256_srli_epi64::<32>(a); + let u = x86_64::_mm256_slli_epi64::<32>(b); + + // Then + // res0 = [ a0 b0 a2 b2 a4 b4 a6 b6 ], + // res1 = [ a1 b1 a3 b3 a5 b5 a7 b7 ]. + ( + x86_64::_mm256_blend_epi32::<0b10101010>(a, u), + x86_64::_mm256_blend_epi32::<0b10101010>(t, b), + ) + } +} + +#[inline] +#[must_use] +fn interleave2(a: __m256i, b: __m256i) -> (__m256i, __m256i) { + // We want this to compile to: + // vpalignr t, b, a, 8 + // vpblendd res0, a, t, cch + // vpblendd res1, t, b, cch + // throughput: 1 cyc/2 vec (16 els/cyc) + // latency: 2 cyc + + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + + // We currently have: + // a = [ a0 a1 a2 a3 a4 a5 a6 a7 ], + // b = [ b0 b1 b2 b3 b4 b5 b6 b7 ]. + // First form + // t = [ a2 a3 b0 b1 a6 a7 b4 b5 ]. + let t = x86_64::_mm256_alignr_epi8::<8>(b, a); + + // Then + // res0 = [ a0 a1 b0 b1 a4 a5 b4 b5 ], + // res1 = [ a2 a3 b2 b3 a6 a7 b6 b7 ]. + ( + x86_64::_mm256_blend_epi32::<0b11001100>(a, t), + x86_64::_mm256_blend_epi32::<0b11001100>(t, b), + ) + } +} + +#[inline] +#[must_use] +fn interleave4(a: __m256i, b: __m256i) -> (__m256i, __m256i) { + // We want this to compile to: + // vperm2i128 t, a, b, 21h + // vpblendd res0, a, t, f0h + // vpblendd res1, t, b, f0h + // throughput: 1 cyc/2 vec (16 els/cyc) + // latency: 4 cyc + + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + + // We currently have: + // a = [ a0 a1 a2 a3 a4 a5 a6 a7 ], + // b = [ b0 b1 b2 b3 b4 b5 b6 b7 ]. + // First form + // t = [ a4 a5 a6 a7 b0 b1 b2 b3 ]. + let t = x86_64::_mm256_permute2x128_si256::<0x21>(a, b); + + // Then + // res0 = [ a0 a1 a2 a3 b0 b1 b2 b3 ], + // res1 = [ a4 a5 a6 a7 b4 b5 b6 b7 ]. + ( + x86_64::_mm256_blend_epi32::<0b11110000>(a, t), + x86_64::_mm256_blend_epi32::<0b11110000>(t, b), + ) + } +} + +unsafe impl PackedValue for PackedMontyField31AVX2 { + type Value = MontyField31; + + const WIDTH: usize = WIDTH; + + #[inline] + fn from_slice(slice: &[MontyField31]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[MontyField31; WIDTH]` can be transmuted to `PackedMontyField31AVX2` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast is + // safe too. + &*slice.as_ptr().cast() + } + } + #[inline] + fn from_slice_mut(slice: &mut [MontyField31]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[MontyField31; WIDTH]` can be transmuted to `PackedMontyField31AVX2` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast is + // safe too. + &mut *slice.as_mut_ptr().cast() + } + } + + /// Similar to `core:array::from_fn`. + #[inline] + fn from_fn MontyField31>(f: F) -> Self { + let vals_arr: [_; WIDTH] = core::array::from_fn(f); + Self(vals_arr) + } + + #[inline] + fn as_slice(&self) -> &[MontyField31] { + &self.0[..] + } + #[inline] + fn as_slice_mut(&mut self) -> &mut [MontyField31] { + &mut self.0[..] + } +} + +unsafe impl PackedField for PackedMontyField31AVX2 { + type Scalar = MontyField31; + + #[inline] + fn packed_linear_combination(coeffs: &[Self::Scalar], vecs: &[Self]) -> Self { + general_dot_product::<_, _, _, N>(coeffs, vecs) + } +} + +unsafe impl PackedFieldPow2 for PackedMontyField31AVX2 { + #[inline] + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { + let (v0, v1) = (self.to_vector(), other.to_vector()); + let (res0, res1) = match block_len { + 1 => interleave1(v0, v1), + 2 => interleave2(v0, v1), + 4 => interleave4(v0, v1), + 8 => (v0, v1), + _ => panic!("unsupported block_len"), + }; + unsafe { + // Safety: all values are in canonical form (we haven't changed them). + (Self::from_vector(res0), Self::from_vector(res1)) + } + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/poseidon2.rs b/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/poseidon2.rs new file mode 100644 index 000000000..01938874d --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/poseidon2.rs @@ -0,0 +1,478 @@ +//! Vectorized AVX2 implementation of Poseidon2 for MontyField31 + +use alloc::vec::Vec; +use core::arch::x86_64::{self, __m256i}; +use core::marker::PhantomData; +use core::mem::transmute; + +use p3_field::PrimeCharacteristicRing; +use p3_poseidon2::{ + ExternalLayer, ExternalLayerConstants, ExternalLayerConstructor, InternalLayer, + InternalLayerConstructor, MDSMat4, external_initial_permute_state, + external_terminal_permute_state, +}; + +use crate::{ + FieldParameters, InternalLayerBaseParameters, MontyField31, MontyParameters, + PackedMontyField31AVX2, PackedMontyParameters, RelativelyPrimePower, add, + apply_func_to_even_odd, halve_avx2, packed_exp_3, packed_exp_5, packed_exp_7, signed_add_avx2, + sub, +}; + +// In the internal layers, it is valuable to treat the first entry of the state differently +// as it is the only entry to which we apply s-box. +// It seems to help the compiler if we introduce a different data structure for these layers. +// Note that we use this structure instead of a tuple so we can force the memory layout to align for transmutes. +#[derive(Clone, Copy)] +#[repr(C)] // This is needed to make `transmute`s safe. +pub struct InternalLayer16 { + s0: PackedMontyField31AVX2, + s_hi: [__m256i; 15], +} + +impl InternalLayer16 { + #[inline] + #[must_use] + /// Convert from `InternalLayer16` to `[PackedMontyField31AVX2; 16]` + /// + /// SAFETY: The caller must ensure that each element of `s_hi` represents a valid `MontyField31`. + /// In particular, each element of each vector must be in `[0, P)` (canonical form). + unsafe fn to_packed_field_array(self) -> [PackedMontyField31AVX2; 16] { + unsafe { + // Safety: It is up to the user to ensure that elements of `s_hi` represent valid + // `MontyField31` values. We must only reason about memory representations. + // As described in packing.rs, PackedMontyField31AVX2 can be transmuted to and from `__m256i`. + + // `InternalLayer16` is `repr(C)` so its memory layout looks like: + // `[PackedMontyField31AVX2, __m256i, ..., __m256i]` + // Thus as `__m256i` can be can be transmuted to `PackedMontyField31AVX2`, + // `InternalLayer16` can be transmuted to `[PackedMontyField31AVX2; 16]`. + transmute(self) + } + } + + #[inline] + #[must_use] + /// Convert from `[PackedMontyField31AVX2; 16]` to `InternalLayer16` + fn from_packed_field_array(vector: [PackedMontyField31AVX2; 16]) -> Self { + unsafe { + // Safety: As described in packing.rs, PackedMontyField31AVX2 can be transmuted to and from `__m256i`. + + // `InternalLayer16` is `repr(C)` so its memory layout looks like: + // `[PackedMontyField31AVX2, __m256i, ..., __m256i]` + // Thus as `PackedMontyField31AVX2` can be can be transmuted to `__m256i`, + // `[PackedMontyField31AVX2; 16]` can be transmuted to `InternalLayer16`. + transmute(vector) + } + } +} + +#[derive(Clone, Copy)] +#[repr(C)] // This is needed to make `transmute`s safe. +pub struct InternalLayer24 { + s0: PackedMontyField31AVX2, + s_hi: [__m256i; 23], +} + +impl InternalLayer24 { + #[inline] + #[must_use] + /// Convert from `InternalLayer24` to `[PackedMontyField31AVX2; 24]` + /// + /// SAFETY: The caller must ensure that each element of `s_hi` represents a valid `MontyField31`. + /// In particular, each element of each vector must be in `[0, P)` (canonical form). + unsafe fn to_packed_field_array(self) -> [PackedMontyField31AVX2; 24] { + unsafe { + // Safety: As described in packing.rs, PackedMontyField31AVX2 can be transmuted to and from `__m256i`. + + // `InternalLayer24` is `repr(C)` so its memory layout looks like: + // `[PackedMontyField31AVX2, __m256i, ..., __m256i]` + // Thus as `__m256i` can be can be transmuted to `PackedMontyField31AVX2`, + // `InternalLayer24` can be transmuted to `[PackedMontyField31AVX2; 24]`. + transmute(self) + } + } + + #[inline] + #[must_use] + /// Convert from `[PackedMontyField31AVX2; 24]` to `InternalLayer24` + fn from_packed_field_array(vector: [PackedMontyField31AVX2; 24]) -> Self { + unsafe { + // Safety: As described in packing.rs, PackedMontyField31AVX2 can be transmuted to and from `__m256i`. + + // `InternalLayer24` is `repr(C)` so its memory layout looks like: + // `[PackedMontyField31AVX2, __m256i, ..., __m256i]` + // Thus as `PackedMontyField31AVX2` can be can be transmuted to `__m256i`, + // `[PackedMontyField31AVX2; 24]` can be transmuted to `InternalLayer24`. + transmute(vector) + } + } +} + +/// The internal layers of the Poseidon2 permutation for Monty31 fields. +/// +/// The packed constants are stored in negative form as this allows some optimizations. +/// This means given a constant `x`, we treat it as an `i32` and +/// pack 8 copies of `x - P` into the corresponding `__m256i` packed constant. +#[derive(Debug, Clone)] +pub struct Poseidon2InternalLayerMonty31< + PMP: PackedMontyParameters, + const WIDTH: usize, + ILP: InternalLayerParametersAVX2, +> { + pub(crate) internal_constants: Vec>, + packed_internal_constants: Vec<__m256i>, + _phantom: PhantomData, +} + +impl> + InternalLayerConstructor> for Poseidon2InternalLayerMonty31 +{ + /// Construct an instance of Poseidon2InternalLayerMersenne31AVX2 from a vector containing + /// the constants for each round. Internally, the constants are transformed into the + /// {-P, ..., 0} representation instead of the standard {0, ..., P} one. + fn new_from_constants(internal_constants: Vec>) -> Self { + let packed_internal_constants = internal_constants + .iter() + .map(|constant| convert_to_vec_neg_form::(constant.value as i32)) + .collect(); + Self { + internal_constants, + packed_internal_constants, + _phantom: PhantomData, + } + } +} + +/// The external layers of the Poseidon2 permutation for Monty31 fields. +/// +/// The packed constants are stored in negative form as this allows some optimizations. +/// This means given a constant `x`, we treat it as an `i32` and +/// pack 8 copies of `x - P` into the corresponding `__m256i` packed constant. +#[derive(Debug, Clone)] +pub struct Poseidon2ExternalLayerMonty31 { + pub(crate) external_constants: ExternalLayerConstants, WIDTH>, + packed_initial_external_constants: Vec<[__m256i; WIDTH]>, + packed_terminal_external_constants: Vec<[__m256i; WIDTH]>, +} + +impl ExternalLayerConstructor, WIDTH> + for Poseidon2ExternalLayerMonty31 +{ + /// Construct an instance of Poseidon2ExternalLayerMersenne31AVX2 from an array of + /// vectors containing the constants for each round. Internally, the constants + /// are transformed into the {-P, ..., 0} representation instead of the standard {0, ..., P} one. + fn new_from_constants( + external_constants: ExternalLayerConstants, WIDTH>, + ) -> Self { + let packed_initial_external_constants = external_constants + .get_initial_constants() + .iter() + .map(|array| array.map(|constant| convert_to_vec_neg_form::(constant.value as i32))) + .collect(); + let packed_terminal_external_constants = external_constants + .get_terminal_constants() + .iter() + .map(|array| array.map(|constant| convert_to_vec_neg_form::(constant.value as i32))) + .collect(); + Self { + external_constants, + packed_initial_external_constants, + packed_terminal_external_constants, + } + } +} + +/// Use hard coded methods to compute `x -> x^D` for the even index entries and small `D`. +/// Inputs should be signed 32-bit integers in `[-P, ..., P]`. +/// Outputs will also be signed integers in `(-P, ..., P)` stored in the odd indices. +/// +/// # Panics +/// This function will panic if `D` is not `3, 5` or `7`. +#[inline(always)] +#[must_use] +fn exp_small(val: __m256i) -> __m256i { + match D { + 3 => packed_exp_3::(val), + 5 => packed_exp_5::(val), + 7 => packed_exp_7::(val), + _ => panic!("No exp function for given D"), + } +} + +/// Compute val -> (val + rc)^D. Each entry of val should be represented in canonical form. +/// Each entry of rc should be represented by an element in [-P, 0]. +/// Each entry of the output will be represented by an element in canonical form. +/// If the inputs do not conform to this representation, the result is undefined. +#[inline(always)] +fn add_rc_and_sbox( + val: &mut PackedMontyField31AVX2, + rc: __m256i, +) { + unsafe { + // As our exponential functions simply assume that + // the input lies in [-P, P] we do not need to perform a reduction provided + // rc is represented by an element in [-P, 0] + let vec_val = val.to_vector(); + let val_plus_rc = x86_64::_mm256_add_epi32(vec_val, rc); + let output = apply_func_to_even_odd::(val_plus_rc, exp_small::); + + *val = PackedMontyField31AVX2::::from_vector(output) + } +} + +/// A trait containing the specific information needed to +/// implement the Poseidon2 Permutation for Monty31 Fields. +pub trait InternalLayerParametersAVX2: + Clone + Sync +{ + type ArrayLike: AsMut<[__m256i]>; + + // diagonal_mul and add_sum morally should be one function but are split because diagonal_mul can happen simultaneously to + // the sbox being applied to the first element of the state which is advantageous as this s-box has very high latency. + // However these functions should only ever be used together and we only make safety guarantees about the output + // of the combined function add_sum(diagonal_mul(state), sum) which will output field elements + // in canonical form provided inputs are in canonical form. + + // For these reason we mark both functions as unsafe. + + // All 4 implementation of this trait (Field = BabyBear/KoalaBear, WIDTH = 16/24) have a similarly structured + // diagonal matrix. The first 9 elements of this matrix are always: [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4] and the remainder + // are all positive or negative inverse powers of two. This common structure lets us write some default implementations. + + /// # Safety + /// + /// This function assumes its output is piped directly into `add_sum`. + /// + /// It might not output field elements in canonical form and indeed may even + /// output incorrect values in places where it is efficient to correct for + /// the computation in `add_sum`. For example it might output `3*x` instead of `-3*x` + /// and have `add_sum` compute `sum - x` instead of `x + sum`. + #[inline(always)] + unsafe fn diagonal_mul(input: &mut Self::ArrayLike) { + unsafe { + Self::diagonal_mul_first_eight(input); // This only affects the first 8 elements. + + Self::diagonal_mul_remainder(input); // This leaves the first 8 elements unchanged. + } + } + + /// # Safety + /// + /// Multiply the first 8 elements of input by the vector `[1, 2, 1/2, 3, 4, 1/2, 3, 4]`. + /// + /// In all implementations of this trait, the first 9 elements of the diagonal matrix are + /// `[-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4]`. The -2 is handled separately and this function handles + /// the remainder. Note that for the last three elements we multiply by `1/2, 3, 4` and not + /// `-1/2, -3, -4`. Hence the value in this location will be the negative of what is desired. + /// This will be handled by `add_sum` and so it is important these elements are not touched + /// before input is passed into `add_sum`. + #[inline(always)] + unsafe fn diagonal_mul_first_eight(input: &mut Self::ArrayLike) { + let input = input.as_mut(); + // The first 5 elements should be multiplied by: 1, 2, 1/2, 3, 4 + + // input[0] is being multiplied by 1 so we ignore it. + + input[1] = add::(input[1], input[1]); + input[2] = halve_avx2::(input[2]); + + let acc3 = add::(input[3], input[3]); + input[3] = add::(acc3, input[3]); + + let acc4 = add::(input[4], input[4]); + input[4] = add::(acc4, acc4); + + // For the final 3 elements we multiply by 1/2, 3, 4. + // This gives the negative of the correct answer which + // will be handled by add_sum(). + + input[5] = halve_avx2::(input[5]); + + let acc6 = add::(input[6], input[6]); + input[6] = add::(acc6, input[6]); + + let acc7 = add::(input[7], input[7]); + input[7] = add::(acc7, acc7); + } + + /// # Safety + /// + /// This function must not touch the first 8 elements of input. + /// It may output values which might not be in canonical form or + /// will be the negative of the expected value. This will be + /// handled by `add_sum` so it is important these elements are + /// not touched before input is passed into `add_sum`. + unsafe fn diagonal_mul_remainder(input: &mut Self::ArrayLike); + + /// # Safety + /// + /// Sum must be in canonical form and input must be exactly the output of `diagonal_mul`. + /// If either of these does not hold, the result is undefined. + /// + /// Morally this function is computing `x -> x + sum` however there are some places where + /// the output of `diagonal_mul` is the negative of the expected value or not canonical. + /// It is the job of add_sum to correct for these irregularities. Where the output is negative + /// we compute `x -> sum - x` instead and when not in canonical form we use `signed_add_avx2` + /// where acts as add where one input is allowed to lie in `(-P, P)`. + #[inline(always)] + unsafe fn add_sum(input: &mut Self::ArrayLike, sum: __m256i) { + unsafe { + // Diagonal mul multiplied these by 1, 2, 1/2, 3, 4 so we simply need to add the sum. + input.as_mut()[..5] + .iter_mut() + .for_each(|x| *x = add::(sum, *x)); + + // Diagonal mul multiplied these by 1/2, 3, 4 instead of -1/2, -3, -4 so we need to subtract instead of adding. + input.as_mut()[5..8] + .iter_mut() + .for_each(|x| *x = sub::(sum, *x)); + + // Diagonal mul output a signed value in (-P, P) so we need to do a signed add. + // Note that signed add's parameters are not interchangeable. The first parameter must be positive. + input.as_mut()[8..] + .iter_mut() + .for_each(|x| *x = signed_add_avx2::(sum, *x)); + } + } +} + +/// Convert elements from canonical form [0, P) to a negative form in [-P, ..., 0) and copy into a vector. +#[inline(always)] +fn convert_to_vec_neg_form(input: i32) -> __m256i { + let input_sub_p = input - (MP::PRIME as i32); + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + x86_64::_mm256_set1_epi32(input_sub_p) + } +} + +impl InternalLayer, 16, D> + for Poseidon2InternalLayerMonty31 +where + FP: FieldParameters, + ILP: InternalLayerParametersAVX2 + + InternalLayerBaseParameters, +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [PackedMontyField31AVX2; 16]) { + unsafe { + // Safety: This return values in canonical form when given values in canonical form. + + /* + Fix a vector v and let Diag(v) denote the diagonal matrix with diagonal given by v. + Additionally, let 1 denote the matrix with all elements equal to 1. + The internal layer consists of an sbox operation then a matrix multiplication by 1 + Diag(v). + Explicitly the internal layer consists of the following 2 operations: + + s0 -> (s0 + rc)^d + s -> (1 + Diag(v))s + + Note that this matrix multiplication is implemented as: + sum = sum_i s_i + s_i -> sum + s_iv_i. + */ + + let mut internal_state = InternalLayer16::from_packed_field_array(*state); + + self.packed_internal_constants.iter().for_each(|&rc| { + add_rc_and_sbox::(&mut internal_state.s0, rc); // s0 -> (s0 + rc)^D + let sum_tail = PackedMontyField31AVX2::::sum_array::<15>(&transmute::< + [__m256i; 15], + [PackedMontyField31AVX2; 15], + >( + internal_state.s_hi, + )); // Get the sum of all elements other than s0. + ILP::diagonal_mul(&mut internal_state.s_hi); // si -> vi * si for all i > 0. + let sum = sum_tail + internal_state.s0; // Get the full sum. + internal_state.s0 = sum_tail - internal_state.s0; // s0 -> sum - 2*s0 = sum_tail - s0. + ILP::add_sum( + &mut internal_state.s_hi, + transmute::, __m256i>(sum), + ); // si -> si + sum for all i > 0. + }); + + // This transformation is safe as the above function returns elements + // in canonical form when given elements in canonical form. + *state = InternalLayer16::to_packed_field_array(internal_state); + } + } +} + +impl InternalLayer, 24, D> + for Poseidon2InternalLayerMonty31 +where + FP: FieldParameters + RelativelyPrimePower, + ILP: InternalLayerParametersAVX2 + + InternalLayerBaseParameters, +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [PackedMontyField31AVX2; 24]) { + unsafe { + // Safety: This return values in canonical form when given values in canonical form. + + /* + Fix a vector v and let Diag(v) denote the diagonal matrix with diagonal given by v. + Additionally, let 1 denote the matrix with all elements equal to 1. + The internal layer consists of an sbox operation then a matrix multiplication by 1 + Diag(v). + Explicitly the internal layer consists of the following 2 operations: + + s0 -> (s0 + rc)^d + s -> (1 + Diag(v))s + + Note that this matrix multiplication is implemented as: + sum = sum_i s_i + s_i -> sum + s_iv_i. + */ + + let mut internal_state = InternalLayer24::from_packed_field_array(*state); + + self.packed_internal_constants.iter().for_each(|&rc| { + add_rc_and_sbox::(&mut internal_state.s0, rc); // s0 -> (s0 + rc)^D + let sum_tail = PackedMontyField31AVX2::::sum_array::<23>(&transmute::< + [__m256i; 23], + [PackedMontyField31AVX2; 23], + >( + internal_state.s_hi, + )); // Get the sum of all elements other than s0. + ILP::diagonal_mul(&mut internal_state.s_hi); // si -> vi * si for all i > 0. + let sum = sum_tail + internal_state.s0; // Get the full sum. + internal_state.s0 = sum_tail - internal_state.s0; // s0 -> sum - 2*s0 = sum_tail - s0. + ILP::add_sum( + &mut internal_state.s_hi, + transmute::, __m256i>(sum), + ); // si -> si + sum for all i > 0. + }); + + // This transformation is safe as the above function returns elements + // in canonical form when given elements in canonical form. + *state = InternalLayer24::to_packed_field_array(internal_state); + } + } +} + +impl ExternalLayer, WIDTH, D> + for Poseidon2ExternalLayerMonty31 +where + FP: FieldParameters + RelativelyPrimePower, +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [PackedMontyField31AVX2; WIDTH]) { + external_initial_permute_state( + state, + &self.packed_initial_external_constants, + add_rc_and_sbox::, + &MDSMat4, + ); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [PackedMontyField31AVX2; WIDTH]) { + external_terminal_permute_state( + state, + &self.packed_terminal_external_constants, + add_rc_and_sbox::, + &MDSMat4, + ); + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/utils.rs b/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/utils.rs new file mode 100644 index 000000000..bec8cad6f --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/x86_64_avx2/utils.rs @@ -0,0 +1,346 @@ +use core::arch::x86_64::{self, __m256i}; +use core::mem::transmute; + +use crate::{MontyParameters, MontyParametersAVX2, TwoAdicData}; + +// Godbolt file showing that these all compile to the expected instructions. (Potentially plus a few memory ops): +// https://godbolt.org/z/9P71nYrqh + +/// Halve a vector of Monty31 field elements in canonical form. +/// If the inputs are not in canonical form, the result is undefined. +#[inline(always)] +pub(crate) fn halve_avx2(input: __m256i) -> __m256i { + /* + We want this to compile to: + vpand least_bit, val, ONE + vpsrld t, val, 1 + vpsignd maybe_half, HALF, least_bit + vpaddd res, t, maybe_half + throughput: 1.33 cyc/vec + latency: 3 cyc + + Given an element val in [0, P), we want to compute val/2 mod P. + If val is even: val/2 mod P = val/2 = val >> 1. + If val is odd: val/2 mod P = (val + P)/2 = (val >> 1) + (P + 1)/2 + */ + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + const ONE: __m256i = unsafe { transmute([1u32; 8]) }; + let half = x86_64::_mm256_set1_epi32((MP::PRIME as i32 + 1) / 2); // Compiler realises this is constant. + + let least_bit = x86_64::_mm256_and_si256(input, ONE); // Determine the parity of val. + let t = x86_64::_mm256_srli_epi32::<1>(input); + // This does nothing when least_bit = 1 and sets the corresponding entry to 0 when least_bit = 0 + let maybe_half = x86_64::_mm256_sign_epi32(half, least_bit); + x86_64::_mm256_add_epi32(t, maybe_half) + } +} + +/// Add two vectors of Monty31 field elements with lhs in canonical form and rhs in (-P, P). +/// +/// # Safety +/// +/// This function is not symmetric in the inputs. The caller must ensure that inputs +/// conform to the expected representation. Each element of lhs must lie in [0, P) and +/// each element of rhs in (-P, P). +#[inline(always)] +pub(crate) unsafe fn signed_add_avx2( + lhs: __m256i, + rhs: __m256i, +) -> __m256i { + /* + We want this to compile to: + vpsignd pos_neg_P, P, rhs + vpaddd sum, lhs, rhs + vpsubd sum_corr, sum, pos_neg_P + vpminud res, sum, sum_corr + throughput: 1.33 cyc/vec + latency: 3 cyc + + While this is more expensive than an add, it is cheaper than reducing the rhs to a canonical value and then adding. + + We give a short proof that the output is correct: + + Let t = lhs + rhs mod 2^32, we want to return t mod P while correcting for any possible wraparound. + We make use of the fact wrapping addition acts identically on signed and unsigned inputs. + + If rhs is positive, lhs + rhs < 2P < 2^32 and so we interpret t as a unsigned 32 bit integer. + In this case, t mod P = min_{u32}(t, t - P) where min_{u32} takes the min treating both inputs as unsigned 32 bit integers. + This works as if t >= P then t - P < t and if t < P then, due to wraparound, t - P outputs t - P + 2^32 > t. + If rhs is negative, -2^31 < -P < lhs + rhs < P < 2^31 so we interpret t as a signed 32 bit integer. + In this case t mod P = min_{u32}(t, t + P) + This works as if t > 0 then t < t + P and if t < 0 then due to wraparound when we interpret t as an unsigned integer it becomes + 2^32 + t > t + P. + if rhs = 0 then we can just return t = lhs as it is already in the desired range. + */ + unsafe { + // If rhs > 0 set the value to P, if rhs < 0 set it to -P and if rhs = 0 set it to 0. + let pos_neg_p = x86_64::_mm256_sign_epi32(MPAVX2::PACKED_P, rhs); + + // Compute t = lhs + rhs + let sum = x86_64::_mm256_add_epi32(lhs, rhs); + + // sum_corr = (t - P) if rhs > 0, t + P if rhs < 0 and t if rhs = 0 as desired. + let sum_corr = x86_64::_mm256_sub_epi32(sum, pos_neg_p); + + x86_64::_mm256_min_epu32(sum, sum_corr) + } +} + +/* + Write our prime P as r * 2^j + 1 for odd r. + The following functions implement x -> +/- 2^{-N} x for varying N and output a value in (-P, P). + There is one approach which works provided N < 15 and r < 2^15. + Similarly, there is another approach which works when N = j and when r = 2^i - 1. + + Both approaches rely on the same basic observation about multiplication by +/- 2^{-N} which we present here. + We will focus on the -2^{-N} case but note that the case of 2^{-N} is essentially identical. + The strategy for these products is to observe that -2^{-N} = r2^{j - N} mod P. + Hence given a field element x write it as x = x_lo + 2^N x_hi where x_lo < 2^N. + Then -2^{-N} x = -x_hi + r2^{j - N} x_lo. + Clearly x_hi < P and, as x_lo < 2^N, r2^{j - N} x_lo < r2^j < P so + -P < r2^{j - N} x_lo - x_hi < P + + It remains to understand how to efficiently compute r2^{j - N} x_lo. This splits into several cases: + + When r < 2^16, N < 15, r2^{j - N} x_lo can be computed efficiently using _mm256_madd_epi16. + This avoids having to split the input in two and doing multiple multiplications and/or monty reductions. + + There is a further improvement possible when if r < 2^7 and N = 8 using _mm256_maddubs_epi16. + This lets us avoid a mask and an and so we implement a specialised version for this. + + When n = j and r = 2^i - 1, rx_lo can also be computed efficiently using a shift and subtraction. +*/ + +/// Multiply a vector of Monty31 field elements in canonical form by 2**{-N}. +/// +/// # Safety +/// +/// The prime P must be of the form P = r * 2^j + 1 with r odd and r < 2^15. +/// N must be between 0 and 15. +/// Input must be given in canonical form. +/// Output is not in canonical form, outputs are only guaranteed to lie in (-P, P). +#[inline(always)] +pub unsafe fn mul_2exp_neg_n_avx2( + input: __m256i, +) -> __m256i { + /* + We want this to compile to: + vpsrld hi, val, N + vpand lo, val, 2^{N} - 1 + vpmaddwd lo_x_r, lo, [r; 8] + vpslld lo_shft, lo_x_r, j - N + vpsubd res, hi, lo_shft + throughput: 1.67 + latency: 8 + */ + unsafe { + assert_eq!(N + N_PRIME, TAD::TWO_ADICITY as i32); // Compiler removes this provided it is satisfied. + + let odd_factor = x86_64::_mm256_set1_epi32(TAD::ODD_FACTOR); // This is [r; 8]. Compiler realises this is a constant. + let mask = x86_64::_mm256_set1_epi32((1_i32 << N) - 1_i32); // Compiler realises this is a constant. + + let hi = x86_64::_mm256_srli_epi32::(input); + let val_lo = x86_64::_mm256_and_si256(input, mask); + + // Whilst it generically does something else, provided + // each entry of val_lo, odd_factor are < 2^15, _mm256_madd_epi16 + // performs an element wise multiplication. + // Thus lo_x_r contains r*x_lo. + let lo_x_r = x86_64::_mm256_madd_epi16(val_lo, odd_factor); + let lo = x86_64::_mm256_slli_epi32::(lo_x_r); + x86_64::_mm256_sub_epi32(hi, lo) + } +} + +/// Multiply a vector of Monty31 field elements in canonical form by -2**{-N}. +/// # Safety +/// +/// The prime P must be of the form P = r * 2^j + 1 with r odd and r < 2^15. +/// N must be between 0 and 15. +/// Input must be given in canonical form. +/// Output is not in canonical form, outputs are only guaranteed to lie in (-P, P). +#[inline(always)] +pub unsafe fn mul_neg_2exp_neg_n_avx2( + input: __m256i, +) -> __m256i { + /* + We want this to compile to: + vpsrld hi, val, N + vpand lo, val, 2^N - 1 + vpmaddwd lo_x_r, lo, [r; 8] + vpslld lo_shft, lo_x_r, j - N + vpsubd res, lo_shft, hi + throughput: 1.67 + latency: 8 + */ + unsafe { + assert_eq!(N + N_PRIME, TAD::TWO_ADICITY as i32); // Compiler removes this provided it is satisfied. + + let odd_factor = x86_64::_mm256_set1_epi32(TAD::ODD_FACTOR); // This is [r; 8]. Compiler realises this is a constant. + let mask = x86_64::_mm256_set1_epi32((1_i32 << N) - 1_i32); // Compiler realises this is a constant. + + let hi = x86_64::_mm256_srli_epi32::(input); + let lo = x86_64::_mm256_and_si256(input, mask); + + // Whilst it generically does something else, provided + // each entry of lo, odd_factor are < 2^15, _mm256_madd_epi16 + // performs an element wise multiplication. + // Thus lo_x_r contains lo * r. + let lo_x_r = x86_64::_mm256_madd_epi16(lo, odd_factor); + let lo_shft = x86_64::_mm256_slli_epi32::(lo_x_r); + x86_64::_mm256_sub_epi32(lo_shft, hi) + } +} + +/// Multiply a vector of Monty31 field elements in canonical form by 2**{-8}. +/// # Safety +/// +/// The prime P must be of the form P = r * 2^j + 1 with r odd and r < 2^7. +/// Input must be given in canonical form. +/// Output is not in canonical form, outputs are only guaranteed to lie in (-P, P). +#[inline(always)] +pub unsafe fn mul_2exp_neg_8_avx2(input: __m256i) -> __m256i { + /* + We want this to compile to: + vpsrld hi, val, 8 + vpmaddubsw lo_x_r, val, [r; 8] + vpslldq lo_shft, lo_x_r, j - 8 + vpsubd t, hi, lo_shft + throughput: 1.33 + latency: 7 + */ + unsafe { + assert_eq!(8 + N_PRIME, TAD::TWO_ADICITY as i32); // Compiler removes this provided it is satisfied. + + let odd_factor = x86_64::_mm256_set1_epi32(TAD::ODD_FACTOR); // This is [r; 8]. Compiler realises this is a constant. + + // Get the hi 16 bits shifted down. + let hi = x86_64::_mm256_srli_epi32::<8>(input); + + // Whilst it generically does something else, provided + // each entry of odd_factor is < 2^7, _mm256_maddubs_epi16 + // performs an element wise multiplication of odd_factor with + // the bottom 8 bits of input interpreted as an unsigned integer + // Thus lo_x_r contains lo * r. + let lo_x_r = x86_64::_mm256_maddubs_epi16(input, odd_factor); + + let lo_shft = x86_64::_mm256_slli_epi32::(lo_x_r); + x86_64::_mm256_sub_epi32(hi, lo_shft) + } +} + +/// Multiply a vector of Monty31 field elements in canonical form by -2**{-8}. +/// # Safety +/// +/// The prime P must be of the form P = r * 2^j + 1 with r odd and r < 2^7. +/// Input must be given in canonical form. +/// Output is not in canonical form, outputs are only guaranteed to lie in (-P, P). +#[inline(always)] +pub unsafe fn mul_neg_2exp_neg_8_avx2( + input: __m256i, +) -> __m256i { + /* + We want this to compile to: + vpsrld hi, val, 8 + vpmaddubsw lo_x_r, val, [r; 8] + vpslldq lo_shft, lo_x_r, j - 8 + vpsubd t, lo_shft, hi + throughput: 1.33 + latency: 7 + */ + unsafe { + assert_eq!(8 + N_PRIME, TAD::TWO_ADICITY as i32); // Compiler removes this provided it is satisfied. + + let odd_factor = x86_64::_mm256_set1_epi32(TAD::ODD_FACTOR); // This is [r; 8]. Compiler realises this is a constant. + + // Get the hi 16 bits shifted down. + let hi = x86_64::_mm256_srli_epi32::<8>(input); + + // Whilst it generically does something else, provided + // each entry of odd_factor is < 2^7, _mm256_maddubs_epi16 + // performs an element wise multiplication of odd_factor with + // the bottom 8 bits of input interpreted as an unsigned integer + // Thus lo_x_r contains lo * r. + let lo_x_r = x86_64::_mm256_maddubs_epi16(input, odd_factor); + + let lo_shft = x86_64::_mm256_slli_epi32::(lo_x_r); + x86_64::_mm256_sub_epi32(lo_shft, hi) + } +} + +/// Multiply a vector of Monty31 field elements in canonical form by 2**{-N} where P = 2^31 - 2^N + 1. +/// # Safety +/// +/// The prime P must have the form P = 2^31 - 2^N + 1. +/// Input must be given in canonical form. +/// Output is not in canonical form, outputs are only guaranteed to lie in (-P, P). +#[inline(always)] +pub unsafe fn mul_2exp_neg_two_adicity_avx2( + input: __m256i, +) -> __m256i { + /* + We want this to compile to: + vpsrld hi, val, N + vpand lo, val, 2^{N} - 1 + vpslld lo_shft, lo, 31 - N + vpaddd lo_plus_hi, lo, hi + vpsubd res lo_plus_hi, lo_shft, + throughput: 1.67 + latency: 3 + */ + unsafe { + assert_eq!(N, (TAD::TWO_ADICITY as i32)); // Compiler removes this provided it is satisfied. + assert_eq!(N + N_PRIME, 31); // Compiler removes this provided it is satisfied. + + let mask = x86_64::_mm256_set1_epi32((1_i32 << N) - 1_i32); // Compiler realises this is a constant. + let hi = x86_64::_mm256_srli_epi32::(input); + + // Provided overflow does not occur, (2^{31 - N} - 1)*x = (x << {31 - N}) - 1. + // lo < 2^N => (lo << {31 - N}) < 2^31 and (lo << {31 - N}) - lo < P. + let lo = x86_64::_mm256_and_si256(input, mask); + let lo_shft = x86_64::_mm256_slli_epi32::(lo); + let lo_plus_hi = x86_64::_mm256_add_epi32(lo, hi); + x86_64::_mm256_sub_epi32(lo_plus_hi, lo_shft) + } +} + +/// Multiply a vector of Monty31 field elements in canonical form by -2**{-N} where P = 2^31 - 2^N + 1. +/// # Safety +/// +/// The prime P must have the form P = 2^31 - 2^N + 1. +/// Input must be given in canonical form. +/// Output is not in canonical form, outputs are only guaranteed to lie in (-P, P). +#[inline(always)] +pub unsafe fn mul_neg_2exp_neg_two_adicity_avx2< + TAD: TwoAdicData, + const N: i32, + const N_PRIME: i32, +>( + input: __m256i, +) -> __m256i { + /* + We want this to compile to: + vpsrld hi, val, N + vpand lo, val, 2^{N} - 1 + vpslld lo_shft, lo, 31 - N + vpaddd lo_plus_hi, lo, hi + vpsubd res lo_shft, lo_plus_hi + throughput: 1.67 + latency: 3 + */ + unsafe { + assert_eq!(N, (TAD::TWO_ADICITY as i32)); // Compiler removes this provided it is satisfied. + assert_eq!(N + N_PRIME, 31); // Compiler removes this provided it is satisfied. + + let mask = x86_64::_mm256_set1_epi32((1_i32 << N) - 1_i32); // Compiler realises this is a constant. + let hi = x86_64::_mm256_srli_epi32::(input); + + // Provided overflow does not occur, (2^{31 - N} - 1)*x = (x << {31 - N}) - 1. + // lo < 2^N => (lo << {31 - N}) < 2^31 and (lo << {31 - N}) - lo < P. + let lo = x86_64::_mm256_and_si256(input, mask); + let lo_shft = x86_64::_mm256_slli_epi32::(lo); + let lo_plus_hi = x86_64::_mm256_add_epi32(lo, hi); + x86_64::_mm256_sub_epi32(lo_shft, lo_plus_hi) + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/mod.rs b/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/mod.rs new file mode 100644 index 000000000..697898094 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/mod.rs @@ -0,0 +1,7 @@ +mod packing; +mod poseidon2; +mod utils; + +pub use packing::*; +pub use poseidon2::*; +pub use utils::*; diff --git a/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/packing.rs b/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/packing.rs new file mode 100644 index 000000000..19dda71e4 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/packing.rs @@ -0,0 +1,1502 @@ +//! Optimised AVX512 implementation for packed vectors of MontyFields31 elements. +//! +//! We check that this compiles to the expected assembly code in: https://godbolt.org/z/Mz1WGYKWe + +use alloc::vec::Vec; +use core::arch::asm; +use core::arch::x86_64::{self, __m512i, __mmask8, __mmask16}; +use core::array; +use core::hint::unreachable_unchecked; +use core::iter::{Product, Sum}; +use core::mem::transmute; +use core::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; + +use p3_field::{ + Algebra, Field, InjectiveMonomial, PackedField, PackedFieldPow2, PackedValue, + PermutationMonomial, PrimeCharacteristicRing, +}; +use p3_util::reconstitute_from_base; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; + +use crate::{FieldParameters, MontyField31, PackedMontyParameters, RelativelyPrimePower}; + +const WIDTH: usize = 16; + +pub trait MontyParametersAVX512 { + const PACKED_P: __m512i; + const PACKED_MU: __m512i; +} + +const EVENS: __mmask16 = 0b0101010101010101; +const EVENS4: __mmask16 = 0x0f0f; + +/// Vectorized AVX-512F implementation of `MontyField31` arithmetic. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(transparent)] // Needed to make `transmute`s safe. +pub struct PackedMontyField31AVX512(pub [MontyField31; WIDTH]); + +impl PackedMontyField31AVX512 { + #[inline] + #[must_use] + /// Get an arch-specific vector representing the packed values. + pub(crate) fn to_vector(self) -> __m512i { + unsafe { + // Safety: `MontyField31` is `repr(transparent)` so it can be transmuted to `u32`. It + // follows that `[MontyField31; WIDTH]` can be transmuted to `[u32; WIDTH]`, which can be + // transmuted to `__m512i`, since arrays are guaranteed to be contiguous in memory. + // Finally `PackedMontyField31AVX512` is `repr(transparent)` so it can be transmuted to + // `[MontyField31; WIDTH]`. + transmute(self) + } + } + + #[inline] + #[must_use] + /// Make a packed field vector from an arch-specific vector. + /// + /// SAFETY: The caller must ensure that each element of `vector` represents a valid + /// `MontyField31`. In particular, each element of vector must be in `0..=P`. + pub(crate) unsafe fn from_vector(vector: __m512i) -> Self { + unsafe { + // Safety: It is up to the user to ensure that elements of `vector` represent valid + // `MontyField31` values. We must only reason about memory representations. `__m512i` can be + // transmuted to `[u32; WIDTH]` (since arrays elements are contiguous in memory), which can + // be transmuted to `[MontyField31; WIDTH]` (since `MontyField31` is `repr(transparent)`), which + // in turn can be transmuted to `PackedMontyField31AVX512` (since `PackedMontyField31AVX512` is also + // `repr(transparent)`). + transmute(vector) + } + } + + /// Copy `value` to all positions in a packed vector. This is the same as + /// `From::from`, but `const`. + #[inline] + #[must_use] + const fn broadcast(value: MontyField31) -> Self { + Self([value; WIDTH]) + } +} + +impl Add for PackedMontyField31AVX512 { + type Output = Self; + #[inline] + fn add(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = add::(lhs, rhs); + unsafe { + // Safety: `add` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Mul for PackedMontyField31AVX512 { + type Output = Self; + #[inline] + fn mul(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = mul::(lhs, rhs); + unsafe { + // Safety: `mul` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Neg for PackedMontyField31AVX512 { + type Output = Self; + #[inline] + fn neg(self) -> Self { + let val = self.to_vector(); + let res = neg::(val); + unsafe { + // Safety: `neg` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +impl Sub for PackedMontyField31AVX512 { + type Output = Self; + #[inline] + fn sub(self, rhs: Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = sub::(lhs, rhs); + unsafe { + // Safety: `sub` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } +} + +/// Add two vectors of MontyField31 elements in canonical form. +/// +/// We allow a slight loosening of the canonical form requirement. One of this inputs +/// must be in canonical form [0, P) but the other is also allowed to equal P. +/// If the inputs do not conform to this representation, the result is undefined. +#[inline] +#[must_use] +pub(crate) fn add(lhs: __m512i, rhs: __m512i) -> __m512i { + // We want this to compile to: + // vpaddd t, lhs, rhs + // vpsubd u, t, P + // vpminud res, t, u + // throughput: 1.5 cyc/vec (10.67 els/cyc) + // latency: 3 cyc + + // Let t := lhs + rhs. We want to return t mod P. Recall that lhs and rhs are in [0, P] + // with at most one of them equal to P. Hence t is in [0, 2P - 1] and so it suffices + // to return t if t < P and t - P otherwise. + // Let u := (t - P) mod 2^32 and r := unsigned_min(t, u). + // If t is in [0, P - 1], then u is in (P - 1 <) 2^32 - P, ..., 2^32 - 1 and r = t. + // Otherwise, t is in [P, 2P - 1], and u is in [0, P - 1] (< P) and r = u. Hence, r is t if + // t < P and t - P otherwise, as desired. + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + let t = x86_64::_mm512_add_epi32(lhs, rhs); + let u = x86_64::_mm512_sub_epi32(t, MPAVX512::PACKED_P); + x86_64::_mm512_min_epu32(t, u) + } +} + +/// Subtract vectors of MontyField31 elements in canonical form. +/// +/// We allow a slight loosening of the canonical form requirement. The +/// rhs input is additionally allowed to be P. +/// If the inputs do not conform to this representation, the result is undefined. +#[inline] +#[must_use] +pub(crate) fn sub(lhs: __m512i, rhs: __m512i) -> __m512i { + // We want this to compile to: + // vpsubd t, lhs, rhs + // vpaddd u, t, P + // vpminud res, t, u + // throughput: 1.5 cyc/vec (10.67 els/cyc) + // latency: 3 cyc + + // Let t := lhs - rhs. We want to return t mod P. Recall that lhs is in [0, P - 1] + // and rhs is in [0, P] so t is in (-2^31 <) -P, ..., P - 1 (< 2^31). It suffices to return t if + // t >= 0 and t + P otherwise. + // Let u := (t + P) mod 2^32 and r := unsigned_min(t, u). + // If t is in [0, P - 1], then u is in P, ..., 2 P - 1 and r = t. + // Otherwise, t is in [-P, -1], u is in [0, P - 1] (< P) and r = u. Hence, r is t if + // t < P and t - P otherwise, as desired. + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + let t = x86_64::_mm512_sub_epi32(lhs, rhs); + let u = x86_64::_mm512_add_epi32(t, MPAVX512::PACKED_P); + x86_64::_mm512_min_epu32(t, u) + } +} + +/// No-op. Prevents the compiler from deducing the value of the vector. +/// +/// Similar to `core::hint::black_box`, it can be used to stop the compiler applying undesirable +/// "optimizations". Unlike the built-in `black_box`, it does not force the value to be written to +/// and then read from the stack. +#[inline] +#[must_use] +fn confuse_compiler(x: __m512i) -> __m512i { + let y; + unsafe { + asm!( + "/*{0}*/", + inlateout(zmm_reg) x => y, + options(nomem, nostack, preserves_flags, pure), + ); + // Below tells the compiler the semantics of this so it can still do constant folding, etc. + // You may ask, doesn't it defeat the point of the inline asm block to tell the compiler + // what it does? The answer is that we still inhibit the transform we want to avoid, so + // apparently not. Idk, LLVM works in mysterious ways. + if transmute::<__m512i, [u32; 16]>(x) != transmute::<__m512i, [u32; 16]>(y) { + unreachable_unchecked(); + } + } + y +} + +// MONTGOMERY MULTIPLICATION +// This implementation is based on [1] but with minor changes. The reduction is as follows: +// +// Constants: P < 2^31 +// B = 2^32 +// μ = P^-1 mod B +// Input: 0 <= C < P B +// Output: 0 <= R < P such that R = C B^-1 (mod P) +// 1. Q := μ C mod B +// 2. D := (C - Q P) / B +// 3. R := if D < 0 then D + P else D +// +// We first show that the division in step 2. is exact. It suffices to show that C = Q P (mod B). By +// definition of Q and μ, we have Q P = μ C P = P^-1 C P = C (mod B). We also have +// C - Q P = C (mod P), so thus D = C B^-1 (mod P). +// +// It remains to show that R is in the correct range. It suffices to show that -P <= D < P. We know +// that 0 <= C < P B and 0 <= Q P < P B. Then -P B < C - QP < P B and -P < D < P, as desired. +// +// [1] Modern Computer Arithmetic, Richard Brent and Paul Zimmermann, Cambridge University Press, +// 2010, algorithm 2.7. + +/// Perform a partial Montgomery reduction on each 64 bit element. +/// Input must lie in {0, ..., 2^32P}. +/// The output will lie in {-P, ..., P} and be stored in the upper 32 bits. +#[inline] +#[must_use] +fn partial_monty_red_unsigned_to_signed( + input: __m512i, +) -> __m512i { + unsafe { + // We throw a confuse compiler here to prevent the compiler from + // using vpmullq instead of vpmuludq in the computations for q_p. + // vpmullq has both higher latency and lower throughput. + let q = confuse_compiler(x86_64::_mm512_mul_epu32(input, MPAVX512::PACKED_MU)); + let q_p = x86_64::_mm512_mul_epu32(q, MPAVX512::PACKED_P); + + // This could equivalently be _mm512_sub_epi64 + x86_64::_mm512_sub_epi32(input, q_p) + } +} + +/// Perform a partial Montgomery reduction on each 64 bit element. +/// Input must lie in {-2^{31}P, ..., 2^31P}. +/// The output will lie in {-P, ..., P} and be stored in the upper 32 bits. +#[inline] +#[must_use] +fn partial_monty_red_signed_to_signed(input: __m512i) -> __m512i { + unsafe { + // We throw a confuse compiler here to prevent the compiler from + // using vpmullq instead of vpmuludq in the computations for q_p. + // vpmullq has both higher latency and lower throughput. + let q = confuse_compiler(x86_64::_mm512_mul_epi32(input, MPAVX512::PACKED_MU)); + let q_p = x86_64::_mm512_mul_epi32(q, MPAVX512::PACKED_P); + + // This could equivalently be _mm512_sub_epi64 + x86_64::_mm512_sub_epi32(input, q_p) + } +} + +/// Viewing the input as a vector of 16 `u32`s, copy the odd elements into the even elements below +/// them. In other words, for all `0 <= i < 8`, set the even elements according to +/// `res[2 * i] := a[2 * i + 1]`, and the odd elements according to +/// `res[2 * i + 1] := a[2 * i + 1]`. +#[inline] +#[must_use] +fn movehdup_epi32(a: __m512i) -> __m512i { + // The instruction is only available in the floating-point flavor; this distinction is only for + // historical reasons and no longer matters. We cast to floats, do the thing, and cast back. + unsafe { + x86_64::_mm512_castps_si512(x86_64::_mm512_movehdup_ps(x86_64::_mm512_castsi512_ps(a))) + } +} + +/// Viewing `a` as a vector of 16 `u32`s, copy the odd elements into the even elements below them, +/// then merge with `src` according to the mask provided. In other words, for all `0 <= i < 8`, set +/// the even elements according to `res[2 * i] := if k[2 * i] { a[2 * i + 1] } else { src[2 * i] }`, +/// and the odd elements according to +/// `res[2 * i + 1] := if k[2 * i + 1] { a[2 * i + 1] } else { src[2 * i + 1] }`. +#[inline] +#[must_use] +fn mask_movehdup_epi32(src: __m512i, k: __mmask16, a: __m512i) -> __m512i { + // The instruction is only available in the floating-point flavor; this distinction is only for + // historical reasons and no longer matters. + + // While we can write this using intrinsics, when inlined, the intrinsic often compiles + // to a vpermt2ps which has worse latency, see https://godbolt.org/z/489aaPhz3. + // Hence we use inline assembly to force the compiler to do the right thing. + unsafe { + let dst: __m512i; + asm!( + "vmovshdup {src_dst}{{{k}}}, {a}", + src_dst = inlateout(zmm_reg) src => dst, + k = in(kreg) k, + a = in(zmm_reg) a, + options(nomem, nostack, preserves_flags, pure), + ); + dst + } +} + +/// Multiply a vector of unsigned field elements return a vector of unsigned field elements lying in [0, P). +/// +/// Note that the input does not need to be in canonical form but must satisfy +/// the bound `lhs * rhs < 2^32 * P`. If this bound is not satisfied, the result +/// is undefined. +#[inline] +#[must_use] +fn mul(lhs: __m512i, rhs: __m512i) -> __m512i { + // We want this to compile to: + // vmovshdup lhs_odd, lhs + // vmovshdup rhs_odd, rhs + // vpmuludq prod_evn, lhs, rhs + // vpmuludq prod_hi, lhs_odd, rhs_odd + // vpmuludq q_evn, prod_evn, MU + // vpmuludq q_odd, prod_hi, MU + // vmovshdup prod_hi{EVENS}, prod_evn + // vpmuludq q_p_evn, q_evn, P + // vpmuludq q_p_hi, q_odd, P + // vmovshdup q_p_hi{EVENS}, q_p_evn + // vpcmpltud underflow, prod_hi, q_p_hi + // vpsubd res, prod_hi, q_p_hi + // vpaddd res{underflow}, res, P + // throughput: 6.5 cyc/vec (2.46 els/cyc) + // latency: 21 cyc + unsafe { + // `vpmuludq` only reads the even doublewords, so when we pass `lhs` and `rhs` directly we + // get the eight products at even positions. + let lhs_evn = lhs; + let rhs_evn = rhs; + + // Copy the odd doublewords into even positions to compute the eight products at odd + // positions. + // NB: The odd doublewords are ignored by `vpmuludq`, so we have a lot of choices for how to + // do this; `vmovshdup` is nice because it runs on a memory port if the operand is in + // memory, thus improving our throughput. + let lhs_odd = movehdup_epi32(lhs); + let rhs_odd = movehdup_epi32(rhs); + + let prod_evn = x86_64::_mm512_mul_epu32(lhs_evn, rhs_evn); + let prod_odd = x86_64::_mm512_mul_epu32(lhs_odd, rhs_odd); + + // We throw a confuse compiler here to prevent the compiler from + // using vpmullq instead of vpmuludq in the computations for q_p. + // vpmullq has both higher latency and lower throughput. + let q_evn = confuse_compiler(x86_64::_mm512_mul_epu32(prod_evn, MPAVX512::PACKED_MU)); + let q_odd = confuse_compiler(x86_64::_mm512_mul_epu32(prod_odd, MPAVX512::PACKED_MU)); + + // Get all the high halves as one vector: this is `(lhs * rhs) >> 32`. + // NB: `vpermt2d` may feel like a more intuitive choice here, but it has much higher + // latency. + let prod_hi = mask_movehdup_epi32(prod_odd, EVENS, prod_evn); + + // Normally we'd want to mask to perform % 2**32, but the instruction below only reads the + // low 32 bits anyway. + let q_p_evn = x86_64::_mm512_mul_epu32(q_evn, MPAVX512::PACKED_P); + let q_p_odd = x86_64::_mm512_mul_epu32(q_odd, MPAVX512::PACKED_P); + + // We can ignore all the low halves of `q_p` as they cancel out. Get all the high halves as + // one vector. + let q_p_hi = mask_movehdup_epi32(q_p_odd, EVENS, q_p_evn); + + // Subtraction `prod_hi - q_p_hi` modulo `P`. + // NB: Normally we'd `vpaddd P` and take the `vpminud`, but `vpminud` runs on port 0, which + // is already under a lot of pressure performing multiplications. To relieve this pressure, + // we check for underflow to generate a mask, and then conditionally add `P`. The underflow + // check runs on port 5, increasing our throughput, although it does cost us an additional + // cycle of latency. + let underflow = x86_64::_mm512_cmplt_epu32_mask(prod_hi, q_p_hi); + let t = x86_64::_mm512_sub_epi32(prod_hi, q_p_hi); + x86_64::_mm512_mask_add_epi32(t, underflow, t, MPAVX512::PACKED_P) + } +} + +/// Compute the elementary arithmetic generalization of `xor`, namely `xor(l, r) = l + r - 2lr` of +/// vectors in canonical form. +/// +/// Inputs are assumed to be in canonical form, if the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn xor(lhs: __m512i, rhs: __m512i) -> __m512i { + // Refactor the expression as r + 2l(1/2 - r). As MONTY_CONSTANT = 2^32, the internal + // representation 1/2 is 2^31 mod P so the product in the above expression is represented + // as 2l(2^31 - r). As 0 < 2l, 2^31 - r < 2^32 and 2l(2^31 - r) < 2^32P, we can compute + // the factors as 32 bit integers and then multiply and monty reduce as usual. + // + // We want this to compile to: + // vpaddd lhs_double, lhs, lhs + // vpsubd sub_rhs, (1 << 31), rhs + // vmovshdup lhs_odd, lhs_double + // vmovshdup rhs_odd, sub_rhs + // vpmuludq prod_evn, lhs_double, sub_rhs + // vpmuludq prod_hi, lhs_odd, rhs_odd + // vpmuludq q_evn, prod_evn, MU + // vpmuludq q_odd, prod_hi, MU + // vmovshdup prod_hi{EVENS}, prod_evn + // vpmuludq q_p_evn, q_evn, P + // vpmuludq q_p_hi, q_odd, P + // vmovshdup q_p_hi{EVENS}, q_p_evn + // vpcmpltud underflow, prod_hi, q_p_hi + // vpsubd res, prod_hi, q_p_hi + // vpaddd res{underflow}, res, P + // vpaddd sum, rhs, t + // vpsubd sum_corr, sum, pos_neg_P + // vpminud res, sum, sum_corr + // throughput: 9 cyc/vec (1.77 els/cyc) + // latency: 25 cyc + unsafe { + // 0 <= 2*lhs < 2P + let double_lhs = x86_64::_mm512_add_epi32(lhs, lhs); + + // Note that 2^31 is represented as an i32 as (-2^31). + // Compiler should realise this is a constant. + let half = x86_64::_mm512_set1_epi32(-1 << 31); + + // 0 < 2^31 - rhs < 2^31 + let half_sub_rhs = x86_64::_mm512_sub_epi32(half, rhs); + + // 2*lhs (2^31 - rhs) < 2P 2^31 < 2^32P so we can use the multiplication function. + let mul_res = mul::(double_lhs, half_sub_rhs); + + // Unfortunately, AVX512 has no equivalent of vpsignd so we can't do the same + // signed_add trick as in the AVX2 case. Instead we get a reduced value from mul + // and add on rhs in the standard way. + add::(rhs, mul_res) + } +} + +/// Compute the elementary arithmetic generalization of `andnot`, namely `andn(l, r) = (1 - l)r` of +/// vectors in canonical form. +/// +/// Inputs are assumed to be in canonical form, if the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn andn(lhs: __m512i, rhs: __m512i) -> __m512i { + // As we are working with MONTY_CONSTANT = 2^32, the internal representation + // of 1 is 2^32 mod P = 2^32 - P mod P. Hence we compute (2^32 - P - l)r. + // This product is less than 2^32P so we can apply our monty reduction to this. + // + // We want this to compile to: + // vpsubd neg_lhs, 2^32 - P, lhs + // vmovshdup lhs_odd, neg_lhs + // vmovshdup rhs_odd, rhs + // vpmuludq prod_evn, neg_lhs, rhs + // vpmuludq prod_hi, lhs_odd, rhs_odd + // vpmuludq q_evn, prod_evn, MU + // vpmuludq q_odd, prod_hi, MU + // vmovshdup prod_hi{EVENS}, prod_evn + // vpmuludq q_p_evn, q_evn, P + // vpmuludq q_p_hi, q_odd, P + // vmovshdup q_p_hi{EVENS}, q_p_evn + // vpcmpltud underflow, prod_hi, q_p_hi + // vpsubd res, prod_hi, q_p_hi + // vpaddd res{underflow}, res, P + // throughput: 7 cyc/vec (2.3 els/cyc) + // latency: 22 cyc + unsafe { + // We use 2^32 - P instead of 2^32 to avoid having to worry about 0's in lhs. + + // Compiler should realise that this is a constant. + let neg_p = x86_64::_mm512_sub_epi32(x86_64::_mm512_setzero_epi32(), MPAVX512::PACKED_P); + let neg_lhs = x86_64::_mm512_sub_epi32(neg_p, lhs); + + // 2*lhs (2^31 - rhs) < 2P 2^31 < 2^32P so we can use the multiplication function. + mul::(neg_lhs, rhs) + } +} + +/// Square the MontyField31 elements in the even index entries. +/// Inputs must be signed 32-bit integers in [-P, ..., P]. +/// Outputs will be a signed integer in (-P, ..., P) copied into both the even and odd indices. +#[inline] +#[must_use] +fn shifted_square(input: __m512i) -> __m512i { + // Note that we do not need a restriction on the size of input[i]^2 as + // 2^30 < P and |i32| <= 2^31 and so => input[i]^2 <= 2^62 < 2^32P. + unsafe { + let square = x86_64::_mm512_mul_epi32(input, input); + let square_red = partial_monty_red_unsigned_to_signed::(square); + movehdup_epi32(square_red) + } +} + +/// Cube the MontyField31 elements in the even index entries. +/// Inputs must be signed 32-bit integers in [-P, ..., P]. +/// Outputs will be signed integers in (-P^2, ..., P^2). +#[inline] +#[must_use] +pub(crate) fn packed_exp_3(input: __m512i) -> __m512i { + unsafe { + let square = shifted_square::(input); + x86_64::_mm512_mul_epi32(square, input) + } +} + +/// Take the fifth power of the MontyField31 elements in the even index entries. +/// Inputs must be signed 32-bit integers in [-P, ..., P]. +/// Outputs will be signed integers in (-P^2, ..., P^2). +#[inline] +#[must_use] +pub(crate) fn packed_exp_5(input: __m512i) -> __m512i { + unsafe { + let square = shifted_square::(input); + let quad = shifted_square::(square); + x86_64::_mm512_mul_epi32(quad, input) + } +} + +/// Take the seventh power of the MontyField31 elements in the even index entries. +/// Inputs must lie in [-P, ..., P]. +/// Outputs will be signed integers in (-P^2, ..., P^2). +#[inline] +#[must_use] +pub(crate) fn packed_exp_7(input: __m512i) -> __m512i { + unsafe { + let square = shifted_square::(input); + let cube_raw = x86_64::_mm512_mul_epi32(square, input); + let cube_red = partial_monty_red_signed_to_signed::(cube_raw); + let cube = movehdup_epi32(cube_red); + let quad = shifted_square::(square); + x86_64::_mm512_mul_epi32(quad, cube) + } +} + +/// Apply func to the even and odd indices of the input vector. +/// +/// func should only depend in the 32 bit entries in the even indices. +/// The input should conform to the requirements of `func`. +/// The output of func must lie in (-P^2, ..., P^2) after which +/// apply_func_to_even_odd will reduce the outputs to lie in [0, P) +/// and recombine the odd and even parts. +#[inline] +#[must_use] +pub(crate) unsafe fn apply_func_to_even_odd( + input: __m512i, + func: fn(__m512i) -> __m512i, +) -> __m512i { + unsafe { + let input_evn = input; + let input_odd = movehdup_epi32(input); + + let output_even = func(input_evn); + let output_odd = func(input_odd); + + // We need to recombine these even and odd parts and, at the same time reduce back to + // an output in [0, P). + + // We throw a confuse compiler here to prevent the compiler from + // using vpmullq instead of vpmuludq in the computations for q_p. + // vpmullq has both higher latency and lower throughput. + let q_evn = confuse_compiler(x86_64::_mm512_mul_epi32(output_even, MPAVX512::PACKED_MU)); + let q_odd = confuse_compiler(x86_64::_mm512_mul_epi32(output_odd, MPAVX512::PACKED_MU)); + + // Get all the high halves as one vector: this is `(lhs * rhs) >> 32`. + // NB: `vpermt2d` may feel like a more intuitive choice here, but it has much higher + // latency. + let output_hi = mask_movehdup_epi32(output_odd, EVENS, output_even); + + // Normally we'd want to mask to perform % 2**32, but the instruction below only reads the + // low 32 bits anyway. + let q_p_evn = x86_64::_mm512_mul_epi32(q_evn, MPAVX512::PACKED_P); + let q_p_odd = x86_64::_mm512_mul_epi32(q_odd, MPAVX512::PACKED_P); + + // We can ignore all the low halves of `q_p` as they cancel out. Get all the high halves as + // one vector. + let q_p_hi = mask_movehdup_epi32(q_p_odd, EVENS, q_p_evn); + + // Subtraction `output_hi - q_p_hi` modulo `P`. + // NB: Normally we'd `vpaddd P` and take the `vpminud`, but `vpminud` runs on port 0, which + // is already under a lot of pressure performing multiplications. To relieve this pressure, + // we check for underflow to generate a mask, and then conditionally add `P`. The underflow + // check runs on port 5, increasing our throughput, although it does cost us an additional + // cycle of latency. + let underflow = x86_64::_mm512_cmplt_epi32_mask(output_hi, q_p_hi); + let t = x86_64::_mm512_sub_epi32(output_hi, q_p_hi); + x86_64::_mm512_mask_add_epi32(t, underflow, t, MPAVX512::PACKED_P) + } +} + +/// Negate a vector of MontyField31 elements in canonical form. +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn neg(val: __m512i) -> __m512i { + // We want this to compile to: + // vptestmd nonzero, val, val + // vpsubd res{nonzero}{z}, P, val + // throughput: 1 cyc/vec (16 els/cyc) + // latency: 4 cyc + + // NB: This routine prioritizes throughput over latency. An alternative method would be to do + // sub(0, val), which would result in shorter latency, but also lower throughput. + + // If val is nonzero, then val is in {1, ..., P - 1} and P - val is in the same range. If val + // is zero, then the result is zeroed by masking. + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + let nonzero = x86_64::_mm512_test_epi32_mask(val, val); + x86_64::_mm512_maskz_sub_epi32(nonzero, MPAVX512::PACKED_P, val) + } +} + +/// Lets us combine some code for MontyField31 and PackedMontyField31AVX2 elements. +/// +/// Provides methods to convert an element into a __m512i element and then shift this __m512i +/// element so that the odd elements now lie in the even positions. Depending on the type of input, +/// the shift might be a no-op. +trait IntoM512: Copy + Into> { + /// Convert the input into a __m512i element. + fn as_m512i(&self) -> __m512i; + + /// Convert the input to a __m512i element and shift so that all elements in odd positions + /// now lie in even positions. + /// + /// The values lying in the even positions are undefined. + #[inline(always)] + fn as_shifted_m512i(&self) -> __m512i { + let vec = self.as_m512i(); + movehdup_epi32(vec) + } +} + +impl IntoM512 for PackedMontyField31AVX512 { + #[inline(always)] + fn as_m512i(&self) -> __m512i { + self.to_vector() + } +} + +impl IntoM512 for MontyField31 { + #[inline(always)] + fn as_m512i(&self) -> __m512i { + unsafe { x86_64::_mm512_set1_epi32(self.value as i32) } + } + + #[inline(always)] + fn as_shifted_m512i(&self) -> __m512i { + unsafe { x86_64::_mm512_set1_epi32(self.value as i32) } + } +} + +/// Compute the elementary function `l0*r0 + l1*r1` given four inputs +/// in canonical form. +/// +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn dot_product_2, RHS: IntoM512>( + lhs: [LHS; 2], + rhs: [RHS; 2], +) -> __m512i { + // The following analysis treats all input arrays as being arrays of PackedMontyField31AVX512. + // If one of the arrays contains MontyField31, we get to avoid the initial vmovshdup. + // + // We improve the throughput by combining the monty reductions together. As all inputs are + // `< P < 2^{31}`, `l0*r0 + l1*r1 < 2P^2 < 2^{32}P` so the montgomery reduction + // algorithm can be applied to the sum of the products instead of to each product individually. + // + // We want this to compile to: + // vmovshdup lhs_odd0, lhs0 + // vmovshdup rhs_odd0, rhs0 + // vmovshdup lhs_odd1, lhs1 + // vmovshdup rhs_odd1, rhs1 + // vpmuludq prod_evn0, lhs0, rhs0 + // vpmuludq prod_odd0, lhs_odd0, rhs_odd0 + // vpmuludq prod_evn1, lhs1, rhs1 + // vpmuludq prod_odd1, lhs_odd1, rhs_odd1 + // vpaddq dot_evn, prod_evn0, prod_evn1 + // vpaddq dot, prod_odd0, prod_odd1 + // vpmuludq q_evn, prod_evn, MU + // vpmuludq q_odd, dot, MU + // vpmuludq q_P_evn, q_evn, P + // vpmuludq q_P, q_odd, P + // vmovshdup dot{EVENS} dot_evn + // vmovshdup q_P{EVENS} q_P_evn + // vpcmpltud underflow, dot, q_P + // vpsubd res, dot, q_P + // vpaddd res{underflow}, res, P + // throughput: 9.5 cyc/vec (1.68 els/cyc) + // latency: 22 cyc + unsafe { + let lhs_evn0 = lhs[0].as_m512i(); + let lhs_odd0 = lhs[0].as_shifted_m512i(); + let lhs_evn1 = lhs[1].as_m512i(); + let lhs_odd1 = lhs[1].as_shifted_m512i(); + + let rhs_evn0 = rhs[0].as_m512i(); + let rhs_odd0 = rhs[0].as_shifted_m512i(); + let rhs_evn1 = rhs[1].as_m512i(); + let rhs_odd1 = rhs[1].as_shifted_m512i(); + + let mul_evn0 = x86_64::_mm512_mul_epu32(lhs_evn0, rhs_evn0); + let mul_evn1 = x86_64::_mm512_mul_epu32(lhs_evn1, rhs_evn1); + let mul_odd0 = x86_64::_mm512_mul_epu32(lhs_odd0, rhs_odd0); + let mul_odd1 = x86_64::_mm512_mul_epu32(lhs_odd1, rhs_odd1); + + let dot_evn = x86_64::_mm512_add_epi64(mul_evn0, mul_evn1); + let dot_odd = x86_64::_mm512_add_epi64(mul_odd0, mul_odd1); + + // We throw a confuse compiler here to prevent the compiler from + // using vpmullq instead of vpmuludq in the computations for q_p. + // vpmullq has both higher latency and lower throughput. + let q_evn = confuse_compiler(x86_64::_mm512_mul_epu32(dot_evn, PMP::PACKED_MU)); + let q_odd = confuse_compiler(x86_64::_mm512_mul_epu32(dot_odd, PMP::PACKED_MU)); + + // Get all the high halves as one vector: this is `dot(lhs, rhs) >> 32`. + // NB: `vpermt2d` may feel like a more intuitive choice here, but it has much higher + // latency. + let dot = mask_movehdup_epi32(dot_odd, EVENS, dot_evn); + + // Normally we'd want to mask to perform % 2**32, but the instruction below only reads the + // low 32 bits anyway. + let q_p_evn = x86_64::_mm512_mul_epu32(q_evn, PMP::PACKED_P); + let q_p_odd = x86_64::_mm512_mul_epu32(q_odd, PMP::PACKED_P); + + // We can ignore all the low halves of `q_p` as they cancel out. Get all the high halves as + // one vector. + let q_p = mask_movehdup_epi32(q_p_odd, EVENS, q_p_evn); + + // Subtraction `prod_hi - q_p_hi` modulo `P`. + // NB: Normally we'd `vpaddd P` and take the `vpminud`, but `vpminud` runs on port 0, which + // is already under a lot of pressure performing multiplications. To relieve this pressure, + // we check for underflow to generate a mask, and then conditionally add `P`. The underflow + // check runs on port 5, increasing our throughput, although it does cost us an additional + // cycle of latency. + let underflow = x86_64::_mm512_cmplt_epu32_mask(dot, q_p); + let t = x86_64::_mm512_sub_epi32(dot, q_p); + x86_64::_mm512_mask_add_epi32(t, underflow, t, PMP::PACKED_P) + } +} + +/// Compute the elementary function `l0*r0 + l1*r1 + l2*r2 + l3*r3` given eight inputs +/// in canonical form. +/// +/// If the inputs are not in canonical form, the result is undefined. +#[inline] +#[must_use] +fn dot_product_4, RHS: IntoM512>( + lhs: [LHS; 4], + rhs: [RHS; 4], +) -> __m512i { + // The following analysis treats all input arrays as being arrays of PackedMontyField31AVX512. + // If one of the arrays contains MontyField31, we get to avoid the initial vmovshdup. + // + // Similarly to dot_product_2, we improve throughput by combining monty reductions however in this case + // we will need to slightly adjust the reduction algorithm. + // + // As all inputs are `< P < 2^{31}`, the sum satisfies: `C = l0*r0 + l1*r1 + l2*r2 + l3*r3 < 4P^2 < 2*2^{32}P`. + // Start by computing Q := μ C mod B as usual. + // We can't proceed as normal however as 2*2^{32}P > C - QP > -2^{32}P which doesn't fit into an i64. + // Instead we do a reduction on C, defining C' = if C < 2^{32}P: {C} else {C - 2^{32}P} + // From here we proceed with the standard montgomery reduction with C replaced by C'. It works identically + // with the Q we already computed as C = C' mod B. + // + // We want this to compile to: + // vmovshdup lhs_odd0, lhs0 + // vmovshdup rhs_odd0, rhs0 + // vmovshdup lhs_odd1, lhs1 + // vmovshdup rhs_odd1, rhs1 + // vmovshdup lhs_odd2, lhs2 + // vmovshdup rhs_odd2, rhs2 + // vmovshdup lhs_odd3, lhs3 + // vmovshdup rhs_odd3, rhs3 + // vpmuludq prod_evn0, lhs0, rhs0 + // vpmuludq prod_odd0, lhs_odd0, rhs_odd0 + // vpmuludq prod_evn1, lhs1, rhs1 + // vpmuludq prod_odd1, lhs_odd1, rhs_odd1 + // vpmuludq prod_evn2, lhs2, rhs2 + // vpmuludq prod_odd2, lhs_odd2, rhs_odd2 + // vpmuludq prod_evn3, lhs3, rhs3 + // vpmuludq prod_odd3, lhs_odd3, rhs_odd3 + // vpaddq dot_evn01, prod_evn0, prod_evn1 + // vpaddq dot_odd01, prod_odd0, prod_odd1 + // vpaddq dot_evn23, prod_evn2, prod_evn3 + // vpaddq dot_odd23, prod_odd2, prod_odd3 + // vpaddq dot_evn, dot_evn01, dot_evn23 + // vpaddq dot, dot_odd01, dot_odd23 + // vpmuludq q_evn, dot_evn, MU + // vpmuludq q_odd, dot, MU + // vpmuludq q_P_evn, q_evn, P + // vpmuludq q_P, q_odd, P + // vmovshdup dot{EVENS} dot_evn + // vpcmpleud over_P, P, dot + // vpsubd dot{underflow}, dot, P + // vmovshdup q_P{EVENS} q_P_evn + // vpcmpltud underflow, dot, q_P + // vpsubd res, dot, q_P + // vpaddd res{underflow}, res, P + // throughput: 16.5 cyc/vec (0.97 els/cyc) + // latency: 23 cyc + unsafe { + let lhs_evn0 = lhs[0].as_m512i(); + let lhs_odd0 = lhs[0].as_shifted_m512i(); + let lhs_evn1 = lhs[1].as_m512i(); + let lhs_odd1 = lhs[1].as_shifted_m512i(); + let lhs_evn2 = lhs[2].as_m512i(); + let lhs_odd2 = lhs[2].as_shifted_m512i(); + let lhs_evn3 = lhs[3].as_m512i(); + let lhs_odd3 = lhs[3].as_shifted_m512i(); + + let rhs_evn0 = rhs[0].as_m512i(); + let rhs_odd0 = rhs[0].as_shifted_m512i(); + let rhs_evn1 = rhs[1].as_m512i(); + let rhs_odd1 = rhs[1].as_shifted_m512i(); + let rhs_evn2 = rhs[2].as_m512i(); + let rhs_odd2 = rhs[2].as_shifted_m512i(); + let rhs_evn3 = rhs[3].as_m512i(); + let rhs_odd3 = rhs[3].as_shifted_m512i(); + + let mul_evn0 = x86_64::_mm512_mul_epu32(lhs_evn0, rhs_evn0); + let mul_evn1 = x86_64::_mm512_mul_epu32(lhs_evn1, rhs_evn1); + let mul_evn2 = x86_64::_mm512_mul_epu32(lhs_evn2, rhs_evn2); + let mul_evn3 = x86_64::_mm512_mul_epu32(lhs_evn3, rhs_evn3); + let mul_odd0 = x86_64::_mm512_mul_epu32(lhs_odd0, rhs_odd0); + let mul_odd1 = x86_64::_mm512_mul_epu32(lhs_odd1, rhs_odd1); + let mul_odd2 = x86_64::_mm512_mul_epu32(lhs_odd2, rhs_odd2); + let mul_odd3 = x86_64::_mm512_mul_epu32(lhs_odd3, rhs_odd3); + + let dot_evn01 = x86_64::_mm512_add_epi64(mul_evn0, mul_evn1); + let dot_odd01 = x86_64::_mm512_add_epi64(mul_odd0, mul_odd1); + let dot_evn23 = x86_64::_mm512_add_epi64(mul_evn2, mul_evn3); + let dot_odd23 = x86_64::_mm512_add_epi64(mul_odd2, mul_odd3); + + let dot_evn = x86_64::_mm512_add_epi64(dot_evn01, dot_evn23); + let dot_odd = x86_64::_mm512_add_epi64(dot_odd01, dot_odd23); + + // We throw a confuse compiler here to prevent the compiler from + // using vpmullq instead of vpmuludq in the computations for q_p. + // vpmullq has both higher latency and lower throughput. + let q_evn = confuse_compiler(x86_64::_mm512_mul_epu32(dot_evn, PMP::PACKED_MU)); + let q_odd = confuse_compiler(x86_64::_mm512_mul_epu32(dot_odd, PMP::PACKED_MU)); + + // Get all the high halves as one vector: this is `dot(lhs, rhs) >> 32`. + // NB: `vpermt2d` may feel like a more intuitive choice here, but it has much higher + // latency. + let dot = mask_movehdup_epi32(dot_odd, EVENS, dot_evn); + + // The elements in dot lie in [0, 2P) so we need to reduce them to [0, P) + // NB: Normally we'd `vpsubq P` and take the `vpminud`, but `vpminud` runs on port 0, which + // is already under a lot of pressure performing multiplications. To relieve this pressure, + // we check for underflow to generate a mask, and then conditionally add `P`. + let over_p = x86_64::_mm512_cmple_epu32_mask(PMP::PACKED_P, dot); + let dot_corr = x86_64::_mm512_mask_sub_epi32(dot, over_p, dot, PMP::PACKED_P); + + // Normally we'd want to mask to perform % 2**32, but the instruction below only reads the + // low 32 bits anyway. + let q_p_evn = x86_64::_mm512_mul_epu32(q_evn, PMP::PACKED_P); + let q_p_odd = x86_64::_mm512_mul_epu32(q_odd, PMP::PACKED_P); + + // We can ignore all the low halves of `q_p` as they cancel out. Get all the high halves as + // one vector. + let q_p = mask_movehdup_epi32(q_p_odd, EVENS, q_p_evn); + + // Subtraction `prod_hi - q_p_hi` modulo `P`. + // NB: Normally we'd `vpaddd P` and take the `vpminud`, but `vpminud` runs on port 0, which + // is already under a lot of pressure performing multiplications. To relieve this pressure, + // we check for underflow to generate a mask, and then conditionally add `P`. The underflow + // check runs on port 5, increasing our throughput, although it does cost us an additional + // cycle of latency. + let underflow = x86_64::_mm512_cmplt_epu32_mask(dot_corr, q_p); + let t = x86_64::_mm512_sub_epi32(dot_corr, q_p); + x86_64::_mm512_mask_add_epi32(t, underflow, t, PMP::PACKED_P) + } +} + +/// A general fast dot product implementation. +/// +/// Maximises the number of calls to `dot_product_4` for dot products involving vectors of length +/// more than 4. The length 64 occurs commonly enough it's useful to have a custom implementation +/// which lets it use a slightly better summation algorithm with lower latency. +#[inline(always)] +fn general_dot_product< + FP: FieldParameters, + LHS: IntoM512, + RHS: IntoM512, + const N: usize, +>( + lhs: &[LHS], + rhs: &[RHS], +) -> PackedMontyField31AVX512 { + assert_eq!(lhs.len(), N); + assert_eq!(rhs.len(), N); + match N { + 0 => PackedMontyField31AVX512::::ZERO, + 1 => (lhs[0]).into() * (rhs[0]).into(), + 2 => { + let res = dot_product_2([lhs[0], lhs[1]], [rhs[0], rhs[1]]); + unsafe { + // Safety: `dot_product_2` returns values in canonical form when given values in canonical form. + PackedMontyField31AVX512::::from_vector(res) + } + } + 3 => { + let lhs2 = lhs[2]; + let rhs2 = rhs[2]; + let res = dot_product_2([lhs[0], lhs[1]], [rhs[0], rhs[1]]); + unsafe { + // Safety: `dot_product_2` returns values in canonical form when given values in canonical form. + PackedMontyField31AVX512::::from_vector(res) + (lhs2.into() * rhs2.into()) + } + } + 4 => { + let res = dot_product_4( + [lhs[0], lhs[1], lhs[2], lhs[3]], + [rhs[0], rhs[1], rhs[2], rhs[3]], + ); + unsafe { + // Safety: `dot_product_4` returns values in canonical form when given values in canonical form. + PackedMontyField31AVX512::::from_vector(res) + } + } + 64 => { + let sum_4s: [PackedMontyField31AVX512; 16] = array::from_fn(|i| { + let res = dot_product_4( + [lhs[4 * i], lhs[4 * i + 1], lhs[4 * i + 2], lhs[4 * i + 3]], + [rhs[4 * i], rhs[4 * i + 1], rhs[4 * i + 2], rhs[4 * i + 3]], + ); + unsafe { + // Safety: `dot_product_4` returns values in canonical form when given values in canonical form. + PackedMontyField31AVX512::::from_vector(res) + } + }); + PackedMontyField31AVX512::::sum_array::<16>(&sum_4s) + } + _ => { + let mut acc = { + let res = dot_product_4( + [lhs[0], lhs[1], lhs[2], lhs[3]], + [rhs[0], rhs[1], rhs[2], rhs[3]], + ); + unsafe { + // Safety: `dot_product_4` returns values in canonical form when given values in canonical form. + PackedMontyField31AVX512::::from_vector(res) + } + }; + for i in (4..(N - 3)).step_by(4) { + let res = dot_product_4( + [lhs[i], lhs[i + 1], lhs[i + 2], lhs[i + 3]], + [rhs[i], rhs[i + 1], rhs[i + 2], rhs[i + 3]], + ); + unsafe { + // Safety: `dot_product_4` returns values in canonical form when given values in canonical form. + acc += PackedMontyField31AVX512::::from_vector(res) + } + } + match N & 3 { + 0 => acc, + 1 => { + acc + general_dot_product::<_, _, _, 1>( + &lhs[(4 * (N / 4))..], + &rhs[(4 * (N / 4))..], + ) + } + 2 => { + acc + general_dot_product::<_, _, _, 2>( + &lhs[(4 * (N / 4))..], + &rhs[(4 * (N / 4))..], + ) + } + 3 => { + acc + general_dot_product::<_, _, _, 3>( + &lhs[(4 * (N / 4))..], + &rhs[(4 * (N / 4))..], + ) + } + _ => unreachable!(), + } + } + } +} + +impl From> for PackedMontyField31AVX512 { + #[inline] + fn from(value: MontyField31) -> Self { + Self::broadcast(value) + } +} + +impl Default for PackedMontyField31AVX512 { + #[inline] + fn default() -> Self { + MontyField31::default().into() + } +} + +impl AddAssign for PackedMontyField31AVX512 { + #[inline] + fn add_assign(&mut self, rhs: Self) { + *self = *self + rhs; + } +} + +impl MulAssign for PackedMontyField31AVX512 { + #[inline] + fn mul_assign(&mut self, rhs: Self) { + *self = *self * rhs; + } +} + +impl SubAssign for PackedMontyField31AVX512 { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + *self = *self - rhs; + } +} + +impl Sum for PackedMontyField31AVX512 { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs + rhs).unwrap_or(Self::ZERO) + } +} + +impl Product for PackedMontyField31AVX512 { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator, + { + iter.reduce(|lhs, rhs| lhs * rhs).unwrap_or(Self::ONE) + } +} + +impl PrimeCharacteristicRing for PackedMontyField31AVX512 { + type PrimeSubfield = MontyField31; + + const ZERO: Self = Self::broadcast(MontyField31::ZERO); + const ONE: Self = Self::broadcast(MontyField31::ONE); + const TWO: Self = Self::broadcast(MontyField31::TWO); + const NEG_ONE: Self = Self::broadcast(MontyField31::NEG_ONE); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + f.into() + } + + #[inline(always)] + fn zero_vec(len: usize) -> Vec { + // SAFETY: this is a repr(transparent) wrapper around an array. + unsafe { reconstitute_from_base(MontyField31::::zero_vec(len * WIDTH)) } + } + + #[inline] + fn cube(&self) -> Self { + let val = self.to_vector(); + unsafe { + // Safety: `apply_func_to_even_odd` returns values in canonical form when given values in canonical form. + let res = apply_func_to_even_odd::(val, packed_exp_3::); + Self::from_vector(res) + } + } + + #[inline] + fn xor(&self, rhs: &Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = xor::(lhs, rhs); + unsafe { + // Safety: `xor` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } + + #[inline] + fn andn(&self, rhs: &Self) -> Self { + let lhs = self.to_vector(); + let rhs = rhs.to_vector(); + let res = andn::(lhs, rhs); + unsafe { + // Safety: `andn` returns values in canonical form when given values in canonical form. + Self::from_vector(res) + } + } + + #[must_use] + #[inline(always)] + fn exp_const_u64(&self) -> Self { + // We provide specialised code for the powers 3, 5, 7 as these turn up regularly. + // The other powers could be specialised similarly but we ignore this for now. + // These ideas could also be used to speed up the more generic exp_u64. + match POWER { + 0 => Self::ONE, + 1 => *self, + 2 => self.square(), + 3 => self.cube(), + 4 => self.square().square(), + 5 => { + let val = self.to_vector(); + unsafe { + // Safety: `apply_func_to_even_odd` returns values in canonical form when given values in canonical form. + let res = apply_func_to_even_odd::(val, packed_exp_5::); + Self::from_vector(res) + } + } + 6 => self.square().cube(), + 7 => { + let val = self.to_vector(); + unsafe { + // Safety: `apply_func_to_even_odd` returns values in canonical form when given values in canonical form. + let res = apply_func_to_even_odd::(val, packed_exp_7::); + Self::from_vector(res) + } + } + _ => self.exp_u64(POWER), + } + } + + #[inline(always)] + fn dot_product(u: &[Self; N], v: &[Self; N]) -> Self { + general_dot_product::<_, _, _, N>(u, v) + } +} + +impl Algebra> for PackedMontyField31AVX512 {} + +impl, const D: u64> InjectiveMonomial + for PackedMontyField31AVX512 +{ +} + +impl, const D: u64> PermutationMonomial + for PackedMontyField31AVX512 +{ + fn injective_exp_root_n(&self) -> Self { + FP::exp_root_d(*self) + } +} + +impl Add> for PackedMontyField31AVX512 { + type Output = Self; + #[inline] + fn add(self, rhs: MontyField31) -> Self { + self + Self::from(rhs) + } +} + +impl Mul> for PackedMontyField31AVX512 { + type Output = Self; + #[inline] + fn mul(self, rhs: MontyField31) -> Self { + self * Self::from(rhs) + } +} + +impl Sub> for PackedMontyField31AVX512 { + type Output = Self; + #[inline] + fn sub(self, rhs: MontyField31) -> Self { + self - Self::from(rhs) + } +} + +impl AddAssign> for PackedMontyField31AVX512 { + #[inline] + fn add_assign(&mut self, rhs: MontyField31) { + *self += Self::from(rhs) + } +} + +impl MulAssign> for PackedMontyField31AVX512 { + #[inline] + fn mul_assign(&mut self, rhs: MontyField31) { + *self *= Self::from(rhs) + } +} + +impl SubAssign> for PackedMontyField31AVX512 { + #[inline] + fn sub_assign(&mut self, rhs: MontyField31) { + *self -= Self::from(rhs) + } +} + +impl Sum> for PackedMontyField31AVX512 { + #[inline] + fn sum(iter: I) -> Self + where + I: Iterator>, + { + iter.sum::>().into() + } +} + +impl Product> for PackedMontyField31AVX512 { + #[inline] + fn product(iter: I) -> Self + where + I: Iterator>, + { + iter.product::>().into() + } +} + +impl Div> for PackedMontyField31AVX512 { + type Output = Self; + #[allow(clippy::suspicious_arithmetic_impl)] + #[inline] + fn div(self, rhs: MontyField31) -> Self { + self * rhs.inverse() + } +} + +impl Add> for MontyField31 { + type Output = PackedMontyField31AVX512; + #[inline] + fn add(self, rhs: PackedMontyField31AVX512) -> PackedMontyField31AVX512 { + PackedMontyField31AVX512::::from(self) + rhs + } +} + +impl Mul> for MontyField31 { + type Output = PackedMontyField31AVX512; + #[inline] + fn mul(self, rhs: PackedMontyField31AVX512) -> PackedMontyField31AVX512 { + PackedMontyField31AVX512::::from(self) * rhs + } +} + +impl Sub> for MontyField31 { + type Output = PackedMontyField31AVX512; + #[inline] + fn sub(self, rhs: PackedMontyField31AVX512) -> PackedMontyField31AVX512 { + PackedMontyField31AVX512::::from(self) - rhs + } +} + +impl Distribution> for StandardUniform { + #[inline] + fn sample(&self, rng: &mut R) -> PackedMontyField31AVX512 { + PackedMontyField31AVX512::(rng.random()) + } +} + +// vpshrdq requires AVX-512VBMI2. +#[cfg(target_feature = "avx512vbmi2")] +#[inline] +#[must_use] +fn interleave1_antidiagonal(x: __m512i, y: __m512i) -> __m512i { + unsafe { + // Safety: If this code got compiled then AVX-512VBMI2 intrinsics are available. + x86_64::_mm512_shrdi_epi64::<32>(x, y) + } +} + +// If we can't use vpshrdq, then do a vpermi2d, but we waste a register and double the latency. +#[cfg(not(target_feature = "avx512vbmi2"))] +#[inline] +#[must_use] +fn interleave1_antidiagonal(x: __m512i, y: __m512i) -> __m512i { + const INTERLEAVE1_INDICES: __m512i = unsafe { + // Safety: `[u32; 16]` is trivially transmutable to `__m512i`. + transmute::<[u32; WIDTH], _>([ + 0x01, 0x10, 0x03, 0x12, 0x05, 0x14, 0x07, 0x16, 0x09, 0x18, 0x0b, 0x1a, 0x0d, 0x1c, + 0x0f, 0x1e, + ]) + }; + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + x86_64::_mm512_permutex2var_epi32(x, INTERLEAVE1_INDICES, y) + } +} + +#[inline] +#[must_use] +fn interleave1(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + // If we have AVX-512VBMI2, we want this to compile to: + // vpshrdq t, x, y, 32 + // vpblendmd res0 {EVENS}, t, x + // vpblendmd res1 {EVENS}, y, t + // throughput: 1.5 cyc/2 vec (21.33 els/cyc) + // latency: 2 cyc + // + // Otherwise, we want it to compile to: + // vmovdqa32 t, INTERLEAVE1_INDICES + // vpermi2d t, x, y + // vpblendmd res0 {EVENS}, t, x + // vpblendmd res1 {EVENS}, y, t + // throughput: 1.5 cyc/2 vec (21.33 els/cyc) + // latency: 4 cyc + + // We currently have: + // x = [ x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf ], + // y = [ y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 ya yb yc yd ye yf ]. + // First form + // t = [ x1 y0 x3 y2 x5 y4 x7 y6 x9 y8 xb ya xd yc xf ye ]. + let t = interleave1_antidiagonal(x, y); + + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + + // Then + // res0 = [ x0 y0 x2 y2 x4 y4 x6 y6 x8 y8 xa ya xc yc xe ye ], + // res1 = [ x1 y1 x3 y3 x5 y5 x7 y7 x9 y9 xb yb xd yd xf yf ]. + ( + x86_64::_mm512_mask_blend_epi32(EVENS, t, x), + x86_64::_mm512_mask_blend_epi32(EVENS, y, t), + ) + } +} + +#[inline] +#[must_use] +fn shuffle_epi64(a: __m512i, b: __m512i) -> __m512i { + // The instruction is only available in the floating-point flavor; this distinction is only for + // historical reasons and no longer matters. We cast to floats, do the thing, and cast back. + unsafe { + let a = x86_64::_mm512_castsi512_pd(a); + let b = x86_64::_mm512_castsi512_pd(b); + x86_64::_mm512_castpd_si512(x86_64::_mm512_shuffle_pd::(a, b)) + } +} + +#[inline] +#[must_use] +fn interleave2(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + // We want this to compile to: + // vshufpd t, x, y, 55h + // vpblendmq res0 {EVENS}, t, x + // vpblendmq res1 {EVENS}, y, t + // throughput: 1.5 cyc/2 vec (21.33 els/cyc) + // latency: 2 cyc + + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + + // We currently have: + // x = [ x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf ], + // y = [ y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 ya yb yc yd ye yf ]. + // First form + // t = [ x2 x3 y0 y1 x6 x7 y4 y5 xa xb y8 y9 xe xf yc yd ]. + let t = shuffle_epi64::<0b01010101>(x, y); + + // Then + // res0 = [ x0 x1 y0 y1 x4 x5 y4 y5 x8 x9 y8 y9 xc xd yc yd ], + // res1 = [ x2 x3 y2 y3 x6 x7 y6 y7 xa xb ya yb xe xf ye yf ]. + ( + x86_64::_mm512_mask_blend_epi64(EVENS as __mmask8, t, x), + x86_64::_mm512_mask_blend_epi64(EVENS as __mmask8, y, t), + ) + } +} + +#[inline] +#[must_use] +fn interleave4(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + // We want this to compile to: + // vmovdqa64 t, INTERLEAVE4_INDICES + // vpermi2q t, x, y + // vpblendmd res0 {EVENS4}, t, x + // vpblendmd res1 {EVENS4}, y, t + // throughput: 1.5 cyc/2 vec (21.33 els/cyc) + // latency: 4 cyc + + const INTERLEAVE4_INDICES: __m512i = unsafe { + // Safety: `[u64; 8]` is trivially transmutable to `__m512i`. + transmute::<[u64; WIDTH / 2], _>([0o02, 0o03, 0o10, 0o11, 0o06, 0o07, 0o14, 0o15]) + }; + + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + + // We currently have: + // x = [ x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf ], + // y = [ y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 ya yb yc yd ye yf ]. + // First form + // t = [ x4 x5 x6 x7 y0 y1 y2 y3 xc xd xe xf y8 y9 ya yb ]. + let t = x86_64::_mm512_permutex2var_epi64(x, INTERLEAVE4_INDICES, y); + + // Then + // res0 = [ x0 x1 x2 x3 y0 y1 y2 y3 x8 x9 xa xb y8 y9 ya yb ], + // res1 = [ x4 x5 x6 x7 y4 y5 y6 y7 xc xd xe xf yc yd ye yf ]. + ( + x86_64::_mm512_mask_blend_epi32(EVENS4, t, x), + x86_64::_mm512_mask_blend_epi32(EVENS4, y, t), + ) + } +} + +#[inline] +#[must_use] +fn interleave8(x: __m512i, y: __m512i) -> (__m512i, __m512i) { + // We want this to compile to: + // vshufi64x2 t, x, b, 4eh + // vpblendmq res0 {EVENS4}, t, x + // vpblendmq res1 {EVENS4}, y, t + // throughput: 1.5 cyc/2 vec (21.33 els/cyc) + // latency: 4 cyc + + unsafe { + // Safety: If this code got compiled then AVX-512F intrinsics are available. + + // We currently have: + // x = [ x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf ], + // y = [ y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 ya yb yc yd ye yf ]. + // First form + // t = [ x8 x9 xa xb xc xd xe xf y0 y1 y2 y3 y4 y5 y6 y7 ]. + let t = x86_64::_mm512_shuffle_i64x2::<0b01_00_11_10>(x, y); + + // Then + // res0 = [ x0 x1 x2 x3 x4 x5 x6 x7 y0 y1 y2 y3 y4 y5 y6 y7 ], + // res1 = [ x8 x9 xa xb xc xd xe xf y8 y9 ya yb yc yd ye yf ]. + ( + x86_64::_mm512_mask_blend_epi64(EVENS4 as __mmask8, t, x), + x86_64::_mm512_mask_blend_epi64(EVENS4 as __mmask8, y, t), + ) + } +} + +unsafe impl PackedValue for PackedMontyField31AVX512 { + type Value = MontyField31; + + const WIDTH: usize = WIDTH; + + #[inline] + fn from_slice(slice: &[MontyField31]) -> &Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[MontyField31; WIDTH]` can be transmuted to `PackedMontyField31AVX512` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast is + // safe too. + &*slice.as_ptr().cast() + } + } + #[inline] + fn from_slice_mut(slice: &mut [MontyField31]) -> &mut Self { + assert_eq!(slice.len(), Self::WIDTH); + unsafe { + // Safety: `[MontyField31; WIDTH]` can be transmuted to `PackedMontyField31AVX512` since the + // latter is `repr(transparent)`. They have the same alignment, so the reference cast is + // safe too. + &mut *slice.as_mut_ptr().cast() + } + } + + /// Similar to `core:array::from_fn`. + #[inline] + fn from_fn MontyField31>(f: F) -> Self { + let vals_arr: [_; WIDTH] = core::array::from_fn(f); + Self(vals_arr) + } + + #[inline] + fn as_slice(&self) -> &[MontyField31] { + &self.0[..] + } + #[inline] + fn as_slice_mut(&mut self) -> &mut [MontyField31] { + &mut self.0[..] + } +} + +unsafe impl PackedField for PackedMontyField31AVX512 { + type Scalar = MontyField31; + + #[inline] + fn packed_linear_combination(coeffs: &[Self::Scalar], vecs: &[Self]) -> Self { + general_dot_product::<_, _, _, N>(coeffs, vecs) + } +} + +unsafe impl PackedFieldPow2 for PackedMontyField31AVX512 { + #[inline] + fn interleave(&self, other: Self, block_len: usize) -> (Self, Self) { + let (v0, v1) = (self.to_vector(), other.to_vector()); + let (res0, res1) = match block_len { + 1 => interleave1(v0, v1), + 2 => interleave2(v0, v1), + 4 => interleave4(v0, v1), + 8 => interleave8(v0, v1), + 16 => (v0, v1), + _ => panic!("unsupported block_len"), + }; + unsafe { + // Safety: all values are in canonical form (we haven't changed them). + (Self::from_vector(res0), Self::from_vector(res1)) + } + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/poseidon2.rs b/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/poseidon2.rs new file mode 100644 index 000000000..00e1b771f --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/poseidon2.rs @@ -0,0 +1,478 @@ +//! Vectorized AVX512 implementation of Poseidon2 for MontyField31 + +use alloc::vec::Vec; +use core::arch::x86_64::{self, __m512i}; +use core::marker::PhantomData; +use core::mem::transmute; + +use p3_field::PrimeCharacteristicRing; +use p3_poseidon2::{ + ExternalLayer, ExternalLayerConstants, ExternalLayerConstructor, InternalLayer, + InternalLayerConstructor, MDSMat4, external_initial_permute_state, + external_terminal_permute_state, +}; + +use super::{add, halve_avx512, sub}; +use crate::{ + FieldParameters, MontyField31, MontyParameters, PackedMontyField31AVX512, + PackedMontyParameters, RelativelyPrimePower, apply_func_to_even_odd, packed_exp_3, + packed_exp_5, packed_exp_7, +}; + +// In the internal layers, it is valuable to treat the first entry of the state differently +// as it is the only entry to which we apply s-box. +// It seems to help the compiler if we introduce a different data structure for these layers. +// Note that we use this structure instead of a tuple so we can force the memory layout to align for transmutes. +#[derive(Clone, Copy)] +#[repr(C)] // This is needed to make `transmute`s safe. +pub struct InternalLayer16 { + s0: PackedMontyField31AVX512, + s_hi: [__m512i; 15], +} + +impl InternalLayer16 { + #[inline] + #[must_use] + /// Convert from `InternalLayer16` to `[PackedMontyField31AVX512; 16]` + /// + /// SAFETY: The caller must ensure that each element of `s_hi` represents a valid `MontyField31`. + /// In particular, each element of each vector must be in `[0, P)` (canonical form). + unsafe fn to_packed_field_array(self) -> [PackedMontyField31AVX512; 16] { + unsafe { + // Safety: It is up to the user to ensure that elements of `s_hi` represent valid + // `MontyField31` values. We must only reason about memory representations. + // As described in packing.rs, PackedMontyField31AVX512 can be transmuted to and from `__m512i`. + + // `InternalLayer16` is `repr(C)` so its memory layout looks like: + // `[PackedMontyField31AVX512, __m512i, ..., __m512i]` + // Thus as `__m512i` can be can be transmuted to `PackedMontyField31AVX512`, + // `InternalLayer16` can be transmuted to `[PackedMontyField31AVX512; 16]`. + transmute(self) + } + } + + #[inline] + #[must_use] + /// Convert from `[PackedMontyField31AVX512; 16]` to `InternalLayer16` + fn from_packed_field_array(vector: [PackedMontyField31AVX512; 16]) -> Self { + unsafe { + // Safety: As described in packing.rs, PackedMontyField31AVX512 can be transmuted to and from `__m512i`. + + // `InternalLayer16` is `repr(C)` so its memory layout looks like: + // `[PackedMontyField31AVX512, __m512i, ..., __m512i]` + // Thus as `PackedMontyField31AVX512` can be can be transmuted to `__m512i`, + // `[PackedMontyField31AVX512; 16]` can be transmuted to `InternalLayer16`. + transmute(vector) + } + } +} + +#[derive(Clone, Copy)] +#[repr(C)] // This is needed to make `transmute`s safe. +pub struct InternalLayer24 { + s0: PackedMontyField31AVX512, + s_hi: [__m512i; 23], +} + +impl InternalLayer24 { + #[inline] + #[must_use] + /// Convert from `InternalLayer24` to `[PackedMontyField31AVX512; 24]` + /// + /// SAFETY: The caller must ensure that each element of `s_hi` represents a valid `MontyField31`. + /// In particular, each element of each vector must be in `[0, P)` (canonical form). + unsafe fn to_packed_field_array(self) -> [PackedMontyField31AVX512; 24] { + unsafe { + // Safety: As described in packing.rs, PackedMontyField31AVX512 can be transmuted to and from `__m512i`. + + // `InternalLayer24` is `repr(C)` so its memory layout looks like: + // `[PackedMontyField31AVX512, __m512i, ..., __m512i]` + // Thus as `__m512i` can be can be transmuted to `PackedMontyField31AVX512`, + // `InternalLayer24` can be transmuted to `[PackedMontyField31AVX512; 24]`. + transmute(self) + } + } + + #[inline] + #[must_use] + /// Convert from `[PackedMontyField31AVX512; 24]` to `InternalLayer24` + fn from_packed_field_array(vector: [PackedMontyField31AVX512; 24]) -> Self { + unsafe { + // Safety: As described in packing.rs, PackedMontyField31AVX512 can be transmuted to and from `__m512i`. + + // `InternalLayer24` is `repr(C)` so its memory layout looks like: + // `[PackedMontyField31AVX512, __m512i, ..., __m512i]` + // Thus as `PackedMontyField31AVX512` can be can be transmuted to `__m512i`, + // `[PackedMontyField31AVX512; 24]` can be transmuted to `InternalLayer24`. + transmute(vector) + } + } +} + +/// The internal layers of the Poseidon2 permutation for Monty31 fields. +/// +/// The packed constants are stored in negative form as this allows some optimizations. +/// This means given a constant `x`, we treat it as an `i32` and +/// pack 16 copies of `x - P` into the corresponding `__m512i` packed constant. +#[derive(Debug, Clone)] +pub struct Poseidon2InternalLayerMonty31< + PMP: PackedMontyParameters, + const WIDTH: usize, + ILP: InternalLayerParametersAVX512, +> { + pub(crate) internal_constants: Vec>, + packed_internal_constants: Vec<__m512i>, + _phantom: PhantomData, +} + +impl> + InternalLayerConstructor> for Poseidon2InternalLayerMonty31 +{ + /// Construct an instance of Poseidon2InternalLayerMersenne31AVX2 from a vector containing + /// the constants for each round. Internally, the constants are transformed into the + /// {-P, ..., 0} representation instead of the standard {0, ..., P} one. + fn new_from_constants(internal_constants: Vec>) -> Self { + let packed_internal_constants = internal_constants + .iter() + .map(|constant| convert_to_vec_neg_form::(constant.value as i32)) + .collect(); + Self { + internal_constants, + packed_internal_constants, + _phantom: PhantomData, + } + } +} + +/// The external layers of the Poseidon2 permutation for Monty31 fields. +/// +/// The packed constants are stored in negative form as this allows some optimizations. +/// This means given a constant `x`, we treat it as an `i32` and +/// pack 16 copies of `x - P` into the corresponding `__m512i` packed constant. +#[derive(Debug, Clone)] +pub struct Poseidon2ExternalLayerMonty31 { + pub(crate) external_constants: ExternalLayerConstants, WIDTH>, + packed_initial_external_constants: Vec<[__m512i; WIDTH]>, + packed_terminal_external_constants: Vec<[__m512i; WIDTH]>, +} + +impl ExternalLayerConstructor, WIDTH> + for Poseidon2ExternalLayerMonty31 +{ + /// Construct an instance of Poseidon2ExternalLayerMersenne31AVX2 from an array of + /// vectors containing the constants for each round. Internally, the constants + /// are transformed into the {-P, ..., 0} representation instead of the standard {0, ..., P} one. + fn new_from_constants( + external_constants: ExternalLayerConstants, WIDTH>, + ) -> Self { + let packed_initial_external_constants = external_constants + .get_initial_constants() + .iter() + .map(|array| array.map(|constant| convert_to_vec_neg_form::(constant.value as i32))) + .collect(); + let packed_terminal_external_constants = external_constants + .get_terminal_constants() + .iter() + .map(|array| array.map(|constant| convert_to_vec_neg_form::(constant.value as i32))) + .collect(); + Self { + external_constants, + packed_initial_external_constants, + packed_terminal_external_constants, + } + } +} + +/// Use hard coded methods to compute `x -> x^D` for the even index entries and small `D`. +/// Inputs should be signed 32-bit integers in `[-P, ..., P]`. +/// Outputs will also be signed integers in `(-P, ..., P)` stored in the odd indices. +/// +/// # Panics +/// This function will panic if `D` is not `3, 5` or `7`. +#[inline(always)] +#[must_use] +fn exp_small(val: __m512i) -> __m512i { + match D { + 3 => packed_exp_3::(val), + 5 => packed_exp_5::(val), + 7 => packed_exp_7::(val), + _ => panic!("No exp function for given D"), + } +} + +/// Compute val -> (val + rc)^D. Each entry of val should be represented in canonical form. +/// Each entry of rc should be represented by an element in [-P, 0]. +/// Each entry of the output will be represented by an element in canonical form. +/// If the inputs do not conform to this representation, the result is undefined. +#[inline(always)] +fn add_rc_and_sbox( + val: &mut PackedMontyField31AVX512, + rc: __m512i, +) { + unsafe { + // As our exponential functions simply assume that + // the input lies in [-P, P] we do not need to perform a reduction provided + // rc is represented by an element in [-P, 0] + let vec_val = val.to_vector(); + let val_plus_rc = x86_64::_mm512_add_epi32(vec_val, rc); + let output = apply_func_to_even_odd::(val_plus_rc, exp_small::); + + *val = PackedMontyField31AVX512::::from_vector(output); + } +} + +/// A trait containing the specific information needed to +/// implement the Poseidon2 Permutation for Monty31 Fields. +pub trait InternalLayerParametersAVX512: + Clone + Sync +{ + type ArrayLike: AsMut<[__m512i]>; + + // diagonal_mul and add_sum morally should be one function but are split because diagonal_mul can happen simultaneously to + // the sbox being applied to the first element of the state which is advantageous as this s-box has very high latency. + // However these functions should only ever be used together and we only make safety guarantees about the output + // of the combined function add_sum(diagonal_mul(state), sum) which will output field elements + // in canonical form provided inputs are in canonical form. + + // For these reason we mark both functions as unsafe. + + // All 4 implementation of this trait (Field = BabyBear/KoalaBear, WIDTH = 16/24) have a similarly structured + // diagonal matrix. The first 9 elements of this matrix are: [-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4] and the remainder + // are all positive or negative inverse powers of two. This common structure lets us write some default implementations. + + /// # Safety + /// + /// This function assumes its output is piped directly into `add_sum`. + /// + /// It might not output field elements in canonical form and indeed may even + /// output incorrect values in places where it is efficient to correct for + /// the computation in `add_sum`. For example it might output `3*x` instead of `-3*x` + /// and have `add_sum` compute `sum - x` instead of `x + sum`. + #[inline(always)] + unsafe fn diagonal_mul(input: &mut Self::ArrayLike) { + unsafe { + Self::diagonal_mul_first_eight(input); + Self::diagonal_mul_remainder(input); + } + } + + /// # Safety + /// + /// Multiply the first 8 elements of input by the vector `[1, 2, 1/2, 3, 4, 1/2, 3, 4]`. + /// + /// In all implementations of this trait, the first 9 elements of the diagonal matrix are + /// `[-2, 1, 2, 1/2, 3, 4, -1/2, -3, -4]`. The -2 is handled separately and this function handles + /// the remainder. Note that for the last three elements we multiply by `1/2, 3, 4` and not + /// `-1/2, -3, -4`. Hence the value in this location will be the negative of what is desired. + /// This will be handled by `add_sum` and so it is important these elements are not touched + /// before input is passed into `add_sum`. + #[inline(always)] + unsafe fn diagonal_mul_first_eight(input: &mut Self::ArrayLike) { + let input = input.as_mut(); + // The first 5 elements should be multiplied by: 1, 2, 1/2, 3, 4 + + // input[0] is being multiplied by 1 so we ignore it. + + input[1] = add::(input[1], input[1]); + input[2] = halve_avx512::(input[2]); + + let acc3 = add::(input[3], input[3]); + input[3] = add::(acc3, input[3]); + + let acc4 = add::(input[4], input[4]); + input[4] = add::(acc4, acc4); + + // For the final 3 elements we multiply by 1/2, 3, 4. + // This gives the negative of the correct answer which + // will be handled by add_sum(). + + input[5] = halve_avx512::(input[5]); + + let acc6 = add::(input[6], input[6]); + input[6] = add::(acc6, input[6]); + + let acc7 = add::(input[7], input[7]); + input[7] = add::(acc7, acc7); + } + + /// # Safety + /// + /// This function must not touch the first 8 elements of input. + /// It may output values which are the negative of the expected + /// value in some places. This will be handled by `add_sum` so + /// it is important these elements are not touched + /// before input is passed into `add_sum`. + unsafe fn diagonal_mul_remainder(input: &mut Self::ArrayLike); + + /// The number of positive inverse powers of two in the diagonal matrix after the 4. + const NUM_POS: usize; + + /// # Safety + /// + /// Sum must be in canonical form and input must be exactly the output of `diagonal_mul`. + /// If either of these does not hold, the result is undefined. + /// + /// Morally this function is computing `x -> x + sum` however there are some places where + /// the output of `diagonal_mul` is the negative of the expected value. + /// It is the job of add_sum to correct for these irregularities. Where the output is negative + /// we compute `x -> sum - x` instead. + #[inline(always)] + unsafe fn add_sum(input: &mut Self::ArrayLike, sum: __m512i) { + // Diagonal mul multiplied these by 1, 2, 1/2, 3, 4 so we simply need to add the sum. + input.as_mut()[..5] + .iter_mut() + .for_each(|x| *x = add::(sum, *x)); + + // Diagonal mul multiplied these by 1/2, 3, 4 instead of -1/2, -3, -4 so we need to subtract instead of adding. + // Similarly we can only cheaply multiply by negative inverse powers of two so we also need to subtract for all + // the positive powers of two. + input.as_mut()[5..(8 + Self::NUM_POS)] + .iter_mut() + .for_each(|x| *x = sub::(sum, *x)); + + // Diagonal mul output a signed value in (-P, P) so we need to do a signed add. + // Note that signed add's parameters are not interchangeable. The first parameter must be positive. + input.as_mut()[8 + Self::NUM_POS..] + .iter_mut() + .for_each(|x| *x = add::(sum, *x)); + } +} + +/// Convert elements from canonical form [0, P) to a negative form in [-P, ..., 0) and copy into a vector. +#[inline(always)] +fn convert_to_vec_neg_form(input: i32) -> __m512i { + let input_sub_p = input - (MP::PRIME as i32); + unsafe { + // Safety: If this code got compiled then AVX512-F intrinsics are available. + x86_64::_mm512_set1_epi32(input_sub_p) + } +} + +impl InternalLayer, 16, D> + for Poseidon2InternalLayerMonty31 +where + FP: FieldParameters + RelativelyPrimePower, + ILP: InternalLayerParametersAVX512, +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [PackedMontyField31AVX512; 16]) { + unsafe { + // Safety: This return values in canonical form when given values in canonical form. + /* + Fix a vector v and let Diag(v) denote the diagonal matrix with diagonal given by v. + Additionally, let 1 denote the matrix with all elements equal to 1. + The internal layer consists of an sbox operation then a matrix multiplication by 1 + Diag(v). + Explicitly the internal layer consists of the following 2 operations: + + s0 -> (s0 + rc)^d + s -> (1 + Diag(v))s + + Note that this matrix multiplication can be implemented as: + sum = sum_i s_i + s_i -> sum + s_iv_i + + which is essentially how we implement it. + */ + + let mut internal_state = InternalLayer16::from_packed_field_array(*state); + + self.packed_internal_constants.iter().for_each(|&rc| { + add_rc_and_sbox::(&mut internal_state.s0, rc); // s0 -> (s0 + rc)^D + let sum_tail = PackedMontyField31AVX512::::sum_array::<15>(&transmute::< + [__m512i; 15], + [PackedMontyField31AVX512; 15], + >( + internal_state.s_hi, + )); // Get the sum of all elements other than s0. + ILP::diagonal_mul(&mut internal_state.s_hi); // si -> vi * si for all i > 0. + let sum = sum_tail + internal_state.s0; // Get the full sum. + internal_state.s0 = sum_tail - internal_state.s0; // s0 -> sum - 2*s0 = sum_tail - s0. + ILP::add_sum( + &mut internal_state.s_hi, + transmute::, __m512i>(sum), + ); // si -> si + sum for all i > 0. + }); + + // This transformation is safe as the above function returns elements + // in canonical form when given elements in canonical form. + *state = InternalLayer16::to_packed_field_array(internal_state); + } + } +} + +impl InternalLayer, 24, D> + for Poseidon2InternalLayerMonty31 +where + FP: FieldParameters, + ILP: InternalLayerParametersAVX512, +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [PackedMontyField31AVX512; 24]) { + unsafe { + // Safety: This return values in canonical form when given values in canonical form. + + /* + Fix a vector v and let Diag(v) denote the diagonal matrix with diagonal given by v. + Additionally, let 1 denote the matrix with all elements equal to 1. + The internal layer consists of an sbox operation then a matrix multiplication by 1 + Diag(v). + Explicitly the internal layer consists of the following 2 operations: + + s0 -> (s0 + rc)^d + s -> (1 + Diag(v))s + + Note that this matrix multiplication is implemented as: + sum = sum_i s_i + s_i -> sum + s_iv_i. + */ + + let mut internal_state = InternalLayer24::from_packed_field_array(*state); + + self.packed_internal_constants.iter().for_each(|&rc| { + add_rc_and_sbox::(&mut internal_state.s0, rc); // s0 -> (s0 + rc)^D + let sum_tail = PackedMontyField31AVX512::::sum_array::<23>(&transmute::< + [__m512i; 23], + [PackedMontyField31AVX512; 23], + >( + internal_state.s_hi, + )); // Get the sum of all elements other than s0. + ILP::diagonal_mul(&mut internal_state.s_hi); // si -> vi * si for all i > 0. + let sum = sum_tail + internal_state.s0; // Get the full sum. + internal_state.s0 = sum_tail - internal_state.s0; // s0 -> sum - 2*s0 = sum_tail - s0. + ILP::add_sum( + &mut internal_state.s_hi, + transmute::, __m512i>(sum), + ); // si -> si + sum for all i > 0. + }); + + // This transformation is safe as the above function returns elements + // in canonical form when given elements in canonical form. + *state = InternalLayer24::to_packed_field_array(internal_state); + } + } +} + +impl ExternalLayer, WIDTH, D> + for Poseidon2ExternalLayerMonty31 +where + FP: FieldParameters + RelativelyPrimePower, +{ + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [PackedMontyField31AVX512; WIDTH]) { + external_initial_permute_state( + state, + &self.packed_initial_external_constants, + add_rc_and_sbox::, + &MDSMat4, + ); + } + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [PackedMontyField31AVX512; WIDTH]) { + external_terminal_permute_state( + state, + &self.packed_terminal_external_constants, + add_rc_and_sbox::, + &MDSMat4, + ); + } +} diff --git a/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/utils.rs b/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/utils.rs new file mode 100644 index 000000000..261ab1ed7 --- /dev/null +++ b/CoqOfRust/plonky3/monty-31/src/x86_64_avx512/utils.rs @@ -0,0 +1,221 @@ +use core::arch::x86_64::{self, __m512i}; +use core::mem::transmute; + +use crate::{MontyParameters, PackedMontyParameters, TwoAdicData}; + +// Godbolt file showing that these all compile to the expected instructions. (Potentially plus a few memory ops): +// https://godbolt.org/z/dvW7r1zjj + +/// Halve a vector of Monty31 field elements in canonical form. +/// If the inputs are not in canonical form, the result is undefined. +#[inline(always)] +pub(crate) fn halve_avx512(input: __m512i) -> __m512i { + /* + We want this to compile to: + vptestmd least_bit, val, ONE + vpsrld res, val, 1 + vpaddd res{least_bit}, res, maybe_half + throughput: 2 cyc/vec + latency: 4 cyc + + Given an element val in [0, P), we want to compute val/2 mod P. + If val is even: val/2 mod P = val/2 = val >> 1. + If val is odd: val/2 mod P = (val + P)/2 = (val >> 1) + (P + 1)/2 + */ + unsafe { + // Safety: If this code got compiled then AVX2 intrinsics are available. + const ONE: __m512i = unsafe { transmute([1u32; 16]) }; + let half = x86_64::_mm512_set1_epi32((MP::PRIME as i32 + 1) / 2); // Compiler realises this is constant. + + let least_bit = x86_64::_mm512_test_epi32_mask(input, ONE); // Determine the parity of val. + let t = x86_64::_mm512_srli_epi32::<1>(input); + // This does nothing when least_bit = 1 and sets the corresponding entry to 0 when least_bit = 0 + x86_64::_mm512_mask_add_epi32(t, least_bit, t, half) + } +} + +/* + Write our prime P as r * 2^j + 1 for odd r. + The following functions implement x -> -2^{-N} x for varying N and output a value in (-P, P). + There is one approach which works provided N < 15 and r < 2^15. + Similarly, there is another approach which works when N = j and when r = 2^i - 1. + + These approaches rely on the same basic observation about multiplication by -2^{-N} which we present here. + The strategy for these products is to observe that -2^{-N} = r2^{j - N} mod P. + Hence given a field element x write it as x = x_lo + 2^N x_hi where x_lo < 2^N and x_hi <= r2^{j - N}. + Then -2^{-N} x = -x_hi + r2^{j - N} x_lo. + + Observe that if x_lo > 0, then x_hi < r2^{j - N}x_lo < P and so r2^{j - N} x_lo - x_hi is canonical. + On the other hand, if x_lo = 0 then the canonical result should be P - x_hi if x_hi > 0 and 0 otherwise. + + Using intrinsics we can efficiently output r2^{j - N} x_lo - x_hi if x_lo > 0 and P - x_hi if x_lo = 0. + Whilst this means the output will not be canonical and instead will lie in [0, P] this will be handled by + a separate function. + + It remains to understand how to efficiently compute r2^{j - N} x_lo. This splits into several cases: + + When r < 2^16, N < 15, r2^{j - N} x_lo can be computed efficiently using _mm512_madd_epi16. + This avoids having to split the input in two and doing multiple multiplications and/or monty reductions. + + There is a further improvement possible when if r < 2^7 and N = 8 using _mm512_maddubs_epi16. + This lets us avoid a mask and an and so we implement a specialised version for this. + + When n = j and r = 2^i - 1, rx_lo can also be computed efficiently using a shift and subtraction. +*/ + +/// Multiply a vector of Monty31 field elements in canonical form by -2**{-N}. +/// # Safety +/// +/// The prime P must be of the form P = r * 2^j + 1 with r odd and r < 2^15. +/// N must be between 0 and 15. +/// Input must be given in canonical form. +/// Output may not be in canonical form but will lie in [0, P]. +#[inline(always)] +pub unsafe fn mul_neg_2exp_neg_n_avx512< + TAD: TwoAdicData + PackedMontyParameters, + const N: u32, + const N_PRIME: u32, +>( + input: __m512i, +) -> __m512i { + /* + We want this to compile to: + mov lo_shft, P This can be a mov or a load. It will not affect throughput/latency. + vpsrld hi, val, N + vpandd lo, val, 2^N - 1 + vptestmd lo_MASK, val, 2^N - 1 + vpmaddwd lo_x_r, lo, [r; 16] + vpslld lo_shft{lo_MASK}, lo_x_r, j - N + vpsubd res, lo_shft, hi + throughput: 3 + latency: 9 + */ + unsafe { + assert_eq!(N + N_PRIME, TAD::TWO_ADICITY as u32); // Compiler removes this provided it is satisfied. + + let odd_factor = x86_64::_mm512_set1_epi32(TAD::ODD_FACTOR); // This is [r; 16]. Compiler realises this is a constant. + let mask = x86_64::_mm512_set1_epi32((1_i32 << N) - 1_i32); // Compiler realises this is a constant. + + let hi = x86_64::_mm512_srli_epi32::(input); + let lo = x86_64::_mm512_and_si512(input, mask); + + // Determine the non 0 values of lo. + let lo_mask = x86_64::_mm512_test_epi32_mask(input, mask); + + // Whilst it generically does something else, provided + // each entry of val_lo, odd_factor are < 2^15, _mm512_madd_epi16 + // performs an element wise multiplication. + // Thus lo_x_r contains lo * r. + let lo_x_r = x86_64::_mm512_madd_epi16(lo, odd_factor); + + // When lo = 0, lo_shft = P + // When lo > 0, lo_shft = r2^{j - N} x_lo + let lo_shft = x86_64::_mm512_mask_slli_epi32::(TAD::PACKED_P, lo_mask, lo_x_r); + + // As hi < r2^{j - N} < P, the output is always in [0, P]. It is equal to P only when input x = 0. + x86_64::_mm512_sub_epi32(lo_shft, hi) + } +} + +/// Multiply a vector of Monty31 field elements in canonical form by -2**{-8}. +/// # Safety +/// +/// The prime P must be of the form P = r * 2^j + 1 with r odd and r < 2^7. +/// Input must be given in canonical form. +/// Output is not in canonical form, outputs are only guaranteed to lie in (-P, P). +#[inline(always)] +pub unsafe fn mul_neg_2exp_neg_8_avx512< + TAD: TwoAdicData + PackedMontyParameters, + const N_PRIME: u32, +>( + input: __m512i, +) -> __m512i { + /* + We want this to compile to: + mov lo_shft, P This can be a mov or a load. It will not affect throughput/latency. + vpsrld hi, val, 8 + vptestmd lo_MASK, val, 2^8 - 1 + vpmaddubsw lo_x_r, val, [r; 16] + vpslld lo_shft{lo_MASK}, lo_x_r, j - 8 + vpsubd res, lo_shft, hi + throughput: 3 + latency: 7 + */ + unsafe { + assert_eq!(8 + N_PRIME, TAD::TWO_ADICITY as u32); // Compiler removes this provided it is satisfied. + + let odd_factor = x86_64::_mm512_set1_epi32(TAD::ODD_FACTOR); // This is [r; 16]. Compiler realises this is a constant. + let hi = x86_64::_mm512_srli_epi32::<8>(input); + + let mask = x86_64::_mm512_set1_epi32((1_i32 << 8) - 1_i32); // Compiler realises this is a constant. + + // Determine the non 0 values of lo. + let lo_mask = x86_64::_mm512_test_epi32_mask(input, mask); + + // Whilst it generically does something else, provided + // each entry of odd_factor is < 2^7, _mm512_maddubs_epi16 + // performs an element wise multiplication of odd_factor with + // the bottom 8 bits of input interpreted as an unsigned integer + // Thus lo_x_r contains lo * r. + let lo_x_r = x86_64::_mm512_maddubs_epi16(input, odd_factor); + + // When lo = 0, lo_shft = P + // When lo > 0, lo_shft = r2^{j - N} x_lo + let lo_shft = x86_64::_mm512_mask_slli_epi32::(TAD::PACKED_P, lo_mask, lo_x_r); + + // As hi < r2^{j - N} < P, the output is always in [0, P]. It is equal to P only when input x = 0. + x86_64::_mm512_sub_epi32(lo_shft, hi) + } +} + +/// Multiply a vector of Monty31 field elements in canonical form by -2**{-N} where P = 2^31 - 2^N + 1. +/// # Safety +/// +/// The prime P must have the form P = 2^31 - 2^N + 1. +/// Input must be given in canonical form. +/// Output is not in canonical form, outputs are only guaranteed to lie in (-P, P). +#[inline(always)] +pub unsafe fn mul_neg_2exp_neg_two_adicity_avx512< + TAD: TwoAdicData + PackedMontyParameters, + const N: u32, + const N_PRIME: u32, +>( + input: __m512i, +) -> __m512i { + /* + We want this to compile to: + vmovdqu32 lo_shft, P // This can be a mov or a load. It will not affect throughput/latency. + vpsrld hi, val, N + vpandd lo, val, 2^N - 1 + vptestmd lo_MASK, val, 2^N - 1 + vpslld lo_shft{lo_MASK}, lo, 31 - N + vpaddd lo_plus_hi, lo, hi + vpsubd res, lo_shft, lo_plus_hi + throughput: 3 + latency: 5 + */ + unsafe { + assert_eq!(N, (TAD::TWO_ADICITY as u32)); // Compiler removes this provided it is satisfied. + assert_eq!(N + N_PRIME, 31); // Compiler removes this provided it is satisfied. + + let mask = x86_64::_mm512_set1_epi32((1_i32 << N) - 1_i32); // Compiler realises this is a constant. + let hi = x86_64::_mm512_srli_epi32::(input); + + // Provided overflow does not occur, (2^{31 - N} - 1)*x = (x << {31 - N}) - 1. + // lo < 2^N => (lo << {31 - N}) < 2^31 and (lo << {31 - N}) - lo < P. + let lo = x86_64::_mm512_and_si512(input, mask); + + // Determine the non 0 values of lo. + let lo_mask = x86_64::_mm512_test_epi32_mask(input, mask); + + // When lo = 0, lo_shft = P + // When lo > 0, lo_shft = r x_lo + let lo_shft = x86_64::_mm512_mask_slli_epi32::(TAD::PACKED_P, lo_mask, lo); + + let lo_plus_hi = x86_64::_mm512_add_epi32(lo, hi); + + // When lo = 0, return P - hi + // When lo > 0 return r*lo - hi + x86_64::_mm512_sub_epi32(lo_shft, lo_plus_hi) + } +} diff --git a/CoqOfRust/plonky3/poseidon/src/lib.rs b/CoqOfRust/plonky3/poseidon/src/lib.rs new file mode 100644 index 000000000..91a15dbea --- /dev/null +++ b/CoqOfRust/plonky3/poseidon/src/lib.rs @@ -0,0 +1,146 @@ +//! The Poseidon permutation. + +#![no_std] + +extern crate alloc; + +use alloc::vec::Vec; + +use p3_field::{Algebra, InjectiveMonomial, PrimeField}; +use p3_mds::MdsPermutation; +use p3_symmetric::{CryptographicPermutation, Permutation}; +use rand::Rng; +use rand::distr::StandardUniform; +use rand::prelude::Distribution; + +/// The Poseidon permutation. +#[derive(Clone, Debug)] +pub struct Poseidon { + half_num_full_rounds: usize, + num_partial_rounds: usize, + constants: Vec, + mds: Mds, +} + +impl Poseidon +where + F: PrimeField + InjectiveMonomial, +{ + /// Create a new Poseidon configuration. + /// + /// # Panics + /// Number of constants must match WIDTH times `num_rounds`; panics otherwise. + pub fn new( + half_num_full_rounds: usize, + num_partial_rounds: usize, + constants: Vec, + mds: Mds, + ) -> Self { + let num_rounds = 2 * half_num_full_rounds + num_partial_rounds; + assert_eq!(constants.len(), WIDTH * num_rounds); + Self { + half_num_full_rounds, + num_partial_rounds, + constants, + mds, + } + } + + pub fn new_from_rng( + half_num_full_rounds: usize, + num_partial_rounds: usize, + mds: Mds, + rng: &mut R, + ) -> Self + where + StandardUniform: Distribution, + { + let num_rounds = 2 * half_num_full_rounds + num_partial_rounds; + let num_constants = WIDTH * num_rounds; + let constants = rng + .sample_iter(StandardUniform) + .take(num_constants) + .collect::>(); + Self { + half_num_full_rounds, + num_partial_rounds, + constants, + mds, + } + } + + fn half_full_rounds(&self, state: &mut [A; WIDTH], round_ctr: &mut usize) + where + A: Algebra + InjectiveMonomial, + Mds: MdsPermutation, + { + for _ in 0..self.half_num_full_rounds { + self.constant_layer(state, *round_ctr); + Self::full_sbox_layer(state); + self.mds.permute_mut(state); + *round_ctr += 1; + } + } + + fn partial_rounds(&self, state: &mut [A; WIDTH], round_ctr: &mut usize) + where + A: Algebra + InjectiveMonomial, + Mds: MdsPermutation, + { + for _ in 0..self.num_partial_rounds { + self.constant_layer(state, *round_ctr); + Self::partial_sbox_layer(state); + self.mds.permute_mut(state); + *round_ctr += 1; + } + } + + fn full_sbox_layer(state: &mut [A; WIDTH]) + where + A: Algebra + InjectiveMonomial, + { + for x in state.iter_mut() { + *x = x.injective_exp_n(); + } + } + + fn partial_sbox_layer(state: &mut [A; WIDTH]) + where + A: Algebra + InjectiveMonomial, + { + state[0] = state[0].injective_exp_n(); + } + + fn constant_layer(&self, state: &mut [A; WIDTH], round: usize) + where + A: Algebra, + { + for (i, x) in state.iter_mut().enumerate() { + *x += self.constants[round * WIDTH + i]; + } + } +} + +impl Permutation<[A; WIDTH]> + for Poseidon +where + F: PrimeField + InjectiveMonomial, + A: Algebra + InjectiveMonomial, + Mds: MdsPermutation, +{ + fn permute_mut(&self, state: &mut [A; WIDTH]) { + let mut round_ctr = 0; + self.half_full_rounds(state, &mut round_ctr); + self.partial_rounds(state, &mut round_ctr); + self.half_full_rounds(state, &mut round_ctr); + } +} + +impl CryptographicPermutation<[A; WIDTH]> + for Poseidon +where + F: PrimeField + InjectiveMonomial, + A: Algebra + InjectiveMonomial, + Mds: MdsPermutation, +{ +} diff --git a/CoqOfRust/plonky3/poseidon/src/lib.v b/CoqOfRust/plonky3/poseidon/src/lib.v new file mode 100644 index 000000000..528b6e48d --- /dev/null +++ b/CoqOfRust/plonky3/poseidon/src/lib.v @@ -0,0 +1,1613 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +(* StructRecord + { + name := "Poseidon"; + const_params := [ "WIDTH"; "ALPHA" ]; + ty_params := [ "F"; "Mds" ]; + fields := + [ + ("half_num_full_rounds", Ty.path "usize"); + ("num_partial_rounds", Ty.path "usize"); + ("constants", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]); + ("mds", Mds) + ]; + } *) + +Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_Mds_for_p3_poseidon_Poseidon_WIDTH_ALPHA_F_Mds. + Definition Self (WIDTH ALPHA : Value.t) (F Mds : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon::Poseidon") [ WIDTH; ALPHA ] [ F; Mds ]. + + (* Clone *) + Definition clone + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_poseidon::Poseidon" + [ + ("half_num_full_rounds", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "half_num_full_rounds" + |) + |) + |) + |) + ] + |)); + ("num_partial_rounds", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "num_partial_rounds" + |) + |) + |) + |) + ] + |)); + ("constants", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "constants" + |) + |) + |) + |) + ] + |)); + ("mds", + M.call_closure (| + Mds, + M.get_trait_method (| "core::clone::Clone", Mds, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "mds" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH ALPHA F Mds) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH ALPHA F Mds)) ]. +End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_Mds_for_p3_poseidon_Poseidon_WIDTH_ALPHA_F_Mds. + +Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_Mds_for_p3_poseidon_Poseidon_WIDTH_ALPHA_F_Mds. + Definition Self (WIDTH ALPHA : Value.t) (F Mds : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon::Poseidon") [ WIDTH; ALPHA ] [ F; Mds ]. + + (* Debug *) + Definition fmt + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field4_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Poseidon" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "half_num_full_rounds" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "half_num_full_rounds" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "num_partial_rounds" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "num_partial_rounds" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "constants" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "constants" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "mds" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "mds" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH ALPHA F Mds) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH ALPHA F Mds)) ]. +End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_Mds_for_p3_poseidon_Poseidon_WIDTH_ALPHA_F_Mds. + +Module Impl_p3_poseidon_Poseidon_WIDTH_ALPHA_F_Mds. + Definition Self (WIDTH ALPHA : Value.t) (F Mds : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon::Poseidon") [ WIDTH; ALPHA ] [ F; Mds ]. + + (* + pub fn new( + half_num_full_rounds: usize, + num_partial_rounds: usize, + constants: Vec, + mds: Mds, + ) -> Self { + let num_rounds = 2 * half_num_full_rounds + num_partial_rounds; + assert_eq!(constants.len(), WIDTH * num_rounds); + Self { + half_num_full_rounds, + num_partial_rounds, + constants, + mds, + } + } + *) + Definition new + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [], [ half_num_full_rounds; num_partial_rounds; constants; mds ] => + ltac:(M.monadic + (let half_num_full_rounds := M.alloc (| half_num_full_rounds |) in + let num_partial_rounds := M.alloc (| num_partial_rounds |) in + let constants := M.alloc (| constants |) in + let mds := M.alloc (| mds |) in + M.read (| + let~ num_rounds : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| half_num_full_rounds |) ] + |); + M.read (| num_partial_rounds |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, constants |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ WIDTH; M.read (| num_rounds |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| + Value.StructRecord + "p3_poseidon::Poseidon" + [ + ("half_num_full_rounds", M.read (| half_num_full_rounds |)); + ("num_partial_rounds", M.read (| num_partial_rounds |)); + ("constants", M.read (| constants |)); + ("mds", M.read (| mds |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH ALPHA F Mds) "new" (new WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn new_from_rng( + half_num_full_rounds: usize, + num_partial_rounds: usize, + mds: Mds, + rng: &mut R, + ) -> Self + where + StandardUniform: Distribution, + { + let num_rounds = 2 * half_num_full_rounds + num_partial_rounds; + let num_constants = WIDTH * num_rounds; + let constants = rng + .sample_iter(StandardUniform) + .take(num_constants) + .collect::>(); + Self { + half_num_full_rounds, + num_partial_rounds, + constants, + mds, + } + } + *) + Definition new_from_rng + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [ R ], [ half_num_full_rounds; num_partial_rounds; mds; rng ] => + ltac:(M.monadic + (let half_num_full_rounds := M.alloc (| half_num_full_rounds |) in + let num_partial_rounds := M.alloc (| num_partial_rounds |) in + let mds := M.alloc (| mds |) in + let rng := M.alloc (| rng |) in + M.read (| + let~ num_rounds : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| half_num_full_rounds |) ] + |); + M.read (| num_partial_rounds |) + ] + |) + |) in + let~ num_constants : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ WIDTH; M.read (| num_rounds |) ] + |) + |) in + let~ constants : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ] + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.apply (Ty.path "&mut") [] [ R ], + [], + [], + "sample_iter", + [], + [ F; Ty.path "rand::distr::StandardUniform" ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |); + Value.StructTuple "rand::distr::StandardUniform" [] + ] + |); + M.read (| num_constants |) + ] + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_poseidon::Poseidon" + [ + ("half_num_full_rounds", M.read (| half_num_full_rounds |)); + ("num_partial_rounds", M.read (| num_partial_rounds |)); + ("constants", M.read (| constants |)); + ("mds", M.read (| mds |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_from_rng : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH ALPHA F Mds) + "new_from_rng" + (new_from_rng WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque new_from_rng. + + (* + fn half_full_rounds(&self, state: &mut [A; WIDTH], round_ctr: &mut usize) + where + A: Algebra + InjectiveMonomial, + Mds: MdsPermutation, + { + for _ in 0..self.half_num_full_rounds { + self.constant_layer(state, *round_ctr); + Self::full_sbox_layer(state); + self.mds.permute_mut(state); + *round_ctr += 1; + } + } + *) + Definition half_full_rounds + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [ A ], [ self; state; round_ctr ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + let round_ctr := M.alloc (| round_ctr |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "half_num_full_rounds" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon::Poseidon") + [ WIDTH; ALPHA ] + [ F; Mds ], + "constant_layer", + [], + [ A ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |); + M.read (| M.deref (| M.read (| round_ctr |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon::Poseidon") + [ WIDTH; ALPHA ] + [ F; Mds ], + "full_sbox_layer", + [], + [ A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Mds, + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ A ] ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "mds" + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := M.deref (| M.read (| round_ctr |) |) in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_half_full_rounds : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH ALPHA F Mds) + "half_full_rounds" + (half_full_rounds WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque half_full_rounds. + + (* + fn partial_rounds(&self, state: &mut [A; WIDTH], round_ctr: &mut usize) + where + A: Algebra + InjectiveMonomial, + Mds: MdsPermutation, + { + for _ in 0..self.num_partial_rounds { + self.constant_layer(state, *round_ctr); + Self::partial_sbox_layer(state); + self.mds.permute_mut(state); + *round_ctr += 1; + } + } + *) + Definition partial_rounds + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [ A ], [ self; state; round_ctr ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + let round_ctr := M.alloc (| round_ctr |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "num_partial_rounds" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon::Poseidon") + [ WIDTH; ALPHA ] + [ F; Mds ], + "constant_layer", + [], + [ A ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |); + M.read (| M.deref (| M.read (| round_ctr |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon::Poseidon") + [ WIDTH; ALPHA ] + [ F; Mds ], + "partial_sbox_layer", + [], + [ A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Mds, + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ A ] ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "mds" + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := M.deref (| M.read (| round_ctr |) |) in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_partial_rounds : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH ALPHA F Mds) + "partial_rounds" + (partial_rounds WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque partial_rounds. + + (* + fn full_sbox_layer(state: &mut [A; WIDTH]) + where + A: Algebra + InjectiveMonomial, + { + for x in state.iter_mut() { + *x = x.injective_exp_n(); + } + } + *) + Definition full_sbox_layer + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [ A ], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&mut") [] [ A ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| x |) |), + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::InjectiveMonomial", + A, + [ ALPHA ], + [], + "injective_exp_n", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x |) |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_full_sbox_layer : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH ALPHA F Mds) + "full_sbox_layer" + (full_sbox_layer WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque full_sbox_layer. + + (* + fn partial_sbox_layer(state: &mut [A; WIDTH]) + where + A: Algebra + InjectiveMonomial, + { + state[0] = state[0].injective_exp_n(); + } + *) + Definition partial_sbox_layer + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [ A ], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::InjectiveMonomial", + A, + [ ALPHA ], + [], + "injective_exp_n", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_partial_sbox_layer : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH ALPHA F Mds) + "partial_sbox_layer" + (partial_sbox_layer WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque partial_sbox_layer. + + (* + fn constant_layer(&self, state: &mut [A; WIDTH], round: usize) + where + A: Algebra, + { + for (i, x) in state.iter_mut().enumerate() { + *x += self.constants[round * WIDTH + i]; + } + } + *) + Definition constant_layer + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [ A ], [ self; state; round ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + let round := M.alloc (| round |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |)) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.apply (Ty.path "&mut") [] [ A ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ A ] ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let i := M.copy (| γ1_0 |) in + let x := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + A, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| x |) |) + |); + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ F ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon::Poseidon", + "constants" + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| round |); WIDTH ] + |); + M.read (| i |) + ] + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_constant_layer : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH ALPHA F Mds) + "constant_layer" + (constant_layer WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque constant_layer. +End Impl_p3_poseidon_Poseidon_WIDTH_ALPHA_F_Mds. + +Module Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_PrimeField_F_where_p3_field_field_InjectiveMonomial_F_where_p3_field_field_Algebra_A_F_where_p3_field_field_InjectiveMonomial_A_where_p3_mds_MdsPermutation_Mds_A_array_WIDTH_A_for_p3_poseidon_Poseidon_WIDTH_ALPHA_F_Mds. + Definition Self (WIDTH ALPHA : Value.t) (F A Mds : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon::Poseidon") [ WIDTH; ALPHA ] [ F; Mds ]. + + (* + fn permute_mut(&self, state: &mut [A; WIDTH]) { + let mut round_ctr = 0; + self.half_full_rounds(state, &mut round_ctr); + self.partial_rounds(state, &mut round_ctr); + self.half_full_rounds(state, &mut round_ctr); + } + *) + Definition permute_mut + (WIDTH ALPHA : Value.t) + (F A Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F A Mds in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ round_ctr : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_poseidon::Poseidon") [ WIDTH; ALPHA ] [ F; Mds ], + "half_full_rounds", + [], + [ A ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, round_ctr |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_poseidon::Poseidon") [ WIDTH; ALPHA ] [ F; Mds ], + "partial_rounds", + [], + [ A ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, round_ctr |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "p3_poseidon::Poseidon") [ WIDTH; ALPHA ] [ F; Mds ], + "half_full_rounds", + [], + [ A ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, round_ctr |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH ALPHA : Value.t) (F A Mds : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ WIDTH ] [ A ] ] + (Self WIDTH ALPHA F A Mds) + (* Instance *) [ ("permute_mut", InstanceField.Method (permute_mut WIDTH ALPHA F A Mds)) ]. +End Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_PrimeField_F_where_p3_field_field_InjectiveMonomial_F_where_p3_field_field_Algebra_A_F_where_p3_field_field_InjectiveMonomial_A_where_p3_mds_MdsPermutation_Mds_A_array_WIDTH_A_for_p3_poseidon_Poseidon_WIDTH_ALPHA_F_Mds. + +Module Impl_p3_symmetric_permutation_CryptographicPermutation_where_p3_field_field_PrimeField_F_where_p3_field_field_InjectiveMonomial_F_where_p3_field_field_Algebra_A_F_where_p3_field_field_InjectiveMonomial_A_where_p3_mds_MdsPermutation_Mds_A_array_WIDTH_A_for_p3_poseidon_Poseidon_WIDTH_ALPHA_F_Mds. + Definition Self (WIDTH ALPHA : Value.t) (F A Mds : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon::Poseidon") [ WIDTH; ALPHA ] [ F; Mds ]. + + Axiom Implements : + forall (WIDTH ALPHA : Value.t) (F A Mds : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::CryptographicPermutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ WIDTH ] [ A ] ] + (Self WIDTH ALPHA F A Mds) + (* Instance *) []. +End Impl_p3_symmetric_permutation_CryptographicPermutation_where_p3_field_field_PrimeField_F_where_p3_field_field_InjectiveMonomial_F_where_p3_field_field_Algebra_A_F_where_p3_field_field_InjectiveMonomial_A_where_p3_mds_MdsPermutation_Mds_A_array_WIDTH_A_for_p3_poseidon_Poseidon_WIDTH_ALPHA_F_Mds. diff --git a/CoqOfRust/plonky3/poseidon2-air/src/air.rs b/CoqOfRust/plonky3/poseidon2-air/src/air.rs new file mode 100644 index 000000000..d34ffb34e --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/air.rs @@ -0,0 +1,288 @@ +use core::borrow::Borrow; +use core::marker::PhantomData; + +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{Field, PrimeCharacteristicRing, PrimeField}; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_poseidon2::GenericPoseidon2LinearLayers; +use rand::distr::{Distribution, StandardUniform}; +use rand::rngs::SmallRng; +use rand::{Rng, SeedableRng}; + +use crate::columns::{Poseidon2Cols, num_cols}; +use crate::constants::RoundConstants; +use crate::{FullRound, PartialRound, SBox, generate_trace_rows}; + +/// Assumes the field size is at least 16 bits. +#[derive(Debug)] +pub struct Poseidon2Air< + F: Field, + LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +> { + pub(crate) constants: RoundConstants, + _phantom: PhantomData, +} + +impl< + F: Field, + LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +> + Poseidon2Air< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + > +{ + pub const fn new( + constants: RoundConstants, + ) -> Self { + Self { + constants, + _phantom: PhantomData, + } + } + + pub fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + StandardUniform: Distribution<[F; WIDTH]>, + { + let mut rng = SmallRng::seed_from_u64(1); + let inputs = (0..num_hashes).map(|_| rng.random()).collect(); + generate_trace_rows::< + _, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >(inputs, &self.constants, extra_capacity_bits) + } +} + +impl< + F: Field, + LinearLayers: Sync, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +> BaseAir + for Poseidon2Air< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + > +{ + fn width(&self) -> usize { + num_cols::() + } +} + +pub(crate) fn eval< + AB: AirBuilder, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +>( + air: &Poseidon2Air< + AB::F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >, + builder: &mut AB, + local: &Poseidon2Cols< + AB::Var, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >, +) { + let mut state: [_; WIDTH] = local.inputs.map(|x| x.into()); + + LinearLayers::external_linear_layer(&mut state); + + for round in 0..HALF_FULL_ROUNDS { + eval_full_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, + &local.beginning_full_rounds[round], + &air.constants.beginning_full_round_constants[round], + builder, + ); + } + + for round in 0..PARTIAL_ROUNDS { + eval_partial_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, + &local.partial_rounds[round], + &air.constants.partial_round_constants[round], + builder, + ); + } + + for round in 0..HALF_FULL_ROUNDS { + eval_full_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, + &local.ending_full_rounds[round], + &air.constants.ending_full_round_constants[round], + builder, + ); + } +} + +impl< + AB: AirBuilder, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +> Air + for Poseidon2Air< + AB::F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + > +{ + #[inline] + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let local = (*local).borrow(); + + eval::<_, _, WIDTH, SBOX_DEGREE, SBOX_REGISTERS, HALF_FULL_ROUNDS, PARTIAL_ROUNDS>( + self, builder, local, + ); + } +} + +#[inline] +fn eval_full_round< + AB: AirBuilder, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, +>( + state: &mut [AB::Expr; WIDTH], + full_round: &FullRound, + round_constants: &[AB::F; WIDTH], + builder: &mut AB, +) { + for (i, (s, r)) in state.iter_mut().zip(round_constants.iter()).enumerate() { + *s += *r; + eval_sbox(&full_round.sbox[i], s, builder); + } + LinearLayers::external_linear_layer(state); + for (state_i, post_i) in state.iter_mut().zip(full_round.post) { + builder.assert_eq(state_i.clone(), post_i); + *state_i = post_i.into(); + } +} + +#[inline] +fn eval_partial_round< + AB: AirBuilder, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, +>( + state: &mut [AB::Expr; WIDTH], + partial_round: &PartialRound, + round_constant: &AB::F, + builder: &mut AB, +) { + state[0] += *round_constant; + eval_sbox(&partial_round.sbox, &mut state[0], builder); + + builder.assert_eq(state[0].clone(), partial_round.post_sbox); + state[0] = partial_round.post_sbox.into(); + + LinearLayers::internal_linear_layer(state); +} + +/// Evaluates the S-box over a degree-1 expression `x`. +/// +/// # Panics +/// +/// This method panics if the number of `REGISTERS` is not chosen optimally for the given +/// `DEGREE` or if the `DEGREE` is not supported by the S-box. The supported degrees are +/// `3`, `5`, `7`, and `11`. +#[inline] +fn eval_sbox( + sbox: &SBox, + x: &mut AB::Expr, + builder: &mut AB, +) where + AB: AirBuilder, +{ + *x = match (DEGREE, REGISTERS) { + (3, 0) => x.cube(), + (5, 0) => x.exp_const_u64::<5>(), + (7, 0) => x.exp_const_u64::<7>(), + (5, 1) => { + let committed_x3 = sbox.0[0].into(); + let x2 = x.square(); + builder.assert_eq(committed_x3.clone(), x2.clone() * x.clone()); + committed_x3 * x2 + } + (7, 1) => { + let committed_x3 = sbox.0[0].into(); + builder.assert_eq(committed_x3.clone(), x.cube()); + committed_x3.square() * x.clone() + } + (11, 2) => { + let committed_x3 = sbox.0[0].into(); + let committed_x9 = sbox.0[1].into(); + let x2 = x.square(); + builder.assert_eq(committed_x3.clone(), x2.clone() * x.clone()); + builder.assert_eq(committed_x9.clone(), committed_x3.cube()); + committed_x9 * x2 + } + _ => panic!( + "Unexpected (DEGREE, REGISTERS) of ({}, {})", + DEGREE, REGISTERS + ), + } +} diff --git a/CoqOfRust/plonky3/poseidon2-air/src/air.v b/CoqOfRust/plonky3/poseidon2-air/src/air.v new file mode 100644 index 000000000..cd7cc7ad9 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/air.v @@ -0,0 +1,3025 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module air. + (* StructRecord + { + name := "Poseidon2Air"; + const_params := + [ "WIDTH"; "SBOX_DEGREE"; "SBOX_REGISTERS"; "HALF_FULL_ROUNDS"; "PARTIAL_ROUNDS" ]; + ty_params := [ "F"; "LinearLayers" ]; + fields := + [ + ("constants", + Ty.apply + (Ty.path "p3_poseidon2_air::constants::RoundConstants") + [ WIDTH; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F ]); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ LinearLayers ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_where_core_fmt_Debug_LinearLayers_for_p3_poseidon2_air_air_Poseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::air::Poseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F; LinearLayers ]. + + (* Debug *) + Definition fmt + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS F LinearLayers in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Poseidon2Air" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "constants" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::air::Poseidon2Air", + "constants" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::air::Poseidon2Air", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS F LinearLayers) + (* Instance *) + [ + ("fmt", + InstanceField.Method + (fmt WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS F LinearLayers)) + ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_where_core_fmt_Debug_LinearLayers_for_p3_poseidon2_air_air_Poseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F_LinearLayers. + + Module Impl_p3_poseidon2_air_air_Poseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::air::Poseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F; LinearLayers ]. + + (* + pub const fn new( + constants: RoundConstants, + ) -> Self { + Self { + constants, + _phantom: PhantomData, + } + } + *) + Definition new + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS F LinearLayers in + match ε, τ, α with + | [], [], [ constants ] => + ltac:(M.monadic + (let constants := M.alloc (| constants |) in + Value.StructRecord + "p3_poseidon2_air::air::Poseidon2Air" + [ + ("constants", M.read (| constants |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS F LinearLayers) + "new" + (new WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS F LinearLayers). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn generate_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + StandardUniform: Distribution<[F; WIDTH]>, + { + let mut rng = SmallRng::seed_from_u64(1); + let inputs = (0..num_hashes).map(|_| rng.random()).collect(); + generate_trace_rows::< + _, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >(inputs, &self.constants, extra_capacity_bits) + } + *) + Definition generate_trace_rows + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS F LinearLayers in + match ε, τ, α with + | [], [], [ self; num_hashes; extra_capacity_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_hashes := M.alloc (| num_hashes |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ inputs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| num_hashes |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ F ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_function (| + "p3_poseidon2_air::generation::generate_trace_rows", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ], + [ F; LinearLayers ] + |), + [ + M.read (| inputs |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::air::Poseidon2Air", + "constants" + |) + |) + |) + |); + M.read (| extra_capacity_bits |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_generate_trace_rows : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS F LinearLayers) + "generate_trace_rows" + (generate_trace_rows + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + F + LinearLayers). + Admitted. + Global Typeclasses Opaque generate_trace_rows. + End Impl_p3_poseidon2_air_air_Poseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F_LinearLayers. + + Module Impl_p3_air_air_BaseAir_where_p3_field_field_Field_F_where_core_marker_Sync_LinearLayers_F_for_p3_poseidon2_air_air_Poseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::air::Poseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F; LinearLayers ]. + + (* + fn width(&self) -> usize { + num_cols::() + } + *) + Definition width + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS F LinearLayers in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_poseidon2_air::columns::num_cols", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ], + [] + |), + [] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F LinearLayers : Ty.t), + M.IsTraitInstance + "p3_air::air::BaseAir" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS F LinearLayers) + (* Instance *) + [ + ("width", + InstanceField.Method + (width + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + F + LinearLayers)) + ]. + End Impl_p3_air_air_BaseAir_where_p3_field_field_Field_F_where_core_marker_Sync_LinearLayers_F_for_p3_poseidon2_air_air_Poseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F_LinearLayers. + + (* + pub(crate) fn eval< + AB: AirBuilder, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + >( + air: &Poseidon2Air< + AB::F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >, + builder: &mut AB, + local: &Poseidon2Cols< + AB::Var, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >, + ) { + let mut state: [_; WIDTH] = local.inputs.map(|x| x.into()); + + LinearLayers::external_linear_layer(&mut state); + + for round in 0..HALF_FULL_ROUNDS { + eval_full_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, + &local.beginning_full_rounds[round], + &air.constants.beginning_full_round_constants[round], + builder, + ); + } + + for round in 0..PARTIAL_ROUNDS { + eval_partial_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, + &local.partial_rounds[round], + &air.constants.partial_round_constants[round], + builder, + ); + } + + for round in 0..HALF_FULL_ROUNDS { + eval_full_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, + &local.ending_full_rounds[round], + &air.constants.ending_full_round_constants[round], + builder, + ); + } + } + *) + Definition eval (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ], + [ AB; LinearLayers ], + [ air; builder; local ] => + ltac:(M.monadic + (let air := M.alloc (| air |) in + let builder := M.alloc (| builder |) in + let local := M.alloc (| local |) in + M.read (| + let~ state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + M.get_associated_function (| + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "map", + [], + [ + Ty.function + [ Ty.tuple [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"); + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_poseidon2_air::columns::Poseidon2Cols", + "inputs" + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + (Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ M.read (| x |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_poseidon2::generic::GenericPoseidon2LinearLayers", + LinearLayers, + [ WIDTH ], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "external_linear_layer", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", HALF_FULL_ROUNDS) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let round := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::air::eval_full_round", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ], + [ AB; LinearLayers ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, state |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_poseidon2_air::columns::Poseidon2Cols", + "beginning_full_rounds" + |), + M.read (| round |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| air |) |), + "p3_poseidon2_air::air::Poseidon2Air", + "constants" + |), + "p3_poseidon2_air::constants::RoundConstants", + "beginning_full_round_constants" + |), + M.read (| round |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", PARTIAL_ROUNDS) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let round := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::air::eval_partial_round", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ], + [ AB; LinearLayers ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, state |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_poseidon2_air::columns::Poseidon2Cols", + "partial_rounds" + |), + M.read (| round |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| air |) |), + "p3_poseidon2_air::air::Poseidon2Air", + "constants" + |), + "p3_poseidon2_air::constants::RoundConstants", + "partial_round_constants" + |), + M.read (| round |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", HALF_FULL_ROUNDS) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let round := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::air::eval_full_round", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ], + [ AB; LinearLayers ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_poseidon2_air::columns::Poseidon2Cols", + "ending_full_rounds" + |), + M.read (| round |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| air |) |), + "p3_poseidon2_air::air::Poseidon2Air", + "constants" + |), + "p3_poseidon2_air::constants::RoundConstants", + "ending_full_round_constants" + |), + M.read (| round |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_eval : M.IsFunction.C "p3_poseidon2_air::air::eval" eval. + Admitted. + Global Typeclasses Opaque eval. + + Module Impl_p3_air_air_Air_where_p3_air_air_AirBuilder_AB_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_air_air_AirBuilder___AB_Expr_AB_for_p3_poseidon2_air_air_Poseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_associated_in_trait_p3_air_air_AirBuilder___AB_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (AB LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::air::Poseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F"; LinearLayers ]. + + (* + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let local = ( *local).borrow(); + + eval::<_, _, WIDTH, SBOX_DEGREE, SBOX_REGISTERS, HALF_FULL_ROUNDS, PARTIAL_ROUNDS>( + self, builder, local, + ); + } + *) + Definition eval + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (AB LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS AB LinearLayers in + match ε, τ, α with + | [], [], [ self; builder ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let builder := M.alloc (| builder |) in + M.read (| + let~ main : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + M.get_trait_method (| "p3_air::air::AirBuilder", AB, [], [], "main", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| builder |) |) |) ] + |) + |) in + let~ local : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "row_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, main |); Value.Integer IntegerKind.Usize 0 ] + |) + |) in + let~ local : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, local |) ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::air::eval", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ], + [ AB; LinearLayers ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| local |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (AB LinearLayers : Ty.t), + M.IsTraitInstance + "p3_air::air::Air" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ AB ] + (Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS AB LinearLayers) + (* Instance *) + [ + ("eval", + InstanceField.Method + (eval + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + AB + LinearLayers)) + ]. + End Impl_p3_air_air_Air_where_p3_air_air_AirBuilder_AB_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_air_air_AirBuilder___AB_Expr_AB_for_p3_poseidon2_air_air_Poseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_associated_in_trait_p3_air_air_AirBuilder___AB_F_LinearLayers. + + (* + fn eval_full_round< + AB: AirBuilder, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + >( + state: &mut [AB::Expr; WIDTH], + full_round: &FullRound, + round_constants: &[AB::F; WIDTH], + builder: &mut AB, + ) { + for (i, (s, r)) in state.iter_mut().zip(round_constants.iter()).enumerate() { + *s += *r; + eval_sbox(&full_round.sbox[i], s, builder); + } + LinearLayers::external_linear_layer(state); + for (state_i, post_i) in state.iter_mut().zip(full_round.post) { + builder.assert_eq(state_i.clone(), post_i); + *state_i = post_i.into(); + } + } + *) + Definition eval_full_round (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ], + [ AB; LinearLayers ], + [ state; full_round; round_constants; builder ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let full_round := M.alloc (| full_round |) in + let round_constants := M.alloc (| round_constants |) in + let builder := M.alloc (| builder |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F" ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F" ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F" + ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| round_constants |) |) + |)) + ] + |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "F" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "F" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let i := M.copy (| γ1_0 |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ1_1, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ1_1, 1 |) in + let s := M.copy (| γ2_0 |) in + let r := M.copy (| γ2_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "F" + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| s |) |) + |); + M.read (| M.deref (| M.read (| r |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::air::eval_sbox", + [ SBOX_DEGREE; SBOX_REGISTERS ], + [ AB ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| full_round |) |), + "p3_poseidon2_air::columns::FullRound", + "sbox" + |), + M.read (| i |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| s |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_poseidon2::generic::GenericPoseidon2LinearLayers", + LinearLayers, + [ WIDTH ], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "external_linear_layer", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ WIDTH ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ WIDTH ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ WIDTH ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |)) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| full_round |) |), + "p3_poseidon2_air::columns::FullRound", + "post" + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ]; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ WIDTH ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let state_i := M.copy (| γ1_0 |) in + let post_i := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr"; + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| state_i |) |) + |) + ] + |); + M.read (| post_i |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| state_i |) |), + M.call_closure (| + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var", + [], + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr" + ], + "into", + [], + [] + |), + [ M.read (| post_i |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_eval_full_round : + M.IsFunction.C "p3_poseidon2_air::air::eval_full_round" eval_full_round. + Admitted. + Global Typeclasses Opaque eval_full_round. + + (* + fn eval_partial_round< + AB: AirBuilder, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + >( + state: &mut [AB::Expr; WIDTH], + partial_round: &PartialRound, + round_constant: &AB::F, + builder: &mut AB, + ) { + state[0] += *round_constant; + eval_sbox(&partial_round.sbox, &mut state[0], builder); + + builder.assert_eq(state[0].clone(), partial_round.post_sbox); + state[0] = partial_round.post_sbox.into(); + + LinearLayers::internal_linear_layer(state); + } + *) + Definition eval_partial_round (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ], + [ AB; LinearLayers ], + [ state; partial_round; round_constant; builder ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let partial_round := M.alloc (| partial_round |) in + let round_constant := M.alloc (| round_constant |) in + let builder := M.alloc (| builder |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F" ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| M.deref (| M.read (| round_constant |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::air::eval_sbox", + [ SBOX_DEGREE; SBOX_REGISTERS ], + [ AB ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| partial_round |) |), + "p3_poseidon2_air::columns::PartialRound", + "sbox" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| partial_round |) |), + "p3_poseidon2_air::columns::PartialRound", + "post_sbox" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| partial_round |) |), + "p3_poseidon2_air::columns::PartialRound", + "post_sbox" + |) + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_poseidon2::generic::GenericPoseidon2LinearLayers", + LinearLayers, + [ WIDTH ], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "internal_linear_layer", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_eval_partial_round : + M.IsFunction.C "p3_poseidon2_air::air::eval_partial_round" eval_partial_round. + Admitted. + Global Typeclasses Opaque eval_partial_round. + + (* + fn eval_sbox( + sbox: &SBox, + x: &mut AB::Expr, + builder: &mut AB, + ) where + AB: AirBuilder, + { + *x = match (DEGREE, REGISTERS) { + (3, 0) => x.cube(), + (5, 0) => x.exp_const_u64::<5>(), + (7, 0) => x.exp_const_u64::<7>(), + (5, 1) => { + let committed_x3 = sbox.0[0].into(); + let x2 = x.square(); + builder.assert_eq(committed_x3.clone(), x2.clone() * x.clone()); + committed_x3 * x2 + } + (7, 1) => { + let committed_x3 = sbox.0[0].into(); + builder.assert_eq(committed_x3.clone(), x.cube()); + committed_x3.square() * x.clone() + } + (11, 2) => { + let committed_x3 = sbox.0[0].into(); + let committed_x9 = sbox.0[1].into(); + let x2 = x.square(); + builder.assert_eq(committed_x3.clone(), x2.clone() * x.clone()); + builder.assert_eq(committed_x9.clone(), committed_x3.cube()); + committed_x9 * x2 + } + _ => panic!( + "Unexpected (DEGREE, REGISTERS) of ({}, {})", + DEGREE, REGISTERS + ), + } + } + *) + Definition eval_sbox (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ DEGREE; REGISTERS ], [ AB ], [ sbox; x; builder ] => + ltac:(M.monadic + (let sbox := M.alloc (| sbox |) in + let x := M.alloc (| x |) in + let builder := M.alloc (| builder |) in + M.write (| + M.deref (| M.read (| x |) |), + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + M.alloc (| Value.Tuple [ DEGREE; REGISTERS ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 3 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 0 + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "cube", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 5 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 0 + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 5 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 7 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 0 + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 7 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 5 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 1 + |) in + let~ committed_x3 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| sbox |) |), + "p3_poseidon2_air::columns::SBox", + 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ x2 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, committed_x3 |) ] + |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x2 |) ] + |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "mul", + [], + [] + |), + [ M.read (| committed_x3 |); M.read (| x2 |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 7 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 1 + |) in + let~ committed_x3 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| sbox |) |), + "p3_poseidon2_air::columns::SBox", + 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, committed_x3 |) ] + |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "cube", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, committed_x3 |) ] + |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 11 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 2 + |) in + let~ committed_x3 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| sbox |) |), + "p3_poseidon2_air::columns::SBox", + 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ committed_x9 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| sbox |) |), + "p3_poseidon2_air::columns::SBox", + 0 + |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + |) in + let~ x2 : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, committed_x3 |) ] + |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x2 |) ] + |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Expr", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::AirBuilder", + AB, + [], + [], + "assert_eq", + [], + [ + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr"; + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| builder |) |) |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, committed_x9 |) ] + |); + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [], + "cube", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, committed_x3 |) ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Expr" ], + "mul", + [], + [] + |), + [ M.read (| committed_x9 |); M.read (| x2 |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "Unexpected (DEGREE, REGISTERS) of (" |); + mk_str (| ", " |); + mk_str (| ")" |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "u64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| DEGREE |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| REGISTERS |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_eval_sbox : + M.IsFunction.C "p3_poseidon2_air::air::eval_sbox" eval_sbox. + Admitted. + Global Typeclasses Opaque eval_sbox. +End air. diff --git a/CoqOfRust/plonky3/poseidon2-air/src/columns.rs b/CoqOfRust/plonky3/poseidon2-air/src/columns.rs new file mode 100644 index 000000000..082f318a2 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/columns.rs @@ -0,0 +1,162 @@ +use core::borrow::{Borrow, BorrowMut}; +use core::mem::size_of; + +/// Columns for a Poseidon2 AIR which computes one permutation per row. +/// +/// The columns of the STARK are divided into the three different round sections of the Poseidon2 +/// Permutation: beginning full rounds, partial rounds, and ending full rounds. For the full +/// rounds we store an [`SBox`] columnset for each state variable, and for the partial rounds we +/// store only for the first state variable. Because the matrix multiplications are linear +/// functions, we need only keep auxiliary columns for the S-box computations. +#[repr(C)] +pub struct Poseidon2Cols< + T, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +> { + pub export: T, + + pub inputs: [T; WIDTH], + + /// Beginning Full Rounds + pub beginning_full_rounds: [FullRound; HALF_FULL_ROUNDS], + + /// Partial Rounds + pub partial_rounds: [PartialRound; PARTIAL_ROUNDS], + + /// Ending Full Rounds + pub ending_full_rounds: [FullRound; HALF_FULL_ROUNDS], +} + +/// Full round columns. +#[repr(C)] +pub struct FullRound { + /// Possible intermediate results within each S-box. + pub sbox: [SBox; WIDTH], + /// The post-state, i.e. the entire layer after this full round. + pub post: [T; WIDTH], +} + +/// Partial round columns. +#[repr(C)] +pub struct PartialRound +{ + /// Possible intermediate results within the S-box. + pub sbox: SBox, + /// The output of the S-box. + pub post_sbox: T, +} + +/// Possible intermediate results within an S-box. +/// +/// Use this column-set for an S-box that can be computed with `REGISTERS`-many intermediate results +/// (not counting the final output). The S-box is checked to ensure that `REGISTERS` is the optimal +/// number of registers for the given `DEGREE` for the degrees given in the Poseidon2 paper: +/// `3`, `5`, `7`, and `11`. See `eval_sbox` for more information. +#[repr(C)] +pub struct SBox(pub [T; REGISTERS]); + +pub const fn num_cols< + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +>() -> usize { + size_of::>( + ) +} + +pub const fn make_col_map< + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +>() -> Poseidon2Cols { + todo!() + // let indices_arr = indices_arr::< + // { num_cols::() }, + // >(); + // unsafe { + // transmute::< + // [usize; + // num_cols::()], + // Poseidon2Cols< + // usize, + // WIDTH, + // SBOX_DEGREE, + // SBOX_REGISTERS, + // HALF_FULL_ROUNDS, + // PARTIAL_ROUNDS, + // >, + // >(indices_arr) + // } +} + +impl< + T, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +> Borrow> + for [T] +{ + fn borrow( + &self, + ) -> &Poseidon2Cols + { + // debug_assert_eq!(self.len(), NUM_COLS); + let (prefix, shorts, suffix) = unsafe { + self.align_to::>() + }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &shorts[0] + } +} + +impl< + T, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +> BorrowMut> + for [T] +{ + fn borrow_mut( + &mut self, + ) -> &mut Poseidon2Cols + { + // debug_assert_eq!(self.len(), NUM_COLS); + let (prefix, shorts, suffix) = unsafe { + self.align_to_mut::>() + }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &mut shorts[0] + } +} diff --git a/CoqOfRust/plonky3/poseidon2-air/src/columns.v b/CoqOfRust/plonky3/poseidon2-air/src/columns.v new file mode 100644 index 000000000..018f3e923 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/columns.v @@ -0,0 +1,1176 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module columns. + (* StructRecord + { + name := "Poseidon2Cols"; + const_params := + [ "WIDTH"; "SBOX_DEGREE"; "SBOX_REGISTERS"; "HALF_FULL_ROUNDS"; "PARTIAL_ROUNDS" ]; + ty_params := [ "T" ]; + fields := + [ + ("export", T); + ("inputs", Ty.apply (Ty.path "array") [ WIDTH ] [ T ]); + ("beginning_full_rounds", + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ T ] + ]); + ("partial_rounds", + Ty.apply + (Ty.path "array") + [ PARTIAL_ROUNDS ] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::PartialRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ T ] + ]); + ("ending_full_rounds", + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ T ] + ]) + ]; + } *) + + (* StructRecord + { + name := "FullRound"; + const_params := [ "WIDTH"; "SBOX_DEGREE"; "SBOX_REGISTERS" ]; + ty_params := [ "T" ]; + fields := + [ + ("sbox", + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::SBox") + [ SBOX_DEGREE; SBOX_REGISTERS ] + [ T ] + ]); + ("post", Ty.apply (Ty.path "array") [ WIDTH ] [ T ]) + ]; + } *) + + (* StructRecord + { + name := "PartialRound"; + const_params := [ "WIDTH"; "SBOX_DEGREE"; "SBOX_REGISTERS" ]; + ty_params := [ "T" ]; + fields := + [ + ("sbox", + Ty.apply + (Ty.path "p3_poseidon2_air::columns::SBox") + [ SBOX_DEGREE; SBOX_REGISTERS ] + [ T ]); + ("post_sbox", T) + ]; + } *) + + (* StructTuple + { + name := "SBox"; + const_params := [ "DEGREE"; "REGISTERS" ]; + ty_params := [ "T" ]; + fields := [ Ty.apply (Ty.path "array") [ REGISTERS ] [ T ] ]; + } *) + + (* + pub const fn num_cols< + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + >() -> usize { + size_of::>( + ) + } + *) + Definition num_cols (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ Ty.path "u8" ] + ] + |), + [] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_num_cols : + M.IsFunction.C "p3_poseidon2_air::columns::num_cols" num_cols. + Admitted. + Global Typeclasses Opaque num_cols. + + (* + pub const fn make_col_map< + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + >() -> Poseidon2Cols { + todo!() + // let indices_arr = indices_arr::< + // { num_cols::() }, + // >(); + // unsafe { + // transmute::< + // [usize; + // num_cols::()], + // Poseidon2Cols< + // usize, + // WIDTH, + // SBOX_DEGREE, + // SBOX_REGISTERS, + // HALF_FULL_ROUNDS, + // PARTIAL_ROUNDS, + // >, + // >(indices_arr) + // } + } + *) + Definition make_col_map (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ], [], [] => + ltac:(M.monadic + (M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "not yet implemented" |) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_make_col_map : + M.IsFunction.C "p3_poseidon2_air::columns::make_col_map" make_col_map. + Admitted. + Global Typeclasses Opaque make_col_map. + + Module Impl_core_borrow_Borrow_p3_poseidon2_air_columns_Poseidon2Cols_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_T_for_slice_T. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (T : Ty.t) + : Ty.t := + Ty.apply (Ty.path "slice") [] [ T ]. + + (* + fn borrow( + &self, + ) -> &Poseidon2Cols + { + // debug_assert_eq!(self.len(), NUM_COLS); + let (prefix, shorts, suffix) = unsafe { + self.align_to::>() + }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &shorts[0] + } + *) + Definition borrow + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ T ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ T ] + ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "align_to", + [], + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ T ] + ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let shorts := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ T ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shorts |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 1 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| shorts |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (T : Ty.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ T ] + ] + (Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS T) + (* Instance *) + [ + ("borrow", + InstanceField.Method + (borrow WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS T)) + ]. + End Impl_core_borrow_Borrow_p3_poseidon2_air_columns_Poseidon2Cols_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_T_for_slice_T. + + Module Impl_core_borrow_BorrowMut_p3_poseidon2_air_columns_Poseidon2Cols_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_T_for_slice_T. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (T : Ty.t) + : Ty.t := + Ty.apply (Ty.path "slice") [] [ T ]. + + (* + fn borrow_mut( + &mut self, + ) -> &mut Poseidon2Cols + { + // debug_assert_eq!(self.len(), NUM_COLS); + let (prefix, shorts, suffix) = unsafe { + self.align_to_mut::>() + }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &mut shorts[0] + } + *) + Definition borrow_mut + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ T ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ T ] + ] + ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "align_to_mut", + [], + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ T ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let shorts := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ T ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shorts |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 1 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| shorts |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + |))) + ] + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (T : Ty.t), + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ T ] + ] + (Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS T) + (* Instance *) + [ + ("borrow_mut", + InstanceField.Method + (borrow_mut WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS T)) + ]. + End Impl_core_borrow_BorrowMut_p3_poseidon2_air_columns_Poseidon2Cols_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_T_for_slice_T. +End columns. diff --git a/CoqOfRust/plonky3/poseidon2-air/src/constants.rs b/CoqOfRust/plonky3/poseidon2-air/src/constants.rs new file mode 100644 index 000000000..927f9b939 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/constants.rs @@ -0,0 +1,43 @@ +use p3_field::Field; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; + +/// Round constants for Poseidon2, in a format that's convenient for the AIR. +#[derive(Debug, Clone)] +pub struct RoundConstants< + F: Field, + const WIDTH: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +> { + pub(crate) beginning_full_round_constants: [[F; WIDTH]; HALF_FULL_ROUNDS], + pub(crate) partial_round_constants: [F; PARTIAL_ROUNDS], + pub(crate) ending_full_round_constants: [[F; WIDTH]; HALF_FULL_ROUNDS], +} + +impl + RoundConstants +{ + pub const fn new( + beginning_full_round_constants: [[F; WIDTH]; HALF_FULL_ROUNDS], + partial_round_constants: [F; PARTIAL_ROUNDS], + ending_full_round_constants: [[F; WIDTH]; HALF_FULL_ROUNDS], + ) -> Self { + Self { + beginning_full_round_constants, + partial_round_constants, + ending_full_round_constants, + } + } + + pub fn from_rng(rng: &mut R) -> Self + where + StandardUniform: Distribution + Distribution<[F; WIDTH]>, + { + Self { + beginning_full_round_constants: core::array::from_fn(|_| rng.sample(StandardUniform)), + partial_round_constants: core::array::from_fn(|_| rng.sample(StandardUniform)), + ending_full_round_constants: core::array::from_fn(|_| rng.sample(StandardUniform)), + } + } +} diff --git a/CoqOfRust/plonky3/poseidon2-air/src/constants.v b/CoqOfRust/plonky3/poseidon2-air/src/constants.v new file mode 100644 index 000000000..3fe043f26 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/constants.v @@ -0,0 +1,543 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module constants. + (* StructRecord + { + name := "RoundConstants"; + const_params := [ "WIDTH"; "HALF_FULL_ROUNDS"; "PARTIAL_ROUNDS" ]; + ty_params := [ "F" ]; + fields := + [ + ("beginning_full_round_constants", + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ]); + ("partial_round_constants", Ty.apply (Ty.path "array") [ PARTIAL_ROUNDS ] [ F ]); + ("ending_full_round_constants", + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_for_p3_poseidon2_air_constants_RoundConstants_WIDTH_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F. + Definition Self (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::constants::RoundConstants") + [ WIDTH; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F ]. + + (* Debug *) + Definition fmt + (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "RoundConstants" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "beginning_full_round_constants" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::constants::RoundConstants", + "beginning_full_round_constants" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "partial_round_constants" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::constants::RoundConstants", + "partial_round_constants" + |) + |) + |) + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "ending_full_round_constants" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::constants::RoundConstants", + "ending_full_round_constants" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F) + (* Instance *) + [ ("fmt", InstanceField.Method (fmt WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_for_p3_poseidon2_air_constants_RoundConstants_WIDTH_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_for_p3_poseidon2_air_constants_RoundConstants_WIDTH_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F. + Definition Self (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::constants::RoundConstants") + [ WIDTH; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F ]. + + (* Clone *) + Definition clone + (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_poseidon2_air::constants::RoundConstants" + [ + ("beginning_full_round_constants", + M.call_closure (| + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::constants::RoundConstants", + "beginning_full_round_constants" + |) + |) + |) + |) + ] + |)); + ("partial_round_constants", + M.call_closure (| + Ty.apply (Ty.path "array") [ PARTIAL_ROUNDS ] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ PARTIAL_ROUNDS ] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::constants::RoundConstants", + "partial_round_constants" + |) + |) + |) + |) + ] + |)); + ("ending_full_round_constants", + M.call_closure (| + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::constants::RoundConstants", + "ending_full_round_constants" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F) + (* Instance *) + [ ("clone", InstanceField.Method (clone WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_p3_field_field_Field_F_for_p3_poseidon2_air_constants_RoundConstants_WIDTH_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F. + + Module Impl_p3_poseidon2_air_constants_RoundConstants_WIDTH_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F. + Definition Self (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::constants::RoundConstants") + [ WIDTH; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F ]. + + (* + pub const fn new( + beginning_full_round_constants: [[F; WIDTH]; HALF_FULL_ROUNDS], + partial_round_constants: [F; PARTIAL_ROUNDS], + ending_full_round_constants: [[F; WIDTH]; HALF_FULL_ROUNDS], + ) -> Self { + Self { + beginning_full_round_constants, + partial_round_constants, + ending_full_round_constants, + } + } + *) + Definition new + (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F in + match ε, τ, α with + | [], + [], + [ beginning_full_round_constants; partial_round_constants; ending_full_round_constants + ] => + ltac:(M.monadic + (let beginning_full_round_constants := M.alloc (| beginning_full_round_constants |) in + let partial_round_constants := M.alloc (| partial_round_constants |) in + let ending_full_round_constants := M.alloc (| ending_full_round_constants |) in + Value.StructRecord + "p3_poseidon2_air::constants::RoundConstants" + [ + ("beginning_full_round_constants", M.read (| beginning_full_round_constants |)); + ("partial_round_constants", M.read (| partial_round_constants |)); + ("ending_full_round_constants", M.read (| ending_full_round_constants |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) (F : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F) + "new" + (new WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn from_rng(rng: &mut R) -> Self + where + StandardUniform: Distribution + Distribution<[F; WIDTH]>, + { + Self { + beginning_full_round_constants: core::array::from_fn(|_| rng.sample(StandardUniform)), + partial_round_constants: core::array::from_fn(|_| rng.sample(StandardUniform)), + ending_full_round_constants: core::array::from_fn(|_| rng.sample(StandardUniform)), + } + } + *) + Definition from_rng + (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F in + match ε, τ, α with + | [], [ R ], [ rng ] => + ltac:(M.monadic + (let rng := M.alloc (| rng |) in + Value.StructRecord + "p3_poseidon2_air::constants::RoundConstants" + [ + ("beginning_full_round_constants", + M.call_closure (| + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ], + M.get_function (| + "core::array::from_fn", + [ HALF_FULL_ROUNDS ], + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ F ], + M.get_trait_method (| + "rand::rng::Rng", + R, + [], + [], + "sample", + [], + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.path "rand::distr::StandardUniform" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| rng |) |) + |); + Value.StructTuple "rand::distr::StandardUniform" [] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |)); + ("partial_round_constants", + M.call_closure (| + Ty.apply (Ty.path "array") [ PARTIAL_ROUNDS ] [ F ], + M.get_function (| + "core::array::from_fn", + [ PARTIAL_ROUNDS ], + [ F; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] F ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + F, + M.get_trait_method (| + "rand::rng::Rng", + R, + [], + [], + "sample", + [], + [ F; Ty.path "rand::distr::StandardUniform" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| rng |) |) + |); + Value.StructTuple "rand::distr::StandardUniform" [] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |)); + ("ending_full_round_constants", + M.call_closure (| + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ], + M.get_function (| + "core::array::from_fn", + [ HALF_FULL_ROUNDS ], + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ F ], + M.get_trait_method (| + "rand::rng::Rng", + R, + [], + [], + "sample", + [], + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.path "rand::distr::StandardUniform" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| rng |) |) + |); + Value.StructTuple "rand::distr::StandardUniform" [] + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_rng : + forall (WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS : Value.t) (F : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F) + "from_rng" + (from_rng WIDTH HALF_FULL_ROUNDS PARTIAL_ROUNDS F). + Admitted. + Global Typeclasses Opaque from_rng. + End Impl_p3_poseidon2_air_constants_RoundConstants_WIDTH_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_F. +End constants. diff --git a/CoqOfRust/plonky3/poseidon2-air/src/generation.rs b/CoqOfRust/plonky3/poseidon2-air/src/generation.rs new file mode 100644 index 000000000..1fe338ef6 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/generation.rs @@ -0,0 +1,288 @@ +use alloc::vec::Vec; +use core::mem::MaybeUninit; + +use p3_field::PrimeField; +use p3_matrix::dense::{RowMajorMatrix, RowMajorMatrixViewMut}; +use p3_maybe_rayon::prelude::*; +use p3_poseidon2::GenericPoseidon2LinearLayers; +use tracing::instrument; + +use crate::columns::{Poseidon2Cols, num_cols}; +use crate::{FullRound, PartialRound, RoundConstants, SBox}; + +#[instrument(name = "generate vectorized Poseidon2 trace", skip_all)] +pub fn generate_vectorized_trace_rows< + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +>( + inputs: Vec<[F; WIDTH]>, + round_constants: &RoundConstants, + extra_capacity_bits: usize, +) -> RowMajorMatrix { + let n = inputs.len(); + assert!( + n % VECTOR_LEN == 0 && (n / VECTOR_LEN).is_power_of_two(), + "Callers expected to pad inputs to VECTOR_LEN times a power of two" + ); + + let nrows = n.div_ceil(VECTOR_LEN); + let ncols = num_cols::() + * VECTOR_LEN; + let mut vec = Vec::with_capacity((nrows * ncols) << extra_capacity_bits); + let trace = &mut vec.spare_capacity_mut()[..nrows * ncols]; + let trace = RowMajorMatrixViewMut::new(trace, ncols); + + let (prefix, perms, suffix) = unsafe { + trace.values.align_to_mut::, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >>() + }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(perms.len(), n); + + perms.par_iter_mut().zip(inputs).for_each(|(perm, input)| { + generate_trace_rows_for_perm::< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >(perm, input, round_constants); + }); + + unsafe { + vec.set_len(nrows * ncols); + } + + RowMajorMatrix::new(vec, ncols) +} + +// TODO: Take generic iterable +#[instrument(name = "generate Poseidon2 trace", skip_all)] +pub fn generate_trace_rows< + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +>( + inputs: Vec<[F; WIDTH]>, + constants: &RoundConstants, + extra_capacity_bits: usize, +) -> RowMajorMatrix { + let n = inputs.len(); + assert!( + n.is_power_of_two(), + "Callers expected to pad inputs to a power of two" + ); + + let ncols = num_cols::(); + let mut vec = Vec::with_capacity((n * ncols) << extra_capacity_bits); + let trace = &mut vec.spare_capacity_mut()[..n * ncols]; + let trace = RowMajorMatrixViewMut::new(trace, ncols); + + let (prefix, perms, suffix) = unsafe { + trace.values.align_to_mut::, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >>() + }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(perms.len(), n); + + perms.par_iter_mut().zip(inputs).for_each(|(perm, input)| { + generate_trace_rows_for_perm::< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >(perm, input, constants); + }); + + unsafe { + vec.set_len(n * ncols); + } + + RowMajorMatrix::new(vec, ncols) +} + +/// `rows` will normally consist of 24 rows, with an exception for the final row. +fn generate_trace_rows_for_perm< + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, +>( + perm: &mut Poseidon2Cols< + MaybeUninit, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >, + mut state: [F; WIDTH], + constants: &RoundConstants, +) { + perm.export.write(F::ONE); + perm.inputs + .iter_mut() + .zip(state.iter()) + .for_each(|(input, &x)| { + input.write(x); + }); + + LinearLayers::external_linear_layer(&mut state); + + for (full_round, constants) in perm + .beginning_full_rounds + .iter_mut() + .zip(&constants.beginning_full_round_constants) + { + generate_full_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, full_round, constants, + ); + } + + for (partial_round, constant) in perm + .partial_rounds + .iter_mut() + .zip(&constants.partial_round_constants) + { + generate_partial_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, + partial_round, + *constant, + ); + } + + for (full_round, constants) in perm + .ending_full_rounds + .iter_mut() + .zip(&constants.ending_full_round_constants) + { + generate_full_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, full_round, constants, + ); + } +} + +#[inline] +fn generate_full_round< + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, +>( + state: &mut [F; WIDTH], + full_round: &mut FullRound, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>, + round_constants: &[F; WIDTH], +) { + // Combine addition of round constants and S-box application in a single loop + for ((state_i, const_i), sbox_i) in state + .iter_mut() + .zip(round_constants.iter()) + .zip(full_round.sbox.iter_mut()) + { + *state_i += *const_i; + generate_sbox(sbox_i, state_i); + } + + LinearLayers::external_linear_layer(state); + full_round + .post + .iter_mut() + .zip(*state) + .for_each(|(post, x)| { + post.write(x); + }); +} + +#[inline] +fn generate_partial_round< + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, +>( + state: &mut [F; WIDTH], + partial_round: &mut PartialRound, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>, + round_constant: F, +) { + state[0] += round_constant; + generate_sbox(&mut partial_round.sbox, &mut state[0]); + partial_round.post_sbox.write(state[0]); + LinearLayers::internal_linear_layer(state); +} + +/// Computes the S-box `x -> x^{DEGREE}` and stores the partial data required to +/// verify the computation. +/// +/// # Panics +/// +/// This method panics if the number of `REGISTERS` is not chosen optimally for the given +/// `DEGREE` or if the `DEGREE` is not supported by the S-box. The supported degrees are +/// `3`, `5`, `7`, and `11`. +#[inline] +fn generate_sbox( + sbox: &mut SBox, DEGREE, REGISTERS>, + x: &mut F, +) { + *x = match (DEGREE, REGISTERS) { + (3, 0) => x.cube(), + (5, 0) => x.exp_const_u64::<5>(), + (7, 0) => x.exp_const_u64::<7>(), + (5, 1) => { + let x2 = x.square(); + let x3 = x2 * *x; + sbox.0[0].write(x3); + x3 * x2 + } + (7, 1) => { + let x3 = x.cube(); + sbox.0[0].write(x3); + x3 * x3 * *x + } + (11, 2) => { + let x2 = x.square(); + let x3 = x2 * *x; + let x9 = x3.cube(); + sbox.0[0].write(x3); + sbox.0[1].write(x9); + x9 * x2 + } + _ => panic!( + "Unexpected (DEGREE, REGISTERS) of ({}, {})", + DEGREE, REGISTERS + ), + } +} diff --git a/CoqOfRust/plonky3/poseidon2-air/src/generation.v b/CoqOfRust/plonky3/poseidon2-air/src/generation.v new file mode 100644 index 000000000..b8ebf3850 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/generation.v @@ -0,0 +1,5861 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module generation. + (* #[instrument(name = "generate vectorized Poseidon2 trace", skip_all)] *) + Definition generate_vectorized_trace_rows + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ], + [ F; LinearLayers ], + [ inputs; round_constants; extra_capacity_bits ] => + ltac:(M.monadic + (let inputs := M.alloc (| inputs |) in + let round_constants := M.alloc (| round_constants |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.catch_return + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_poseidon2_air::generation::generate_vectorized_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_poseidon2_air::generation::generate_vectorized_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_poseidon2_air::generation::generate_vectorized_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_poseidon2_air::generation::generate_vectorized_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inputs |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| n |); VECTOR_LEN ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "usize", + "is_power_of_two", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| n |); VECTOR_LEN ] + |) + ] + |))) + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Callers expected to pad inputs to VECTOR_LEN times a power of two" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ nrows : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "div_ceil", [], [] |), + [ M.read (| n |); VECTOR_LEN ] + |) + |) in + let~ ncols : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_poseidon2_air::columns::num_cols", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ], + [] + |), + [] + |); + VECTOR_LEN + ] + |) + |) in + let~ vec : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "with_capacity", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| nrows |); M.read (| ncols |) ] + |); + M.read (| extra_capacity_bits |) + ] + |) + ] + |) + |) in + let~ trace : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + [], + [ Ty.apply (Ty.path "core::ops::range::RangeTo") [] [ Ty.path "usize" ] ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "spare_capacity_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, vec |) ] + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| nrows |); M.read (| ncols |) ] + |)) + ] + ] + |) + |) + |) + |) in + let~ trace : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ] + ], + "new", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| trace |) |) |); + M.read (| ncols |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + "align_to_mut", + [], + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + trace, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let perms := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Alignment should match" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Alignment should match" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| perms |) |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, n |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ F ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelRefMutIterator", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + [], + [], + "par_iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| perms |) |) + |) + ] + |); + M.read (| inputs |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ F ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let perm := M.copy (| γ0_0 |) in + let input := M.copy (| γ0_1 |) in + M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::generation::generate_trace_rows_for_perm", + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ], + [ F; LinearLayers ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| perm |) |) + |); + M.read (| input |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| round_constants |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "set_len", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, vec |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| nrows |); M.read (| ncols |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |); M.read (| ncols |) ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_vectorized_trace_rows : + M.IsFunction.C + "p3_poseidon2_air::generation::generate_vectorized_trace_rows" + generate_vectorized_trace_rows. + Admitted. + Global Typeclasses Opaque generate_vectorized_trace_rows. + + (* #[instrument(name = "generate Poseidon2 trace", skip_all)] *) + Definition generate_trace_rows (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ], + [ F; LinearLayers ], + [ inputs; constants; extra_capacity_bits ] => + ltac:(M.monadic + (let inputs := M.alloc (| inputs |) in + let constants := M.alloc (| constants |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.catch_return + (Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_poseidon2_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_poseidon2_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_poseidon2_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_poseidon2_air::generation::generate_trace_rows::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inputs |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "usize", + "is_power_of_two", + [], + [] + |), + [ M.read (| n |) ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Callers expected to pad inputs to a power of two" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ ncols : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_poseidon2_air::columns::num_cols", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ], + [] + |), + [] + |) + |) in + let~ vec : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + "with_capacity", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| n |); M.read (| ncols |) ] + |); + M.read (| extra_capacity_bits |) + ] + |) + ] + |) + |) in + let~ trace : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + [], + [ Ty.apply (Ty.path "core::ops::range::RangeTo") [] [ Ty.path "usize" ] ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "spare_capacity_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, vec |) ] + |) + |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| n |); M.read (| ncols |) ] + |)) + ] + ] + |) + |) + |) + |) in + let~ trace : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ] + ], + "new", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| trace |) |) |); + M.read (| ncols |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + "align_to_mut", + [], + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + trace, + "p3_matrix::dense::DenseMatrix", + "values" + |) + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let perms := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Alignment should match" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Alignment should match" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| perms |) |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, n |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ F ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelRefMutIterator", + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + [], + [], + "par_iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| perms |) |) + |) + ] + |); + M.read (| inputs |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path + "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.apply + (Ty.path + "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ F ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let perm := M.copy (| γ0_0 |) in + let input := M.copy (| γ0_1 |) in + M.read (| + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::generation::generate_trace_rows_for_perm", + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ], + [ F; LinearLayers ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| perm |) |) + |); + M.read (| input |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| constants |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + "set_len", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, vec |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| n |); M.read (| ncols |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |); M.read (| ncols |) ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_trace_rows : + M.IsFunction.C "p3_poseidon2_air::generation::generate_trace_rows" generate_trace_rows. + Admitted. + Global Typeclasses Opaque generate_trace_rows. + + (* + fn generate_trace_rows_for_perm< + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + >( + perm: &mut Poseidon2Cols< + MaybeUninit, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >, + mut state: [F; WIDTH], + constants: &RoundConstants, + ) { + perm.export.write(F::ONE); + perm.inputs + .iter_mut() + .zip(state.iter()) + .for_each(|(input, &x)| { + input.write(x); + }); + + LinearLayers::external_linear_layer(&mut state); + + for (full_round, constants) in perm + .beginning_full_rounds + .iter_mut() + .zip(&constants.beginning_full_round_constants) + { + generate_full_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, full_round, constants, + ); + } + + for (partial_round, constant) in perm + .partial_rounds + .iter_mut() + .zip(&constants.partial_round_constants) + { + generate_partial_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, + partial_round, + *constant, + ); + } + + for (full_round, constants) in perm + .ending_full_rounds + .iter_mut() + .zip(&constants.ending_full_round_constants) + { + generate_full_round::<_, LinearLayers, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>( + &mut state, full_round, constants, + ); + } + } + *) + Definition generate_trace_rows_for_perm + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ], + [ F; LinearLayers ], + [ perm; state; constants ] => + ltac:(M.monadic + (let perm := M.alloc (| perm |) in + let state := M.alloc (| state |) in + let constants := M.alloc (| constants |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&mut") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| perm |) |), + "p3_poseidon2_air::columns::Poseidon2Cols", + "export" + |) + |); + M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| perm |) |), + "p3_poseidon2_air::columns::Poseidon2Cols", + "inputs" + |) + |)) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ (* Unsize *) M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, state |)) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + Ty.apply (Ty.path "&") [] [ F ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let input := M.copy (| γ0_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let x := M.copy (| γ0_1 |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "&mut") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| input |) |) + |); + M.read (| x |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_poseidon2::generic::GenericPoseidon2LinearLayers", + LinearLayers, + [ WIDTH ], + [ F ], + "external_linear_layer", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| perm |) |), + "p3_poseidon2_air::columns::Poseidon2Cols", + "beginning_full_rounds" + |) + |)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| constants |) |), + "p3_poseidon2_air::constants::RoundConstants", + "beginning_full_round_constants" + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let full_round := M.copy (| γ1_0 |) in + let constants := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::generation::generate_full_round", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ], + [ F; LinearLayers ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, state |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| full_round |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| constants |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::PartialRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::PartialRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::PartialRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::PartialRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ PARTIAL_ROUNDS ] [ F ] ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::PartialRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::PartialRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| perm |) |), + "p3_poseidon2_air::columns::Poseidon2Cols", + "partial_rounds" + |) + |)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| constants |) |), + "p3_poseidon2_air::constants::RoundConstants", + "partial_round_constants" + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::PartialRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply (Ty.path "&") [] [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::PartialRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let partial_round := M.copy (| γ1_0 |) in + let constant := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::generation::generate_partial_round", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ], + [ F; LinearLayers ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, state |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| partial_round |) |) + |); + M.read (| M.deref (| M.read (| constant |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ HALF_FULL_ROUNDS ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| perm |) |), + "p3_poseidon2_air::columns::Poseidon2Cols", + "ending_full_rounds" + |) + |)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| constants |) |), + "p3_poseidon2_air::constants::RoundConstants", + "ending_full_round_constants" + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::FullRound") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let full_round := M.copy (| γ1_0 |) in + let constants := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::generation::generate_full_round", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ], + [ F; LinearLayers ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| full_round |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| constants |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_trace_rows_for_perm : + M.IsFunction.C + "p3_poseidon2_air::generation::generate_trace_rows_for_perm" + generate_trace_rows_for_perm. + Admitted. + Global Typeclasses Opaque generate_trace_rows_for_perm. + + (* + fn generate_full_round< + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + >( + state: &mut [F; WIDTH], + full_round: &mut FullRound, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>, + round_constants: &[F; WIDTH], + ) { + // Combine addition of round constants and S-box application in a single loop + for ((state_i, const_i), sbox_i) in state + .iter_mut() + .zip(round_constants.iter()) + .zip(full_round.sbox.iter_mut()) + { + *state_i += *const_i; + generate_sbox(sbox_i, state_i); + } + + LinearLayers::external_linear_layer(state); + full_round + .post + .iter_mut() + .zip( *state) + .for_each(|(post, x)| { + post.write(x); + }); + } + *) + Definition generate_full_round (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ], + [ F; LinearLayers ], + [ state; full_round; round_constants ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let full_round := M.alloc (| full_round |) in + let round_constants := M.alloc (| round_constants |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::SBox") + [ SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::SBox") + [ SBOX_DEGREE; SBOX_REGISTERS ] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::SBox") + [ SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::SBox") + [ SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| round_constants |) |) + |)) + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::SBox") + [ SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::SBox") + [ SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| full_round |) |), + "p3_poseidon2_air::columns::FullRound", + "sbox" + |) + |)) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ F ]; + Ty.apply (Ty.path "&") [] [ F ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::SBox") + [ SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ F ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ] + ]; + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::SBox") + [ SBOX_DEGREE; SBOX_REGISTERS ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ1_0, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ1_0, 1 |) in + let state_i := M.copy (| γ2_0 |) in + let const_i := M.copy (| γ2_1 |) in + let sbox_i := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state_i |) |) + |); + M.read (| M.deref (| M.read (| const_i |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::generation::generate_sbox", + [ SBOX_DEGREE; SBOX_REGISTERS ], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| sbox_i |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state_i |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_poseidon2::generic::GenericPoseidon2LinearLayers", + LinearLayers, + [ WIDTH ], + [ F ], + "external_linear_layer", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ WIDTH ] [ F ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + F + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ]; + Ty.apply (Ty.path "core::array::iter::IntoIter") [ WIDTH ] [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + [], + [], + "zip", + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ] ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| full_round |) |), + "p3_poseidon2_air::columns::FullRound", + "post" + |) + |)) + ] + |); + M.read (| M.deref (| M.read (| state |) |) |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ] + ]; + F + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let post := M.copy (| γ0_0 |) in + let x := M.copy (| γ0_1 |) in + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "&mut") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ F ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| post |) |) + |); + M.read (| x |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_full_round : + M.IsFunction.C "p3_poseidon2_air::generation::generate_full_round" generate_full_round. + Admitted. + Global Typeclasses Opaque generate_full_round. + + (* + fn generate_partial_round< + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + >( + state: &mut [F; WIDTH], + partial_round: &mut PartialRound, WIDTH, SBOX_DEGREE, SBOX_REGISTERS>, + round_constant: F, + ) { + state[0] += round_constant; + generate_sbox(&mut partial_round.sbox, &mut state[0]); + partial_round.post_sbox.write(state[0]); + LinearLayers::internal_linear_layer(state); + } + *) + Definition generate_partial_round (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS ], + [ F; LinearLayers ], + [ state; partial_round; round_constant ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let partial_round := M.alloc (| partial_round |) in + let round_constant := M.alloc (| round_constant |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + F, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| round_constant |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::generation::generate_sbox", + [ SBOX_DEGREE; SBOX_REGISTERS ], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| partial_round |) |), + "p3_poseidon2_air::columns::PartialRound", + "sbox" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&mut") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| partial_round |) |), + "p3_poseidon2_air::columns::PartialRound", + "post_sbox" + |) + |); + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_poseidon2::generic::GenericPoseidon2LinearLayers", + LinearLayers, + [ WIDTH ], + [ F ], + "internal_linear_layer", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_partial_round : + M.IsFunction.C "p3_poseidon2_air::generation::generate_partial_round" generate_partial_round. + Admitted. + Global Typeclasses Opaque generate_partial_round. + + (* + fn generate_sbox( + sbox: &mut SBox, DEGREE, REGISTERS>, + x: &mut F, + ) { + *x = match (DEGREE, REGISTERS) { + (3, 0) => x.cube(), + (5, 0) => x.exp_const_u64::<5>(), + (7, 0) => x.exp_const_u64::<7>(), + (5, 1) => { + let x2 = x.square(); + let x3 = x2 * *x; + sbox.0[0].write(x3); + x3 * x2 + } + (7, 1) => { + let x3 = x.cube(); + sbox.0[0].write(x3); + x3 * x3 * *x + } + (11, 2) => { + let x2 = x.square(); + let x3 = x2 * *x; + let x9 = x3.cube(); + sbox.0[0].write(x3); + sbox.0[1].write(x9); + x9 * x2 + } + _ => panic!( + "Unexpected (DEGREE, REGISTERS) of ({}, {})", + DEGREE, REGISTERS + ), + } + } + *) + Definition generate_sbox (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ DEGREE; REGISTERS ], [ F ], [ sbox; x ] => + ltac:(M.monadic + (let sbox := M.alloc (| sbox |) in + let x := M.alloc (| x |) in + M.write (| + M.deref (| M.read (| x |) |), + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ F ], + M.alloc (| Value.Tuple [ DEGREE; REGISTERS ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 3 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 0 + |) in + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "cube", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 5 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 0 + |) in + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 5 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 7 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 0 + |) in + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "exp_const_u64", + [ Value.Integer IntegerKind.U64 7 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 5 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 1 + |) in + let~ x2 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ x3 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| x2 |); M.read (| M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&mut") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| sbox |) |), + "p3_poseidon2_air::columns::SBox", + 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| x3 |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| x3 |); M.read (| x2 |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 7 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 1 + |) in + let~ x3 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "cube", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&mut") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| sbox |) |), + "p3_poseidon2_air::columns::SBox", + 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| x3 |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| x3 |); M.read (| x3 |) ] + |); + M.read (| M.deref (| M.read (| x |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 11 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.Usize 2 + |) in + let~ x2 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "square", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ x3 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| x2 |); M.read (| M.deref (| M.read (| x |) |) |) ] + |) + |) in + let~ x9 : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "cube", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x3 |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&mut") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| sbox |) |), + "p3_poseidon2_air::columns::SBox", + 0 + |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.read (| x3 |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&mut") [] [ F ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ F ], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| sbox |) |), + "p3_poseidon2_air::columns::SBox", + 0 + |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| x9 |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| x9 |); M.read (| x2 |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "Unexpected (DEGREE, REGISTERS) of (" |); + mk_str (| ", " |); + mk_str (| ")" |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "u64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| DEGREE |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| REGISTERS |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_generate_sbox : + M.IsFunction.C "p3_poseidon2_air::generation::generate_sbox" generate_sbox. + Admitted. + Global Typeclasses Opaque generate_sbox. +End generation. diff --git a/CoqOfRust/plonky3/poseidon2-air/src/lib.rs b/CoqOfRust/plonky3/poseidon2-air/src/lib.rs new file mode 100644 index 000000000..e21683c89 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/lib.rs @@ -0,0 +1,17 @@ +//! And AIR for the Poseidon2 permutation. + +#![no_std] + +extern crate alloc; + +mod air; +mod columns; +mod constants; +mod generation; +mod vectorized; + +pub use air::*; +pub use columns::*; +pub use constants::*; +pub use generation::*; +pub use vectorized::*; diff --git a/CoqOfRust/plonky3/poseidon2-air/src/vectorized.rs b/CoqOfRust/plonky3/poseidon2-air/src/vectorized.rs new file mode 100644 index 000000000..33a40e67b --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/vectorized.rs @@ -0,0 +1,275 @@ +use core::borrow::{Borrow, BorrowMut}; + +use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::{Field, PrimeField}; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_poseidon2::GenericPoseidon2LinearLayers; +use rand::distr::StandardUniform; +use rand::prelude::Distribution; +use rand::rngs::SmallRng; +use rand::{Rng, SeedableRng}; + +use crate::air::eval; +use crate::constants::RoundConstants; +use crate::{Poseidon2Air, Poseidon2Cols, generate_vectorized_trace_rows}; + +/// A "vectorized" version of Poseidon2Cols, for computing multiple Poseidon2 permutations per row. +#[repr(C)] +pub struct VectorizedPoseidon2Cols< + T, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> { + pub(crate) cols: + [Poseidon2Cols; + VECTOR_LEN], +} + +impl< + T, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> + Borrow< + VectorizedPoseidon2Cols< + T, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + >, + > for [T] +{ + fn borrow( + &self, + ) -> &VectorizedPoseidon2Cols< + T, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > { + // debug_assert_eq!(self.len(), NUM_COLS); + let (prefix, shorts, suffix) = unsafe { + self.align_to::>() + }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &shorts[0] + } +} + +impl< + T, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> + BorrowMut< + VectorizedPoseidon2Cols< + T, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + >, + > for [T] +{ + fn borrow_mut( + &mut self, + ) -> &mut VectorizedPoseidon2Cols< + T, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > { + // debug_assert_eq!(self.len(), NUM_COLS); + let (prefix, shorts, suffix) = unsafe { + self.align_to_mut::>() + }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &mut shorts[0] + } +} + +/// A "vectorized" version of Poseidon2Air, for computing multiple Poseidon2 permutations per row. +pub struct VectorizedPoseidon2Air< + F: Field, + LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> { + pub(crate) air: Poseidon2Air< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + >, +} + +impl< + F: Field, + LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> + VectorizedPoseidon2Air< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > +{ + pub const fn new( + constants: RoundConstants, + ) -> Self { + Self { + air: Poseidon2Air::new(constants), + } + } + + pub fn generate_vectorized_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + StandardUniform: Distribution<[F; WIDTH]>, + { + let mut rng = SmallRng::seed_from_u64(1); + let inputs = (0..num_hashes).map(|_| rng.random()).collect(); + generate_vectorized_trace_rows::< + _, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + >(inputs, &self.air.constants, extra_capacity_bits) + } +} + +impl< + F: Field, + LinearLayers: Sync, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> BaseAir + for VectorizedPoseidon2Air< + F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > +{ + fn width(&self) -> usize { + self.air.width() * VECTOR_LEN + } +} + +impl< + AB: AirBuilder, + LinearLayers: GenericPoseidon2LinearLayers, + const WIDTH: usize, + const SBOX_DEGREE: u64, + const SBOX_REGISTERS: usize, + const HALF_FULL_ROUNDS: usize, + const PARTIAL_ROUNDS: usize, + const VECTOR_LEN: usize, +> Air + for VectorizedPoseidon2Air< + AB::F, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > +{ + #[inline] + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let local: &VectorizedPoseidon2Cols< + _, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > = (*local).borrow(); + for perm in &local.cols { + eval(&self.air, builder, perm); + } + } +} diff --git a/CoqOfRust/plonky3/poseidon2-air/src/vectorized.v b/CoqOfRust/plonky3/poseidon2-air/src/vectorized.v new file mode 100644 index 000000000..854f4690a --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2-air/src/vectorized.v @@ -0,0 +1,1996 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module vectorized. + (* StructRecord + { + name := "VectorizedPoseidon2Cols"; + const_params := + [ + "WIDTH"; + "SBOX_DEGREE"; + "SBOX_REGISTERS"; + "HALF_FULL_ROUNDS"; + "PARTIAL_ROUNDS"; + "VECTOR_LEN" + ]; + ty_params := [ "T" ]; + fields := + [ + ("cols", + Ty.apply + (Ty.path "array") + [ VECTOR_LEN ] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ T ] + ]) + ]; + } *) + + Module Impl_core_borrow_Borrow_p3_poseidon2_air_vectorized_VectorizedPoseidon2Cols_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_T_for_slice_T. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (T : Ty.t) + : Ty.t := + Ty.apply (Ty.path "slice") [] [ T ]. + + (* + fn borrow( + &self, + ) -> &VectorizedPoseidon2Cols< + T, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > { + // debug_assert_eq!(self.len(), NUM_COLS); + let (prefix, shorts, suffix) = unsafe { + self.align_to::>() + }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &shorts[0] + } + *) + Definition borrow + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ T ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ T ] + ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "align_to", + [], + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ T ] + ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let shorts := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ T ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shorts |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 1 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| M.read (| left_val |) |) + |); + M.read (| + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| shorts |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (T : Ty.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ] + [ T ] + ] + (Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN T) + (* Instance *) + [ + ("borrow", + InstanceField.Method + (borrow + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + T)) + ]. + End Impl_core_borrow_Borrow_p3_poseidon2_air_vectorized_VectorizedPoseidon2Cols_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_T_for_slice_T. + + Module Impl_core_borrow_BorrowMut_p3_poseidon2_air_vectorized_VectorizedPoseidon2Cols_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_T_for_slice_T. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (T : Ty.t) + : Ty.t := + Ty.apply (Ty.path "slice") [] [ T ]. + + (* + fn borrow_mut( + &mut self, + ) -> &mut VectorizedPoseidon2Cols< + T, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > { + // debug_assert_eq!(self.len(), NUM_COLS); + let (prefix, shorts, suffix) = unsafe { + self.align_to_mut::>() + }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert!(suffix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &mut shorts[0] + } + *) + Definition borrow_mut + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ T ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ T ] + ] + ]; + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "align_to_mut", + [], + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ T ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let prefix := M.copy (| γ0_0 |) in + let shorts := M.copy (| γ0_1 |) in + let suffix := M.copy (| γ0_2 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| prefix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| suffix |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Alignment should match" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ T ] + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| shorts |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 1 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| + M.deref (| + M.read (| left_val |) + |) + |); + M.read (| + M.deref (| + M.read (| right_val |) + |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ + Ty.path + "core::panicking::AssertKind" + ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| left_val |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| right_val |) + |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| shorts |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |) + |))) + ] + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (T : Ty.t), + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ] + [ T ] + ] + (Self WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN T) + (* Instance *) + [ + ("borrow_mut", + InstanceField.Method + (borrow_mut + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + T)) + ]. + End Impl_core_borrow_BorrowMut_p3_poseidon2_air_vectorized_VectorizedPoseidon2Cols_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_T_for_slice_T. + + (* StructRecord + { + name := "VectorizedPoseidon2Air"; + const_params := + [ + "WIDTH"; + "SBOX_DEGREE"; + "SBOX_REGISTERS"; + "HALF_FULL_ROUNDS"; + "PARTIAL_ROUNDS"; + "VECTOR_LEN" + ]; + ty_params := [ "F"; "LinearLayers" ]; + fields := + [ + ("air", + Ty.apply + (Ty.path "p3_poseidon2_air::air::Poseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F; LinearLayers ]) + ]; + } *) + + Module Impl_p3_poseidon2_air_vectorized_VectorizedPoseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ] + [ F; LinearLayers ]. + + (* + pub const fn new( + constants: RoundConstants, + ) -> Self { + Self { + air: Poseidon2Air::new(constants), + } + } + *) + Definition new + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers in + match ε, τ, α with + | [], [], [ constants ] => + ltac:(M.monadic + (let constants := M.alloc (| constants |) in + Value.StructRecord + "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air" + [ + ("air", + M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2_air::air::Poseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F; LinearLayers ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2_air::air::Poseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F; LinearLayers ], + "new", + [], + [] + |), + [ M.read (| constants |) ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t), + M.IsAssociatedFunction.C + (Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers) + "new" + (new + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn generate_vectorized_trace_rows( + &self, + num_hashes: usize, + extra_capacity_bits: usize, + ) -> RowMajorMatrix + where + F: PrimeField, + LinearLayers: GenericPoseidon2LinearLayers, + StandardUniform: Distribution<[F; WIDTH]>, + { + let mut rng = SmallRng::seed_from_u64(1); + let inputs = (0..num_hashes).map(|_| rng.random()).collect(); + generate_vectorized_trace_rows::< + _, + LinearLayers, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + >(inputs, &self.air.constants, extra_capacity_bits) + } + *) + Definition generate_vectorized_trace_rows + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers in + match ε, τ, α with + | [], [], [ self; num_hashes; extra_capacity_bits ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let num_hashes := M.alloc (| num_hashes |) in + let extra_capacity_bits := M.alloc (| extra_capacity_bits |) in + M.read (| + let~ rng : Ty.apply (Ty.path "*") [] [ Ty.path "rand::rngs::small::SmallRng" ] := + M.alloc (| + M.call_closure (| + Ty.path "rand::rngs::small::SmallRng", + M.get_trait_method (| + "rand_core::SeedableRng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "seed_from_u64", + [], + [] + |), + [ Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ inputs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| num_hashes |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ F ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.path "rand::rngs::small::SmallRng", + [], + [], + "random", + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ F ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, rng |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] + ], + M.get_function (| + "p3_poseidon2_air::generation::generate_vectorized_trace_rows", + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN + ], + [ F; LinearLayers ] + |), + [ + M.read (| inputs |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air", + "air" + |), + "p3_poseidon2_air::air::Poseidon2Air", + "constants" + |) + |) + |) + |); + M.read (| extra_capacity_bits |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_generate_vectorized_trace_rows : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t), + M.IsAssociatedFunction.C + (Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers) + "generate_vectorized_trace_rows" + (generate_vectorized_trace_rows + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers). + Admitted. + Global Typeclasses Opaque generate_vectorized_trace_rows. + End Impl_p3_poseidon2_air_vectorized_VectorizedPoseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_F_LinearLayers. + + Module Impl_p3_air_air_BaseAir_where_p3_field_field_Field_F_where_core_marker_Sync_LinearLayers_F_for_p3_poseidon2_air_vectorized_VectorizedPoseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ] + [ F; LinearLayers ]. + + (* + fn width(&self) -> usize { + self.air.width() * VECTOR_LEN + } + *) + Definition width + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_air::air::BaseAir", + Ty.apply + (Ty.path "p3_poseidon2_air::air::Poseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ F; LinearLayers ], + [], + [ F ], + "width", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air", + "air" + |) + |) + ] + |); + VECTOR_LEN + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (F LinearLayers : Ty.t), + M.IsTraitInstance + "p3_air::air::BaseAir" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers) + (* Instance *) + [ + ("width", + InstanceField.Method + (width + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + F + LinearLayers)) + ]. + End Impl_p3_air_air_BaseAir_where_p3_field_field_Field_F_where_core_marker_Sync_LinearLayers_F_for_p3_poseidon2_air_vectorized_VectorizedPoseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_F_LinearLayers. + + Module Impl_p3_air_air_Air_where_p3_air_air_AirBuilder_AB_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_air_air_AirBuilder___AB_Expr_AB_for_p3_poseidon2_air_vectorized_VectorizedPoseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_associated_in_trait_p3_air_air_AirBuilder___AB_F_LinearLayers. + Definition Self + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (AB LinearLayers : Ty.t) + : Ty.t := + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS; VECTOR_LEN ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "F"; LinearLayers ]. + + (* + fn eval(&self, builder: &mut AB) { + let main = builder.main(); + let local = main.row_slice(0); + let local: &VectorizedPoseidon2Cols< + _, + WIDTH, + SBOX_DEGREE, + SBOX_REGISTERS, + HALF_FULL_ROUNDS, + PARTIAL_ROUNDS, + VECTOR_LEN, + > = ( *local).borrow(); + for perm in &local.cols { + eval(&self.air, builder, perm); + } + } + *) + Definition eval + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (AB LinearLayers : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := + Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + AB + LinearLayers in + match ε, τ, α with + | [], [], [ self; builder ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let builder := M.alloc (| builder |) in + M.read (| + let~ main : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M" ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + M.get_trait_method (| "p3_air::air::AirBuilder", AB, [], [], "main", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| builder |) |) |) ] + |) + |) in + let~ local : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M", + [], + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + "row_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, main |); Value.Integer IntegerKind.Usize 0 ] + |) + |) in + let~ local : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "slice") + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ], + [], + [ + Ty.apply + (Ty.path "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS; + VECTOR_LEN + ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.associated_in_trait + "p3_matrix::Matrix" + [] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" + ] + (Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "M") + "{{synthetic}}'2", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, local |) ] + |) + |) + |) + ] + |) + |) + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ WIDTH; SBOX_DEGREE; SBOX_REGISTERS; HALF_FULL_ROUNDS; PARTIAL_ROUNDS ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ VECTOR_LEN ] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ Ty.associated_in_trait "p3_air::air::AirBuilder" [] [] AB "Var" ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| local |) |), + "p3_poseidon2_air::vectorized::VectorizedPoseidon2Cols", + "cols" + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2_air::columns::Poseidon2Cols") + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + AB + "Var" + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let perm := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2_air::air::eval", + [ + WIDTH; + SBOX_DEGREE; + SBOX_REGISTERS; + HALF_FULL_ROUNDS; + PARTIAL_ROUNDS + ], + [ AB; LinearLayers ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2_air::vectorized::VectorizedPoseidon2Air", + "air" + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| builder |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| perm |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall + (WIDTH SBOX_DEGREE SBOX_REGISTERS HALF_FULL_ROUNDS PARTIAL_ROUNDS VECTOR_LEN : Value.t) + (AB LinearLayers : Ty.t), + M.IsTraitInstance + "p3_air::air::Air" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ AB ] + (Self + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + AB + LinearLayers) + (* Instance *) + [ + ("eval", + InstanceField.Method + (eval + WIDTH + SBOX_DEGREE + SBOX_REGISTERS + HALF_FULL_ROUNDS + PARTIAL_ROUNDS + VECTOR_LEN + AB + LinearLayers)) + ]. + End Impl_p3_air_air_Air_where_p3_air_air_AirBuilder_AB_where_p3_poseidon2_generic_GenericPoseidon2LinearLayers_LinearLayers_associated_in_trait_p3_air_air_AirBuilder___AB_Expr_AB_for_p3_poseidon2_air_vectorized_VectorizedPoseidon2Air_WIDTH_SBOX_DEGREE_SBOX_REGISTERS_HALF_FULL_ROUNDS_PARTIAL_ROUNDS_VECTOR_LEN_associated_in_trait_p3_air_air_AirBuilder___AB_F_LinearLayers. +End vectorized. diff --git a/CoqOfRust/plonky3/poseidon2/src/external.rs b/CoqOfRust/plonky3/poseidon2/src/external.rs new file mode 100644 index 000000000..4104375be --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2/src/external.rs @@ -0,0 +1,267 @@ +use alloc::vec::Vec; + +use p3_field::{Field, PrimeCharacteristicRing}; +use p3_mds::MdsPermutation; +use p3_symmetric::Permutation; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; + +/// Multiply a 4-element vector x by +/// [ 5 7 1 3 ] +/// [ 4 6 1 1 ] +/// [ 1 3 5 7 ] +/// [ 1 1 4 6 ]. +/// This uses the formula from the start of Appendix B in the Poseidon2 paper, with multiplications unrolled into additions. +/// It is also the matrix used by the Horizon Labs implementation. +#[inline(always)] +fn apply_hl_mat4(x: &mut [R; 4]) +where + R: PrimeCharacteristicRing, +{ + let t0 = x[0].clone() + x[1].clone(); + let t1 = x[2].clone() + x[3].clone(); + let t2 = x[1].clone() + x[1].clone() + t1.clone(); + let t3 = x[3].clone() + x[3].clone() + t0.clone(); + let t4 = t1.double().double() + t3.clone(); + let t5 = t0.double().double() + t2.clone(); + let t6 = t3 + t5.clone(); + let t7 = t2 + t4.clone(); + x[0] = t6; + x[1] = t5; + x[2] = t7; + x[3] = t4; +} + +// It turns out we can find a 4x4 matrix which is more efficient than the above. + +/// Multiply a 4-element vector x by: +/// [ 2 3 1 1 ] +/// [ 1 2 3 1 ] +/// [ 1 1 2 3 ] +/// [ 3 1 1 2 ]. +#[inline(always)] +fn apply_mat4(x: &mut [R; 4]) +where + R: PrimeCharacteristicRing, +{ + let t01 = x[0].clone() + x[1].clone(); + let t23 = x[2].clone() + x[3].clone(); + let t0123 = t01.clone() + t23.clone(); + let t01123 = t0123.clone() + x[1].clone(); + let t01233 = t0123 + x[3].clone(); + // The order here is important. Need to overwrite x[0] and x[2] after x[1] and x[3]. + x[3] = t01233.clone() + x[0].double(); // 3*x[0] + x[1] + x[2] + 2*x[3] + x[1] = t01123.clone() + x[2].double(); // x[0] + 2*x[1] + 3*x[2] + x[3] + x[0] = t01123 + t01; // 2*x[0] + 3*x[1] + x[2] + x[3] + x[2] = t01233 + t23; // x[0] + x[1] + 2*x[2] + 3*x[3] +} + +/// The 4x4 MDS matrix used by the Horizon Labs implementation of Poseidon2. +/// +/// This requires 10 additions and 4 doubles to compute. +#[derive(Clone, Default)] +pub struct HLMDSMat4; + +impl Permutation<[R; 4]> for HLMDSMat4 { + #[inline(always)] + fn permute_mut(&self, input: &mut [R; 4]) { + apply_hl_mat4(input) + } +} +impl MdsPermutation for HLMDSMat4 {} + +/// The fastest 4x4 MDS matrix. +/// +/// This requires 7 additions and 2 doubles to compute. +#[derive(Clone, Default)] +pub struct MDSMat4; + +impl Permutation<[R; 4]> for MDSMat4 { + #[inline(always)] + fn permute_mut(&self, input: &mut [R; 4]) { + apply_mat4(input) + } +} +impl MdsPermutation for MDSMat4 {} + +/// Implement the matrix multiplication used by the external layer. +/// +/// Given a 4x4 MDS matrix M, we multiply by the `4N x 4N` matrix +/// `[[2M M ... M], [M 2M ... M], ..., [M M ... 2M]]`. +/// +/// # Panics +/// This will panic if `WIDTH` is not supported. Currently, the +/// supported `WIDTH` values are 2, 3, 4, 8, 12, 16, 20, 24.` +#[inline(always)] +pub fn mds_light_permutation< + R: PrimeCharacteristicRing, + MdsPerm4: MdsPermutation, + const WIDTH: usize, +>( + state: &mut [R; WIDTH], + mdsmat: &MdsPerm4, +) { + match WIDTH { + 2 => { + let sum = state[0].clone() + state[1].clone(); + state[0] += sum.clone(); + state[1] += sum; + } + + 3 => { + let sum = state[0].clone() + state[1].clone() + state[2].clone(); + state[0] += sum.clone(); + state[1] += sum.clone(); + state[2] += sum; + } + + 4 | 8 | 12 | 16 | 20 | 24 => { + // First, we apply M_4 to each consecutive four elements of the state. + // In Appendix B's terminology, this replaces each x_i with x_i'. + for chunk in state.chunks_exact_mut(4) { + mdsmat.permute_mut(chunk.try_into().unwrap()); + } + // Now, we apply the outer circulant matrix (to compute the y_i values). + + // We first precompute the four sums of every four elements. + let sums: [R; 4] = core::array::from_fn(|k| { + (0..WIDTH) + .step_by(4) + .map(|j| state[j + k].clone()) + .sum::() + }); + + // The formula for each y_i involves 2x_i' term and x_j' terms for each j that equals i mod 4. + // In other words, we can add a single copy of x_i' to the appropriate one of our precomputed sums + state + .iter_mut() + .enumerate() + .for_each(|(i, elem)| *elem += sums[i % 4].clone()); + } + + _ => { + panic!("Unsupported width"); + } + } +} + +/// A struct which holds the constants for the external layer. +#[derive(Debug, Clone)] +pub struct ExternalLayerConstants { + // Once initialised, these constants should be immutable. + initial: Vec<[T; WIDTH]>, + terminal: Vec<[T; WIDTH]>, // We use terminal instead of final as final is a reserved keyword. +} + +impl ExternalLayerConstants { + pub fn new(initial: Vec<[T; WIDTH]>, terminal: Vec<[T; WIDTH]>) -> Self { + assert_eq!( + initial.len(), + terminal.len(), + "The number of initial and terminal external rounds should be equal." + ); + Self { initial, terminal } + } + + pub fn new_from_rng(external_round_number: usize, rng: &mut R) -> Self + where + StandardUniform: Distribution<[T; WIDTH]>, + { + let half_f = external_round_number / 2; + assert_eq!( + 2 * half_f, + external_round_number, + "The total number of external rounds should be even" + ); + let initial_constants = rng.sample_iter(StandardUniform).take(half_f).collect(); + let terminal_constants = rng.sample_iter(StandardUniform).take(half_f).collect(); + + Self::new(initial_constants, terminal_constants) + } + + pub fn new_from_saved_array( + [initial, terminal]: [[[U; WIDTH]; N]; 2], + conversion_fn: fn([U; WIDTH]) -> [T; WIDTH], + ) -> Self + where + T: Clone, + { + let initial_consts = initial.map(conversion_fn).to_vec(); + let terminal_consts = terminal.map(conversion_fn).to_vec(); + Self::new(initial_consts, terminal_consts) + } + + pub const fn get_initial_constants(&self) -> &Vec<[T; WIDTH]> { + &self.initial + } + + pub const fn get_terminal_constants(&self) -> &Vec<[T; WIDTH]> { + &self.terminal + } +} + +/// Initialize an external layer from a set of constants. +pub trait ExternalLayerConstructor +where + F: Field, +{ + /// A constructor which internally will convert the supplied + /// constants into the appropriate form for the implementation. + fn new_from_constants(external_constants: ExternalLayerConstants) -> Self; +} + +/// A trait containing all data needed to implement the external layers of Poseidon2. +pub trait ExternalLayer: Sync + Clone +where + R: PrimeCharacteristicRing, +{ + // permute_state_initial, permute_state_terminal are split as the Poseidon2 specifications are slightly different + // with the initial rounds involving an extra matrix multiplication. + + /// Perform the initial external layers of the Poseidon2 permutation on the given state. + fn permute_state_initial(&self, state: &mut [R; WIDTH]); + + /// Perform the terminal external layers of the Poseidon2 permutation on the given state. + fn permute_state_terminal(&self, state: &mut [R; WIDTH]); +} + +/// A helper method which allow any field to easily implement the terminal External Layer. +#[inline] +pub fn external_terminal_permute_state< + R: PrimeCharacteristicRing, + CT: Copy, // Whatever type the constants are stored as. + MdsPerm4: MdsPermutation, + const WIDTH: usize, +>( + state: &mut [R; WIDTH], + terminal_external_constants: &[[CT; WIDTH]], + add_rc_and_sbox: fn(&mut R, CT), + mat4: &MdsPerm4, +) { + for elem in terminal_external_constants { + state + .iter_mut() + .zip(elem.iter()) + .for_each(|(s, &rc)| add_rc_and_sbox(s, rc)); + mds_light_permutation(state, mat4); + } +} + +/// A helper method which allow any field to easily implement the initial External Layer. +#[inline] +pub fn external_initial_permute_state< + R: PrimeCharacteristicRing, + CT: Copy, // Whatever type the constants are stored as. + MdsPerm4: MdsPermutation, + const WIDTH: usize, +>( + state: &mut [R; WIDTH], + initial_external_constants: &[[CT; WIDTH]], + add_rc_and_sbox: fn(&mut R, CT), + mat4: &MdsPerm4, +) { + mds_light_permutation(state, mat4); + // After the initial mds_light_permutation, the remaining layers are identical + // to the terminal permutation simply with different constants. + external_terminal_permute_state(state, initial_external_constants, add_rc_and_sbox, mat4) +} diff --git a/CoqOfRust/plonky3/poseidon2/src/external.v b/CoqOfRust/plonky3/poseidon2/src/external.v new file mode 100644 index 000000000..7356a34f0 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2/src/external.v @@ -0,0 +1,3500 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module external. + (* + fn apply_hl_mat4(x: &mut [R; 4]) + where + R: PrimeCharacteristicRing, + { + let t0 = x[0].clone() + x[1].clone(); + let t1 = x[2].clone() + x[3].clone(); + let t2 = x[1].clone() + x[1].clone() + t1.clone(); + let t3 = x[3].clone() + x[3].clone() + t0.clone(); + let t4 = t1.double().double() + t3.clone(); + let t5 = t0.double().double() + t2.clone(); + let t6 = t3 + t5.clone(); + let t7 = t2 + t4.clone(); + x[0] = t6; + x[1] = t5; + x[2] = t7; + x[3] = t4; + } + *) + Definition apply_hl_mat4 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + let~ t0 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) in + let~ t1 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + ] + |) + |) in + let~ t2 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t1 |) ] + |) + ] + |) + |) in + let~ t3 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t0 |) ] + |) + ] + |) + |) in + let~ t4 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, t1 |) ] + |) + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t3 |) ] + |) + ] + |) + |) in + let~ t5 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, t0 |) ] + |) + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t2 |) ] + |) + ] + |) + |) in + let~ t6 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.read (| t3 |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t5 |) ] + |) + ] + |) + |) in + let~ t7 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.read (| t2 |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t4 |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| t6 |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| t5 |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.read (| t7 |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.read (| t4 |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_apply_hl_mat4 : + M.IsFunction.C "p3_poseidon2::external::apply_hl_mat4" apply_hl_mat4. + Admitted. + Global Typeclasses Opaque apply_hl_mat4. + + (* + fn apply_mat4(x: &mut [R; 4]) + where + R: PrimeCharacteristicRing, + { + let t01 = x[0].clone() + x[1].clone(); + let t23 = x[2].clone() + x[3].clone(); + let t0123 = t01.clone() + t23.clone(); + let t01123 = t0123.clone() + x[1].clone(); + let t01233 = t0123 + x[3].clone(); + // The order here is important. Need to overwrite x[0] and x[2] after x[1] and x[3]. + x[3] = t01233.clone() + x[0].double(); // 3*x[0] + x[1] + x[2] + 2*x[3] + x[1] = t01123.clone() + x[2].double(); // x[0] + 2*x[1] + 3*x[2] + x[3] + x[0] = t01123 + t01; // 2*x[0] + 3*x[1] + x[2] + x[3] + x[2] = t01233 + t23; // x[0] + x[1] + 2*x[2] + 3*x[3] + } + *) + Definition apply_mat4 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ R ], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + let~ t01 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) in + let~ t23 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + ] + |) + |) in + let~ t0123 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t01 |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t23 |) ] + |) + ] + |) + |) in + let~ t01123 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t0123 |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) in + let~ t01233 : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.read (| t0123 |); + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 3 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 3 + |), + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t01233 |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ + M.call_closure (| + R, + M.get_trait_method (| "core::clone::Clone", R, [], [], "clone", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, t01123 |) ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + R, + [], + [], + "double", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ M.read (| t01123 |); M.read (| t01 |) ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| x |) |), + Value.Integer IntegerKind.Usize 2 + |), + M.call_closure (| + R, + M.get_trait_method (| "core::ops::arith::Add", R, [], [ R ], "add", [], [] |), + [ M.read (| t01233 |); M.read (| t23 |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_apply_mat4 : + M.IsFunction.C "p3_poseidon2::external::apply_mat4" apply_mat4. + Admitted. + Global Typeclasses Opaque apply_mat4. + + (* StructTuple + { + name := "HLMDSMat4"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_clone_Clone_for_p3_poseidon2_external_HLMDSMat4. + Definition Self : Ty.t := Ty.path "p3_poseidon2::external::HLMDSMat4". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_poseidon2::external::HLMDSMat4" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_poseidon2_external_HLMDSMat4. + + Module Impl_core_default_Default_for_p3_poseidon2_external_HLMDSMat4. + Definition Self : Ty.t := Ty.path "p3_poseidon2::external::HLMDSMat4". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => ltac:(M.monadic (Value.StructTuple "p3_poseidon2::external::HLMDSMat4" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_poseidon2_external_HLMDSMat4. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_PrimeCharacteristicRing_R_array_Usize_4_R_for_p3_poseidon2_external_HLMDSMat4. + Definition Self (R : Ty.t) : Ty.t := Ty.path "p3_poseidon2::external::HLMDSMat4". + + (* + fn permute_mut(&self, input: &mut [R; 4]) { + apply_hl_mat4(input) + } + *) + Definition permute_mut (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_poseidon2::external::apply_hl_mat4", [], [ R ] |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (R : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ R ] ] + (Self R) + (* Instance *) [ ("permute_mut", InstanceField.Method (permute_mut R)) ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_PrimeCharacteristicRing_R_array_Usize_4_R_for_p3_poseidon2_external_HLMDSMat4. + + Module Impl_p3_mds_MdsPermutation_where_p3_field_field_PrimeCharacteristicRing_R_Usize_4_R_for_p3_poseidon2_external_HLMDSMat4. + Definition Self (R : Ty.t) : Ty.t := Ty.path "p3_poseidon2::external::HLMDSMat4". + + Axiom Implements : + forall (R : Ty.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 4 ] + (* Trait polymorphic types *) [ R ] + (Self R) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_where_p3_field_field_PrimeCharacteristicRing_R_Usize_4_R_for_p3_poseidon2_external_HLMDSMat4. + + (* StructTuple + { + name := "MDSMat4"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_clone_Clone_for_p3_poseidon2_external_MDSMat4. + Definition Self : Ty.t := Ty.path "p3_poseidon2::external::MDSMat4". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_poseidon2::external::MDSMat4" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_poseidon2_external_MDSMat4. + + Module Impl_core_default_Default_for_p3_poseidon2_external_MDSMat4. + Definition Self : Ty.t := Ty.path "p3_poseidon2::external::MDSMat4". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => ltac:(M.monadic (Value.StructTuple "p3_poseidon2::external::MDSMat4" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_p3_poseidon2_external_MDSMat4. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_PrimeCharacteristicRing_R_array_Usize_4_R_for_p3_poseidon2_external_MDSMat4. + Definition Self (R : Ty.t) : Ty.t := Ty.path "p3_poseidon2::external::MDSMat4". + + (* + fn permute_mut(&self, input: &mut [R; 4]) { + apply_mat4(input) + } + *) + Definition permute_mut (R : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self R in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_poseidon2::external::apply_mat4", [], [ R ] |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| input |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (R : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ R ] ] + (Self R) + (* Instance *) [ ("permute_mut", InstanceField.Method (permute_mut R)) ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_PrimeCharacteristicRing_R_array_Usize_4_R_for_p3_poseidon2_external_MDSMat4. + + Module Impl_p3_mds_MdsPermutation_where_p3_field_field_PrimeCharacteristicRing_R_Usize_4_R_for_p3_poseidon2_external_MDSMat4. + Definition Self (R : Ty.t) : Ty.t := Ty.path "p3_poseidon2::external::MDSMat4". + + Axiom Implements : + forall (R : Ty.t), + M.IsTraitInstance + "p3_mds::MdsPermutation" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 4 ] + (* Trait polymorphic types *) [ R ] + (Self R) + (* Instance *) []. + End Impl_p3_mds_MdsPermutation_where_p3_field_field_PrimeCharacteristicRing_R_Usize_4_R_for_p3_poseidon2_external_MDSMat4. + + (* + pub fn mds_light_permutation< + R: PrimeCharacteristicRing, + MdsPerm4: MdsPermutation, + const WIDTH: usize, + >( + state: &mut [R; WIDTH], + mdsmat: &MdsPerm4, + ) { + match WIDTH { + 2 => { + let sum = state[0].clone() + state[1].clone(); + state[0] += sum.clone(); + state[1] += sum; + } + + 3 => { + let sum = state[0].clone() + state[1].clone() + state[2].clone(); + state[0] += sum.clone(); + state[1] += sum.clone(); + state[2] += sum; + } + + 4 | 8 | 12 | 16 | 20 | 24 => { + // First, we apply M_4 to each consecutive four elements of the state. + // In Appendix B's terminology, this replaces each x_i with x_i'. + for chunk in state.chunks_exact_mut(4) { + mdsmat.permute_mut(chunk.try_into().unwrap()); + } + // Now, we apply the outer circulant matrix (to compute the y_i values). + + // We first precompute the four sums of every four elements. + let sums: [R; 4] = core::array::from_fn(|k| { + (0..WIDTH) + .step_by(4) + .map(|j| state[j + k].clone()) + .sum::() + }); + + // The formula for each y_i involves 2x_i' term and x_j' terms for each j that equals i mod 4. + // In other words, we can add a single copy of x_i' to the appropriate one of our precomputed sums + state + .iter_mut() + .enumerate() + .for_each(|(i, elem)| *elem += sums[i % 4].clone()); + } + + _ => { + panic!("Unsupported width"); + } + } + } + *) + Definition mds_light_permutation (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH ], [ R; MdsPerm4 ], [ state; mdsmat ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let mdsmat := M.alloc (| mdsmat |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| WIDTH |), + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 2 + |) in + let~ sum : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, sum |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.read (| sum |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 3 + |) in + let~ sum : Ty.apply (Ty.path "*") [] [ R ] := + M.alloc (| + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::ops::arith::Add", + R, + [], + [ R ], + "add", + [], + [] + |), + [ + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |) + ] + |) + ] + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, sum |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 1 + |) + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, sum |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 2 + |) + |); + M.read (| sum |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (Ty.tuple []) (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 4 + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 8 + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 12 + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 16 + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 20 + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.Usize 24 + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ R ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ R ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "chunks_exact_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)); + Value.Integer IntegerKind.Usize 4 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ R ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::ChunksExactMut") + [] + [ R ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, iter |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let chunk := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + MdsPerm4, + [], + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ R ] + ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| mdsmat |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ R ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ R ] + ]; + Ty.path + "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ R ] + ]; + Ty.path + "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ R ] + ], + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 4 + ] + [ R ] + ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| chunk |) + |) + |) + ] + |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ sums : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ R ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ R ], + M.get_function (| + "core::array::from_fn", + [ Value.Integer IntegerKind.Usize 4 ], + [ R; Ty.function [ Ty.tuple [ Ty.path "usize" ] ] R ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] R + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let k := M.copy (| γ |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + R + ], + [], + [], + "sum", + [], + [ R ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + R + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + [], + [], + "map", + [], + [ + R; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + R + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::step_by::StepBy") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "step_by", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", WIDTH) + ]; + Value.Integer IntegerKind.Usize 4 + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + R + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let j := + M.copy (| γ |) in + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + state + |) + |), + M.call_closure (| + Ty.path + "usize", + BinOp.Wrap.add, + [ + M.read (| + j + |); + M.read (| + k + |) + ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ R ] ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&mut") [] [ R ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ R ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ R ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&mut") [] [ R ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let i := M.copy (| γ0_0 |) in + let elem := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + R, + [], + [ R ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| elem |) |) + |); + M.call_closure (| + R, + M.get_trait_method (| + "core::clone::Clone", + R, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + sums, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.read (| i |); + Value.Integer + IntegerKind.Usize + 4 + ] + |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ mk_str (| "Unsupported width" |) ] |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_mds_light_permutation : + M.IsFunction.C "p3_poseidon2::external::mds_light_permutation" mds_light_permutation. + Admitted. + Global Typeclasses Opaque mds_light_permutation. + + (* StructRecord + { + name := "ExternalLayerConstants"; + const_params := [ "WIDTH" ]; + ty_params := [ "T" ]; + fields := + [ + ("initial", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" ]); + ("terminal", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_T_for_p3_poseidon2_external_ExternalLayerConstants_WIDTH_T. + Definition Self (WIDTH : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon2::external::ExternalLayerConstants") [ WIDTH ] [ T ]. + + (* Debug *) + Definition fmt + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "ExternalLayerConstants" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "initial" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::external::ExternalLayerConstants", + "initial" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "terminal" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::external::ExternalLayerConstants", + "terminal" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH T) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH T)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_T_for_p3_poseidon2_external_ExternalLayerConstants_WIDTH_T. + + Module Impl_core_clone_Clone_where_core_clone_Clone_T_for_p3_poseidon2_external_ExternalLayerConstants_WIDTH_T. + Definition Self (WIDTH : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon2::external::ExternalLayerConstants") [ WIDTH ] [ T ]. + + (* Clone *) + Definition clone + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_poseidon2::external::ExternalLayerConstants" + [ + ("initial", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::external::ExternalLayerConstants", + "initial" + |) + |) + |) + |) + ] + |)); + ("terminal", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::external::ExternalLayerConstants", + "terminal" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH T) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH T)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_T_for_p3_poseidon2_external_ExternalLayerConstants_WIDTH_T. + + Module Impl_p3_poseidon2_external_ExternalLayerConstants_WIDTH_T. + Definition Self (WIDTH : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon2::external::ExternalLayerConstants") [ WIDTH ] [ T ]. + + (* + pub fn new(initial: Vec<[T; WIDTH]>, terminal: Vec<[T; WIDTH]>) -> Self { + assert_eq!( + initial.len(), + terminal.len(), + "The number of initial and terminal external rounds should be equal." + ); + Self { initial, terminal } + } + *) + Definition new + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [], [ initial; terminal ] => + ltac:(M.monadic + (let initial := M.alloc (| initial |) in + let terminal := M.alloc (| terminal |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, initial |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, terminal |) ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "The number of initial and terminal external rounds should be equal." + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| + Value.StructRecord + "p3_poseidon2::external::ExternalLayerConstants" + [ ("initial", M.read (| initial |)); ("terminal", M.read (| terminal |)) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (WIDTH : Value.t) (T : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH T) "new" (new WIDTH T). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn new_from_rng(external_round_number: usize, rng: &mut R) -> Self + where + StandardUniform: Distribution<[T; WIDTH]>, + { + let half_f = external_round_number / 2; + assert_eq!( + 2 * half_f, + external_round_number, + "The total number of external rounds should be even" + ); + let initial_constants = rng.sample_iter(StandardUniform).take(half_f).collect(); + let terminal_constants = rng.sample_iter(StandardUniform).take(half_f).collect(); + + Self::new(initial_constants, terminal_constants) + } + *) + Definition new_from_rng + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [ R ], [ external_round_number; rng ] => + ltac:(M.monadic + (let external_round_number := M.alloc (| external_round_number |) in + let rng := M.alloc (| rng |) in + M.read (| + let~ half_f : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| external_round_number |); Value.Integer IntegerKind.Usize 2 ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; M.read (| half_f |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, external_round_number |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "The total number of external rounds should be even" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ initial_constants : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ T ] + ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ T ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ T ] + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ T ] + ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.apply (Ty.path "&mut") [] [ R ], + [], + [], + "sample_iter", + [], + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; + Ty.path "rand::distr::StandardUniform" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |); + Value.StructTuple "rand::distr::StandardUniform" [] + ] + |); + M.read (| half_f |) + ] + |) + ] + |) + |) in + let~ terminal_constants : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ T ] + ] + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ T ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ T ] + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + Ty.apply (Ty.path "array") [ WIDTH ] [ T ] + ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.apply (Ty.path "&mut") [] [ R ], + [], + [], + "sample_iter", + [], + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; + Ty.path "rand::distr::StandardUniform" + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |); + Value.StructTuple "rand::distr::StandardUniform" [] + ] + |); + M.read (| half_f |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_poseidon2::external::ExternalLayerConstants") [ WIDTH ] [ T ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ T ], + "new", + [], + [] + |), + [ M.read (| initial_constants |); M.read (| terminal_constants |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_from_rng : + forall (WIDTH : Value.t) (T : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH T) "new_from_rng" (new_from_rng WIDTH T). + Admitted. + Global Typeclasses Opaque new_from_rng. + + (* + pub fn new_from_saved_array( + [initial, terminal]: [[[U; WIDTH]; N]; 2], + conversion_fn: fn([U; WIDTH]) -> [T; WIDTH], + ) -> Self + where + T: Clone, + { + let initial_consts = initial.map(conversion_fn).to_vec(); + let terminal_consts = terminal.map(conversion_fn).to_vec(); + Self::new(initial_consts, terminal_consts) + } + *) + Definition new_from_saved_array + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [ N ], [ U ], [ β0; conversion_fn ] => + ltac:(M.monadic + (let β0 := M.alloc (| β0 |) in + let conversion_fn := M.alloc (| conversion_fn |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_poseidon2::external::ExternalLayerConstants") [ WIDTH ] [ T ] + ], + β0, + [ + fun γ => + ltac:(M.monadic + (let _ := is_constant_or_break_match (| M.read (| γ |), UnsupportedLiteral |) in + M.read (| + let~ initial_consts : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ], + "to_vec", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ U ] ], + "map", + [], + [ + Ty.function + [ Ty.apply (Ty.path "array") [ WIDTH ] [ U ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ T ]); + Ty.apply (Ty.path "array") [ WIDTH ] [ T ] + ] + |), + [ M.read (| initial |); M.read (| conversion_fn |) ] + |) + |) + |)) + ] + |) + |) in + let~ terminal_consts : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "array") [ WIDTH ] [ T ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ], + "to_vec", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ U ] ], + "map", + [], + [ + Ty.function + [ Ty.apply (Ty.path "array") [ WIDTH ] [ U ] ] + (Ty.apply (Ty.path "array") [ WIDTH ] [ T ]); + Ty.apply (Ty.path "array") [ WIDTH ] [ T ] + ] + |), + [ M.read (| terminal |); M.read (| conversion_fn |) ] + |) + |) + |)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ T ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ T ], + "new", + [], + [] + |), + [ M.read (| initial_consts |); M.read (| terminal_consts |) ] + |) + |) + |))) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_from_saved_array : + forall (WIDTH : Value.t) (T : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH T) "new_from_saved_array" (new_from_saved_array WIDTH T). + Admitted. + Global Typeclasses Opaque new_from_saved_array. + + (* + pub const fn get_initial_constants(&self) -> &Vec<[T; WIDTH]> { + &self.initial + } + *) + Definition get_initial_constants + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::external::ExternalLayerConstants", + "initial" + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_get_initial_constants : + forall (WIDTH : Value.t) (T : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH T) + "get_initial_constants" + (get_initial_constants WIDTH T). + Admitted. + Global Typeclasses Opaque get_initial_constants. + + (* + pub const fn get_terminal_constants(&self) -> &Vec<[T; WIDTH]> { + &self.terminal + } + *) + Definition get_terminal_constants + (WIDTH : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::external::ExternalLayerConstants", + "terminal" + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_get_terminal_constants : + forall (WIDTH : Value.t) (T : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH T) + "get_terminal_constants" + (get_terminal_constants WIDTH T). + Admitted. + Global Typeclasses Opaque get_terminal_constants. + End Impl_p3_poseidon2_external_ExternalLayerConstants_WIDTH_T. + + (* Trait *) + (* Empty module 'ExternalLayerConstructor' *) + + (* Trait *) + (* Empty module 'ExternalLayer' *) + + (* + pub fn external_terminal_permute_state< + R: PrimeCharacteristicRing, + CT: Copy, // Whatever type the constants are stored as. + MdsPerm4: MdsPermutation, + const WIDTH: usize, + >( + state: &mut [R; WIDTH], + terminal_external_constants: &[[CT; WIDTH]], + add_rc_and_sbox: fn(&mut R, CT), + mat4: &MdsPerm4, + ) { + for elem in terminal_external_constants { + state + .iter_mut() + .zip(elem.iter()) + .for_each(|(s, &rc)| add_rc_and_sbox(s, rc)); + mds_light_permutation(state, mat4); + } + } + *) + Definition external_terminal_permute_state + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ WIDTH ], + [ R; CT; MdsPerm4 ], + [ state; terminal_external_constants; add_rc_and_sbox; mat4 ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let terminal_external_constants := M.alloc (| terminal_external_constants |) in + let add_rc_and_sbox := M.alloc (| add_rc_and_sbox |) in + let mat4 := M.alloc (| mat4 |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ CT ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ CT ] ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| terminal_external_constants |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ CT ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "array") [ WIDTH ] [ CT ] ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let elem := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ R ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ CT ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ R ]; + Ty.apply (Ty.path "&") [] [ CT ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ R ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ CT ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ R ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ CT ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ R ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ R ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ CT ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ CT ], + "iter", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| elem |) |) + |)) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ R ]; + Ty.apply + (Ty.path "&") + [] + [ CT ] + ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let s := M.copy (| γ0_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let rc := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.tuple [], + M.read (| add_rc_and_sbox |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| s |) |) + |); + M.read (| rc |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::mds_light_permutation", + [ WIDTH ], + [ R; MdsPerm4 ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| mat4 |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_external_terminal_permute_state : + M.IsFunction.C + "p3_poseidon2::external::external_terminal_permute_state" + external_terminal_permute_state. + Admitted. + Global Typeclasses Opaque external_terminal_permute_state. + + (* + pub fn external_initial_permute_state< + R: PrimeCharacteristicRing, + CT: Copy, // Whatever type the constants are stored as. + MdsPerm4: MdsPermutation, + const WIDTH: usize, + >( + state: &mut [R; WIDTH], + initial_external_constants: &[[CT; WIDTH]], + add_rc_and_sbox: fn(&mut R, CT), + mat4: &MdsPerm4, + ) { + mds_light_permutation(state, mat4); + // After the initial mds_light_permutation, the remaining layers are identical + // to the terminal permutation simply with different constants. + external_terminal_permute_state(state, initial_external_constants, add_rc_and_sbox, mat4) + } + *) + Definition external_initial_permute_state + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [ WIDTH ], + [ R; CT; MdsPerm4 ], + [ state; initial_external_constants; add_rc_and_sbox; mat4 ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let initial_external_constants := M.alloc (| initial_external_constants |) in + let add_rc_and_sbox := M.alloc (| add_rc_and_sbox |) in + let mat4 := M.alloc (| mat4 |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::mds_light_permutation", + [ WIDTH ], + [ R; MdsPerm4 ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat4 |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::external_terminal_permute_state", + [ WIDTH ], + [ R; CT; MdsPerm4 ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| initial_external_constants |) |) + |); + M.read (| add_rc_and_sbox |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| mat4 |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_external_initial_permute_state : + M.IsFunction.C + "p3_poseidon2::external::external_initial_permute_state" + external_initial_permute_state. + Admitted. + Global Typeclasses Opaque external_initial_permute_state. +End external. diff --git a/CoqOfRust/plonky3/poseidon2/src/generic.rs b/CoqOfRust/plonky3/poseidon2/src/generic.rs new file mode 100644 index 000000000..d59f1ba54 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2/src/generic.rs @@ -0,0 +1,42 @@ +//! Whilst high speed implementations of Poseidon2 rely on a detailed understanding of the underlying field structure +//! it is also useful to have a generic constructor which works for a much larger range of rings. +//! +//! Indeed, for a fixed field F, the Poseidon2 permutation consists of three basic operations: +//! - Addition by elements in F. +//! - A power map x -> x^n. +//! - Multiplication by an F valued matrix. +//! +//! This means that it is possible to define a Poseidon2 over any ring implementing `Algebra`. +//! +//! This file implements the generic methods from which Poseidon2 can be built. + +use p3_field::{Algebra, Field, InjectiveMonomial, PrimeCharacteristicRing}; + +use crate::{MDSMat4, mds_light_permutation}; + +/// A generic method performing the transformation: +/// +/// `s -> (s + rc)^D` +/// +/// This is a little slower than field specific implementations (particularly for packed fields) so should +/// only be used in non performance critical places. +#[inline(always)] +pub fn add_rc_and_sbox_generic + InjectiveMonomial, const D: u64>( + val: &mut A, + rc: F, +) { + *val += rc; + *val = val.injective_exp_n(); +} + +pub trait GenericPoseidon2LinearLayers: + Sync +{ + /// A generic implementation of the internal linear layer. + fn internal_linear_layer(state: &mut [R; WIDTH]); + + /// A generic implementation of the external linear layer. + fn external_linear_layer(state: &mut [R; WIDTH]) { + mds_light_permutation(state, &MDSMat4); + } +} diff --git a/CoqOfRust/plonky3/poseidon2/src/generic.v b/CoqOfRust/plonky3/poseidon2/src/generic.v new file mode 100644 index 000000000..574930887 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2/src/generic.v @@ -0,0 +1,118 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module generic. + (* + pub fn add_rc_and_sbox_generic + InjectiveMonomial, const D: u64>( + val: &mut A, + rc: F, + ) { + *val += rc; + *val = val.injective_exp_n(); + } + *) + Definition add_rc_and_sbox_generic (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ D ], [ F; A ], [ val; rc ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + let rc := M.alloc (| rc |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + A, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| val |) |) |); + M.read (| rc |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| val |) |), + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::InjectiveMonomial", + A, + [ D ], + [], + "injective_exp_n", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| val |) |) |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_add_rc_and_sbox_generic : + M.IsFunction.C "p3_poseidon2::generic::add_rc_and_sbox_generic" add_rc_and_sbox_generic. + Admitted. + Global Typeclasses Opaque add_rc_and_sbox_generic. + + (* Trait *) + Module GenericPoseidon2LinearLayers. + Definition external_linear_layer + (WIDTH : Value.t) + (R Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ state ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::external::mds_light_permutation", + [ WIDTH ], + [ R; Ty.path "p3_poseidon2::external::MDSMat4" ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.StructTuple "p3_poseidon2::external::MDSMat4" [] |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_external_linear_layer : + forall (WIDTH : Value.t) (R : Ty.t), + M.IsProvidedMethod + "p3_poseidon2::generic::GenericPoseidon2LinearLayers" + "external_linear_layer" + (external_linear_layer WIDTH R). + End GenericPoseidon2LinearLayers. +End generic. diff --git a/CoqOfRust/plonky3/poseidon2/src/internal.rs b/CoqOfRust/plonky3/poseidon2/src/internal.rs new file mode 100644 index 000000000..9137abce3 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2/src/internal.rs @@ -0,0 +1,84 @@ +//! Inside the Poseidon2 paper, they describe that the internal layers of the hash +//! function do not require the full properties of MDS matrices. +//! +//! > For the partial rounds, the MDS property is not required anymore, and +//! > we can set up the matrix MI focusing only on providing full diffusion, breaking +//! > arbitrarily long subspace trails, and ensuring that the polynomial representation +//! > of the scheme is dense. (Section 5.2) +//! +//! This file implements a trait for linear layers that satisfy these three properties. + +// The requirements translate to the following 3 properties: +// 1: All entries are non 0. +// 2: No Subspace Trails. +// 3: For a matrix of the form 1 + D, the diagonal D should also be non 0. +// +// Properties 1 and 3 are essentially immediate to check and a sufficient condition for property 2 +// is that the minimal polynomial of the matrix M and all its powers M^2, ..., M^{2WIDTH} are maximal and irreducible. +// This is equivalent to all the characteristic polynomials being irreducible. +// +// These can be verified by the following sage code (Changing field/vector/length as desired): +// +// field = GF(2^31 - 1); +// length = 16; +// vector = [-2, 1, 2, 4, 8, 16, 32, 64, 128, 256, 1024, 4096, 8192, 16384, 32768, 65536]; +// const_mat = matrix.ones(field, length); +// diag_mat = diagonal_matrix(field, vector); +// for i in range(1, 2 * length + 1) +// assert ((const_mat + diag_mat)^i).characteristic_polynomial().is_irreducible() + +use alloc::vec::Vec; + +use p3_field::{Algebra, Field, InjectiveMonomial, PrimeCharacteristicRing}; + +use crate::add_rc_and_sbox_generic; + +/// Initialize an internal layer from a set of constants. +pub trait InternalLayerConstructor +where + F: Field, +{ + /// A constructor which internally will convert the supplied + /// constants into the appropriate form for the implementation. + fn new_from_constants(internal_constants: Vec) -> Self; +} + +/// Given a vector v compute the matrix vector product (1 + diag(v))state with 1 denoting the constant matrix of ones. +pub fn matmul_internal, const WIDTH: usize>( + state: &mut [A; WIDTH], + mat_internal_diag_m_1: [F; WIDTH], +) { + let sum: A = A::sum_array::(state); + for i in 0..WIDTH { + state[i] *= mat_internal_diag_m_1[i]; + state[i] += sum.clone(); + } +} + +/// A trait containing all data needed to implement the internal layers of Poseidon2. +pub trait InternalLayer: Sync + Clone +where + R: PrimeCharacteristicRing, +{ + /// Perform the internal layers of the Poseidon2 permutation on the given state. + fn permute_state(&self, state: &mut [R; WIDTH]); +} + +/// A helper method which allows any field to easily implement Internal Layer. +/// This should only be used in places where performance is not critical. +#[inline] +pub fn internal_permute_state< + F: Field, + A: Algebra + InjectiveMonomial, + const WIDTH: usize, + const D: u64, +>( + state: &mut [A; WIDTH], + diffusion_mat: fn(&mut [A; WIDTH]), + internal_constants: &[F], +) { + for elem in internal_constants { + add_rc_and_sbox_generic(&mut state[0], *elem); + diffusion_mat(state); + } +} diff --git a/CoqOfRust/plonky3/poseidon2/src/internal.v b/CoqOfRust/plonky3/poseidon2/src/internal.v new file mode 100644 index 000000000..66ed95b1b --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2/src/internal.v @@ -0,0 +1,348 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module internal. + (* Trait *) + (* Empty module 'InternalLayerConstructor' *) + + (* + pub fn matmul_internal, const WIDTH: usize>( + state: &mut [A; WIDTH], + mat_internal_diag_m_1: [F; WIDTH], + ) { + let sum: A = A::sum_array::(state); + for i in 0..WIDTH { + state[i] *= mat_internal_diag_m_1[i]; + state[i] += sum.clone(); + } + } + *) + Definition matmul_internal (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH ], [ F; A ], [ state; mat_internal_diag_m_1 ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let mat_internal_diag_m_1 := M.alloc (| mat_internal_diag_m_1 |) in + M.read (| + let~ sum : Ty.apply (Ty.path "*") [] [ A ] := + M.alloc (| + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + A, + [], + [], + "sum_array", + [ WIDTH ], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| state |) |) |)) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", WIDTH) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + A, + [], + [ F ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + M.read (| i |) + |) + |); + M.read (| + M.SubPointer.get_array_field (| + mat_internal_diag_m_1, + M.read (| i |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + A, + [], + [ A ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + M.read (| i |) + |) + |); + M.call_closure (| + A, + M.get_trait_method (| + "core::clone::Clone", + A, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, sum |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_matmul_internal : + M.IsFunction.C "p3_poseidon2::internal::matmul_internal" matmul_internal. + Admitted. + Global Typeclasses Opaque matmul_internal. + + (* Trait *) + (* Empty module 'InternalLayer' *) + + (* + pub fn internal_permute_state< + F: Field, + A: Algebra + InjectiveMonomial, + const WIDTH: usize, + const D: u64, + >( + state: &mut [A; WIDTH], + diffusion_mat: fn(&mut [A; WIDTH]), + internal_constants: &[F], + ) { + for elem in internal_constants { + add_rc_and_sbox_generic(&mut state[0], *elem); + diffusion_mat(state); + } + } + *) + Definition internal_permute_state (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ WIDTH; D ], [ F; A ], [ state; diffusion_mat; internal_constants ] => + ltac:(M.monadic + (let state := M.alloc (| state |) in + let diffusion_mat := M.alloc (| diffusion_mat |) in + let internal_constants := M.alloc (| internal_constants |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| internal_constants |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ F ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ F ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let elem := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_poseidon2::generic::add_rc_and_sbox_generic", + [ D ], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_array_field (| + M.deref (| M.read (| state |) |), + Value.Integer IntegerKind.Usize 0 + |) + |) + |) + |); + M.read (| M.deref (| M.read (| elem |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.read (| diffusion_mat |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_internal_permute_state : + M.IsFunction.C "p3_poseidon2::internal::internal_permute_state" internal_permute_state. + Admitted. + Global Typeclasses Opaque internal_permute_state. +End internal. diff --git a/CoqOfRust/plonky3/poseidon2/src/lib.rs b/CoqOfRust/plonky3/poseidon2/src/lib.rs new file mode 100644 index 000000000..3f265f858 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2/src/lib.rs @@ -0,0 +1,123 @@ +//! The Poseidon2 permutation. +//! +//! This implementation was based upon the following resources: +//! - `` +//! - `` + +#![no_std] + +extern crate alloc; + +mod external; +mod generic; +mod internal; +mod round_numbers; +use alloc::vec::Vec; +use core::marker::PhantomData; + +pub use external::*; +pub use generic::*; +pub use internal::*; +use p3_field::{Algebra, InjectiveMonomial, PrimeField, PrimeField64}; +use p3_symmetric::{CryptographicPermutation, Permutation}; +use rand::Rng; +use rand::distr::{Distribution, StandardUniform}; +pub use round_numbers::poseidon2_round_numbers_128; + +const SUPPORTED_WIDTHS: [usize; 8] = [2, 3, 4, 8, 12, 16, 20, 24]; + +/// The Poseidon2 permutation. +#[derive(Clone, Debug)] +pub struct Poseidon2 { + /// The permutations used in External Rounds. + external_layer: ExternalPerm, + + /// The permutation used in Internal Rounds. + internal_layer: InternalPerm, + + _phantom: PhantomData, +} + +impl + Poseidon2 +where + F: PrimeField, + ExternalPerm: ExternalLayerConstructor, + InternalPerm: InternalLayerConstructor, +{ + /// Create a new Poseidon2 configuration. + /// This internally converts the given constants to the relevant packed versions. + pub fn new( + external_constants: ExternalLayerConstants, + internal_constants: Vec, + ) -> Self { + assert!(SUPPORTED_WIDTHS.contains(&WIDTH)); + let external_layer = ExternalPerm::new_from_constants(external_constants); + let internal_layer = InternalPerm::new_from_constants(internal_constants); + + Self { + external_layer, + internal_layer, + _phantom: PhantomData, + } + } + + /// Create a new Poseidon2 configuration with random parameters. + pub fn new_from_rng(rounds_f: usize, rounds_p: usize, rng: &mut R) -> Self + where + StandardUniform: Distribution + Distribution<[F; WIDTH]>, + { + let external_constants = ExternalLayerConstants::new_from_rng(rounds_f, rng); + let internal_constants = rng.sample_iter(StandardUniform).take(rounds_p).collect(); + + Self::new(external_constants, internal_constants) + } +} + +impl + Poseidon2 +where + F: PrimeField64, + ExternalPerm: ExternalLayerConstructor, + InternalPerm: InternalLayerConstructor, +{ + /// Create a new Poseidon2 configuration with 128 bit security and random rounds constants. + /// + /// # Panics + /// This will panic if D and F::ORDER_U64 - 1 are not relatively prime. + /// This will panic if the optimal parameters for the given field and width have not been computed. + pub fn new_from_rng_128(rng: &mut R) -> Self + where + StandardUniform: Distribution + Distribution<[F; WIDTH]>, + { + let round_numbers = poseidon2_round_numbers_128::(WIDTH, D); + let (rounds_f, rounds_p) = + round_numbers.unwrap_or_else(|_| panic!("{}", round_numbers.unwrap_err())); + Self::new_from_rng(rounds_f, rounds_p, rng) + } +} + +impl Permutation<[A; WIDTH]> + for Poseidon2 +where + F: PrimeField + InjectiveMonomial, + A: Algebra + Sync + InjectiveMonomial, + ExternalPerm: ExternalLayer, + InternalPerm: InternalLayer, +{ + fn permute_mut(&self, state: &mut [A; WIDTH]) { + self.external_layer.permute_state_initial(state); + self.internal_layer.permute_state(state); + self.external_layer.permute_state_terminal(state); + } +} + +impl + CryptographicPermutation<[A; WIDTH]> for Poseidon2 +where + F: PrimeField + InjectiveMonomial, + A: Algebra + Sync + InjectiveMonomial, + ExternalPerm: ExternalLayer, + InternalPerm: InternalLayer, +{ +} diff --git a/CoqOfRust/plonky3/poseidon2/src/lib.v b/CoqOfRust/plonky3/poseidon2/src/lib.v new file mode 100644 index 000000000..2bba58e61 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2/src/lib.v @@ -0,0 +1,898 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Definition value_SUPPORTED_WIDTHS (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 4; + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 12; + Value.Integer IntegerKind.Usize 16; + Value.Integer IntegerKind.Usize 20; + Value.Integer IntegerKind.Usize 24 + ] + |))). + +Global Instance Instance_IsConstant_value_SUPPORTED_WIDTHS : + M.IsFunction.C "p3_poseidon2::SUPPORTED_WIDTHS" value_SUPPORTED_WIDTHS. +Admitted. +Global Typeclasses Opaque value_SUPPORTED_WIDTHS. + +(* StructRecord + { + name := "Poseidon2"; + const_params := [ "WIDTH"; "D" ]; + ty_params := [ "F"; "ExternalPerm"; "InternalPerm" ]; + fields := + [ + ("external_layer", ExternalPerm); + ("internal_layer", InternalPerm); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ]) + ]; + } *) + +Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_ExternalPerm_where_core_clone_Clone_InternalPerm_for_p3_poseidon2_Poseidon2_WIDTH_D_F_ExternalPerm_InternalPerm. + Definition Self (WIDTH D : Value.t) (F ExternalPerm InternalPerm : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon2::Poseidon2") [ WIDTH; D ] [ F; ExternalPerm; InternalPerm ]. + + (* Clone *) + Definition clone + (WIDTH D : Value.t) + (F ExternalPerm InternalPerm : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH D F ExternalPerm InternalPerm in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_poseidon2::Poseidon2" + [ + ("external_layer", + M.call_closure (| + ExternalPerm, + M.get_trait_method (| + "core::clone::Clone", + ExternalPerm, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::Poseidon2", + "external_layer" + |) + |) + |) + |) + ] + |)); + ("internal_layer", + M.call_closure (| + InternalPerm, + M.get_trait_method (| + "core::clone::Clone", + InternalPerm, + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::Poseidon2", + "internal_layer" + |) + |) + |) + |) + ] + |)); + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::Poseidon2", + "_phantom" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH D : Value.t) (F ExternalPerm InternalPerm : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH D F ExternalPerm InternalPerm) + (* Instance *) + [ ("clone", InstanceField.Method (clone WIDTH D F ExternalPerm InternalPerm)) ]. +End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_ExternalPerm_where_core_clone_Clone_InternalPerm_for_p3_poseidon2_Poseidon2_WIDTH_D_F_ExternalPerm_InternalPerm. + +Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_ExternalPerm_where_core_fmt_Debug_InternalPerm_for_p3_poseidon2_Poseidon2_WIDTH_D_F_ExternalPerm_InternalPerm. + Definition Self (WIDTH D : Value.t) (F ExternalPerm InternalPerm : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon2::Poseidon2") [ WIDTH; D ] [ F; ExternalPerm; InternalPerm ]. + + (* Debug *) + Definition fmt + (WIDTH D : Value.t) + (F ExternalPerm InternalPerm : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH D F ExternalPerm InternalPerm in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Poseidon2" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "external_layer" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::Poseidon2", + "external_layer" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "internal_layer" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::Poseidon2", + "internal_layer" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::Poseidon2", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH D : Value.t) (F ExternalPerm InternalPerm : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH D F ExternalPerm InternalPerm) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH D F ExternalPerm InternalPerm)) ]. +End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_ExternalPerm_where_core_fmt_Debug_InternalPerm_for_p3_poseidon2_Poseidon2_WIDTH_D_F_ExternalPerm_InternalPerm. + +Module Impl_p3_poseidon2_Poseidon2_WIDTH_D_F_ExternalPerm_InternalPerm. + Definition Self (WIDTH D : Value.t) (F ExternalPerm InternalPerm : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon2::Poseidon2") [ WIDTH; D ] [ F; ExternalPerm; InternalPerm ]. + + (* + pub fn new( + external_constants: ExternalLayerConstants, + internal_constants: Vec, + ) -> Self { + assert!(SUPPORTED_WIDTHS.contains(&WIDTH)); + let external_layer = ExternalPerm::new_from_constants(external_constants); + let internal_layer = InternalPerm::new_from_constants(internal_constants); + + Self { + external_layer, + internal_layer, + _phantom: PhantomData, + } + } + *) + Definition new + (WIDTH D : Value.t) + (F ExternalPerm InternalPerm : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH D F ExternalPerm InternalPerm in + match ε, τ, α with + | [], [], [ external_constants; internal_constants ] => + ltac:(M.monadic + (let external_constants := M.alloc (| external_constants |) in + let internal_constants := M.alloc (| internal_constants |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "usize" ], + "contains", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_poseidon2::SUPPORTED_WIDTHS", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "usize" ] + |) + |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, M.alloc (| WIDTH |) |) |) + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: SUPPORTED_WIDTHS.contains(&WIDTH)" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ external_layer : Ty.apply (Ty.path "*") [] [ ExternalPerm ] := + M.alloc (| + M.call_closure (| + ExternalPerm, + M.get_trait_method (| + "p3_poseidon2::external::ExternalLayerConstructor", + ExternalPerm, + [ WIDTH ], + [ F ], + "new_from_constants", + [], + [] + |), + [ M.read (| external_constants |) ] + |) + |) in + let~ internal_layer : Ty.apply (Ty.path "*") [] [ InternalPerm ] := + M.alloc (| + M.call_closure (| + InternalPerm, + M.get_trait_method (| + "p3_poseidon2::internal::InternalLayerConstructor", + InternalPerm, + [], + [ F ], + "new_from_constants", + [], + [] + |), + [ M.read (| internal_constants |) ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_poseidon2::Poseidon2" + [ + ("external_layer", M.read (| external_layer |)); + ("internal_layer", M.read (| internal_layer |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (WIDTH D : Value.t) (F ExternalPerm InternalPerm : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH D F ExternalPerm InternalPerm) + "new" + (new WIDTH D F ExternalPerm InternalPerm). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn new_from_rng(rounds_f: usize, rounds_p: usize, rng: &mut R) -> Self + where + StandardUniform: Distribution + Distribution<[F; WIDTH]>, + { + let external_constants = ExternalLayerConstants::new_from_rng(rounds_f, rng); + let internal_constants = rng.sample_iter(StandardUniform).take(rounds_p).collect(); + + Self::new(external_constants, internal_constants) + } + *) + Definition new_from_rng + (WIDTH D : Value.t) + (F ExternalPerm InternalPerm : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH D F ExternalPerm InternalPerm in + match ε, τ, α with + | [], [ R ], [ rounds_f; rounds_p; rng ] => + ltac:(M.monadic + (let rounds_f := M.alloc (| rounds_f |) in + let rounds_p := M.alloc (| rounds_p |) in + let rng := M.alloc (| rng |) in + M.read (| + let~ external_constants : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_poseidon2::external::ExternalLayerConstants") [ WIDTH ] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::external::ExternalLayerConstants") + [ WIDTH ] + [ F ], + "new_from_rng", + [], + [ R ] + |), + [ + M.read (| rounds_f |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |) + ] + |) + |) in + let~ internal_constants : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ] + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.apply (Ty.path "&mut") [] [ R ], + [], + [], + "sample_iter", + [], + [ F; Ty.path "rand::distr::StandardUniform" ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |); + Value.StructTuple "rand::distr::StandardUniform" [] + ] + |); + M.read (| rounds_p |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ WIDTH; D ] + [ F; ExternalPerm; InternalPerm ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ WIDTH; D ] + [ F; ExternalPerm; InternalPerm ], + "new", + [], + [] + |), + [ M.read (| external_constants |); M.read (| internal_constants |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_from_rng : + forall (WIDTH D : Value.t) (F ExternalPerm InternalPerm : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH D F ExternalPerm InternalPerm) + "new_from_rng" + (new_from_rng WIDTH D F ExternalPerm InternalPerm). + Admitted. + Global Typeclasses Opaque new_from_rng. + (* + pub fn new_from_rng_128(rng: &mut R) -> Self + where + StandardUniform: Distribution + Distribution<[F; WIDTH]>, + { + let round_numbers = poseidon2_round_numbers_128::(WIDTH, D); + let (rounds_f, rounds_p) = + round_numbers.unwrap_or_else(|_| panic!("{}", round_numbers.unwrap_err())); + Self::new_from_rng(rounds_f, rounds_p, rng) + } + *) + Definition new_from_rng_128 + (WIDTH D : Value.t) + (F ExternalPerm InternalPerm : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH D F ExternalPerm InternalPerm in + match ε, τ, α with + | [], [ R ], [ rng ] => + ltac:(M.monadic + (let rng := M.alloc (| rng |) in + M.read (| + let~ round_numbers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ], + M.get_function (| + "p3_poseidon2::round_numbers::poseidon2_round_numbers_128", + [], + [ F ] + |), + [ WIDTH; D ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ WIDTH; D ] + [ F; ExternalPerm; InternalPerm ] + ], + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ], + "unwrap_or_else", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ] + |), + [ + M.read (| round_numbers |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] ] + (Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.read (| + (* Unimplemented parent_kind *) + M.alloc (| Value.Tuple [] |) + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple + [ Ty.path "usize"; Ty.path "usize" ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ], + "unwrap_err", + [], + [] + |), + [ M.read (| round_numbers |) ] + |) + |) + |) + |) + |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let rounds_f := M.copy (| γ0_0 |) in + let rounds_p := M.copy (| γ0_1 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ WIDTH; D ] + [ F; ExternalPerm; InternalPerm ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_poseidon2::Poseidon2") + [ WIDTH; D ] + [ F; ExternalPerm; InternalPerm ], + "new_from_rng", + [], + [ R ] + |), + [ + M.read (| rounds_f |); + M.read (| rounds_p |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_from_rng_128 : + forall (WIDTH D : Value.t) (F ExternalPerm InternalPerm : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH D F ExternalPerm InternalPerm) + "new_from_rng_128" + (new_from_rng_128 WIDTH D F ExternalPerm InternalPerm). + Admitted. + Global Typeclasses Opaque new_from_rng_128. +End Impl_p3_poseidon2_Poseidon2_WIDTH_D_F_ExternalPerm_InternalPerm. + + +Module Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_PrimeField_F_where_p3_field_field_InjectiveMonomial_F_where_p3_field_field_Algebra_A_F_where_core_marker_Sync_A_where_p3_field_field_InjectiveMonomial_A_where_p3_poseidon2_external_ExternalLayer_ExternalPerm_A_where_p3_poseidon2_internal_InternalLayer_InternalPerm_A_array_WIDTH_A_for_p3_poseidon2_Poseidon2_WIDTH_D_F_ExternalPerm_InternalPerm. + Definition Self (WIDTH D : Value.t) (F A ExternalPerm InternalPerm : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon2::Poseidon2") [ WIDTH; D ] [ F; ExternalPerm; InternalPerm ]. + + (* + fn permute_mut(&self, state: &mut [A; WIDTH]) { + self.external_layer.permute_state_initial(state); + self.internal_layer.permute_state(state); + self.external_layer.permute_state_terminal(state); + } + *) + Definition permute_mut + (WIDTH D : Value.t) + (F A ExternalPerm InternalPerm : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH D F A ExternalPerm InternalPerm in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_poseidon2::external::ExternalLayer", + ExternalPerm, + [ WIDTH; D ], + [ A ], + "permute_state_initial", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::Poseidon2", + "external_layer" + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_poseidon2::internal::InternalLayer", + InternalPerm, + [ WIDTH; D ], + [ A ], + "permute_state", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::Poseidon2", + "internal_layer" + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_poseidon2::external::ExternalLayer", + ExternalPerm, + [ WIDTH; D ], + [ A ], + "permute_state_terminal", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_poseidon2::Poseidon2", + "external_layer" + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH D : Value.t) (F A ExternalPerm InternalPerm : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ WIDTH ] [ A ] ] + (Self WIDTH D F A ExternalPerm InternalPerm) + (* Instance *) + [ ("permute_mut", InstanceField.Method (permute_mut WIDTH D F A ExternalPerm InternalPerm)) ]. +End Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_PrimeField_F_where_p3_field_field_InjectiveMonomial_F_where_p3_field_field_Algebra_A_F_where_core_marker_Sync_A_where_p3_field_field_InjectiveMonomial_A_where_p3_poseidon2_external_ExternalLayer_ExternalPerm_A_where_p3_poseidon2_internal_InternalLayer_InternalPerm_A_array_WIDTH_A_for_p3_poseidon2_Poseidon2_WIDTH_D_F_ExternalPerm_InternalPerm. + +Module Impl_p3_symmetric_permutation_CryptographicPermutation_where_p3_field_field_PrimeField_F_where_p3_field_field_InjectiveMonomial_F_where_p3_field_field_Algebra_A_F_where_core_marker_Sync_A_where_p3_field_field_InjectiveMonomial_A_where_p3_poseidon2_external_ExternalLayer_ExternalPerm_A_where_p3_poseidon2_internal_InternalLayer_InternalPerm_A_array_WIDTH_A_for_p3_poseidon2_Poseidon2_WIDTH_D_F_ExternalPerm_InternalPerm. + Definition Self (WIDTH D : Value.t) (F A ExternalPerm InternalPerm : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_poseidon2::Poseidon2") [ WIDTH; D ] [ F; ExternalPerm; InternalPerm ]. + + Axiom Implements : + forall (WIDTH D : Value.t) (F A ExternalPerm InternalPerm : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::CryptographicPermutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ WIDTH ] [ A ] ] + (Self WIDTH D F A ExternalPerm InternalPerm) + (* Instance *) []. +End Impl_p3_symmetric_permutation_CryptographicPermutation_where_p3_field_field_PrimeField_F_where_p3_field_field_InjectiveMonomial_F_where_p3_field_field_Algebra_A_F_where_core_marker_Sync_A_where_p3_field_field_InjectiveMonomial_A_where_p3_poseidon2_external_ExternalLayer_ExternalPerm_A_where_p3_poseidon2_internal_InternalLayer_InternalPerm_A_array_WIDTH_A_for_p3_poseidon2_Poseidon2_WIDTH_D_F_ExternalPerm_InternalPerm. diff --git a/CoqOfRust/plonky3/poseidon2/src/round_numbers.rs b/CoqOfRust/plonky3/poseidon2/src/round_numbers.rs new file mode 100644 index 000000000..7aac89e11 --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2/src/round_numbers.rs @@ -0,0 +1,80 @@ +//! As the security analysis of Poseidon2 is identical to that of Poseidon, +//! the relevant constraints regarding the number of full/partial rounds required can be found in +//! the original paper: `` and the associated codebase: +//! `` (See generate_params_poseidon.sage) +//! +//! These constraints are broken down into 6 equations: +//! statistical, interpolation, Gröbner 1, 2, 3 and +//! an extra constraint coming from the paper ``. +//! +//! For our parameters (M = 128, p > 2^30, WIDTH = t >= 8, D = alpha < 12), +//! the statistical constraint always simplifies to requiring RF >= 6. +//! Additionally p does not appear in Gröbner 3 or the constraint coming from ``. +//! The remaining 3 constraints all can be rearranged into the form: +//! F(RF, RP) >= G(p) where G is a function which is non-decreasing with respect to p. +//! +//! Thus, if some tuple (M, p, WIDTH, D, RF, RP) satisfies all constraints, then so will +//! the tuple (M, q, WIDTH, D, RF, RP) for any 2^30 < q < p. +//! Moreover if RF, RP are the "optimal" round numbers (Optimal meaning minimising the number of S-box operations we need to perform) +//! for two tuples (M, p, WIDTH, D) and (M, q, WIDTH, D), then +//! they will also be optimal for (M, r, WIDTH, D) for any q < r < p. +//! +//! We compute the optimal required number of external (full) and internal (partial) rounds using: +//! `` +//! Using the above analysis we can conclude that the round numbers are equal +//! for all 31 bit primes and 64 bit primes respectively. + +use p3_field::PrimeField64; +use p3_util::relatively_prime_u64; + +/// Given a field, a width and an D return the number of full and partial rounds needed to achieve 128 bit security. +/// +/// If d is not a valid permutation of the given field or the optimal parameters for that size of prime +/// have not been computed, an error is returned. +pub const fn poseidon2_round_numbers_128( + width: usize, + d: u64, +) -> Result<(usize, usize), &'static str> { + // Start by checking that d is a valid permutation. + if !relatively_prime_u64(d, F::ORDER_U64 - 1) { + return Err("Invalid permutation: gcd(d, F::ORDER_U64 - 1) must be 1"); + } + + // Next compute the number of bits in p. + let prime_bit_number = F::ORDER_U64.ilog2() + 1; + + match prime_bit_number { + 31 => match (width, d) { + (16, 3) => Ok((8, 20)), + (16, 5) => Ok((8, 14)), + (16, 7) => Ok((8, 13)), + (16, 9) => Ok((8, 13)), + (16, 11) => Ok((8, 13)), + (24, 3) => Ok((8, 23)), + (24, 5) => Ok((8, 22)), + (24, 7) => Ok((8, 21)), + (24, 9) => Ok((8, 21)), + (24, 11) => Ok((8, 21)), + _ => Err("The given pair of width and D has not been checked for these fields"), + }, + 64 => match (width, d) { + (8, 3) => Ok((8, 41)), + (8, 5) => Ok((8, 27)), + (8, 7) => Ok((8, 22)), + (8, 9) => Ok((8, 19)), + (8, 11) => Ok((8, 17)), + (12, 3) => Ok((8, 42)), + (12, 5) => Ok((8, 27)), + (12, 7) => Ok((8, 22)), + (12, 9) => Ok((8, 20)), + (12, 11) => Ok((8, 18)), + (16, 3) => Ok((8, 42)), + (16, 5) => Ok((8, 27)), + (16, 7) => Ok((8, 22)), + (16, 9) => Ok((8, 20)), + (16, 11) => Ok((8, 18)), + _ => Err("The given pair of width and D has not been checked for these fields"), + }, + _ => Err("The optimal parameters for that size of prime have not been computed."), + } +} diff --git a/CoqOfRust/plonky3/poseidon2/src/round_numbers.v b/CoqOfRust/plonky3/poseidon2/src/round_numbers.v new file mode 100644 index 000000000..438e8e10a --- /dev/null +++ b/CoqOfRust/plonky3/poseidon2/src/round_numbers.v @@ -0,0 +1,902 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module round_numbers. + (* + pub const fn poseidon2_round_numbers_128( + width: usize, + d: u64, + ) -> Result<(usize, usize), &'static str> { + // Start by checking that d is a valid permutation. + if !relatively_prime_u64(d, F::ORDER_U64 - 1) { + return Err("Invalid permutation: gcd(d, F::ORDER_U64 - 1) must be 1"); + } + + // Next compute the number of bits in p. + let prime_bit_number = F::ORDER_U64.ilog2() + 1; + + match prime_bit_number { + 31 => match (width, d) { + (16, 3) => Ok((8, 20)), + (16, 5) => Ok((8, 14)), + (16, 7) => Ok((8, 13)), + (16, 9) => Ok((8, 13)), + (16, 11) => Ok((8, 13)), + (24, 3) => Ok((8, 23)), + (24, 5) => Ok((8, 22)), + (24, 7) => Ok((8, 21)), + (24, 9) => Ok((8, 21)), + (24, 11) => Ok((8, 21)), + _ => Err("The given pair of width and D has not been checked for these fields"), + }, + 64 => match (width, d) { + (8, 3) => Ok((8, 41)), + (8, 5) => Ok((8, 27)), + (8, 7) => Ok((8, 22)), + (8, 9) => Ok((8, 19)), + (8, 11) => Ok((8, 17)), + (12, 3) => Ok((8, 42)), + (12, 5) => Ok((8, 27)), + (12, 7) => Ok((8, 22)), + (12, 9) => Ok((8, 20)), + (12, 11) => Ok((8, 18)), + (16, 3) => Ok((8, 42)), + (16, 5) => Ok((8, 27)), + (16, 7) => Ok((8, 22)), + (16, 9) => Ok((8, 20)), + (16, 11) => Ok((8, 18)), + _ => Err("The given pair of width and D has not been checked for these fields"), + }, + _ => Err("The optimal parameters for that size of prime have not been computed."), + } + } + *) + Definition poseidon2_round_numbers_128 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ width; d ] => + ltac:(M.monadic + (let width := M.alloc (| width |) in + let d := M.alloc (| d |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_function (| "p3_util::relatively_prime_u64", [], [] |), + [ + M.read (| d |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |); + Value.Integer IntegerKind.U64 1 + ] + |) + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "Invalid permutation: gcd(d, F::ORDER_U64 - 1) must be 1" + |) + |) + |) + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ prime_bit_number : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u64", "ilog2", [], [] |), + [ + M.read (| + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + ] + |); + Value.Integer IntegerKind.U32 1 + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ] + ], + prime_bit_number, + [ + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U32 31 + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ] + ], + M.alloc (| Value.Tuple [ M.read (| width |); M.read (| d |) ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 16 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 3 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 20 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 16 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 5 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 14 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 16 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 7 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 13 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 16 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 9 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 13 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 16 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 11 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 13 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 24 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 3 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 23 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 24 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 5 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 22 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 24 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 7 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 21 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 24 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 9 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 21 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 24 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 11 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 21 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::result::Result::Err" + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "The given pair of width and D has not been checked for these fields" + |) + |) + |) + ] + |))) + ] + |))); + fun γ => + ltac:(M.monadic + (let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U32 64 + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple [ Ty.path "usize"; Ty.path "usize" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ] + ], + M.alloc (| Value.Tuple [ M.read (| width |); M.read (| d |) ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 8 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 3 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 41 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 8 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 5 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 27 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 8 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 7 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 22 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 8 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 9 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 19 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 8 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 11 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 17 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 12 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 3 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 42 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 12 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 5 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 27 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 12 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 7 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 22 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 12 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 9 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 20 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 12 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 11 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 18 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 16 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 3 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 42 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 16 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 5 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 27 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 16 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 7 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 22 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 16 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 9 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 20 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.Usize 16 + |) in + let _ := + is_constant_or_break_match (| + M.read (| γ0_1 |), + Value.Integer IntegerKind.U64 11 + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.Tuple + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 18 + ] + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::result::Result::Err" + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "The given pair of width and D has not been checked for these fields" + |) + |) + |) + ] + |))) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::result::Result::Err" + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + mk_str (| + "The optimal parameters for that size of prime have not been computed." + |) + |) + |) + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_poseidon2_round_numbers_128 : + M.IsFunction.C + "p3_poseidon2::round_numbers::poseidon2_round_numbers_128" + poseidon2_round_numbers_128. + Admitted. + Global Typeclasses Opaque poseidon2_round_numbers_128. +End round_numbers. diff --git a/CoqOfRust/plonky3/rescue/src/lib.rs b/CoqOfRust/plonky3/rescue/src/lib.rs new file mode 100644 index 000000000..b4e463e55 --- /dev/null +++ b/CoqOfRust/plonky3/rescue/src/lib.rs @@ -0,0 +1,9 @@ +#![allow(dead_code)] // TODO: remove when we settle on implementation details and publicly export +#![no_std] + +extern crate alloc; + +mod rescue; +mod util; + +pub use rescue::*; diff --git a/CoqOfRust/plonky3/rescue/src/rescue.rs b/CoqOfRust/plonky3/rescue/src/rescue.rs new file mode 100644 index 000000000..929858bd0 --- /dev/null +++ b/CoqOfRust/plonky3/rescue/src/rescue.rs @@ -0,0 +1,245 @@ +use alloc::format; +use alloc::vec::Vec; + +use itertools::Itertools; +use p3_field::{Algebra, PermutationMonomial, PrimeField, PrimeField64}; +use p3_mds::MdsPermutation; +use p3_symmetric::{CryptographicPermutation, Permutation}; +use rand::Rng; +use rand::distr::StandardUniform; +use rand::prelude::Distribution; + +use crate::util::{log2_binom, shake256_hash}; + +/// The Rescue-XLIX permutation. +#[derive(Clone, Debug)] +pub struct Rescue { + num_rounds: usize, + mds: Mds, + round_constants: Vec, +} + +impl Rescue +where + F: PrimeField + PermutationMonomial, +{ + pub const fn new(num_rounds: usize, round_constants: Vec, mds: Mds) -> Self { + Self { + num_rounds, + mds, + round_constants, + } + } + + /// Calculate the number of rounds needed to attain 2^sec_level security. + /// + /// The formulas here are direct translations of those from the + /// Rescue Prime paper in Section 2.5 and following. See the paper + /// for justifications. + pub fn num_rounds(capacity: usize, sec_level: usize) -> usize { + let rate = (WIDTH - capacity) as u64; + // This iterator produces pairs (dcon, v) increasing by a fixed + // amount (determined by the formula in the paper) each iteration, + // together with the value log2(binomial(v + dcon, v)). These values + // are fed into `find` which picks the first that exceed the desired + // security level. + let rnds = (1..) + .scan((2, rate), |(dcon, v), r| { + let log2_bin = log2_binom(*v + *dcon, *v); + + // ALPHA is a prime > 2, so ALPHA + 1 is even, hence this + // division is exact. + *dcon += WIDTH as u64 * (ALPHA + 1) / 2; + *v += WIDTH as u64; + + Some((r, log2_bin)) + }) + .find(|(_r, log2_bin)| 2.0 * log2_bin > sec_level as f32) + .unwrap(); // Guaranteed to succeed for suff. large (dcon,v). + let rnds = rnds.0; + + // The paper mandates a minimum of 5 rounds and adds a 50% + // safety margin: ceil(1.5 * max{5, rnds}) + (3 * rnds.max(5_usize)).div_ceil(2) + } + + // For a general field, we provide a generic constructor for the round constants. + pub fn get_round_constants_from_rng(num_rounds: usize, rng: &mut R) -> Vec + where + StandardUniform: Distribution, + { + let num_constants = 2 * WIDTH * num_rounds; + rng.sample_iter(StandardUniform) + .take(num_constants) + .collect() + } + + fn get_round_constants_rescue_prime( + num_rounds: usize, + capacity: usize, + sec_level: usize, + ) -> Vec + where + F: PrimeField64, + { + let num_constants = 2 * WIDTH * num_rounds; + let bytes_per_constant = F::bits().div_ceil(8) + 1; + let num_bytes = bytes_per_constant * num_constants; + + let seed_string = format!( + "Rescue-XLIX({},{},{},{})", + F::ORDER_U64, + WIDTH, + capacity, + sec_level, + ); + let byte_string = shake256_hash(seed_string.as_bytes(), num_bytes); + + byte_string + .iter() + .chunks(bytes_per_constant) + .into_iter() + .map(|chunk| { + let integer = chunk + .collect_vec() + .iter() + .rev() + .fold(0, |acc, &byte| (acc << 8) + *byte as u64); + F::from_u64(integer) + }) + .collect() + } +} + +impl Permutation<[A; WIDTH]> + for Rescue +where + F: PrimeField + PermutationMonomial, + A: Algebra + PermutationMonomial, + Mds: MdsPermutation, +{ + fn permute_mut(&self, state: &mut [A; WIDTH]) { + for round in 0..self.num_rounds { + // S-box + state.iter_mut().for_each(|x| *x = x.injective_exp_n()); + + // MDS + self.mds.permute_mut(state); + + // Constants + for (state_item, &round_constant) in state + .iter_mut() + .zip(&self.round_constants[round * WIDTH * 2..]) + { + *state_item += round_constant; + } + + // Inverse S-box + state.iter_mut().for_each(|x| *x = x.injective_exp_root_n()); + + // MDS + self.mds.permute_mut(state); + + // Constants + for (state_item, &round_constant) in state + .iter_mut() + .zip(&self.round_constants[round * WIDTH * 2 + WIDTH..]) + { + *state_item += round_constant; + } + } + } +} + +impl CryptographicPermutation<[A; WIDTH]> + for Rescue +where + F: PrimeField + PermutationMonomial, + A: Algebra + PermutationMonomial, + Mds: MdsPermutation, +{ +} + +#[cfg(test)] +mod tests { + use p3_field::PrimeCharacteristicRing; + use p3_mersenne_31::{MdsMatrixMersenne31, Mersenne31}; + use p3_symmetric::{CryptographicHasher, PaddingFreeSponge, Permutation}; + + use crate::rescue::Rescue; + + const WIDTH: usize = 12; + const ALPHA: u64 = 5; + type RescuePrimeM31Default = Rescue; + + fn new_rescue_prime_m31_default() -> RescuePrimeM31Default { + let num_rounds = RescuePrimeM31Default::num_rounds(6, 128); + let round_constants = + RescuePrimeM31Default::get_round_constants_rescue_prime(num_rounds, 6, 128); + let mds = MdsMatrixMersenne31 {}; + + RescuePrimeM31Default::new(num_rounds, round_constants, mds) + } + + const NUM_TESTS: usize = 3; + + const PERMUTATION_INPUTS: [[u64; WIDTH]; NUM_TESTS] = [ + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], + [ + 144096679, 1638468327, 1550998769, 1713522258, 730676443, 955614588, 1970746889, + 1473251100, 1575313887, 1867935938, 364960233, 91318724, + ], + [ + 1946786350, 648783024, 470775457, 573110744, 2049365630, 710763043, 1694076126, + 1852085316, 1518834534, 249604062, 45487116, 1543494419, + ], + ]; + + // Generated using the rescue_XLIX_permutation function of + // https://github.com/KULeuven-COSIC/Marvellous/blob/master/rescue_prime.sage + const PERMUTATION_OUTPUTS: [[u64; WIDTH]; NUM_TESTS] = [ + [ + 1415867641, 1662872101, 1070605392, 450708029, 1752877321, 144003686, 623713963, + 13124252, 1719755748, 1164265443, 1031746503, 656034061, + ], + [ + 745601819, 399135364, 1705560828, 1125372012, 2039222953, 1144119753, 1606567447, + 1152559313, 1762793605, 424623198, 651056006, 1227670410, + ], + [ + 277798368, 1055656487, 366843969, 917136738, 1286790161, 1840518903, 161567750, + 974017246, 1102241644, 633393178, 896102012, 1791619348, + ], + ]; + + #[test] + fn test_rescue_xlix_permutation() { + let rescue_prime = new_rescue_prime_m31_default(); + + for test_run in 0..NUM_TESTS { + let state: [Mersenne31; WIDTH] = PERMUTATION_INPUTS[test_run].map(Mersenne31::from_u64); + + let expected: [Mersenne31; WIDTH] = + PERMUTATION_OUTPUTS[test_run].map(Mersenne31::from_u64); + + let actual = rescue_prime.permute(state); + assert_eq!(actual, expected); + } + } + + #[test] + fn test_rescue_sponge() { + let rescue_prime = new_rescue_prime_m31_default(); + let rescue_sponge = PaddingFreeSponge::<_, WIDTH, 8, 6>::new(rescue_prime); + + let input: [Mersenne31; 6] = [1, 2, 3, 4, 5, 6].map(Mersenne31::from_u8); + + let expected: [Mersenne31; 6] = [ + 2055426095, 968531194, 1592692524, 136824376, 175318858, 1160805485, + ] + .map(Mersenne31::from_u64); + + let actual = rescue_sponge.hash_iter(input); + assert_eq!(actual, expected); + } +} diff --git a/CoqOfRust/plonky3/rescue/src/rescue.v b/CoqOfRust/plonky3/rescue/src/rescue.v new file mode 100644 index 000000000..7b5c849fe --- /dev/null +++ b/CoqOfRust/plonky3/rescue/src/rescue.v @@ -0,0 +1,2718 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module rescue. + (* StructRecord + { + name := "Rescue"; + const_params := [ "WIDTH"; "ALPHA" ]; + ty_params := [ "F"; "Mds" ]; + fields := + [ + ("num_rounds", Ty.path "usize"); + ("mds", Mds); + ("round_constants", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ]) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_Mds_for_p3_rescue_rescue_Rescue_WIDTH_ALPHA_F_Mds. + Definition Self (WIDTH ALPHA : Value.t) (F Mds : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_rescue::rescue::Rescue") [ WIDTH; ALPHA ] [ F; Mds ]. + + (* Clone *) + Definition clone + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_rescue::rescue::Rescue" + [ + ("num_rounds", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "num_rounds" + |) + |) + |) + |) + ] + |)); + ("mds", + M.call_closure (| + Mds, + M.get_trait_method (| "core::clone::Clone", Mds, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "mds" + |) + |) + |) + |) + ] + |)); + ("round_constants", + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "round_constants" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH ALPHA F Mds) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH ALPHA F Mds)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_Mds_for_p3_rescue_rescue_Rescue_WIDTH_ALPHA_F_Mds. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_Mds_for_p3_rescue_rescue_Rescue_WIDTH_ALPHA_F_Mds. + Definition Self (WIDTH ALPHA : Value.t) (F Mds : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_rescue::rescue::Rescue") [ WIDTH; ALPHA ] [ F; Mds ]. + + (* Debug *) + Definition fmt + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Rescue" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "num_rounds" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "num_rounds" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "mds" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "mds" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "round_constants" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "round_constants" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH ALPHA F Mds) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH ALPHA F Mds)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_Mds_for_p3_rescue_rescue_Rescue_WIDTH_ALPHA_F_Mds. + + Module Impl_p3_rescue_rescue_Rescue_WIDTH_ALPHA_F_Mds. + Definition Self (WIDTH ALPHA : Value.t) (F Mds : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_rescue::rescue::Rescue") [ WIDTH; ALPHA ] [ F; Mds ]. + + (* + pub const fn new(num_rounds: usize, round_constants: Vec, mds: Mds) -> Self { + Self { + num_rounds, + mds, + round_constants, + } + } + *) + Definition new + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [], [ num_rounds; round_constants; mds ] => + ltac:(M.monadic + (let num_rounds := M.alloc (| num_rounds |) in + let round_constants := M.alloc (| round_constants |) in + let mds := M.alloc (| mds |) in + Value.StructRecord + "p3_rescue::rescue::Rescue" + [ + ("num_rounds", M.read (| num_rounds |)); + ("mds", M.read (| mds |)); + ("round_constants", M.read (| round_constants |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH ALPHA F Mds) "new" (new WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn num_rounds(capacity: usize, sec_level: usize) -> usize { + let rate = (WIDTH - capacity) as u64; + // This iterator produces pairs (dcon, v) increasing by a fixed + // amount (determined by the formula in the paper) each iteration, + // together with the value log2(binomial(v + dcon, v)). These values + // are fed into `find` which picks the first that exceed the desired + // security level. + let rnds = (1..) + .scan((2, rate), |(dcon, v), r| { + let log2_bin = log2_binom( *v + *dcon, *v); + + // ALPHA is a prime > 2, so ALPHA + 1 is even, hence this + // division is exact. + *dcon += WIDTH as u64 * (ALPHA + 1) / 2; + *v += WIDTH as u64; + + Some((r, log2_bin)) + }) + .find(|(_r, log2_bin)| 2.0 * log2_bin > sec_level as f32) + .unwrap(); // Guaranteed to succeed for suff. large (dcon,v). + let rnds = rnds.0; + + // The paper mandates a minimum of 5 rounds and adds a 50% + // safety margin: ceil(1.5 * max{5, rnds}) + (3 * rnds.max(5_usize)).div_ceil(2) + } + *) + Definition num_rounds + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [], [ capacity; sec_level ] => + ltac:(M.monadic + (let capacity := M.alloc (| capacity |) in + let sec_level := M.alloc (| sec_level |) in + M.read (| + let~ rate : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.cast + (Ty.path "u64") + (M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ WIDTH; M.read (| capacity |) ] + |)) + |) in + let~ rnds : Ty.apply (Ty.path "*") [] [ Ty.tuple [ Ty.path "usize"; Ty.path "f32" ] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "usize"; Ty.path "f32" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.path "f32" ] ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.path "f32" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::scan::Scan") + [] + [ + Ty.apply (Ty.path "core::ops::range::RangeFrom") [] [ Ty.path "usize" ]; + Ty.tuple [ Ty.path "u64"; Ty.path "u64" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.tuple [ Ty.path "u64"; Ty.path "u64" ] ]; + Ty.path "usize" + ] + ] + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.path "f32" ] ]) + ], + [], + [], + "find", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.path "f32" ] ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::scan::Scan") + [] + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ]; + Ty.tuple [ Ty.path "u64"; Ty.path "u64" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.tuple [ Ty.path "u64"; Ty.path "u64" ] ]; + Ty.path "usize" + ] + ] + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.path "f32" ] ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ], + [], + [], + "scan", + [], + [ + Ty.tuple [ Ty.path "u64"; Ty.path "u64" ]; + Ty.tuple [ Ty.path "usize"; Ty.path "f32" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.tuple [ Ty.path "u64"; Ty.path "u64" ] ]; + Ty.path "usize" + ] + ] + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.path "f32" ] ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ]; + Value.Tuple [ Value.Integer IntegerKind.U64 2; M.read (| rate |) ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.tuple + [ Ty.path "u64"; Ty.path "u64" ] + ]; + Ty.path "usize" + ] + ] + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.path "f32" ] ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let dcon := M.alloc (| γ1_0 |) in + let v := M.alloc (| γ1_1 |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.tuple + [ Ty.path "u64"; Ty.path "u64" + ] + ]; + Ty.path "usize" + ] + ] + (Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ Ty.path "usize"; Ty.path "f32" ] + ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let r := M.copy (| γ |) in + M.read (| + let~ log2_bin : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "f32" ] := + M.alloc (| + M.call_closure (| + Ty.path "f32", + M.get_function (| + "p3_rescue::util::log2_binom", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ + M.read (| + M.deref (| + M.read (| v |) + |) + |); + M.read (| + M.deref (| + M.read (| dcon |) + |) + |) + ] + |); + M.read (| + M.deref (| M.read (| v |) |) + |) + ] + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + let β := + M.deref (| M.read (| dcon |) |) in + M.write (| + β, + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ + M.read (| β |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.mul, + [ + M.cast + (Ty.path "u64") + WIDTH; + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ + ALPHA; + Value.Integer + IntegerKind.U64 + 1 + ] + |) + ] + |); + Value.Integer + IntegerKind.U64 + 2 + ] + |) + ] + |) + |) + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + let β := + M.deref (| M.read (| v |) |) in + M.write (| + β, + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ + M.read (| β |); + M.cast (Ty.path "u64") WIDTH + ] + |) + |) + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + Value.Tuple + [ + M.read (| r |); + M.read (| log2_bin |) + ] + ] + |) + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.tuple [ Ty.path "usize"; Ty.path "f32" ] ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _r := M.alloc (| γ1_0 |) in + let log2_bin := M.alloc (| γ1_1 |) in + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ + M.call_closure (| + Ty.path "f32", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "f32", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "f32" ] ], + "mul", + [], + [] + |), + [ + M.read (| UnsupportedLiteral |); + M.read (| log2_bin |) + ] + |); + M.cast (Ty.path "f32") (M.read (| sec_level |)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ rnds : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.copy (| M.SubPointer.get_tuple_field (| rnds, 0 |) |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "div_ceil", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + Value.Integer IntegerKind.Usize 3; + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "usize", + [], + [], + "max", + [], + [] + |), + [ M.read (| rnds |); Value.Integer IntegerKind.Usize 5 ] + |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_num_rounds : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH ALPHA F Mds) "num_rounds" (num_rounds WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque num_rounds. + + (* + pub fn get_round_constants_from_rng(num_rounds: usize, rng: &mut R) -> Vec + where + StandardUniform: Distribution, + { + let num_constants = 2 * WIDTH * num_rounds; + rng.sample_iter(StandardUniform) + .take(num_constants) + .collect() + } + *) + Definition get_round_constants_from_rng + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [ R ], [ num_rounds; rng ] => + ltac:(M.monadic + (let num_rounds := M.alloc (| num_rounds |) in + let rng := M.alloc (| rng |) in + M.read (| + let~ num_constants : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; WIDTH ] + |); + M.read (| num_rounds |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ] + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "rand::distr::distribution::Iter") + [] + [ + Ty.path "rand::distr::StandardUniform"; + Ty.apply (Ty.path "&mut") [] [ R ]; + F + ], + M.get_trait_method (| + "rand::rng::Rng", + Ty.apply (Ty.path "&mut") [] [ R ], + [], + [], + "sample_iter", + [], + [ F; Ty.path "rand::distr::StandardUniform" ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| rng |) |) |); + Value.StructTuple "rand::distr::StandardUniform" [] + ] + |); + M.read (| num_constants |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_get_round_constants_from_rng : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH ALPHA F Mds) + "get_round_constants_from_rng" + (get_round_constants_from_rng WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque get_round_constants_from_rng. + + (* + fn get_round_constants_rescue_prime( + num_rounds: usize, + capacity: usize, + sec_level: usize, + ) -> Vec + where + F: PrimeField64, + { + let num_constants = 2 * WIDTH * num_rounds; + let bytes_per_constant = F::bits().div_ceil(8) + 1; + let num_bytes = bytes_per_constant * num_constants; + + let seed_string = format!( + "Rescue-XLIX({},{},{},{})", + F::ORDER_U64, + WIDTH, + capacity, + sec_level, + ); + let byte_string = shake256_hash(seed_string.as_bytes(), num_bytes); + + byte_string + .iter() + .chunks(bytes_per_constant) + .into_iter() + .map(|chunk| { + let integer = chunk + .collect_vec() + .iter() + .rev() + .fold(0, |acc, &byte| (acc << 8) + *byte as u64); + F::from_u64(integer) + }) + .collect() + } + *) + Definition get_round_constants_rescue_prime + (WIDTH ALPHA : Value.t) + (F Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F Mds in + match ε, τ, α with + | [], [], [ num_rounds; capacity; sec_level ] => + ltac:(M.monadic + (let num_rounds := M.alloc (| num_rounds |) in + let capacity := M.alloc (| capacity |) in + let sec_level := M.alloc (| sec_level |) in + M.read (| + let~ num_constants : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ Value.Integer IntegerKind.Usize 2; WIDTH ] + |); + M.read (| num_rounds |) + ] + |) + |) in + let~ bytes_per_constant : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "div_ceil", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "bits", + [], + [] + |), + [] + |); + Value.Integer IntegerKind.Usize 8 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) in + let~ num_bytes : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| bytes_per_constant |); M.read (| num_constants |) ] + |) + |) in + let~ seed_string : Ty.apply (Ty.path "*") [] [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : Ty.apply (Ty.path "*") [] [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 5; + Value.Integer IntegerKind.Usize 4 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "Rescue-XLIX(" |); + mk_str (| "," |); + mk_str (| "," |); + mk_str (| "," |); + mk_str (| ")" |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "u64" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "p3_field::field::PrimeField64::ORDER_U64", + Ty.path "u64" + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| WIDTH |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, capacity |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, sec_level |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) in + let~ byte_string : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_function (| "p3_rescue::util::shake256_hash", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| + Ty.path "alloc::string::String", + "as_bytes", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, seed_string |) ] + |) + |) + |); + M.read (| num_bytes |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunk") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] ] + ] + ] + F + ], + [], + [], + "collect", + [], + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ F; Ty.path "alloc::alloc::Global" ] ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunk") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] + ] + ] + ] + F + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] ], + [], + [], + "map", + [], + [ + F; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunk") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] + ] + ] + ] + F + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "itertools::groupbylazy::IntoChunks") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "itertools::groupbylazy::IntoChunks") + [] + [ Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ], + [], + [], + "chunks", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, byte_string |) ] + |) + |) + |) + ] + |); + M.read (| bytes_per_constant |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunk") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.path "u8" ] + ] + ] + ] + F + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let chunk := M.copy (| γ |) in + M.read (| + let~ integer : + Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] + ] + ], + [], + [], + "fold", + [], + [ + Ty.path "u64"; + Ty.function + [ + Ty.tuple + [ + Ty.path "u64"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.path "u64") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::rev::Rev") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u8" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] + ], + [], + [], + "rev", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u8" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u8" ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u8" ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u8" ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u8" ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ Ty.path "u8" ] + ], + [], + [], + "collect_vec", + [], + [] + |), + [ M.read (| chunk |) ] + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + Value.Integer IntegerKind.U64 0; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "u64"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path "u64"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.path + "u8" + ] + ] + ] + ] + (Ty.path "u64") + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.read (| γ |) in + let byte := + M.copy (| γ |) in + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ + M.read (| + acc + |); + Value.Integer + IntegerKind.I32 + 8 + ] + |); + M.cast + (Ty.path "u64") + (M.read (| + M.deref (| + M.read (| + byte + |) + |) + |)) + ] + |))) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_u64", + [], + [] + |), + [ M.read (| integer |) ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_get_round_constants_rescue_prime : + forall (WIDTH ALPHA : Value.t) (F Mds : Ty.t), + M.IsAssociatedFunction.C + (Self WIDTH ALPHA F Mds) + "get_round_constants_rescue_prime" + (get_round_constants_rescue_prime WIDTH ALPHA F Mds). + Admitted. + Global Typeclasses Opaque get_round_constants_rescue_prime. + End Impl_p3_rescue_rescue_Rescue_WIDTH_ALPHA_F_Mds. + + Module Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_PrimeField_F_where_p3_field_field_PermutationMonomial_F_where_p3_field_field_Algebra_A_F_where_p3_field_field_PermutationMonomial_A_where_p3_mds_MdsPermutation_Mds_A_array_WIDTH_A_for_p3_rescue_rescue_Rescue_WIDTH_ALPHA_F_Mds. + Definition Self (WIDTH ALPHA : Value.t) (F A Mds : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_rescue::rescue::Rescue") [ WIDTH; ALPHA ] [ F; Mds ]. + + (* + fn permute_mut(&self, state: &mut [A; WIDTH]) { + for round in 0..self.num_rounds { + // S-box + state.iter_mut().for_each(|x| *x = x.injective_exp_n()); + + // MDS + self.mds.permute_mut(state); + + // Constants + for (state_item, &round_constant) in state + .iter_mut() + .zip(&self.round_constants[round * WIDTH * 2..]) + { + *state_item += round_constant; + } + + // Inverse S-box + state.iter_mut().for_each(|x| *x = x.injective_exp_root_n()); + + // MDS + self.mds.permute_mut(state); + + // Constants + for (state_item, &round_constant) in state + .iter_mut() + .zip(&self.round_constants[round * WIDTH * 2 + WIDTH..]) + { + *state_item += round_constant; + } + } + } + *) + Definition permute_mut + (WIDTH ALPHA : Value.t) + (F A Mds : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH ALPHA F A Mds in + match ε, τ, α with + | [], [], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "num_rounds" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let round := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ A ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ A ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.write (| + M.deref (| M.read (| x |) |), + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::InjectiveMonomial", + A, + [ ALPHA ], + [], + "injective_exp_n", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x |) |) + |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Mds, + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ A ] ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "mds" + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "round_constants" + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| round |); WIDTH + ] + |); + Value.Integer + IntegerKind.Usize + 2 + ] + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ A ]; + Ty.apply (Ty.path "&") [] [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ A ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let state_item := M.copy (| γ1_0 |) in + let γ1_1 := M.read (| γ1_1 |) in + let round_constant := + M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + A, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| state_item |) + |) + |); + M.read (| round_constant |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ A ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ A ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.write (| + M.deref (| M.read (| x |) |), + M.call_closure (| + A, + M.get_trait_method (| + "p3_field::field::PermutationMonomial", + A, + [ ALPHA ], + [], + "injective_exp_root_n", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| x |) |) + |) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Mds, + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ A ] ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "mds" + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ]; + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ A ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ A ], + "iter_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| state |) |) + |)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_rescue::rescue::Rescue", + "round_constants" + |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.read (| round |); + WIDTH + ] + |); + Value.Integer + IntegerKind.Usize + 2 + ] + |); + WIDTH + ] + |)) + ] + ] + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ A ]; + Ty.apply (Ty.path "&") [] [ F ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::IterMut") + [] + [ A ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ F ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let state_item := M.copy (| γ1_0 |) in + let γ1_1 := M.read (| γ1_1 |) in + let round_constant := + M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + A, + [], + [ F ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| state_item |) + |) + |); + M.read (| round_constant |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH ALPHA : Value.t) (F A Mds : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::Permutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ WIDTH ] [ A ] ] + (Self WIDTH ALPHA F A Mds) + (* Instance *) [ ("permute_mut", InstanceField.Method (permute_mut WIDTH ALPHA F A Mds)) ]. + End Impl_p3_symmetric_permutation_Permutation_where_p3_field_field_PrimeField_F_where_p3_field_field_PermutationMonomial_F_where_p3_field_field_Algebra_A_F_where_p3_field_field_PermutationMonomial_A_where_p3_mds_MdsPermutation_Mds_A_array_WIDTH_A_for_p3_rescue_rescue_Rescue_WIDTH_ALPHA_F_Mds. + + Module Impl_p3_symmetric_permutation_CryptographicPermutation_where_p3_field_field_PrimeField_F_where_p3_field_field_PermutationMonomial_F_where_p3_field_field_Algebra_A_F_where_p3_field_field_PermutationMonomial_A_where_p3_mds_MdsPermutation_Mds_A_array_WIDTH_A_for_p3_rescue_rescue_Rescue_WIDTH_ALPHA_F_Mds. + Definition Self (WIDTH ALPHA : Value.t) (F A Mds : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_rescue::rescue::Rescue") [ WIDTH; ALPHA ] [ F; Mds ]. + + Axiom Implements : + forall (WIDTH ALPHA : Value.t) (F A Mds : Ty.t), + M.IsTraitInstance + "p3_symmetric::permutation::CryptographicPermutation" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ WIDTH ] [ A ] ] + (Self WIDTH ALPHA F A Mds) + (* Instance *) []. + End Impl_p3_symmetric_permutation_CryptographicPermutation_where_p3_field_field_PrimeField_F_where_p3_field_field_PermutationMonomial_F_where_p3_field_field_Algebra_A_F_where_p3_field_field_PermutationMonomial_A_where_p3_mds_MdsPermutation_Mds_A_array_WIDTH_A_for_p3_rescue_rescue_Rescue_WIDTH_ALPHA_F_Mds. +End rescue. diff --git a/CoqOfRust/plonky3/rescue/src/util.rs b/CoqOfRust/plonky3/rescue/src/util.rs new file mode 100644 index 000000000..a9b92ac94 --- /dev/null +++ b/CoqOfRust/plonky3/rescue/src/util.rs @@ -0,0 +1,112 @@ +use alloc::vec; +use alloc::vec::Vec; + +use p3_util::log2_ceil_u64; +use sha3::Shake256; +use sha3::digest::{ExtendableOutput, Update, XofReader}; + +/// Compute the SHAKE256 variant of SHA-3. +/// This is used to generate the round constants from a seed string. +pub(crate) fn shake256_hash(seed_bytes: &[u8], num_bytes: usize) -> Vec { + let mut hasher = Shake256::default(); + hasher.update(seed_bytes); + let mut reader = hasher.finalize_xof(); + let mut result = vec![0u8; num_bytes]; + reader.read(&mut result); + result +} + +/// Return y such that |y - 2^x| < tol for x an f32. +/// +/// This is a replacement for f32::powf() when libm isn't available; +/// it is slow and shouldn't be used for anything important. +/// +/// Algorithm is a direct evaluation of the corresponding Taylor +/// series. As x increases, increase the precision P until the +/// accuracy is sufficient. +#[must_use] +fn pow2_no_std(x: f32, tol: f32) -> f32 { + let y = x * core::f32::consts::LN_2; + let mut t = 1.0; // ith Taylor term = (x ln(2))^i/i! + let mut two_pow_x = t; + for i in 1.. { + t *= y / (i as f32); + if t < tol { + break; + } + two_pow_x += t; + } + two_pow_x +} + +/// Return log2(x) for x a u64. +/// +/// This is a replacement for f64::log2() when libm isn't available; +/// it is slow and shouldn't be used for anything important. +/// +/// At least for inputs up to a few hundred the accuracy of this +/// function is better than 0.001. It will produce wrong answers once +/// x exceeds about 1000. +/// +/// Algorithm is just three iterations of Newton-Raphson. This is +/// sufficient for the one use in this crate. It should be generalised +/// to multiple iterations (with a suitable analysis of the precision +/// passed to pow2_no_std) before being used more widely. +#[must_use] +fn log2_no_std(x: u64) -> f32 { + const LOG2_E: f32 = core::f32::consts::LOG2_E; + const POW2_TOL: f32 = 0.0001; + // Initial estimate x0 = floor(log2(x)) + let x0 = log2_ceil_u64(x + 1) - 1; + let p0 = (1 << x0) as f32; // 2^x0 + let x1 = x0 as f32 - LOG2_E * (1.0 - x as f32 / p0); + // precision 20 determined by experiment + let p1 = pow2_no_std(x1, POW2_TOL); + let x2 = x1 - LOG2_E * (1.0 - x as f32 / p1); + let p2 = pow2_no_std(x2, POW2_TOL); + x2 - LOG2_E * (1.0 - x as f32 / p2) +} + +/// Compute an approximation to log2(binomial(n, k)). +/// +/// This calculation relies on a slow version of log2 and shouldn't be +/// used for anything important. +/// +/// The algorithm uses the approximation +/// +/// log2(binom(n,k)) ≈ n log2(n) - k log2(k) - (n-k) log2(n-k) +/// + (log2(n) - log2(k) - log2(n-k) - log2(2π))/2 +/// +/// coming from Stirling's approximation for n!. +pub(crate) fn log2_binom(n: u64, k: u64) -> f32 { + const LOG2_2PI: f32 = 2.6514961; + let log2_n = log2_no_std(n); + let log2_k = log2_no_std(k); + let log2_nmk = log2_no_std(n - k); + + n as f32 * log2_n - k as f32 * log2_k - (n - k) as f32 * log2_nmk + + 0.5 * (log2_n - log2_k - log2_nmk - LOG2_2PI) +} + +#[cfg(test)] +mod test { + use super::log2_no_std; + + const TOLERANCE: f32 = 0.001; + + #[test] + fn test_log2_no_std() { + let inputs = [ + 11, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, + 200, + ]; + let expected = [ + 3.459432, 4.321928, 4.906891, 5.321928, 5.643856, 5.906891, 6.129283, 6.321928, + 6.491853, 6.643856, 6.78136, 6.906891, 7.022368, 7.129283, 7.228819, 7.321928, + 7.409391, 7.491853, 7.569856, 7.643856, + ]; + for (&x, y) in inputs.iter().zip(expected) { + assert!((log2_no_std(x) - y) < TOLERANCE); + } + } +} diff --git a/CoqOfRust/plonky3/rescue/src/util.v b/CoqOfRust/plonky3/rescue/src/util.v new file mode 100644 index 000000000..b353b1fc6 --- /dev/null +++ b/CoqOfRust/plonky3/rescue/src/util.v @@ -0,0 +1,705 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module util. + (* + pub(crate) fn shake256_hash(seed_bytes: &[u8], num_bytes: usize) -> Vec { + let mut hasher = Shake256::default(); + hasher.update(seed_bytes); + let mut reader = hasher.finalize_xof(); + let mut result = vec![0u8; num_bytes]; + reader.read(&mut result); + result + } + *) + Definition shake256_hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ seed_bytes; num_bytes ] => + ltac:(M.monadic + (let seed_bytes := M.alloc (| seed_bytes |) in + let num_bytes := M.alloc (| num_bytes |) in + M.read (| + let~ hasher : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake256Core" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake256Core" ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake256Core" ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::Update", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake256Core" ], + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, hasher |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| seed_bytes |) |) |) + ] + |) + |) in + let~ reader : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "digest::core_api::xof_reader::XofReaderCoreWrapper") + [] + [ Ty.path "sha3::Shake256ReaderCore" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "digest::core_api::xof_reader::XofReaderCoreWrapper") + [] + [ Ty.path "sha3::Shake256ReaderCore" ], + M.get_trait_method (| + "digest::ExtendableOutput", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ Ty.path "sha3::Shake256Core" ], + [], + [], + "finalize_xof", + [], + [] + |), + [ M.read (| hasher |) ] + |) + |) in + let~ result : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloc::vec::from_elem", [], [ Ty.path "u8" ] |), + [ Value.Integer IntegerKind.U8 0; M.read (| num_bytes |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::XofReader", + Ty.apply + (Ty.path "digest::core_api::xof_reader::XofReaderCoreWrapper") + [] + [ Ty.path "sha3::Shake256ReaderCore" ], + [], + [], + "read", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, reader |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, result |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + result + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_shake256_hash : + M.IsFunction.C "p3_rescue::util::shake256_hash" shake256_hash. + Admitted. + Global Typeclasses Opaque shake256_hash. + + (* + fn pow2_no_std(x: f32, tol: f32) -> f32 { + let y = x * core::f32::consts::LN_2; + let mut t = 1.0; // ith Taylor term = (x ln(2))^i/i! + let mut two_pow_x = t; + for i in 1.. { + t *= y / (i as f32); + if t < tol { + break; + } + two_pow_x += t; + } + two_pow_x + } + *) + Definition pow2_no_std (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x; tol ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let tol := M.alloc (| tol |) in + M.read (| + let~ y : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := + M.alloc (| + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.mul, + [ + M.read (| x |); + M.read (| get_constant (| "core::f32::consts::LN_2", Ty.path "f32" |) |) + ] + |) + |) in + let~ t : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := M.copy (| UnsupportedLiteral |) in + let~ two_pow_x : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := M.copy (| t |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::RangeFrom") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::RangeFrom") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.I32 1) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := t in + M.write (| + β, + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.mul, + [ + M.read (| β |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.div, + [ + M.read (| y |); + M.cast (Ty.path "f32") (M.read (| i |)) + ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| t |); M.read (| tol |) ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := two_pow_x in + M.write (| + β, + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.add, + [ M.read (| β |); M.read (| t |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + two_pow_x + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_pow2_no_std : + M.IsFunction.C "p3_rescue::util::pow2_no_std" pow2_no_std. + Admitted. + Global Typeclasses Opaque pow2_no_std. + + (* + fn log2_no_std(x: u64) -> f32 { + const LOG2_E: f32 = core::f32::consts::LOG2_E; + const POW2_TOL: f32 = 0.0001; + // Initial estimate x0 = floor(log2(x)) + let x0 = log2_ceil_u64(x + 1) - 1; + let p0 = (1 << x0) as f32; // 2^x0 + let x1 = x0 as f32 - LOG2_E * (1.0 - x as f32 / p0); + // precision 20 determined by experiment + let p1 = pow2_no_std(x1, POW2_TOL); + let x2 = x1 - LOG2_E * (1.0 - x as f32 / p1); + let p2 = pow2_no_std(x2, POW2_TOL); + x2 - LOG2_E * (1.0 - x as f32 / p2) + } + *) + Definition log2_no_std (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + let~ x0 : Ty.apply (Ty.path "*") [] [ Ty.path "u64" ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "u64", + M.get_function (| "p3_util::log2_ceil_u64", [], [] |), + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.add, + [ M.read (| x |); Value.Integer IntegerKind.U64 1 ] + |) + ] + |); + Value.Integer IntegerKind.U64 1 + ] + |) + |) in + let~ p0 : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := + M.alloc (| + M.cast + (Ty.path "f32") + (M.call_closure (| + Ty.path "i32", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.I32 1; M.read (| x0 |) ] + |)) + |) in + let~ x1 : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := + M.alloc (| + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ + M.cast (Ty.path "f32") (M.read (| x0 |)); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.mul, + [ + M.read (| + get_constant (| "p3_rescue::util::log2_no_std::LOG2_E", Ty.path "f32" |) + |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ + M.read (| UnsupportedLiteral |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.div, + [ M.cast (Ty.path "f32") (M.read (| x |)); M.read (| p0 |) ] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ p1 : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := + M.alloc (| + M.call_closure (| + Ty.path "f32", + M.get_function (| "p3_rescue::util::pow2_no_std", [], [] |), + [ + M.read (| x1 |); + M.read (| + get_constant (| "p3_rescue::util::log2_no_std::POW2_TOL", Ty.path "f32" |) + |) + ] + |) + |) in + let~ x2 : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := + M.alloc (| + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ + M.read (| x1 |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.mul, + [ + M.read (| + get_constant (| "p3_rescue::util::log2_no_std::LOG2_E", Ty.path "f32" |) + |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ + M.read (| UnsupportedLiteral |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.div, + [ M.cast (Ty.path "f32") (M.read (| x |)); M.read (| p1 |) ] + |) + ] + |) + ] + |) + ] + |) + |) in + let~ p2 : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := + M.alloc (| + M.call_closure (| + Ty.path "f32", + M.get_function (| "p3_rescue::util::pow2_no_std", [], [] |), + [ + M.read (| x2 |); + M.read (| + get_constant (| "p3_rescue::util::log2_no_std::POW2_TOL", Ty.path "f32" |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ + M.read (| x2 |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.mul, + [ + M.read (| + get_constant (| "p3_rescue::util::log2_no_std::LOG2_E", Ty.path "f32" |) + |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ + M.read (| UnsupportedLiteral |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.div, + [ M.cast (Ty.path "f32") (M.read (| x |)); M.read (| p2 |) ] + |) + ] + |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_log2_no_std : + M.IsFunction.C "p3_rescue::util::log2_no_std" log2_no_std. + Admitted. + Global Typeclasses Opaque log2_no_std. + + Module log2_no_std. + Definition value_LOG2_E (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (get_constant (| "core::f32::consts::LOG2_E", Ty.path "f32" |))). + + Global Instance Instance_IsConstant_value_LOG2_E : + M.IsFunction.C "p3_rescue::util::log2_no_std::LOG2_E" value_LOG2_E. + Admitted. + Global Typeclasses Opaque value_LOG2_E. + + Definition value_POW2_TOL (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic UnsupportedLiteral). + + Global Instance Instance_IsConstant_value_POW2_TOL : + M.IsFunction.C "p3_rescue::util::log2_no_std::POW2_TOL" value_POW2_TOL. + Admitted. + Global Typeclasses Opaque value_POW2_TOL. + End log2_no_std. + + (* + pub(crate) fn log2_binom(n: u64, k: u64) -> f32 { + const LOG2_2PI: f32 = 2.6514961; + let log2_n = log2_no_std(n); + let log2_k = log2_no_std(k); + let log2_nmk = log2_no_std(n - k); + + n as f32 * log2_n - k as f32 * log2_k - (n - k) as f32 * log2_nmk + + 0.5 * (log2_n - log2_k - log2_nmk - LOG2_2PI) + } + *) + Definition log2_binom (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ n; k ] => + ltac:(M.monadic + (let n := M.alloc (| n |) in + let k := M.alloc (| k |) in + M.read (| + let~ log2_n : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := + M.alloc (| + M.call_closure (| + Ty.path "f32", + M.get_function (| "p3_rescue::util::log2_no_std", [], [] |), + [ M.read (| n |) ] + |) + |) in + let~ log2_k : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := + M.alloc (| + M.call_closure (| + Ty.path "f32", + M.get_function (| "p3_rescue::util::log2_no_std", [], [] |), + [ M.read (| k |) ] + |) + |) in + let~ log2_nmk : Ty.apply (Ty.path "*") [] [ Ty.path "f32" ] := + M.alloc (| + M.call_closure (| + Ty.path "f32", + M.get_function (| "p3_rescue::util::log2_no_std", [], [] |), + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ M.read (| n |); M.read (| k |) ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.mul, + [ M.cast (Ty.path "f32") (M.read (| n |)); M.read (| log2_n |) ] + |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.mul, + [ M.cast (Ty.path "f32") (M.read (| k |)); M.read (| log2_k |) ] + |) + ] + |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.mul, + [ + M.cast + (Ty.path "f32") + (M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ M.read (| n |); M.read (| k |) ] + |)); + M.read (| log2_nmk |) + ] + |) + ] + |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.mul, + [ + M.read (| UnsupportedLiteral |); + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "f32", + BinOp.Wrap.sub, + [ M.read (| log2_n |); M.read (| log2_k |) ] + |); + M.read (| log2_nmk |) + ] + |); + M.read (| + get_constant (| "p3_rescue::util::log2_binom::LOG2_2PI", Ty.path "f32" |) + |) + ] + |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_log2_binom : + M.IsFunction.C "p3_rescue::util::log2_binom" log2_binom. + Admitted. + Global Typeclasses Opaque log2_binom. + + Module log2_binom. + Definition value_LOG2_2PI (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic UnsupportedLiteral). + + Global Instance Instance_IsConstant_value_LOG2_2PI : + M.IsFunction.C "p3_rescue::util::log2_binom::LOG2_2PI" value_LOG2_2PI. + Admitted. + Global Typeclasses Opaque value_LOG2_2PI. + End log2_binom. +End util. diff --git a/CoqOfRust/plonky3/sha256/src/lib.rs b/CoqOfRust/plonky3/sha256/src/lib.rs new file mode 100644 index 000000000..9d446df53 --- /dev/null +++ b/CoqOfRust/plonky3/sha256/src/lib.rs @@ -0,0 +1,95 @@ +//! The SHA2-256 hash function. + +#![no_std] + +use p3_symmetric::{CompressionFunction, CryptographicHasher, PseudoCompressionFunction}; +use sha2::Digest; +use sha2::digest::generic_array::GenericArray; +use sha2::digest::typenum::U64; + +pub const H256_256: [u32; 8] = [ + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, +]; + +/// The SHA2-256 hash function. +#[derive(Copy, Clone, Debug)] +pub struct Sha256; + +impl CryptographicHasher for Sha256 { + fn hash_iter(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + const BUFLEN: usize = 512; // Tweakable parameter; determined by experiment + let mut hasher = sha2::Sha256::new(); + p3_util::apply_to_chunks::(input, |buf| hasher.update(buf)); + hasher.finalize().into() + } + + fn hash_iter_slices<'a, I>(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + let mut hasher = sha2::Sha256::new(); + for chunk in input { + hasher.update(chunk); + } + hasher.finalize().into() + } +} + +/// SHA2-256 without the padding (pre-processing), intended to be used +/// as a 2-to-1 [PseudoCompressionFunction]. +#[derive(Copy, Clone, Debug)] +pub struct Sha256Compress; + +impl PseudoCompressionFunction<[u8; 32], 2> for Sha256Compress { + fn compress(&self, input: [[u8; 32]; 2]) -> [u8; 32] { + let mut state = H256_256; + // GenericArray has same memory layout as [u8; 64] + let block: GenericArray = unsafe { core::mem::transmute(input) }; + sha2::compress256(&mut state, &[block]); + + let mut output = [0u8; 32]; + for (chunk, word) in output.chunks_exact_mut(4).zip(state) { + chunk.copy_from_slice(&word.to_be_bytes()); + } + output + } +} + +impl CompressionFunction<[u8; 32], 2> for Sha256Compress {} + +#[cfg(test)] +mod tests { + use hex_literal::hex; + use p3_symmetric::{CryptographicHasher, PseudoCompressionFunction}; + + use crate::{Sha256, Sha256Compress}; + + #[test] + fn test_hello_world() { + let input = b"hello world"; + let expected = hex!( + " + b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 + " + ); + + let sha256 = Sha256; + assert_eq!(sha256.hash_iter(input.to_vec())[..], expected[..]); + } + + #[test] + fn test_compress() { + let left = [0u8; 32]; + // `right` will simulate the SHA256 padding + let mut right = [0u8; 32]; + right[0] = 1 << 7; + right[30] = 1; // left has length 256 in bits, L = 0x100 + + let expected = Sha256.hash_iter(left); + let sha256_compress = Sha256Compress; + assert_eq!(sha256_compress.compress([left, right]), expected); + } +} diff --git a/CoqOfRust/plonky3/sha256/src/lib.v b/CoqOfRust/plonky3/sha256/src/lib.v new file mode 100644 index 000000000..ca6d1f58d --- /dev/null +++ b/CoqOfRust/plonky3/sha256/src/lib.v @@ -0,0 +1,1668 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Definition value_H256_256 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U32 1779033703; + Value.Integer IntegerKind.U32 3144134277; + Value.Integer IntegerKind.U32 1013904242; + Value.Integer IntegerKind.U32 2773480762; + Value.Integer IntegerKind.U32 1359893119; + Value.Integer IntegerKind.U32 2600822924; + Value.Integer IntegerKind.U32 528734635; + Value.Integer IntegerKind.U32 1541459225 + ] + |))). + +Global Instance Instance_IsConstant_value_H256_256 : + M.IsFunction.C "p3_sha256::H256_256" value_H256_256. +Admitted. +Global Typeclasses Opaque value_H256_256. + +(* StructTuple + { + name := "Sha256"; + const_params := []; + ty_params := []; + fields := []; + } *) + +Module Impl_core_marker_Copy_for_p3_sha256_Sha256. + Definition Self : Ty.t := Ty.path "p3_sha256::Sha256". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. +End Impl_core_marker_Copy_for_p3_sha256_Sha256. + +Module Impl_core_clone_Clone_for_p3_sha256_Sha256. + Definition Self : Ty.t := Ty.path "p3_sha256::Sha256". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. +End Impl_core_clone_Clone_for_p3_sha256_Sha256. + +Module Impl_core_fmt_Debug_for_p3_sha256_Sha256. + Definition Self : Ty.t := Ty.path "p3_sha256::Sha256". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Sha256" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. +End Impl_core_fmt_Debug_for_p3_sha256_Sha256. + +Module Impl_p3_symmetric_hasher_CryptographicHasher_u8_array_Usize_32_u8_for_p3_sha256_Sha256. + Definition Self : Ty.t := Ty.path "p3_sha256::Sha256". + + (* + fn hash_iter(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + const BUFLEN: usize = 512; // Tweakable parameter; determined by experiment + let mut hasher = sha2::Sha256::new(); + p3_util::apply_to_chunks::(input, |buf| hasher.update(buf)); + hasher.finalize().into() + } + *) + Definition hash_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ hasher : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ + Ty.apply + (Ty.path "digest::core_api::ct_variable::CtVariableCoreWrapper") + [] + [ + Ty.path "sha2::core_api::Sha256VarCore"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "sha2::OidSha256" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ + Ty.apply + (Ty.path "digest::core_api::ct_variable::CtVariableCoreWrapper") + [] + [ + Ty.path "sha2::core_api::Sha256VarCore"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "sha2::OidSha256" + ] + ], + M.get_trait_method (| + "digest::digest::Digest", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ + Ty.apply + (Ty.path "digest::core_api::ct_variable::CtVariableCoreWrapper") + [] + [ + Ty.path "sha2::core_api::Sha256VarCore"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "sha2::OidSha256" + ] + ], + [], + [], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::apply_to_chunks", + [ Value.Integer IntegerKind.Usize 512 ], + [ + I; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.read (| input |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ] + (Ty.tuple []) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let buf := M.copy (| γ |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::digest::Digest", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ + Ty.apply + (Ty.path + "digest::core_api::ct_variable::CtVariableCoreWrapper") + [] + [ + Ty.path "sha2::core_api::Sha256VarCore"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path + "typenum::uint::UInt") + [] + [ + Ty.path + "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "sha2::OidSha256" + ] + ], + [], + [], + "update", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, hasher |); M.read (| buf |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply + (Ty.path "generic_array::GenericArray") + [] + [ + Ty.path "u8"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ] + ], + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "generic_array::GenericArray") + [] + [ + Ty.path "u8"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ] + ], + M.get_trait_method (| + "digest::digest::Digest", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ + Ty.apply + (Ty.path "digest::core_api::ct_variable::CtVariableCoreWrapper") + [] + [ + Ty.path "sha2::core_api::Sha256VarCore"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "sha2::OidSha256" + ] + ], + [], + [], + "finalize", + [], + [] + |), + [ M.read (| hasher |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn hash_iter_slices<'a, I>(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + let mut hasher = sha2::Sha256::new(); + for chunk in input { + hasher.update(chunk); + } + hasher.finalize().into() + } + *) + Definition hash_iter_slices (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ hasher : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ + Ty.apply + (Ty.path "digest::core_api::ct_variable::CtVariableCoreWrapper") + [] + [ + Ty.path "sha2::core_api::Sha256VarCore"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "sha2::OidSha256" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ + Ty.apply + (Ty.path "digest::core_api::ct_variable::CtVariableCoreWrapper") + [] + [ + Ty.path "sha2::core_api::Sha256VarCore"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "sha2::OidSha256" + ] + ], + M.get_trait_method (| + "digest::digest::Digest", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ + Ty.apply + (Ty.path "digest::core_api::ct_variable::CtVariableCoreWrapper") + [] + [ + Ty.path "sha2::core_api::Sha256VarCore"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "sha2::OidSha256" + ] + ], + [], + [], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let chunk := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "digest::digest::Digest", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ + Ty.apply + (Ty.path + "digest::core_api::ct_variable::CtVariableCoreWrapper") + [] + [ + Ty.path "sha2::core_api::Sha256VarCore"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path + "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path + "typenum::uint::UInt") + [] + [ + Ty.path + "typenum::uint::UTerm"; + Ty.path + "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "sha2::OidSha256" + ] + ], + [], + [], + "update", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, hasher |); + M.read (| chunk |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply + (Ty.path "generic_array::GenericArray") + [] + [ + Ty.path "u8"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ] + ], + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "generic_array::GenericArray") + [] + [ + Ty.path "u8"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ] + ], + M.get_trait_method (| + "digest::digest::Digest", + Ty.apply + (Ty.path "digest::core_api::wrapper::CoreWrapper") + [] + [ + Ty.apply + (Ty.path "digest::core_api::ct_variable::CtVariableCoreWrapper") + [] + [ + Ty.path "sha2::core_api::Sha256VarCore"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "sha2::OidSha256" + ] + ], + [], + [], + "finalize", + [], + [] + |), + [ M.read (| hasher |) ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::hasher::CryptographicHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.path "u8"; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ] + Self + (* Instance *) + [ + ("hash_iter", InstanceField.Method hash_iter); + ("hash_iter_slices", InstanceField.Method hash_iter_slices) + ]. +End Impl_p3_symmetric_hasher_CryptographicHasher_u8_array_Usize_32_u8_for_p3_sha256_Sha256. + +(* StructTuple + { + name := "Sha256Compress"; + const_params := []; + ty_params := []; + fields := []; + } *) + +Module Impl_core_marker_Copy_for_p3_sha256_Sha256Compress. + Definition Self : Ty.t := Ty.path "p3_sha256::Sha256Compress". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. +End Impl_core_marker_Copy_for_p3_sha256_Sha256Compress. + +Module Impl_core_clone_Clone_for_p3_sha256_Sha256Compress. + Definition Self : Ty.t := Ty.path "p3_sha256::Sha256Compress". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. +End Impl_core_clone_Clone_for_p3_sha256_Sha256Compress. + +Module Impl_core_fmt_Debug_for_p3_sha256_Sha256Compress. + Definition Self : Ty.t := Ty.path "p3_sha256::Sha256Compress". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Sha256Compress" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. +End Impl_core_fmt_Debug_for_p3_sha256_Sha256Compress. + +Module Impl_p3_symmetric_compression_PseudoCompressionFunction_Usize_2_array_Usize_32_u8_for_p3_sha256_Sha256Compress. + Definition Self : Ty.t := Ty.path "p3_sha256::Sha256Compress". + + (* + fn compress(&self, input: [[u8; 32]; 2]) -> [u8; 32] { + let mut state = H256_256; + // GenericArray has same memory layout as [u8; 64] + let block: GenericArray = unsafe { core::mem::transmute(input) }; + sha2::compress256(&mut state, &[block]); + + let mut output = [0u8; 32]; + for (chunk, word) in output.chunks_exact_mut(4).zip(state) { + chunk.copy_from_slice(&word.to_be_bytes()); + } + output + } + *) + Definition compress (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ state : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "u32" ] + ] := + M.copy (| + get_constant (| + "p3_sha256::H256_256", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "u32" ] + |) + |) in + let~ block : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "generic_array::GenericArray") + [] + [ + Ty.path "u8"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "generic_array::GenericArray") + [] + [ + Ty.path "u8"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "generic_array::GenericArray") + [] + [ + Ty.path "u8"; + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.apply + (Ty.path "typenum::uint::UInt") + [] + [ + Ty.path "typenum::uint::UTerm"; + Ty.path "typenum::bit::B1" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ]; + Ty.path "typenum::bit::B0" + ] + ] + ] + |), + [ M.read (| input |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "sha2::sha256::compress256", [], [] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ M.read (| block |) ] |) + |) + |) + |)) + ] + |) + |) in + let~ output : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ] := + M.alloc (| + repeat (| Value.Integer IntegerKind.U8 0, Value.Integer IntegerKind.Usize 32 |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::ChunksExactMut") [] [ Ty.path "u8" ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u32" ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.path "u8" ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u32" ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.path "u8" ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u32" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.path "u8" ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u32" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "chunks_exact_mut", + [], + [] + |), + [ + (* Unsize *) + M.pointer_coercion (M.borrow (| Pointer.Kind.MutRef, output |)); + Value.Integer IntegerKind.Usize 4 + ] + |); + M.read (| state |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ]; + Ty.path "u32" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::ChunksExactMut") + [] + [ Ty.path "u8" ]; + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u32" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let chunk := M.copy (| γ1_0 |) in + let word := M.copy (| γ1_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| chunk |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "u32", + "to_be_bytes", + [], + [] + |), + [ M.read (| word |) ] + |) + |) + |) + |) + |)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + output + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::compression::PseudoCompressionFunction" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 2 ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("compress", InstanceField.Method compress) ]. +End Impl_p3_symmetric_compression_PseudoCompressionFunction_Usize_2_array_Usize_32_u8_for_p3_sha256_Sha256Compress. + +Module Impl_p3_symmetric_compression_CompressionFunction_Usize_2_array_Usize_32_u8_for_p3_sha256_Sha256Compress. + Definition Self : Ty.t := Ty.path "p3_sha256::Sha256Compress". + + Axiom Implements : + M.IsTraitInstance + "p3_symmetric::compression::CompressionFunction" + (* Trait polymorphic consts *) [ Value.Integer IntegerKind.Usize 2 ] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] ] + Self + (* Instance *) []. +End Impl_p3_symmetric_compression_CompressionFunction_Usize_2_array_Usize_32_u8_for_p3_sha256_Sha256Compress. diff --git a/CoqOfRust/plonky3/symmetric/src/compression.rs b/CoqOfRust/plonky3/symmetric/src/compression.rs new file mode 100644 index 000000000..cb2fc44e7 --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/compression.rs @@ -0,0 +1,176 @@ +use crate::hasher::CryptographicHasher; +use crate::permutation::CryptographicPermutation; + +/// An `N`-to-1 compression function collision-resistant in a hash tree setting. +/// +/// Unlike `CompressionFunction`, it may not be collision-resistant in general. +/// Instead it is only collision-resistant in hash-tree like settings where +/// the preimage of a non-leaf node must consist of compression outputs. +pub trait PseudoCompressionFunction: Clone { + fn compress(&self, input: [T; N]) -> T; +} + +/// An `N`-to-1 compression function. +pub trait CompressionFunction: PseudoCompressionFunction {} + +#[derive(Clone, Debug)] +pub struct TruncatedPermutation { + inner_permutation: InnerP, +} + +impl + TruncatedPermutation +{ + pub const fn new(inner_permutation: InnerP) -> Self { + Self { inner_permutation } + } +} + +impl + PseudoCompressionFunction<[T; CHUNK], N> for TruncatedPermutation +where + T: Copy + Default, + InnerP: CryptographicPermutation<[T; WIDTH]>, +{ + fn compress(&self, input: [[T; CHUNK]; N]) -> [T; CHUNK] { + debug_assert!(CHUNK * N <= WIDTH); + let mut pre = [T::default(); WIDTH]; + for i in 0..N { + pre[i * CHUNK..(i + 1) * CHUNK].copy_from_slice(&input[i]); + } + let post = self.inner_permutation.permute(pre); + post[..CHUNK].try_into().unwrap() + } +} + +#[derive(Clone, Debug)] +pub struct CompressionFunctionFromHasher { + hasher: H, +} + +impl CompressionFunctionFromHasher { + pub const fn new(hasher: H) -> Self { + Self { hasher } + } +} + +impl PseudoCompressionFunction<[T; CHUNK], N> + for CompressionFunctionFromHasher +where + T: Clone, + H: CryptographicHasher, +{ + fn compress(&self, input: [[T; CHUNK]; N]) -> [T; CHUNK] { + self.hasher.hash_iter(input.into_iter().flatten()) + } +} + +impl CompressionFunction<[T; CHUNK], N> + for CompressionFunctionFromHasher +where + T: Clone, + H: CryptographicHasher, +{ +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::Permutation; + + #[derive(Clone)] + struct MockPermutation; + + impl Permutation<[T; WIDTH]> for MockPermutation + where + T: Copy + core::ops::Add + Default, + { + fn permute_mut(&self, input: &mut [T; WIDTH]) { + let sum: T = input.iter().copied().fold(T::default(), |acc, x| acc + x); + // Simplest impl: set every element to the sum + *input = [sum; WIDTH]; + } + } + + impl CryptographicPermutation<[T; WIDTH]> for MockPermutation where + T: Copy + core::ops::Add + Default + { + } + + #[derive(Clone)] + struct MockHasher; + + impl CryptographicHasher for MockHasher { + fn hash_iter>(&self, iter: I) -> [u64; CHUNK] { + let sum: u64 = iter.into_iter().sum(); + // Simplest impl: set every element to the sum + [sum; CHUNK] + } + } + + #[test] + fn test_truncated_permutation_compress() { + const N: usize = 2; + const CHUNK: usize = 4; + const WIDTH: usize = 8; + + let permutation = MockPermutation; + let compressor = TruncatedPermutation::::new(permutation); + + let input: [[u64; CHUNK]; N] = [[1, 2, 3, 4], [5, 6, 7, 8]]; + let output = compressor.compress(input); + let expected_sum = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8; + + assert_eq!(output, [expected_sum; CHUNK]); + } + + #[test] + fn test_compression_function_from_hasher_compress() { + const N: usize = 2; + const CHUNK: usize = 4; + + let hasher = MockHasher; + let compressor = CompressionFunctionFromHasher::::new(hasher); + + let input = [[10, 20, 30, 40], [50, 60, 70, 80]]; + let output = compressor.compress(input); + let expected_sum = 10 + 20 + 30 + 40 + 50 + 60 + 70 + 80; + + assert_eq!(output, [expected_sum; CHUNK]); + } + + #[test] + fn test_truncated_permutation_with_zeros() { + const N: usize = 2; + const CHUNK: usize = 4; + const WIDTH: usize = 8; + + let permutation = MockPermutation; + let compressor = TruncatedPermutation::::new(permutation); + + let input: [[u64; CHUNK]; N] = [[0, 0, 0, 0], [0, 0, 0, 0]]; + let output = compressor.compress(input); + + assert_eq!(output, [0; CHUNK]); + } + + #[test] + fn test_truncated_permutation_with_extra_width() { + const N: usize = 2; + const CHUNK: usize = 3; + const WIDTH: usize = 10; // More than `CHUNK * N` (6 < 10) + + let permutation = MockPermutation; + let compressor = TruncatedPermutation::::new(permutation); + + let input: [[u64; CHUNK]; N] = [[1, 2, 3], [4, 5, 6]]; + let output = compressor.compress(input); + + let expected_sum = 1 + 2 + 3 + 4 + 5 + 6; + + assert_eq!( + output, [expected_sum; CHUNK], + "Compression should correctly handle extra WIDTH space." + ); + } +} diff --git a/CoqOfRust/plonky3/symmetric/src/compression.v b/CoqOfRust/plonky3/symmetric/src/compression.v new file mode 100644 index 000000000..534f7d423 --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/compression.v @@ -0,0 +1,860 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module compression. + (* Trait *) + (* Empty module 'PseudoCompressionFunction' *) + + (* Trait *) + (* Empty module 'CompressionFunction' *) + + (* StructRecord + { + name := "TruncatedPermutation"; + const_params := [ "N"; "CHUNK"; "WIDTH" ]; + ty_params := [ "InnerP" ]; + fields := [ ("inner_permutation", InnerP) ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_InnerP_for_p3_symmetric_compression_TruncatedPermutation_N_CHUNK_WIDTH_InnerP. + Definition Self (N CHUNK WIDTH : Value.t) (InnerP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ N; CHUNK; WIDTH ] + [ InnerP ]. + + (* Clone *) + Definition clone + (N CHUNK WIDTH : Value.t) + (InnerP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N CHUNK WIDTH InnerP in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_symmetric::compression::TruncatedPermutation" + [ + ("inner_permutation", + M.call_closure (| + InnerP, + M.get_trait_method (| "core::clone::Clone", InnerP, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::compression::TruncatedPermutation", + "inner_permutation" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N CHUNK WIDTH : Value.t) (InnerP : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N CHUNK WIDTH InnerP) + (* Instance *) [ ("clone", InstanceField.Method (clone N CHUNK WIDTH InnerP)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_InnerP_for_p3_symmetric_compression_TruncatedPermutation_N_CHUNK_WIDTH_InnerP. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_InnerP_for_p3_symmetric_compression_TruncatedPermutation_N_CHUNK_WIDTH_InnerP. + Definition Self (N CHUNK WIDTH : Value.t) (InnerP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ N; CHUNK; WIDTH ] + [ InnerP ]. + + (* Debug *) + Definition fmt + (N CHUNK WIDTH : Value.t) + (InnerP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N CHUNK WIDTH InnerP in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "TruncatedPermutation" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inner_permutation" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::compression::TruncatedPermutation", + "inner_permutation" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N CHUNK WIDTH : Value.t) (InnerP : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N CHUNK WIDTH InnerP) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N CHUNK WIDTH InnerP)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_InnerP_for_p3_symmetric_compression_TruncatedPermutation_N_CHUNK_WIDTH_InnerP. + + Module Impl_p3_symmetric_compression_TruncatedPermutation_N_CHUNK_WIDTH_InnerP. + Definition Self (N CHUNK WIDTH : Value.t) (InnerP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ N; CHUNK; WIDTH ] + [ InnerP ]. + + (* + pub const fn new(inner_permutation: InnerP) -> Self { + Self { inner_permutation } + } + *) + Definition new + (N CHUNK WIDTH : Value.t) + (InnerP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N CHUNK WIDTH InnerP in + match ε, τ, α with + | [], [], [ inner_permutation ] => + ltac:(M.monadic + (let inner_permutation := M.alloc (| inner_permutation |) in + Value.StructRecord + "p3_symmetric::compression::TruncatedPermutation" + [ ("inner_permutation", M.read (| inner_permutation |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (N CHUNK WIDTH : Value.t) (InnerP : Ty.t), + M.IsAssociatedFunction.C (Self N CHUNK WIDTH InnerP) "new" (new N CHUNK WIDTH InnerP). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_symmetric_compression_TruncatedPermutation_N_CHUNK_WIDTH_InnerP. + + Module Impl_p3_symmetric_compression_PseudoCompressionFunction_where_core_marker_Copy_T_where_core_default_Default_T_where_p3_symmetric_permutation_CryptographicPermutation_InnerP_array_WIDTH_T_N_array_CHUNK_T_for_p3_symmetric_compression_TruncatedPermutation_N_CHUNK_WIDTH_InnerP. + Definition Self (N CHUNK WIDTH : Value.t) (T InnerP : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::compression::TruncatedPermutation") + [ N; CHUNK; WIDTH ] + [ InnerP ]. + + (* + fn compress(&self, input: [[T; CHUNK]; N]) -> [T; CHUNK] { + debug_assert!(CHUNK * N <= WIDTH); + let mut pre = [T::default(); WIDTH]; + for i in 0..N { + pre[i * CHUNK..(i + 1) * CHUNK].copy_from_slice(&input[i]); + } + let post = self.inner_permutation.permute(pre); + post[..CHUNK].try_into().unwrap() + } + *) + Definition compress + (N CHUNK WIDTH : Value.t) + (T InnerP : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N CHUNK WIDTH T InnerP in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ CHUNK; N ] + |); + WIDTH + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: CHUNK * N <= WIDTH" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ pre : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ] := + M.alloc (| + repeat (| + M.call_closure (| + T, + M.get_trait_method (| "core::default::Default", T, [], [], "default", [], [] |), + [] + |), + WIDTH + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ T ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply (Ty.path "array") [ WIDTH ] [ T ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, pre |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ M.read (| i |); CHUNK ] + |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer + IntegerKind.Usize + 1 + ] + |); + CHUNK + ] + |)) + ] + ] + |) + |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + input, + M.read (| i |) + |) + |) + |) + |)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ post : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ T ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + InnerP, + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ], + "permute", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::compression::TruncatedPermutation", + "inner_permutation" + |) + |); + M.read (| pre |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ CHUNK ] [ T ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ CHUNK ] [ T ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ CHUNK ] [ T ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + [], + [ Ty.apply (Ty.path "array") [ CHUNK ] [ T ] ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ WIDTH ] [ T ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, post |); + Value.StructRecord "core::ops::range::RangeTo" [ ("end_", CHUNK) ] + ] + |) + |) + |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N CHUNK WIDTH : Value.t) (T InnerP : Ty.t), + M.IsTraitInstance + "p3_symmetric::compression::PseudoCompressionFunction" + (* Trait polymorphic consts *) [ N ] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ CHUNK ] [ T ] ] + (Self N CHUNK WIDTH T InnerP) + (* Instance *) [ ("compress", InstanceField.Method (compress N CHUNK WIDTH T InnerP)) ]. + End Impl_p3_symmetric_compression_PseudoCompressionFunction_where_core_marker_Copy_T_where_core_default_Default_T_where_p3_symmetric_permutation_CryptographicPermutation_InnerP_array_WIDTH_T_N_array_CHUNK_T_for_p3_symmetric_compression_TruncatedPermutation_N_CHUNK_WIDTH_InnerP. + + (* StructRecord + { + name := "CompressionFunctionFromHasher"; + const_params := [ "N"; "CHUNK" ]; + ty_params := [ "H" ]; + fields := [ ("hasher", H) ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_H_for_p3_symmetric_compression_CompressionFunctionFromHasher_N_CHUNK_H. + Definition Self (N CHUNK : Value.t) (H : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ N; CHUNK ] + [ H ]. + + (* Clone *) + Definition clone + (N CHUNK : Value.t) + (H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N CHUNK H in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_symmetric::compression::CompressionFunctionFromHasher" + [ + ("hasher", + M.call_closure (| + H, + M.get_trait_method (| "core::clone::Clone", H, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::compression::CompressionFunctionFromHasher", + "hasher" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N CHUNK : Value.t) (H : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N CHUNK H) + (* Instance *) [ ("clone", InstanceField.Method (clone N CHUNK H)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_H_for_p3_symmetric_compression_CompressionFunctionFromHasher_N_CHUNK_H. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_H_for_p3_symmetric_compression_CompressionFunctionFromHasher_N_CHUNK_H. + Definition Self (N CHUNK : Value.t) (H : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ N; CHUNK ] + [ H ]. + + (* Debug *) + Definition fmt + (N CHUNK : Value.t) + (H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N CHUNK H in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "CompressionFunctionFromHasher" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "hasher" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::compression::CompressionFunctionFromHasher", + "hasher" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N CHUNK : Value.t) (H : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N CHUNK H) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N CHUNK H)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_H_for_p3_symmetric_compression_CompressionFunctionFromHasher_N_CHUNK_H. + + Module Impl_p3_symmetric_compression_CompressionFunctionFromHasher_N_CHUNK_H. + Definition Self (N CHUNK : Value.t) (H : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ N; CHUNK ] + [ H ]. + + (* + pub const fn new(hasher: H) -> Self { + Self { hasher } + } + *) + Definition new + (N CHUNK : Value.t) + (H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N CHUNK H in + match ε, τ, α with + | [], [], [ hasher ] => + ltac:(M.monadic + (let hasher := M.alloc (| hasher |) in + Value.StructRecord + "p3_symmetric::compression::CompressionFunctionFromHasher" + [ ("hasher", M.read (| hasher |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (N CHUNK : Value.t) (H : Ty.t), + M.IsAssociatedFunction.C (Self N CHUNK H) "new" (new N CHUNK H). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_symmetric_compression_CompressionFunctionFromHasher_N_CHUNK_H. + + Module Impl_p3_symmetric_compression_PseudoCompressionFunction_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_CHUNK_T_N_array_CHUNK_T_for_p3_symmetric_compression_CompressionFunctionFromHasher_N_CHUNK_H. + Definition Self (N CHUNK : Value.t) (T H : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ N; CHUNK ] + [ H ]. + + (* + fn compress(&self, input: [[T; CHUNK]; N]) -> [T; CHUNK] { + self.hasher.hash_iter(input.into_iter().flatten()) + } + *) + Definition compress + (N CHUNK : Value.t) + (T H : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N CHUNK T H in + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ CHUNK ] [ T ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + H, + [], + [ T; Ty.apply (Ty.path "array") [ CHUNK ] [ T ] ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::flatten::Flatten") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ N ] + [ Ty.apply (Ty.path "array") [ CHUNK ] [ T ] ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::compression::CompressionFunctionFromHasher", + "hasher" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::Flatten") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ N ] + [ Ty.apply (Ty.path "array") [ CHUNK ] [ T ] ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ N ] + [ Ty.apply (Ty.path "array") [ CHUNK ] [ T ] ], + [], + [], + "flatten", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ N ] + [ Ty.apply (Ty.path "array") [ CHUNK ] [ T ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ N ] + [ Ty.apply (Ty.path "array") [ CHUNK ] [ T ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N CHUNK : Value.t) (T H : Ty.t), + M.IsTraitInstance + "p3_symmetric::compression::PseudoCompressionFunction" + (* Trait polymorphic consts *) [ N ] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ CHUNK ] [ T ] ] + (Self N CHUNK T H) + (* Instance *) [ ("compress", InstanceField.Method (compress N CHUNK T H)) ]. + End Impl_p3_symmetric_compression_PseudoCompressionFunction_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_CHUNK_T_N_array_CHUNK_T_for_p3_symmetric_compression_CompressionFunctionFromHasher_N_CHUNK_H. + + Module Impl_p3_symmetric_compression_CompressionFunction_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_CHUNK_T_N_array_CHUNK_T_for_p3_symmetric_compression_CompressionFunctionFromHasher_N_CHUNK_H. + Definition Self (N CHUNK : Value.t) (T H : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::compression::CompressionFunctionFromHasher") + [ N; CHUNK ] + [ H ]. + + Axiom Implements : + forall (N CHUNK : Value.t) (T H : Ty.t), + M.IsTraitInstance + "p3_symmetric::compression::CompressionFunction" + (* Trait polymorphic consts *) [ N ] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ CHUNK ] [ T ] ] + (Self N CHUNK T H) + (* Instance *) []. + End Impl_p3_symmetric_compression_CompressionFunction_where_core_clone_Clone_T_where_p3_symmetric_hasher_CryptographicHasher_H_T_array_CHUNK_T_N_array_CHUNK_T_for_p3_symmetric_compression_CompressionFunctionFromHasher_N_CHUNK_H. +End compression. diff --git a/CoqOfRust/plonky3/symmetric/src/hash.rs b/CoqOfRust/plonky3/symmetric/src/hash.rs new file mode 100644 index 000000000..d39783a45 --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/hash.rs @@ -0,0 +1,58 @@ +use core::borrow::Borrow; +use core::marker::PhantomData; + +use serde::{Deserialize, Serialize}; + +/// A wrapper around an array digest, with a phantom type parameter to ensure that the digest is +/// associated with a particular field. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(bound(serialize = "[W; DIGEST_ELEMS]: Serialize"))] +#[serde(bound(deserialize = "[W; DIGEST_ELEMS]: Deserialize<'de>"))] +pub struct Hash { + value: [W; DIGEST_ELEMS], + _marker: PhantomData, +} + +impl From<[W; DIGEST_ELEMS]> for Hash { + fn from(value: [W; DIGEST_ELEMS]) -> Self { + Self { + value, + _marker: PhantomData, + } + } +} + +impl From> for [W; DIGEST_ELEMS] { + fn from(value: Hash) -> [W; DIGEST_ELEMS] { + value.value + } +} + +impl PartialEq<[W; DIGEST_ELEMS]> + for Hash +{ + fn eq(&self, other: &[W; DIGEST_ELEMS]) -> bool { + self.value == *other + } +} + +impl IntoIterator for Hash { + type Item = W; + type IntoIter = core::array::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.value.into_iter() + } +} + +impl Borrow<[W; DIGEST_ELEMS]> for Hash { + fn borrow(&self) -> &[W; DIGEST_ELEMS] { + &self.value + } +} + +impl AsRef<[W; DIGEST_ELEMS]> for Hash { + fn as_ref(&self) -> &[W; DIGEST_ELEMS] { + &self.value + } +} diff --git a/CoqOfRust/plonky3/symmetric/src/hash.v b/CoqOfRust/plonky3/symmetric/src/hash.v new file mode 100644 index 000000000..5cc07de14 --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/hash.v @@ -0,0 +1,1347 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module hash. + (* StructRecord + { + name := "Hash"; + const_params := [ "DIGEST_ELEMS" ]; + ty_params := [ "F"; "W" ]; + fields := + [ + ("value", Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]); + ("_marker", Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ]) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* Clone *) + Definition clone + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_symmetric::hash::Hash" + [ + ("value", + M.call_closure (| + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "value" + |) + |) + |) + |) + ] + |)); + ("_marker", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "_marker" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W) + (* Instance *) [ ("clone", InstanceField.Method (clone DIGEST_ELEMS F W)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + + Module Impl_core_marker_Copy_where_core_marker_Copy_F_where_core_marker_Copy_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_F_where_core_marker_Copy_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* Debug *) + Definition fmt + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Hash" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "value" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "value" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_marker" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "_marker" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W) + (* Instance *) [ ("fmt", InstanceField.Method (fmt DIGEST_ELEMS F W)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + + Module Impl_core_marker_StructuralPartialEq_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + + Module Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_where_core_cmp_PartialEq_W_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* PartialEq *) + Definition eq + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ], + [], + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "value" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_symmetric::hash::Hash", + "value" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [ Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "_marker" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "p3_symmetric::hash::Hash", + "_marker" + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ] ] + (Self DIGEST_ELEMS F W) + (* Instance *) [ ("eq", InstanceField.Method (eq DIGEST_ELEMS F W)) ]. + End Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_F_where_core_cmp_PartialEq_W_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + + Module Impl_core_cmp_Eq_where_core_cmp_Eq_F_where_core_cmp_Eq_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* Eq *) + Definition assert_receiver_is_total_eq + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W) + (* Instance *) + [ + ("assert_receiver_is_total_eq", + InstanceField.Method (assert_receiver_is_total_eq DIGEST_ELEMS F W)) + ]. + End Impl_core_cmp_Eq_where_core_cmp_Eq_F_where_core_cmp_Eq_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + + Module underscore. + Module Impl_serde_ser_Serialize_where_serde_ser_Serialize_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* Serialize *) + Definition serialize + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "Hash" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "value" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "value" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ] ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "_marker" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "_marker" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W) + (* Instance *) [ ("serialize", InstanceField.Method (serialize DIGEST_ELEMS F W)) ]. + End Impl_serde_ser_Serialize_where_serde_ser_Serialize_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Module Impl_serde_de_Deserialize_where_serde_de_Deserialize_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* Deserialize *) + Definition deserialize + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_symmetric::hash::_'1::deserialize::__Visitor") + [ DIGEST_ELEMS ] + [ F; W ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "Hash" |); + M.read (| + get_constant (| + "p3_symmetric::hash::_'1::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_symmetric::hash::_'1::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize DIGEST_ELEMS F W)) ]. + End Impl_serde_de_Deserialize_where_serde_de_Deserialize_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + End underscore. + + + Module Impl_core_convert_From_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* + fn from(value: [W; DIGEST_ELEMS]) -> Self { + Self { + value, + _marker: PhantomData, + } + } + *) + Definition from + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructRecord + "p3_symmetric::hash::Hash" + [ + ("value", M.read (| value |)); + ("_marker", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ] + (Self DIGEST_ELEMS F W) + (* Instance *) [ ("from", InstanceField.Method (from DIGEST_ELEMS F W)) ]. + End Impl_core_convert_From_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + + Module Impl_core_convert_From_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W_for_array_DIGEST_ELEMS_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ]. + + (* + fn from(value: Hash) -> [W; DIGEST_ELEMS] { + value.value + } + *) + Definition from + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + M.SubPointer.get_struct_record_field (| value, "p3_symmetric::hash::Hash", "value" |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ] ] + (Self DIGEST_ELEMS F W) + (* Instance *) [ ("from", InstanceField.Method (from DIGEST_ELEMS F W)) ]. + End Impl_core_convert_From_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W_for_array_DIGEST_ELEMS_W. + + Module Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_W_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* + fn eq(&self, other: &[W; DIGEST_ELEMS]) -> bool { + self.value == *other + } + *) + Definition eq + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ], + [], + [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "value" + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ] + (Self DIGEST_ELEMS F W) + (* Instance *) [ ("eq", InstanceField.Method (eq DIGEST_ELEMS F W)) ]. + End Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_W_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + + Module Impl_core_iter_traits_collect_IntoIterator_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* type Item = W; *) + Definition _Item (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := W. + + (* type IntoIter = core::array::IntoIter; *) + Definition _IntoIter (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "core::array::iter::IntoIter") [ DIGEST_ELEMS ] [ W ]. + + (* + fn into_iter(self) -> Self::IntoIter { + self.value.into_iter() + } + *) + Definition into_iter + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "core::array::iter::IntoIter") [ DIGEST_ELEMS ] [ W ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| self, "p3_symmetric::hash::Hash", "value" |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self DIGEST_ELEMS F W) + (* Instance *) + [ + ("Item", InstanceField.Ty (_Item DIGEST_ELEMS F W)); + ("IntoIter", InstanceField.Ty (_IntoIter DIGEST_ELEMS F W)); + ("into_iter", InstanceField.Method (into_iter DIGEST_ELEMS F W)) + ]. + End Impl_core_iter_traits_collect_IntoIterator_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + + Module Impl_core_borrow_Borrow_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* + fn borrow(&self) -> &[W; DIGEST_ELEMS] { + &self.value + } + *) + Definition borrow + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "value" + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ] + (Self DIGEST_ELEMS F W) + (* Instance *) [ ("borrow", InstanceField.Method (borrow DIGEST_ELEMS F W)) ]. + End Impl_core_borrow_Borrow_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + + Module Impl_core_convert_AsRef_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. + Definition Self (DIGEST_ELEMS : Value.t) (F W : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::hash::Hash") [ DIGEST_ELEMS ] [ F; W ]. + + (* + fn as_ref(&self) -> &[W; DIGEST_ELEMS] { + &self.value + } + *) + Definition as_ref + (DIGEST_ELEMS : Value.t) + (F W : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self DIGEST_ELEMS F W in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::hash::Hash", + "value" + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (DIGEST_ELEMS : Value.t) (F W : Ty.t), + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ DIGEST_ELEMS ] [ W ] ] + (Self DIGEST_ELEMS F W) + (* Instance *) [ ("as_ref", InstanceField.Method (as_ref DIGEST_ELEMS F W)) ]. + End Impl_core_convert_AsRef_array_DIGEST_ELEMS_W_for_p3_symmetric_hash_Hash_DIGEST_ELEMS_F_W. +End hash. diff --git a/CoqOfRust/plonky3/symmetric/src/hasher.rs b/CoqOfRust/plonky3/symmetric/src/hasher.rs new file mode 100644 index 000000000..60194138b --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/hasher.rs @@ -0,0 +1,21 @@ +pub trait CryptographicHasher: Clone { + fn hash_iter(&self, input: I) -> Out + where + I: IntoIterator; + + fn hash_iter_slices<'a, I>(&self, input: I) -> Out + where + I: IntoIterator, + Item: 'a, + { + self.hash_iter(input.into_iter().flatten().cloned()) + } + + fn hash_slice(&self, input: &[Item]) -> Out { + self.hash_iter_slices(core::iter::once(input)) + } + + fn hash_item(&self, input: Item) -> Out { + self.hash_slice(&[input]) + } +} diff --git a/CoqOfRust/plonky3/symmetric/src/hasher.v b/CoqOfRust/plonky3/symmetric/src/hasher.v new file mode 100644 index 000000000..1c052804c --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/hasher.v @@ -0,0 +1,244 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module hasher. + (* Trait *) + Module CryptographicHasher. + Definition hash_iter_slices + (Item Out Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Out, + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + Self, + [], + [ Item; Out ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::flatten::Flatten") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ] + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::cloned::Cloned") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::flatten::Flatten") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::flatten::Flatten") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ], + [], + [], + "cloned", + [], + [ Item ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::Flatten") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "flatten", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |) + ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_hash_iter_slices : + forall (Item Out : Ty.t), + M.IsProvidedMethod + "p3_symmetric::hasher::CryptographicHasher" + "hash_iter_slices" + (hash_iter_slices Item Out). + Definition hash_slice + (Item Out Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Out, + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + Self, + [], + [ Item; Out ], + "hash_iter_slices", + [], + [ + Ty.apply + (Ty.path "core::iter::sources::once::Once") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Item ] ] ] + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::sources::once::Once") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Item ] ] ], + M.get_function (| + "core::iter::sources::once::once", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Item ] ] ] + |), + [ M.read (| input |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_hash_slice : + forall (Item Out : Ty.t), + M.IsProvidedMethod + "p3_symmetric::hasher::CryptographicHasher" + "hash_slice" + (hash_slice Item Out). + Definition hash_item + (Item Out Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Out, + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + Self, + [], + [ Item; Out ], + "hash_slice", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ M.read (| input |) ] |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_hash_item : + forall (Item Out : Ty.t), + M.IsProvidedMethod + "p3_symmetric::hasher::CryptographicHasher" + "hash_item" + (hash_item Item Out). + End CryptographicHasher. +End hasher. diff --git a/CoqOfRust/plonky3/symmetric/src/lib.rs b/CoqOfRust/plonky3/symmetric/src/lib.rs new file mode 100644 index 000000000..3c96eed26 --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/lib.rs @@ -0,0 +1,19 @@ +//! A framework for symmetric cryptography primitives. + +#![no_std] + +extern crate alloc; + +mod compression; +mod hash; +mod hasher; +mod permutation; +mod serializing_hasher; +mod sponge; + +pub use compression::*; +pub use hash::*; +pub use hasher::*; +pub use permutation::*; +pub use serializing_hasher::*; +pub use sponge::*; diff --git a/CoqOfRust/plonky3/symmetric/src/permutation.rs b/CoqOfRust/plonky3/symmetric/src/permutation.rs new file mode 100644 index 000000000..f62f9b766 --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/permutation.rs @@ -0,0 +1,14 @@ +/// A permutation in the mathematical sense. +pub trait Permutation: Clone + Sync { + #[inline(always)] + fn permute(&self, mut input: T) -> T { + self.permute_mut(&mut input); + input + } + + fn permute_mut(&self, input: &mut T); +} + +/// A permutation thought to be cryptographically secure, in the sense that it is thought to be +/// difficult to distinguish (in a nontrivial way) from a random permutation. +pub trait CryptographicPermutation: Permutation {} diff --git a/CoqOfRust/plonky3/symmetric/src/permutation.v b/CoqOfRust/plonky3/symmetric/src/permutation.v new file mode 100644 index 000000000..d7229a393 --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/permutation.v @@ -0,0 +1,48 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module permutation. + (* Trait *) + Module Permutation. + Definition permute (T Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + Self, + [], + [ T ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, input |) |) + |) + ] + |) + |) in + input + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_permute : + forall (T : Ty.t), + M.IsProvidedMethod "p3_symmetric::permutation::Permutation" "permute" (permute T). + End Permutation. + + (* Trait *) + (* Empty module 'CryptographicPermutation' *) +End permutation. diff --git a/CoqOfRust/plonky3/symmetric/src/serializing_hasher.rs b/CoqOfRust/plonky3/symmetric/src/serializing_hasher.rs new file mode 100644 index 000000000..c09e92fad --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/serializing_hasher.rs @@ -0,0 +1,149 @@ +use core::iter; + +use p3_field::{PackedValue, PrimeField32, PrimeField64}; + +use crate::CryptographicHasher; + +/// Serializes 32-bit field elements to bytes (i.e. the little-endian encoding of their canonical +/// values), then hashes those bytes using some inner hasher, and outputs a `[u8; 32]`. +#[derive(Copy, Clone, Debug)] +pub struct SerializingHasher32 { + inner: Inner, +} + +/// Serializes 32-bit field elements to u64s (packing two canonical values together), then hashes +/// those u64s using some inner hasher, and outputs a `[u64; 4]`. +#[derive(Copy, Clone, Debug)] +pub struct SerializingHasher32To64 { + inner: Inner, +} + +/// Serializes 64-bit field elements to bytes (i.e. the little-endian encoding of their canonical +/// values), then hashes those bytes using some inner hasher, and outputs a `[u8; 32]`. +#[derive(Copy, Clone, Debug)] +pub struct SerializingHasher64 { + inner: Inner, +} + +impl SerializingHasher32 { + pub const fn new(inner: Inner) -> Self { + Self { inner } + } +} + +impl SerializingHasher32To64 { + pub const fn new(inner: Inner) -> Self { + Self { inner } + } +} + +impl SerializingHasher64 { + pub const fn new(inner: Inner) -> Self { + Self { inner } + } +} + +impl CryptographicHasher for SerializingHasher32 +where + F: PrimeField32, + Inner: CryptographicHasher, +{ + fn hash_iter(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + self.inner.hash_iter( + input + .into_iter() + .flat_map(|x| x.to_unique_u32().to_le_bytes()), + ) + } +} + +impl CryptographicHasher for SerializingHasher32 +where + P: PackedValue, + P::Value: PrimeField32, + PW: PackedValue, + Inner: CryptographicHasher, +{ + fn hash_iter(&self, input: I) -> [PW; 8] + where + I: IntoIterator, + { + self.inner.hash_iter( + input + .into_iter() + .map(|x| PW::from_fn(|i| x.as_slice()[i].to_unique_u32())), + ) + } +} + +impl CryptographicHasher for SerializingHasher32To64 +where + P: PackedValue, + P::Value: PrimeField32, + PW: PackedValue, + Inner: CryptographicHasher, +{ + fn hash_iter(&self, input: I) -> [PW; 4] + where + I: IntoIterator, + { + assert_eq!(P::WIDTH, PW::WIDTH); + let mut input = input.into_iter(); + self.inner.hash_iter(iter::from_fn( + #[inline] + || { + let a = input.next(); + let b = input.next(); + if let (Some(a), Some(b)) = (a, b) { + let ab = PW::from_fn(|i| { + let a_i = a.as_slice()[i].to_unique_u64(); + let b_i = b.as_slice()[i].to_unique_u64(); + a_i | (b_i << 32) + }); + Some(ab) + } else { + a.map(|a| PW::from_fn(|i| a.as_slice()[i].to_unique_u64())) + } + }, + )) + } +} + +impl CryptographicHasher for SerializingHasher64 +where + F: PrimeField64, + Inner: CryptographicHasher, +{ + fn hash_iter(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + self.inner.hash_iter( + input + .into_iter() + .flat_map(|x| x.to_unique_u64().to_le_bytes()), + ) + } +} + +impl CryptographicHasher for SerializingHasher64 +where + P: PackedValue, + P::Value: PrimeField64, + PW: PackedValue, + Inner: CryptographicHasher, +{ + fn hash_iter(&self, input: I) -> [PW; 4] + where + I: IntoIterator, + { + self.inner.hash_iter( + input + .into_iter() + .map(|x| PW::from_fn(|i| x.as_slice()[i].to_unique_u64())), + ) + } +} diff --git a/CoqOfRust/plonky3/symmetric/src/serializing_hasher.v b/CoqOfRust/plonky3/symmetric/src/serializing_hasher.v new file mode 100644 index 000000000..a1d1d9e59 --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/serializing_hasher.v @@ -0,0 +1,2149 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module serializing_hasher. + (* StructRecord + { + name := "SerializingHasher32"; + const_params := []; + ty_params := [ "Inner" ]; + fields := [ ("inner", Inner) ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32") [] [ Inner ]. + + Axiom Implements : + forall (Inner : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Inner) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + + Module Impl_core_clone_Clone_where_core_clone_Clone_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32") [] [ Inner ]. + + (* Clone *) + Definition clone (Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Inner in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_symmetric::serializing_hasher::SerializingHasher32" + [ + ("inner", + M.call_closure (| + Inner, + M.get_trait_method (| "core::clone::Clone", Inner, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher32", + "inner" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Inner : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Inner) + (* Instance *) [ ("clone", InstanceField.Method (clone Inner)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32") [] [ Inner ]. + + (* Debug *) + Definition fmt (Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Inner in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "SerializingHasher32" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inner" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher32", + "inner" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Inner : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Inner) + (* Instance *) [ ("fmt", InstanceField.Method (fmt Inner)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + + (* StructRecord + { + name := "SerializingHasher32To64"; + const_params := []; + ty_params := [ "Inner" ]; + fields := [ ("inner", Inner) ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32To64_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") [] [ Inner ]. + + Axiom Implements : + forall (Inner : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Inner) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32To64_Inner. + + Module Impl_core_clone_Clone_where_core_clone_Clone_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32To64_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") [] [ Inner ]. + + (* Clone *) + Definition clone (Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Inner in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_symmetric::serializing_hasher::SerializingHasher32To64" + [ + ("inner", + M.call_closure (| + Inner, + M.get_trait_method (| "core::clone::Clone", Inner, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher32To64", + "inner" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Inner : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Inner) + (* Instance *) [ ("clone", InstanceField.Method (clone Inner)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32To64_Inner. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32To64_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") [] [ Inner ]. + + (* Debug *) + Definition fmt (Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Inner in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "SerializingHasher32To64" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inner" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher32To64", + "inner" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Inner : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Inner) + (* Instance *) [ ("fmt", InstanceField.Method (fmt Inner)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher32To64_Inner. + + (* StructRecord + { + name := "SerializingHasher64"; + const_params := []; + ty_params := [ "Inner" ]; + fields := [ ("inner", Inner) ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher64") [] [ Inner ]. + + Axiom Implements : + forall (Inner : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Inner) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + + Module Impl_core_clone_Clone_where_core_clone_Clone_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher64") [] [ Inner ]. + + (* Clone *) + Definition clone (Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Inner in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_symmetric::serializing_hasher::SerializingHasher64" + [ + ("inner", + M.call_closure (| + Inner, + M.get_trait_method (| "core::clone::Clone", Inner, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher64", + "inner" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Inner : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Inner) + (* Instance *) [ ("clone", InstanceField.Method (clone Inner)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher64") [] [ Inner ]. + + (* Debug *) + Definition fmt (Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Inner in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "SerializingHasher64" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inner" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher64", + "inner" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Inner : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Inner) + (* Instance *) [ ("fmt", InstanceField.Method (fmt Inner)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Inner_for_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + + Module Impl_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32") [] [ Inner ]. + + (* + pub const fn new(inner: Inner) -> Self { + Self { inner } + } + *) + Definition new (Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Inner in + match ε, τ, α with + | [], [], [ inner ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + Value.StructRecord + "p3_symmetric::serializing_hasher::SerializingHasher32" + [ ("inner", M.read (| inner |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (Inner : Ty.t), + M.IsAssociatedFunction.C (Self Inner) "new" (new Inner). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + + Module Impl_p3_symmetric_serializing_hasher_SerializingHasher32To64_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") [] [ Inner ]. + + (* + pub const fn new(inner: Inner) -> Self { + Self { inner } + } + *) + Definition new (Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Inner in + match ε, τ, α with + | [], [], [ inner ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + Value.StructRecord + "p3_symmetric::serializing_hasher::SerializingHasher32To64" + [ ("inner", M.read (| inner |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (Inner : Ty.t), + M.IsAssociatedFunction.C (Self Inner) "new" (new Inner). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_symmetric_serializing_hasher_SerializingHasher32To64_Inner. + + Module Impl_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + Definition Self (Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher64") [] [ Inner ]. + + (* + pub const fn new(inner: Inner) -> Self { + Self { inner } + } + *) + Definition new (Inner : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Inner in + match ε, τ, α with + | [], [], [ inner ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + Value.StructRecord + "p3_symmetric::serializing_hasher::SerializingHasher64" + [ ("inner", M.read (| inner |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (Inner : Ty.t), + M.IsAssociatedFunction.C (Self Inner) "new" (new Inner). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + + Module Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_field_PrimeField32_F_where_p3_symmetric_hasher_CryptographicHasher_Inner_u8_array_Usize_32_u8_F_array_Usize_32_u8_for_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32") [] [ Inner ]. + + (* + fn hash_iter(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + self.inner.hash_iter( + input + .into_iter() + .flat_map(|x| x.to_unique_u32().to_le_bytes()), + ) + } + *) + Definition hash_iter + (F Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + Inner, + [], + [ + Ty.path "u8"; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter"; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ]; + Ty.function + [ Ty.tuple [ F ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ]) + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher32", + "inner" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter"; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ]; + Ty.function + [ Ty.tuple [ F ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ]; + Ty.function + [ Ty.tuple [ F ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ]) + ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ F ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "u32", + "to_le_bytes", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + F, + [], + [], + "to_unique_u32", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "p3_symmetric::hasher::CryptographicHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ F; Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] ] + (Self F Inner) + (* Instance *) [ ("hash_iter", InstanceField.Method (hash_iter F Inner)) ]. + End Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_field_PrimeField32_F_where_p3_symmetric_hasher_CryptographicHasher_Inner_u8_array_Usize_32_u8_F_array_Usize_32_u8_for_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + + Module Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_packed_PackedValue_P_where_p3_field_field_PrimeField32_associated_in_trait_p3_field_packed_PackedValue___P_Value_where_p3_field_packed_PackedValue_PW_where_p3_symmetric_hasher_CryptographicHasher_Inner_PW_array_Usize_8_PW_P_array_Usize_8_PW_for_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + Definition Self (P PW Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32") [] [ Inner ]. + + (* + fn hash_iter(&self, input: I) -> [PW; 8] + where + I: IntoIterator, + { + self.inner.hash_iter( + input + .into_iter() + .map(|x| PW::from_fn(|i| x.as_slice()[i].to_unique_u32())), + ) + } + *) + Definition hash_iter + (P PW Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self P PW Inner in + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ PW ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + Inner, + [], + [ PW; Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ PW ] ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter"; + Ty.function [ Ty.tuple [ P ] ] PW + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher32", + "inner" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter"; + Ty.function [ Ty.tuple [ P ] ] PW + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "map", + [], + [ PW; Ty.function [ Ty.tuple [ P ] ] PW ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ P ] ] PW ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + PW, + M.get_trait_method (| + "p3_field::packed::PackedValue", + PW, + [], + [], + "from_fn", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u32") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u32") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.path "u32", + M.get_trait_method (| + "p3_field::field::PrimeField32", + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value", + [], + [], + "to_unique_u32", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + P, + [], + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + x + |) + ] + |) + |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (P PW Inner : Ty.t), + M.IsTraitInstance + "p3_symmetric::hasher::CryptographicHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ P; Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ PW ] ] + (Self P PW Inner) + (* Instance *) [ ("hash_iter", InstanceField.Method (hash_iter P PW Inner)) ]. + End Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_packed_PackedValue_P_where_p3_field_field_PrimeField32_associated_in_trait_p3_field_packed_PackedValue___P_Value_where_p3_field_packed_PackedValue_PW_where_p3_symmetric_hasher_CryptographicHasher_Inner_PW_array_Usize_8_PW_P_array_Usize_8_PW_for_p3_symmetric_serializing_hasher_SerializingHasher32_Inner. + + Module Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_packed_PackedValue_P_where_p3_field_field_PrimeField32_associated_in_trait_p3_field_packed_PackedValue___P_Value_where_p3_field_packed_PackedValue_PW_where_p3_symmetric_hasher_CryptographicHasher_Inner_PW_array_Usize_4_PW_P_array_Usize_4_PW_for_p3_symmetric_serializing_hasher_SerializingHasher32To64_Inner. + Definition Self (P PW Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher32To64") [] [ Inner ]. + + (* + fn hash_iter(&self, input: I) -> [PW; 4] + where + I: IntoIterator, + { + assert_eq!(P::WIDTH, PW::WIDTH); + let mut input = input.into_iter(); + self.inner.hash_iter(iter::from_fn( + #[inline] + || { + let a = input.next(); + let b = input.next(); + if let (Some(a), Some(b)) = (a, b) { + let ab = PW::from_fn(|i| { + let a_i = a.as_slice()[i].to_unique_u64(); + let b_i = b.as_slice()[i].to_unique_u64(); + a_i | (b_i << 32) + }); + Some(ab) + } else { + a.map(|a| PW::from_fn(|i| a.as_slice()[i].to_unique_u64())) + } + }, + )) + } + *) + Definition hash_iter + (P PW Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self P PW Inner in + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::packed::PackedValue::WIDTH", Ty.path "usize" |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ input : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ PW ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + Inner, + [], + [ PW; Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ PW ] ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::sources::from_fn::FromFn") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "core::option::Option") [] [ PW ]) + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher32To64", + "inner" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::sources::from_fn::FromFn") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "core::option::Option") [] [ PW ]) + ], + M.get_function (| + "core::iter::sources::from_fn::from_fn", + [], + [ + PW; + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "core::option::Option") [] [ PW ]) + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply (Ty.path "core::option::Option") [] [ PW ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.read (| + let~ a : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::option::Option") [] [ P ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ P ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, input |) ] + |) + |) in + let~ b : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::option::Option") [] [ P ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ P ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, input |) ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::option::Option") [] [ PW ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + Value.Tuple [ M.read (| a |); M.read (| b |) ] + |) in + let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "core::option::Option::Some", + 0 + |) in + let a := M.copy (| γ1_0 |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "core::option::Option::Some", + 0 + |) in + let b := M.copy (| γ1_0 |) in + let~ ab : Ty.apply (Ty.path "*") [] [ PW ] := + M.alloc (| + M.call_closure (| + PW, + M.get_trait_method (| + "p3_field::packed::PackedValue", + PW, + [], + [], + "from_fn", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u64") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.path "usize" ] + ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := + M.copy (| γ |) in + M.read (| + let~ a_i : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "u64" + ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value", + [], + [], + "to_unique_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + P, + [], + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + a + |) + ] + |) + |), + M.read (| + i + |) + |) + |) + ] + |) + |) in + let~ b_i : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "u64" + ] := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value", + [], + [], + "to_unique_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + P, + [], + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + b + |) + ] + |) + |), + M.read (| + i + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_or, + [ + M.read (| + a_i + |); + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shl, + [ + M.read (| + b_i + |); + Value.Integer + IntegerKind.I32 + 32 + ] + |) + ] + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.read (| ab |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ PW ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ P ], + "map", + [], + [ PW; Ty.function [ Ty.tuple [ P ] ] PW ] + |), + [ + M.read (| a |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ P ] ] + PW + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let a := + M.copy (| γ |) in + M.call_closure (| + PW, + M.get_trait_method (| + "p3_field::packed::PackedValue", + PW, + [], + [], + "from_fn", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.path "u64") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.path + "u64") + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + i := + M.copy (| + γ + |) in + M.call_closure (| + Ty.path + "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value", + [], + [], + "to_unique_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + P, + [], + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + a + |) + ] + |) + |), + M.read (| + i + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + |))) + ] + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (P PW Inner : Ty.t), + M.IsTraitInstance + "p3_symmetric::hasher::CryptographicHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ P; Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ PW ] ] + (Self P PW Inner) + (* Instance *) [ ("hash_iter", InstanceField.Method (hash_iter P PW Inner)) ]. + End Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_packed_PackedValue_P_where_p3_field_field_PrimeField32_associated_in_trait_p3_field_packed_PackedValue___P_Value_where_p3_field_packed_PackedValue_PW_where_p3_symmetric_hasher_CryptographicHasher_Inner_PW_array_Usize_4_PW_P_array_Usize_4_PW_for_p3_symmetric_serializing_hasher_SerializingHasher32To64_Inner. + + Module Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_field_PrimeField64_F_where_p3_symmetric_hasher_CryptographicHasher_Inner_u8_array_Usize_32_u8_F_array_Usize_32_u8_for_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + Definition Self (F Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher64") [] [ Inner ]. + + (* + fn hash_iter(&self, input: I) -> [u8; 32] + where + I: IntoIterator, + { + self.inner.hash_iter( + input + .into_iter() + .flat_map(|x| x.to_unique_u64().to_le_bytes()), + ) + } + *) + Definition hash_iter + (F Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F Inner in + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + Inner, + [], + [ + Ty.path "u8"; + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] + ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter"; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ]; + Ty.function + [ Ty.tuple [ F ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ]) + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher64", + "inner" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter"; + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ]; + Ty.function + [ Ty.tuple [ F ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ]; + Ty.function + [ Ty.tuple [ F ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ]) + ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ F ] ] + (Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "u64", + "to_le_bytes", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + F, + [], + [], + "to_unique_u64", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, x |) ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F Inner : Ty.t), + M.IsTraitInstance + "p3_symmetric::hasher::CryptographicHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ F; Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ] ] + (Self F Inner) + (* Instance *) [ ("hash_iter", InstanceField.Method (hash_iter F Inner)) ]. + End Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_field_PrimeField64_F_where_p3_symmetric_hasher_CryptographicHasher_Inner_u8_array_Usize_32_u8_F_array_Usize_32_u8_for_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + + Module Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_packed_PackedValue_P_where_p3_field_field_PrimeField64_associated_in_trait_p3_field_packed_PackedValue___P_Value_where_p3_field_packed_PackedValue_PW_where_p3_symmetric_hasher_CryptographicHasher_Inner_PW_array_Usize_4_PW_P_array_Usize_4_PW_for_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. + Definition Self (P PW Inner : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::serializing_hasher::SerializingHasher64") [] [ Inner ]. + + (* + fn hash_iter(&self, input: I) -> [PW; 4] + where + I: IntoIterator, + { + self.inner.hash_iter( + input + .into_iter() + .map(|x| PW::from_fn(|i| x.as_slice()[i].to_unique_u64())), + ) + } + *) + Definition hash_iter + (P PW Inner : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self P PW Inner in + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ PW ], + M.get_trait_method (| + "p3_symmetric::hasher::CryptographicHasher", + Inner, + [], + [ PW; Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ PW ] ], + "hash_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter"; + Ty.function [ Ty.tuple [ P ] ] PW + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::serializing_hasher::SerializingHasher64", + "inner" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter"; + Ty.function [ Ty.tuple [ P ] ] PW + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "map", + [], + [ PW; Ty.function [ Ty.tuple [ P ] ] PW ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.function [ Ty.tuple [ P ] ] PW ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + PW, + M.get_trait_method (| + "p3_field::packed::PackedValue", + PW, + [], + [], + "from_fn", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u64") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.path "u64") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "p3_field::field::PrimeField64", + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value", + [], + [], + "to_unique_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::packed::PackedValue" + [] + [] + P + "Value" + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + P, + [], + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + x + |) + ] + |) + |), + M.read (| i |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (P PW Inner : Ty.t), + M.IsTraitInstance + "p3_symmetric::hasher::CryptographicHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ P; Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ PW ] ] + (Self P PW Inner) + (* Instance *) [ ("hash_iter", InstanceField.Method (hash_iter P PW Inner)) ]. + End Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_packed_PackedValue_P_where_p3_field_field_PrimeField64_associated_in_trait_p3_field_packed_PackedValue___P_Value_where_p3_field_packed_PackedValue_PW_where_p3_symmetric_hasher_CryptographicHasher_Inner_PW_array_Usize_4_PW_P_array_Usize_4_PW_for_p3_symmetric_serializing_hasher_SerializingHasher64_Inner. +End serializing_hasher. diff --git a/CoqOfRust/plonky3/symmetric/src/sponge.rs b/CoqOfRust/plonky3/symmetric/src/sponge.rs new file mode 100644 index 000000000..441e46680 --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/sponge.rs @@ -0,0 +1,205 @@ +use alloc::string::String; +use core::marker::PhantomData; + +use itertools::Itertools; +use p3_field::{Field, PrimeField, PrimeField32, reduce_32}; + +use crate::hasher::CryptographicHasher; +use crate::permutation::CryptographicPermutation; + +/// A padding-free, overwrite-mode sponge function. +/// +/// `WIDTH` is the sponge's rate plus the sponge's capacity. +#[derive(Copy, Clone, Debug)] +pub struct PaddingFreeSponge { + permutation: P, +} + +impl + PaddingFreeSponge +{ + pub const fn new(permutation: P) -> Self { + Self { permutation } + } +} + +impl CryptographicHasher + for PaddingFreeSponge +where + T: Default + Copy, + P: CryptographicPermutation<[T; WIDTH]>, +{ + fn hash_iter(&self, input: I) -> [T; OUT] + where + I: IntoIterator, + { + // static_assert(RATE < WIDTH) + let mut state = [T::default(); WIDTH]; + let mut input = input.into_iter(); + + // Itertools' chunks() is more convenient, but seems to add more overhead, + // hence the more manual loop. + 'outer: loop { + for i in 0..RATE { + if let Some(x) = input.next() { + state[i] = x; + } else { + if i != 0 { + self.permutation.permute_mut(&mut state); + } + break 'outer; + } + } + self.permutation.permute_mut(&mut state); + } + + state[..OUT].try_into().unwrap() + } +} + +/// A padding-free, overwrite-mode sponge function that operates natively over PF but accepts elements +/// of F: PrimeField32. +/// +/// `WIDTH` is the sponge's rate plus the sponge's capacity. +#[derive(Clone, Debug)] +pub struct MultiField32PaddingFreeSponge< + F, + PF, + P, + const WIDTH: usize, + const RATE: usize, + const OUT: usize, +> { + permutation: P, + num_f_elms: usize, + _phantom: PhantomData<(F, PF)>, +} + +impl + MultiField32PaddingFreeSponge +where + F: PrimeField32, + PF: Field, +{ + pub fn new(permutation: P) -> Result { + if F::order() >= PF::order() { + return Err(String::from("F::order() must be less than PF::order()")); + } + + let num_f_elms = PF::bits() / F::bits(); + Ok(Self { + permutation, + num_f_elms, + _phantom: PhantomData, + }) + } +} + +impl + CryptographicHasher for MultiField32PaddingFreeSponge +where + F: PrimeField32, + PF: PrimeField + Default + Copy, + P: CryptographicPermutation<[PF; WIDTH]>, +{ + fn hash_iter(&self, input: I) -> [PF; OUT] + where + I: IntoIterator, + { + let mut state = [PF::default(); WIDTH]; + for block_chunk in &input.into_iter().chunks(RATE) { + for (chunk_id, chunk) in (&block_chunk.chunks(self.num_f_elms)) + .into_iter() + .enumerate() + { + state[chunk_id] = reduce_32(&chunk.collect_vec()); + } + state = self.permutation.permute(state); + } + + state[..OUT].try_into().unwrap() + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::Permutation; + + #[derive(Clone)] + struct MockPermutation; + + impl Permutation<[T; WIDTH]> for MockPermutation + where + T: Copy + core::ops::Add + Default, + { + fn permute_mut(&self, input: &mut [T; WIDTH]) { + let sum: T = input.iter().copied().fold(T::default(), |acc, x| acc + x); + // Set every element to the sum + *input = [sum; WIDTH]; + } + } + + impl CryptographicPermutation<[T; WIDTH]> for MockPermutation where + T: Copy + core::ops::Add + Default + { + } + + #[test] + fn test_padding_free_sponge_basic() { + const WIDTH: usize = 4; + const RATE: usize = 2; + const OUT: usize = 2; + + let permutation = MockPermutation; + let sponge = PaddingFreeSponge::::new(permutation); + + let input = [1, 2, 3, 4, 5]; + let output = sponge.hash_iter(input); + + // Explanation of why the final state results in [44, 44, 44, 44]: + // Initial state: [0, 0, 0, 0] + // First input chunk [1, 2] overwrites first two positions: [1, 2, 0, 0] + // Apply permutation (sum all elements and overwrite): [3, 3, 3, 3] + // Second input chunk [3, 4] overwrites first two positions: [3, 4, 3, 3] + // Apply permutation: [13, 13, 13, 13] (3 + 4 + 3 + 3 = 13) + // Third input chunk [5] overwrites first position: [5, 13, 13, 13] + // Apply permutation: [44, 44, 44, 44] (5 + 13 + 13 + 13 = 44) + + assert_eq!(output, [44; OUT]); + } + + #[test] + fn test_padding_free_sponge_empty_input() { + const WIDTH: usize = 4; + const RATE: usize = 2; + const OUT: usize = 2; + + let permutation = MockPermutation; + let sponge = PaddingFreeSponge::::new(permutation); + + let input: [u64; 0] = []; + let output = sponge.hash_iter(input); + + assert_eq!( + output, [0; OUT], + "Should return default values when input is empty." + ); + } + + #[test] + fn test_padding_free_sponge_exact_block_size() { + const WIDTH: usize = 6; + const RATE: usize = 3; + const OUT: usize = 2; + + let permutation = MockPermutation; + let sponge = PaddingFreeSponge::::new(permutation); + + let input = [10, 20, 30]; + let output = sponge.hash_iter(input); + + let expected_sum = 10 + 20 + 30; + assert_eq!(output, [expected_sum; OUT]); + } +} diff --git a/CoqOfRust/plonky3/symmetric/src/sponge.v b/CoqOfRust/plonky3/symmetric/src/sponge.v new file mode 100644 index 000000000..03c98ca66 --- /dev/null +++ b/CoqOfRust/plonky3/symmetric/src/sponge.v @@ -0,0 +1,1861 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module sponge. + (* StructRecord + { + name := "PaddingFreeSponge"; + const_params := [ "WIDTH"; "RATE"; "OUT" ]; + ty_params := [ "P" ]; + fields := [ ("permutation", P) ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_P_for_p3_symmetric_sponge_PaddingFreeSponge_WIDTH_RATE_OUT_P. + Definition Self (WIDTH RATE OUT : Value.t) (P : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") [ WIDTH; RATE; OUT ] [ P ]. + + Axiom Implements : + forall (WIDTH RATE OUT : Value.t) (P : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE OUT P) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_P_for_p3_symmetric_sponge_PaddingFreeSponge_WIDTH_RATE_OUT_P. + + Module Impl_core_clone_Clone_where_core_clone_Clone_P_for_p3_symmetric_sponge_PaddingFreeSponge_WIDTH_RATE_OUT_P. + Definition Self (WIDTH RATE OUT : Value.t) (P : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") [ WIDTH; RATE; OUT ] [ P ]. + + (* Clone *) + Definition clone + (WIDTH RATE OUT : Value.t) + (P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE OUT P in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_symmetric::sponge::PaddingFreeSponge" + [ + ("permutation", + M.call_closure (| + P, + M.get_trait_method (| "core::clone::Clone", P, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::sponge::PaddingFreeSponge", + "permutation" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE OUT : Value.t) (P : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE OUT P) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH RATE OUT P)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_P_for_p3_symmetric_sponge_PaddingFreeSponge_WIDTH_RATE_OUT_P. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_P_for_p3_symmetric_sponge_PaddingFreeSponge_WIDTH_RATE_OUT_P. + Definition Self (WIDTH RATE OUT : Value.t) (P : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") [ WIDTH; RATE; OUT ] [ P ]. + + (* Debug *) + Definition fmt + (WIDTH RATE OUT : Value.t) + (P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE OUT P in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "PaddingFreeSponge" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "permutation" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::sponge::PaddingFreeSponge", + "permutation" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE OUT : Value.t) (P : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE OUT P) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH RATE OUT P)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_P_for_p3_symmetric_sponge_PaddingFreeSponge_WIDTH_RATE_OUT_P. + + Module Impl_p3_symmetric_sponge_PaddingFreeSponge_WIDTH_RATE_OUT_P. + Definition Self (WIDTH RATE OUT : Value.t) (P : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") [ WIDTH; RATE; OUT ] [ P ]. + + (* + pub const fn new(permutation: P) -> Self { + Self { permutation } + } + *) + Definition new + (WIDTH RATE OUT : Value.t) + (P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE OUT P in + match ε, τ, α with + | [], [], [ permutation ] => + ltac:(M.monadic + (let permutation := M.alloc (| permutation |) in + Value.StructRecord + "p3_symmetric::sponge::PaddingFreeSponge" + [ ("permutation", M.read (| permutation |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (WIDTH RATE OUT : Value.t) (P : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH RATE OUT P) "new" (new WIDTH RATE OUT P). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_symmetric_sponge_PaddingFreeSponge_WIDTH_RATE_OUT_P. + + Module Impl_p3_symmetric_hasher_CryptographicHasher_where_core_default_Default_T_where_core_marker_Copy_T_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_T_T_array_OUT_T_for_p3_symmetric_sponge_PaddingFreeSponge_WIDTH_RATE_OUT_P. + Definition Self (WIDTH RATE OUT : Value.t) (T P : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_symmetric::sponge::PaddingFreeSponge") [ WIDTH; RATE; OUT ] [ P ]. + + (* + fn hash_iter(&self, input: I) -> [T; OUT] + where + I: IntoIterator, + { + // static_assert(RATE < WIDTH) + let mut state = [T::default(); WIDTH]; + let mut input = input.into_iter(); + + // Itertools' chunks() is more convenient, but seems to add more overhead, + // hence the more manual loop. + 'outer: loop { + for i in 0..RATE { + if let Some(x) = input.next() { + state[i] = x; + } else { + if i != 0 { + self.permutation.permute_mut(&mut state); + } + break 'outer; + } + } + self.permutation.permute_mut(&mut state); + } + + state[..OUT].try_into().unwrap() + } + *) + Definition hash_iter + (WIDTH RATE OUT : Value.t) + (T P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE OUT T P in + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ state : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ] := + M.alloc (| + repeat (| + M.call_closure (| + T, + M.get_trait_method (| "core::default::Default", T, [], [], "default", [], [] |), + [] + |), + WIDTH + |) + |) in + let~ input : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", RATE) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ T ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + input + |) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let x := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + state, + M.read (| i |) + |), + M.read (| x |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.read (| i |); + Value.Integer + IntegerKind.Usize + 0 + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + P, + [], + [ + Ty.apply + (Ty.path "array") + [ WIDTH ] + [ T ] + ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_symmetric::sponge::PaddingFreeSponge", + "permutation" + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + state + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.break (||) + |) + |) + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + P, + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ T ] ], + "permute_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::sponge::PaddingFreeSponge", + "permutation" + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, state |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ OUT ] [ T ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ OUT ] [ T ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ OUT ] [ T ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + [], + [ Ty.apply (Ty.path "array") [ OUT ] [ T ] ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ WIDTH ] [ T ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, state |); + Value.StructRecord "core::ops::range::RangeTo" [ ("end_", OUT) ] + ] + |) + |) + |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE OUT : Value.t) (T P : Ty.t), + M.IsTraitInstance + "p3_symmetric::hasher::CryptographicHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T; Ty.apply (Ty.path "array") [ OUT ] [ T ] ] + (Self WIDTH RATE OUT T P) + (* Instance *) [ ("hash_iter", InstanceField.Method (hash_iter WIDTH RATE OUT T P)) ]. + End Impl_p3_symmetric_hasher_CryptographicHasher_where_core_default_Default_T_where_core_marker_Copy_T_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_T_T_array_OUT_T_for_p3_symmetric_sponge_PaddingFreeSponge_WIDTH_RATE_OUT_P. + + (* StructRecord + { + name := "MultiField32PaddingFreeSponge"; + const_params := [ "WIDTH"; "RATE"; "OUT" ]; + ty_params := [ "F"; "PF"; "P" ]; + fields := + [ + ("permutation", P); + ("num_f_elms", Ty.path "usize"); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ Ty.tuple [ F; PF ] ]) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_PF_where_core_clone_Clone_P_for_p3_symmetric_sponge_MultiField32PaddingFreeSponge_WIDTH_RATE_OUT_F_PF_P. + Definition Self (WIDTH RATE OUT : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::sponge::MultiField32PaddingFreeSponge") + [ WIDTH; RATE; OUT ] + [ F; PF; P ]. + + (* Clone *) + Definition clone + (WIDTH RATE OUT : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE OUT F PF P in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_symmetric::sponge::MultiField32PaddingFreeSponge" + [ + ("permutation", + M.call_closure (| + P, + M.get_trait_method (| "core::clone::Clone", P, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::sponge::MultiField32PaddingFreeSponge", + "permutation" + |) + |) + |) + |) + ] + |)); + ("num_f_elms", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::sponge::MultiField32PaddingFreeSponge", + "num_f_elms" + |) + |) + |) + |) + ] + |)); + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ Ty.tuple [ F; PF ] ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ Ty.tuple [ F; PF ] ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::sponge::MultiField32PaddingFreeSponge", + "_phantom" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE OUT : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE OUT F PF P) + (* Instance *) [ ("clone", InstanceField.Method (clone WIDTH RATE OUT F PF P)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_where_core_clone_Clone_PF_where_core_clone_Clone_P_for_p3_symmetric_sponge_MultiField32PaddingFreeSponge_WIDTH_RATE_OUT_F_PF_P. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_PF_where_core_fmt_Debug_P_for_p3_symmetric_sponge_MultiField32PaddingFreeSponge_WIDTH_RATE_OUT_F_PF_P. + Definition Self (WIDTH RATE OUT : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::sponge::MultiField32PaddingFreeSponge") + [ WIDTH; RATE; OUT ] + [ F; PF; P ]. + + (* Debug *) + Definition fmt + (WIDTH RATE OUT : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE OUT F PF P in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "MultiField32PaddingFreeSponge" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "permutation" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::sponge::MultiField32PaddingFreeSponge", + "permutation" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "num_f_elms" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::sponge::MultiField32PaddingFreeSponge", + "num_f_elms" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::sponge::MultiField32PaddingFreeSponge", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE OUT : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self WIDTH RATE OUT F PF P) + (* Instance *) [ ("fmt", InstanceField.Method (fmt WIDTH RATE OUT F PF P)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_core_fmt_Debug_PF_where_core_fmt_Debug_P_for_p3_symmetric_sponge_MultiField32PaddingFreeSponge_WIDTH_RATE_OUT_F_PF_P. + + Module Impl_p3_symmetric_sponge_MultiField32PaddingFreeSponge_WIDTH_RATE_OUT_F_PF_P. + Definition Self (WIDTH RATE OUT : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::sponge::MultiField32PaddingFreeSponge") + [ WIDTH; RATE; OUT ] + [ F; PF; P ]. + + (* + pub fn new(permutation: P) -> Result { + if F::order() >= PF::order() { + return Err(String::from("F::order() must be less than PF::order()")); + } + + let num_f_elms = PF::bits() / F::bits(); + Ok(Self { + permutation, + num_f_elms, + _phantom: PhantomData, + }) + } + *) + Definition new + (WIDTH RATE OUT : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE OUT F PF P in + match ε, τ, α with + | [], [], [ permutation ] => + ltac:(M.monadic + (let permutation := M.alloc (| permutation |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "p3_symmetric::sponge::MultiField32PaddingFreeSponge") + [ WIDTH; RATE; OUT ] + [ F; PF; P ]; + Ty.path "alloc::string::String" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "num_bigint::biguint::BigUint", + [], + [ Ty.path "num_bigint::biguint::BigUint" ], + "ge", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "order", + [], + [] + |), + [] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "num_bigint::biguint::BigUint", + M.get_trait_method (| + "p3_field::field::Field", + PF, + [], + [], + "order", + [], + [] + |), + [] + |) + |) + |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "core::convert::From", + Ty.path "alloc::string::String", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + "from", + [], + [] + |), + [ mk_str (| "F::order() must be less than PF::order()" |) ] + |) + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ num_f_elms : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_field::field::Field", + PF, + [], + [], + "bits", + [], + [] + |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_field::field::Field", + F, + [], + [], + "bits", + [], + [] + |), + [] + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructRecord + "p3_symmetric::sponge::MultiField32PaddingFreeSponge" + [ + ("permutation", M.read (| permutation |)); + ("num_f_elms", M.read (| num_f_elms |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (WIDTH RATE OUT : Value.t) (F PF P : Ty.t), + M.IsAssociatedFunction.C (Self WIDTH RATE OUT F PF P) "new" (new WIDTH RATE OUT F PF P). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_symmetric_sponge_MultiField32PaddingFreeSponge_WIDTH_RATE_OUT_F_PF_P. + + Module Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_core_default_Default_PF_where_core_marker_Copy_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_F_array_OUT_PF_for_p3_symmetric_sponge_MultiField32PaddingFreeSponge_WIDTH_RATE_OUT_F_PF_P. + Definition Self (WIDTH RATE OUT : Value.t) (F PF P : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_symmetric::sponge::MultiField32PaddingFreeSponge") + [ WIDTH; RATE; OUT ] + [ F; PF; P ]. + + (* + fn hash_iter(&self, input: I) -> [PF; OUT] + where + I: IntoIterator, + { + let mut state = [PF::default(); WIDTH]; + for block_chunk in &input.into_iter().chunks(RATE) { + for (chunk_id, chunk) in (&block_chunk.chunks(self.num_f_elms)) + .into_iter() + .enumerate() + { + state[chunk_id] = reduce_32(&chunk.collect_vec()); + } + state = self.permutation.permute(state); + } + + state[..OUT].try_into().unwrap() + } + *) + Definition hash_iter + (WIDTH RATE OUT : Value.t) + (F PF P : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self WIDTH RATE OUT F PF P in + match ε, τ, α with + | [], [ _ as I ], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ state : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ WIDTH ] [ PF ] ] := + M.alloc (| + repeat (| + M.call_closure (| + PF, + M.get_trait_method (| + "core::default::Default", + PF, + [], + [], + "default", + [], + [] + |), + [] + |), + WIDTH + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "itertools::groupbylazy::IntoChunks") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "itertools::groupbylazy::IntoChunks") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + [], + [], + "chunks", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |); + RATE + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let block_chunk := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "itertools::groupbylazy::Chunks") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::IntoChunks") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "itertools::groupbylazy::IntoChunks") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ], + [], + [], + "chunks", + [], + [] + |), + [ + M.read (| block_chunk |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_symmetric::sponge::MultiField32PaddingFreeSponge", + "num_f_elms" + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunks") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ0_0, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ0_0, + 1 + |) in + let chunk_id := M.copy (| γ1_0 |) in + let chunk := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + state, + M.read (| chunk_id |) + |), + M.call_closure (| + PF, + M.get_function (| + "p3_field::helpers::reduce_32", + [], + [ F; PF ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + F; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.apply + (Ty.path + "itertools::groupbylazy::Chunk") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.read (| + chunk + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + state, + M.call_closure (| + Ty.apply (Ty.path "array") [ WIDTH ] [ PF ], + M.get_trait_method (| + "p3_symmetric::permutation::Permutation", + P, + [], + [ Ty.apply (Ty.path "array") [ WIDTH ] [ PF ] ], + "permute", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_symmetric::sponge::MultiField32PaddingFreeSponge", + "permutation" + |) + |); + M.read (| state |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "array") [ OUT ] [ PF ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ OUT ] [ PF ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ OUT ] [ PF ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ PF ] ], + [], + [ Ty.apply (Ty.path "array") [ OUT ] [ PF ] ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ PF ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ WIDTH ] [ PF ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, state |); + Value.StructRecord "core::ops::range::RangeTo" [ ("end_", OUT) ] + ] + |) + |) + |) + ] + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (WIDTH RATE OUT : Value.t) (F PF P : Ty.t), + M.IsTraitInstance + "p3_symmetric::hasher::CryptographicHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F; Ty.apply (Ty.path "array") [ OUT ] [ PF ] ] + (Self WIDTH RATE OUT F PF P) + (* Instance *) [ ("hash_iter", InstanceField.Method (hash_iter WIDTH RATE OUT F PF P)) ]. + End Impl_p3_symmetric_hasher_CryptographicHasher_where_p3_field_field_PrimeField32_F_where_p3_field_field_PrimeField_PF_where_core_default_Default_PF_where_core_marker_Copy_PF_where_p3_symmetric_permutation_CryptographicPermutation_P_array_WIDTH_PF_F_array_OUT_PF_for_p3_symmetric_sponge_MultiField32PaddingFreeSponge_WIDTH_RATE_OUT_F_PF_P. +End sponge. diff --git a/CoqOfRust/plonky3/uni-stark/src/check_constraints.rs b/CoqOfRust/plonky3/uni-stark/src/check_constraints.rs new file mode 100644 index 000000000..d24932d90 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/check_constraints.rs @@ -0,0 +1,110 @@ +use alloc::vec::Vec; + +use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues}; +use p3_field::Field; +use p3_matrix::Matrix; +use p3_matrix::dense::{RowMajorMatrix, RowMajorMatrixView}; +use p3_matrix::stack::VerticalPair; +use tracing::instrument; + +#[instrument(name = "check constraints", skip_all)] +pub(crate) fn check_constraints(air: &A, main: &RowMajorMatrix, public_values: &Vec) +where + F: Field, + A: for<'a> Air>, +{ + let height = main.height(); + + (0..height).for_each(|i| { + let i_next = (i + 1) % height; + + let local = main.row_slice(i); + let next = main.row_slice(i_next); + let main = VerticalPair::new( + RowMajorMatrixView::new_row(&*local), + RowMajorMatrixView::new_row(&*next), + ); + + let mut builder = DebugConstraintBuilder { + row_index: i, + main, + public_values, + is_first_row: F::from_bool(i == 0), + is_last_row: F::from_bool(i == height - 1), + is_transition: F::from_bool(i != height - 1), + }; + + air.eval(&mut builder); + }); +} + +/// An `AirBuilder` which asserts that each constraint is zero, allowing any failed constraints to +/// be detected early. +#[derive(Debug)] +pub struct DebugConstraintBuilder<'a, F: Field> { + row_index: usize, + main: VerticalPair, RowMajorMatrixView<'a, F>>, + public_values: &'a [F], + is_first_row: F, + is_last_row: F, + is_transition: F, +} + +impl<'a, F> AirBuilder for DebugConstraintBuilder<'a, F> +where + F: Field, +{ + type F = F; + type Expr = F; + type Var = F; + type M = VerticalPair, RowMajorMatrixView<'a, F>>; + + fn main(&self) -> Self::M { + self.main + } + + fn is_first_row(&self) -> Self::Expr { + self.is_first_row + } + + fn is_last_row(&self) -> Self::Expr { + self.is_last_row + } + + /// # Panics + /// This function panics if `size` is not `2`. + fn is_transition_window(&self, size: usize) -> Self::Expr { + if size == 2 { + self.is_transition + } else { + panic!("only supports a window size of 2") + } + } + + fn assert_zero>(&mut self, x: I) { + assert_eq!( + x.into(), + F::ZERO, + "constraints had nonzero value on row {}", + self.row_index + ); + } + + fn assert_eq, I2: Into>(&mut self, x: I1, y: I2) { + let x = x.into(); + let y = y.into(); + assert_eq!( + x, y, + "values didn't match on row {}: {} != {}", + self.row_index, x, y + ); + } +} + +impl AirBuilderWithPublicValues for DebugConstraintBuilder<'_, F> { + type PublicVar = Self::F; + + fn public_values(&self) -> &[Self::F] { + self.public_values + } +} diff --git a/CoqOfRust/plonky3/uni-stark/src/check_constraints.v b/CoqOfRust/plonky3/uni-stark/src/check_constraints.v new file mode 100644 index 000000000..3dc4e5554 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/check_constraints.v @@ -0,0 +1,2149 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module check_constraints. + (* #[instrument(name = "check constraints", skip_all)] *) + Definition check_constraints (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; A ], [ air; main; public_values ] => + ltac:(M.monadic + (let air := M.alloc (| air |) in + let main := M.alloc (| main |) in + let public_values := M.alloc (| public_values |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::check_constraints::check_constraints::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::check_constraints::check_constraints::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::check_constraints::check_constraints::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::check_constraints::check_constraints::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ height : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| main |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "for_each", + [], + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.tuple []) ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| height |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.function [ Ty.tuple [ Ty.path "usize" ] ] (Ty.tuple []) ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + let~ i_next : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 1 + ] + |); + M.read (| height |) + ] + |) + |) in + let~ local : + Ty.apply (Ty.path "*") [] [ Ty.associated_unknown ] := + M.alloc (| + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "row_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| main |) |) + |); + M.read (| i |) + ] + |) + |) in + let~ next : + Ty.apply (Ty.path "*") [] [ Ty.associated_unknown ] := + M.alloc (| + M.call_closure (| + Ty.associated_unknown, + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ] + ], + [], + [ F ], + "row_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| main |) |) + |); + M.read (| i_next |) + ] + |) + |) in + let~ main : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] + ], + "new", + [], + [ F ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + "new_row", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.associated_unknown, + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + local + |) + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + F; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ], + "new_row", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ F ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.associated_unknown, + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + next + |) + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) in + let~ builder : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::check_constraints::DebugConstraintBuilder") + [] + [ F ] + ] := + M.alloc (| + Value.StructRecord + "p3_uni_stark::check_constraints::DebugConstraintBuilder" + [ + ("row_index", M.read (| i |)); + ("main", M.read (| main |)); + ("public_values", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ F; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| public_values |) + |) + |) + ] + |) + |) + |)); + ("is_first_row", + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_bool", + [], + [] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| i |); + Value.Integer IntegerKind.Usize 0 + ] + |) + ] + |)); + ("is_last_row", + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_bool", + [], + [] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| i |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| height |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |)); + ("is_transition", + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_bool", + [], + [] + |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.read (| i |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.read (| height |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::Air", + A, + [], + [ + Ty.apply + (Ty.path + "p3_uni_stark::check_constraints::DebugConstraintBuilder") + [] + [ F ] + ], + "eval", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| air |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, builder |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_check_constraints : + M.IsFunction.C "p3_uni_stark::check_constraints::check_constraints" check_constraints. + Admitted. + Global Typeclasses Opaque check_constraints. + + (* StructRecord + { + name := "DebugConstraintBuilder"; + const_params := []; + ty_params := [ "F" ]; + fields := + [ + ("row_index", Ty.path "usize"); + ("main", + Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + ]); + ("public_values", Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ]); + ("is_first_row", F); + ("is_last_row", F); + ("is_transition", F) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_for_p3_uni_stark_check_constraints_DebugConstraintBuilder_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::check_constraints::DebugConstraintBuilder") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + let~ names : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 6 ] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "row_index" |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "main" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "public_values" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "is_first_row" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "is_last_row" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "is_transition" |) |) + |) + ] + |) + |) + |) + |) + |) in + let~ values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.dyn [ ("core::fmt::Debug::Trait", []) ] ] + ] + ] + ] := + M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "row_index" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "main" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "public_values" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "is_first_row" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "is_last_row" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "is_transition" + |) + |) + |) + |) + |) + |)) + ] + |) + |) + |) + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_fields_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "DebugConstraintBuilder" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| names |) |) |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| values |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_for_p3_uni_stark_check_constraints_DebugConstraintBuilder_F. + + Module Impl_p3_air_air_AirBuilder_where_p3_field_field_Field_F_for_p3_uni_stark_check_constraints_DebugConstraintBuilder_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::check_constraints::DebugConstraintBuilder") [] [ F ]. + + (* type F = F; *) + Definition _F (F : Ty.t) : Ty.t := F. + + (* type Expr = F; *) + Definition _Expr (F : Ty.t) : Ty.t := F. + + (* type Var = F; *) + Definition _Var (F : Ty.t) : Ty.t := F. + + (* type M = VerticalPair, RowMajorMatrixView<'a, F>>; *) + Definition _M_ (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ F; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ F ] ] ] + ]. + + (* + fn main(&self) -> Self::M { + self.main + } + *) + Definition main (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "main" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_first_row(&self) -> Self::Expr { + self.is_first_row + } + *) + Definition is_first_row (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "is_first_row" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_last_row(&self) -> Self::Expr { + self.is_last_row + } + *) + Definition is_last_row (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "is_last_row" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_transition_window(&self, size: usize) -> Self::Expr { + if size == 2 { + self.is_transition + } else { + panic!("only supports a window size of 2") + } + } + *) + Definition is_transition_window + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let size := M.alloc (| size |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ F ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| size |); Value.Integer IntegerKind.Usize 2 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "is_transition" + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "only supports a window size of 2" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn assert_zero>(&mut self, x: I) { + assert_eq!( + x.into(), + F::ZERO, + "constraints had nonzero value on row {}", + self.row_index + ); + } + *) + Definition assert_zero (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ _ as I ], [ self; x ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x := M.alloc (| x |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| + "core::convert::Into", + I, + [], + [ F ], + "into", + [], + [] + |), + [ M.read (| x |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 1; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "constraints had nonzero value on row " + |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "row_index" + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn assert_eq, I2: Into>(&mut self, x: I1, y: I2) { + let x = x.into(); + let y = y.into(); + assert_eq!( + x, y, + "values didn't match on row {}: {} != {}", + self.row_index, x, y + ); + } + *) + Definition assert_eq (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ I1; I2 ], [ self; x; y ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + M.read (| + let~ x : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::convert::Into", I1, [], [ F ], "into", [], [] |), + [ M.read (| x |) ] + |) + |) in + let~ y : Ty.apply (Ty.path "*") [] [ F ] := + M.alloc (| + M.call_closure (| + F, + M.get_trait_method (| "core::convert::Into", I2, [], [ F ], "into", [], [] |), + [ M.read (| y |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ M.borrow (| Pointer.Kind.Ref, x |); M.borrow (| Pointer.Kind.Ref, y |) ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + F, + [], + [ F ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ F; F ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 3 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "values didn't match on row " + |); + mk_str (| ": " |); + mk_str (| " != " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "row_index" + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + x + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + y + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_air::air::AirBuilder" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ + ("F", InstanceField.Ty (_F F)); + ("Expr", InstanceField.Ty (_Expr F)); + ("Var", InstanceField.Ty (_Var F)); + ("M_", InstanceField.Ty (_M_ F)); + ("main", InstanceField.Method (main F)); + ("is_first_row", InstanceField.Method (is_first_row F)); + ("is_last_row", InstanceField.Method (is_last_row F)); + ("is_transition_window", InstanceField.Method (is_transition_window F)); + ("assert_zero", InstanceField.Method (assert_zero F)); + ("assert_eq", InstanceField.Method (assert_eq F)) + ]. + End Impl_p3_air_air_AirBuilder_where_p3_field_field_Field_F_for_p3_uni_stark_check_constraints_DebugConstraintBuilder_F. + + Module Impl_p3_air_air_AirBuilderWithPublicValues_where_p3_field_field_Field_F_for_p3_uni_stark_check_constraints_DebugConstraintBuilder_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::check_constraints::DebugConstraintBuilder") [] [ F ]. + + (* type PublicVar = Self::F; *) + Definition _PublicVar (F : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + (Ty.apply (Ty.path "p3_uni_stark::check_constraints::DebugConstraintBuilder") [] [ F ]) + "F". + + (* + fn public_values(&self) -> &[Self::F] { + self.public_values + } + *) + Definition public_values (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::check_constraints::DebugConstraintBuilder", + "public_values" + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_air::air::AirBuilderWithPublicValues" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ + ("PublicVar", InstanceField.Ty (_PublicVar F)); + ("public_values", InstanceField.Method (public_values F)) + ]. + End Impl_p3_air_air_AirBuilderWithPublicValues_where_p3_field_field_Field_F_for_p3_uni_stark_check_constraints_DebugConstraintBuilder_F. +End check_constraints. diff --git a/CoqOfRust/plonky3/uni-stark/src/config.rs b/CoqOfRust/plonky3/uni-stark/src/config.rs new file mode 100644 index 000000000..0700b7d76 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/config.rs @@ -0,0 +1,82 @@ +use core::marker::PhantomData; + +use p3_challenger::{CanObserve, CanSample, FieldChallenger}; +use p3_commit::{Pcs, PolynomialSpace}; +use p3_field::{ExtensionField, Field}; + +pub type PcsError = <::Pcs as Pcs< + ::Challenge, + ::Challenger, +>>::Error; + +pub type Domain = <::Pcs as Pcs< + ::Challenge, + ::Challenger, +>>::Domain; + +pub type Val = as PolynomialSpace>::Val; + +pub type PackedVal = as Field>::Packing; + +pub type PackedChallenge = + <::Challenge as ExtensionField>>::ExtensionPacking; + +pub trait StarkGenericConfig { + /// The PCS used to commit to trace polynomials. + type Pcs: Pcs; + + /// The field from which most random challenges are drawn. + type Challenge: ExtensionField>; + + /// The challenger (Fiat-Shamir) implementation used. + type Challenger: FieldChallenger> + + CanObserve<>::Commitment> + + CanSample; + + /// Get a reference to the PCS used by this proof configuration. + fn pcs(&self) -> &Self::Pcs; + + /// Get an initialisation of the challenger used by this proof configuration. + fn initialise_challenger(&self) -> Self::Challenger; +} + +#[derive(Debug)] +pub struct StarkConfig { + /// The PCS used to commit polynomials and prove opening proofs. + pcs: Pcs, + /// An initialised instance of the challenger. + challenger: Challenger, + _phantom: PhantomData, +} + +impl StarkConfig { + pub const fn new(pcs: Pcs, challenger: Challenger) -> Self { + Self { + pcs, + challenger, + _phantom: PhantomData, + } + } +} + +impl StarkGenericConfig for StarkConfig +where + Challenge: ExtensionField<::Val>, + Pcs: p3_commit::Pcs, + Challenger: FieldChallenger<::Val> + + CanObserve<>::Commitment> + + CanSample + + Clone, +{ + type Pcs = Pcs; + type Challenge = Challenge; + type Challenger = Challenger; + + fn pcs(&self) -> &Self::Pcs { + &self.pcs + } + + fn initialise_challenger(&self) -> Self::Challenger { + self.challenger.clone() + } +} diff --git a/CoqOfRust/plonky3/uni-stark/src/config.v b/CoqOfRust/plonky3/uni-stark/src/config.v new file mode 100644 index 000000000..0e1963fb6 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/config.v @@ -0,0 +1,369 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module config. + Axiom PcsError : + forall (SC : Ty.t), + (Ty.apply (Ty.path "p3_uni_stark::config::PcsError") [] [ SC ]) = + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"; + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Error"). + + Axiom Domain : + forall (SC : Ty.t), + (Ty.apply (Ty.path "p3_uni_stark::config::Domain") [] [ SC ]) = + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"; + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain"). + + Axiom Val : + forall (SC : Ty.t), + (Ty.apply (Ty.path "p3_uni_stark::config::Val") [] [ SC ]) = + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"; + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val"). + + Axiom PackedVal : + forall (SC : Ty.t), + (Ty.apply (Ty.path "p3_uni_stark::config::PackedVal") [] [ SC ]) = + (Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val") + "Packing"). + + Axiom PackedChallenge : + forall (SC : Ty.t), + (Ty.apply (Ty.path "p3_uni_stark::config::PackedChallenge") [] [ SC ]) = + (Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge") + "ExtensionPacking"). + + (* Trait *) + (* Empty module 'StarkGenericConfig' *) + + (* StructRecord + { + name := "StarkConfig"; + const_params := []; + ty_params := [ "Pcs"; "Challenge"; "Challenger" ]; + fields := + [ + ("pcs", Pcs); + ("challenger", Challenger); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ Challenge ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Pcs_where_core_fmt_Debug_Challenge_where_core_fmt_Debug_Challenger_for_p3_uni_stark_config_StarkConfig_Pcs_Challenge_Challenger. + Definition Self (Pcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::config::StarkConfig") [] [ Pcs; Challenge; Challenger ]. + + (* Debug *) + Definition fmt + (Pcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Pcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "StarkConfig" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "pcs" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::config::StarkConfig", + "pcs" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "challenger" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::config::StarkConfig", + "challenger" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::config::StarkConfig", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Pcs Challenge Challenger : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Pcs Challenge Challenger) + (* Instance *) [ ("fmt", InstanceField.Method (fmt Pcs Challenge Challenger)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Pcs_where_core_fmt_Debug_Challenge_where_core_fmt_Debug_Challenger_for_p3_uni_stark_config_StarkConfig_Pcs_Challenge_Challenger. + + Module Impl_p3_uni_stark_config_StarkConfig_Pcs_Challenge_Challenger. + Definition Self (Pcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::config::StarkConfig") [] [ Pcs; Challenge; Challenger ]. + + (* + pub const fn new(pcs: Pcs, challenger: Challenger) -> Self { + Self { + pcs, + challenger, + _phantom: PhantomData, + } + } + *) + Definition new + (Pcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Pcs Challenge Challenger in + match ε, τ, α with + | [], [], [ pcs; challenger ] => + ltac:(M.monadic + (let pcs := M.alloc (| pcs |) in + let challenger := M.alloc (| challenger |) in + Value.StructRecord + "p3_uni_stark::config::StarkConfig" + [ + ("pcs", M.read (| pcs |)); + ("challenger", M.read (| challenger |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (Pcs Challenge Challenger : Ty.t), + M.IsAssociatedFunction.C (Self Pcs Challenge Challenger) "new" (new Pcs Challenge Challenger). + Admitted. + Global Typeclasses Opaque new. + End Impl_p3_uni_stark_config_StarkConfig_Pcs_Challenge_Challenger. + + Module Impl_p3_uni_stark_config_StarkGenericConfig_where_p3_field_field_ExtensionField_Challenge_associated_in_trait_p3_commit_domain_PolynomialSpace___associated_in_trait_p3_commit_pcs_Pcs__Challenge_Challenger_Pcs_Domain_Val_where_p3_commit_pcs_Pcs_Pcs_Challenge_Challenger_where_p3_challenger_FieldChallenger_Challenger_associated_in_trait_p3_commit_domain_PolynomialSpace___associated_in_trait_p3_commit_pcs_Pcs__Challenge_Challenger_Pcs_Domain_Val_where_p3_challenger_CanObserve_Challenger_associated_in_trait_p3_commit_pcs_Pcs__Challenge_Challenger_Pcs_Commitment_where_p3_challenger_CanSample_Challenger_Challenge_where_core_clone_Clone_Challenger_for_p3_uni_stark_config_StarkConfig_Pcs_Challenge_Challenger. + Definition Self (Pcs Challenge Challenger : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::config::StarkConfig") [] [ Pcs; Challenge; Challenger ]. + + (* type Pcs = Pcs; *) + Definition _Pcs (Pcs Challenge Challenger : Ty.t) : Ty.t := Pcs. + + (* type Challenge = Challenge; *) + Definition _Challenge (Pcs Challenge Challenger : Ty.t) : Ty.t := Challenge. + + (* type Challenger = Challenger; *) + Definition _Challenger (Pcs Challenge Challenger : Ty.t) : Ty.t := Challenger. + + (* + fn pcs(&self) -> &Self::Pcs { + &self.pcs + } + *) + Definition pcs + (Pcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Pcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::config::StarkConfig", + "pcs" + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn initialise_challenger(&self) -> Self::Challenger { + self.challenger.clone() + } + *) + Definition initialise_challenger + (Pcs Challenge Challenger : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Pcs Challenge Challenger in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Challenger, + M.get_trait_method (| "core::clone::Clone", Challenger, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::config::StarkConfig", + "challenger" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Pcs Challenge Challenger : Ty.t), + M.IsTraitInstance + "p3_uni_stark::config::StarkGenericConfig" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Pcs Challenge Challenger) + (* Instance *) + [ + ("Pcs", InstanceField.Ty (_Pcs Pcs Challenge Challenger)); + ("Challenge", InstanceField.Ty (_Challenge Pcs Challenge Challenger)); + ("Challenger", InstanceField.Ty (_Challenger Pcs Challenge Challenger)); + ("pcs", InstanceField.Method (pcs Pcs Challenge Challenger)); + ("initialise_challenger", + InstanceField.Method (initialise_challenger Pcs Challenge Challenger)) + ]. + End Impl_p3_uni_stark_config_StarkGenericConfig_where_p3_field_field_ExtensionField_Challenge_associated_in_trait_p3_commit_domain_PolynomialSpace___associated_in_trait_p3_commit_pcs_Pcs__Challenge_Challenger_Pcs_Domain_Val_where_p3_commit_pcs_Pcs_Pcs_Challenge_Challenger_where_p3_challenger_FieldChallenger_Challenger_associated_in_trait_p3_commit_domain_PolynomialSpace___associated_in_trait_p3_commit_pcs_Pcs__Challenge_Challenger_Pcs_Domain_Val_where_p3_challenger_CanObserve_Challenger_associated_in_trait_p3_commit_pcs_Pcs__Challenge_Challenger_Pcs_Commitment_where_p3_challenger_CanSample_Challenger_Challenge_where_core_clone_Clone_Challenger_for_p3_uni_stark_config_StarkConfig_Pcs_Challenge_Challenger. +End config. diff --git a/CoqOfRust/plonky3/uni-stark/src/folder.rs b/CoqOfRust/plonky3/uni-stark/src/folder.rs new file mode 100644 index 000000000..efa85df72 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/folder.rs @@ -0,0 +1,138 @@ +use alloc::vec::Vec; + +use p3_air::{AirBuilder, AirBuilderWithPublicValues}; +use p3_field::{BasedVectorSpace, PackedField}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; + +use crate::{PackedChallenge, PackedVal, StarkGenericConfig, Val}; + +#[derive(Debug)] +pub struct ProverConstraintFolder<'a, SC: StarkGenericConfig> { + pub main: RowMajorMatrixView<'a, PackedVal>, + pub public_values: &'a Vec>, + pub is_first_row: PackedVal, + pub is_last_row: PackedVal, + pub is_transition: PackedVal, + pub alpha_powers: &'a [SC::Challenge], + pub decomposed_alpha_powers: &'a [Vec>], + pub accumulator: PackedChallenge, + pub constraint_index: usize, +} + +type ViewPair<'a, T> = VerticalPair, RowMajorMatrixView<'a, T>>; + +#[derive(Debug)] +pub struct VerifierConstraintFolder<'a, SC: StarkGenericConfig> { + pub main: ViewPair<'a, SC::Challenge>, + pub public_values: &'a Vec>, + pub is_first_row: SC::Challenge, + pub is_last_row: SC::Challenge, + pub is_transition: SC::Challenge, + pub alpha: SC::Challenge, + pub accumulator: SC::Challenge, +} + +impl<'a, SC: StarkGenericConfig> AirBuilder for ProverConstraintFolder<'a, SC> { + type F = Val; + type Expr = PackedVal; + type Var = PackedVal; + type M = RowMajorMatrixView<'a, PackedVal>; + + #[inline] + fn main(&self) -> Self::M { + self.main + } + + #[inline] + fn is_first_row(&self) -> Self::Expr { + self.is_first_row + } + + #[inline] + fn is_last_row(&self) -> Self::Expr { + self.is_last_row + } + + /// # Panics + /// This function panics if `size` is not `2`. + #[inline] + fn is_transition_window(&self, size: usize) -> Self::Expr { + if size == 2 { + self.is_transition + } else { + panic!("uni-stark only supports a window size of 2") + } + } + + #[inline] + fn assert_zero>(&mut self, x: I) { + let x: PackedVal = x.into(); + let alpha_power = self.alpha_powers[self.constraint_index]; + self.accumulator += Into::>::into(alpha_power) * x; + self.constraint_index += 1; + } + + #[inline] + fn assert_zeros>(&mut self, array: [I; N]) { + let expr_array: [Self::Expr; N] = array.map(Into::into); + self.accumulator += PackedChallenge::::from_basis_coefficients_fn(|i| { + let alpha_powers = &self.decomposed_alpha_powers[i] + [self.constraint_index..(self.constraint_index + N)]; + PackedVal::::packed_linear_combination::(alpha_powers, &expr_array) + }); + self.constraint_index += N; + } +} + +impl AirBuilderWithPublicValues for ProverConstraintFolder<'_, SC> { + type PublicVar = Self::F; + + #[inline] + fn public_values(&self) -> &[Self::F] { + self.public_values + } +} + +impl<'a, SC: StarkGenericConfig> AirBuilder for VerifierConstraintFolder<'a, SC> { + type F = Val; + type Expr = SC::Challenge; + type Var = SC::Challenge; + type M = ViewPair<'a, SC::Challenge>; + + fn main(&self) -> Self::M { + self.main + } + + fn is_first_row(&self) -> Self::Expr { + self.is_first_row + } + + fn is_last_row(&self) -> Self::Expr { + self.is_last_row + } + + /// # Panics + /// This function panics if `size` is not `2`. + fn is_transition_window(&self, size: usize) -> Self::Expr { + if size == 2 { + self.is_transition + } else { + panic!("uni-stark only supports a window size of 2") + } + } + + fn assert_zero>(&mut self, x: I) { + let x: SC::Challenge = x.into(); + self.accumulator *= self.alpha; + self.accumulator += x; + } +} + +impl AirBuilderWithPublicValues for VerifierConstraintFolder<'_, SC> { + type PublicVar = Self::F; + + fn public_values(&self) -> &[Self::F] { + self.public_values + } +} diff --git a/CoqOfRust/plonky3/uni-stark/src/folder.v b/CoqOfRust/plonky3/uni-stark/src/folder.v new file mode 100644 index 000000000..2cdc466c0 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/folder.v @@ -0,0 +1,3489 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module folder. + (* StructRecord + { + name := "ProverConstraintFolder"; + const_params := []; + ty_params := [ "SC" ]; + fields := + [ + ("main", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] + ] + ]); + ("public_values", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ]); + ("is_first_row", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val") + "Packing"); + ("is_last_row", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val") + "Packing"); + ("is_transition", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val") + "Packing"); + ("alpha_powers", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ]); + ("decomposed_alpha_powers", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ] + ]); + ("accumulator", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking"); + ("constraint_index", Ty.path "usize") + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_SC_where_p3_uni_stark_config_StarkGenericConfig_SC_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_for_p3_uni_stark_folder_ProverConstraintFolder_SC. + Definition Self (SC : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::folder::ProverConstraintFolder") [] [ SC ]. + + (* Debug *) + Definition fmt (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + let~ names : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 9 ] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "main" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "public_values" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "is_first_row" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "is_last_row" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "is_transition" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "alpha_powers" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "decomposed_alpha_powers" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "accumulator" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "constraint_index" |) |) + |) + ] + |) + |) + |) + |) + |) in + let~ values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.dyn [ ("core::fmt::Debug::Trait", []) ] ] + ] + ] + ] := + M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "main" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "public_values" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "is_first_row" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "is_last_row" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "is_transition" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "alpha_powers" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "decomposed_alpha_powers" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "accumulator" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "constraint_index" + |) + |) + |) + |) + |) + |)) + ] + |) + |) + |) + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_fields_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "ProverConstraintFolder" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| names |) |) |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| values |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (SC : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self SC) + (* Instance *) [ ("fmt", InstanceField.Method (fmt SC)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_SC_where_p3_uni_stark_config_StarkGenericConfig_SC_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_for_p3_uni_stark_folder_ProverConstraintFolder_SC. + + Axiom ViewPair : + forall (T : Ty.t), + (Ty.apply (Ty.path "p3_uni_stark::folder::ViewPair") [] [ T ]) = + (Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ T; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ T; Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ] + ]). + + (* StructRecord + { + name := "VerifierConstraintFolder"; + const_params := []; + ty_params := [ "SC" ]; + fields := + [ + ("main", + Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + ]); + ("public_values", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ]); + ("is_first_row", + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"); + ("is_last_row", + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"); + ("is_transition", + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"); + ("alpha", + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"); + ("accumulator", + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge") + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_SC_where_p3_uni_stark_config_StarkGenericConfig_SC_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_for_p3_uni_stark_folder_VerifierConstraintFolder_SC. + Definition Self (SC : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::folder::VerifierConstraintFolder") [] [ SC ]. + + (* Debug *) + Definition fmt (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + let~ names : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 7 ] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "main" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "public_values" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "is_first_row" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "is_last_row" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "is_transition" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "alpha" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "accumulator" |) |) + |) + ] + |) + |) + |) + |) + |) in + let~ values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.dyn [ ("core::fmt::Debug::Trait", []) ] ] + ] + ] + ] := + M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "main" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "public_values" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "is_first_row" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "is_last_row" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "is_transition" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "alpha" + |) + |) + |) + |)); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "accumulator" + |) + |) + |) + |) + |) + |)) + ] + |) + |) + |) + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_fields_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "VerifierConstraintFolder" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| names |) |) |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| values |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (SC : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self SC) + (* Instance *) [ ("fmt", InstanceField.Method (fmt SC)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_SC_where_p3_uni_stark_config_StarkGenericConfig_SC_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_where_core_fmt_Debug_associated_in_trait_p3_uni_stark_config_StarkGenericConfig___SC_Challenge_for_p3_uni_stark_folder_VerifierConstraintFolder_SC. + + Module Impl_p3_air_air_AirBuilder_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_folder_ProverConstraintFolder_SC. + Definition Self (SC : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::folder::ProverConstraintFolder") [] [ SC ]. + + (* type F = Val; *) + Definition _F (SC : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"; + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val". + + (* type Expr = PackedVal; *) + Definition _Expr (SC : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val") + "Packing". + + (* type Var = PackedVal; *) + Definition _Var (SC : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val") + "Packing". + + (* type M = RowMajorMatrixView<'a, PackedVal>; *) + Definition _M_ (SC : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val") + "Packing"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] + ] + ]. + + (* + fn main(&self) -> Self::M { + self.main + } + *) + Definition main (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "main" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_first_row(&self) -> Self::Expr { + self.is_first_row + } + *) + Definition is_first_row (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "is_first_row" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_last_row(&self) -> Self::Expr { + self.is_last_row + } + *) + Definition is_last_row (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "is_last_row" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_transition_window(&self, size: usize) -> Self::Expr { + if size == 2 { + self.is_transition + } else { + panic!("uni-stark only supports a window size of 2") + } + } + *) + Definition is_transition_window + (SC : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self; size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let size := M.alloc (| size |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| size |); Value.Integer IntegerKind.Usize 2 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "is_transition" + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "uni-stark only supports a window size of 2" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn assert_zero>(&mut self, x: I) { + let x: PackedVal = x.into(); + let alpha_power = self.alpha_powers[self.constraint_index]; + self.accumulator += Into::>::into(alpha_power) * x; + self.constraint_index += 1; + } + *) + Definition assert_zero (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [ _ as I ], [ self; x ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x := M.alloc (| x |) in + M.read (| + let~ x : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing", + M.get_trait_method (| + "core::convert::Into", + I, + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + "into", + [], + [] + |), + [ M.read (| x |) ] + |) + |) in + let~ alpha_power : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] := + M.copy (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "alpha_powers" + |) + |) + |), + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "constraint_index" + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking", + [], + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking" + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "accumulator" + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking", + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking", + M.get_trait_method (| + "core::convert::Into", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking" + ], + "into", + [], + [] + |), + [ M.read (| alpha_power |) ] + |); + M.read (| x |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "constraint_index" + |) in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn assert_zeros>(&mut self, array: [I; N]) { + let expr_array: [Self::Expr; N] = array.map(Into::into); + self.accumulator += PackedChallenge::::from_basis_coefficients_fn(|i| { + let alpha_powers = &self.decomposed_alpha_powers[i] + [self.constraint_index..(self.constraint_index + N)]; + PackedVal::::packed_linear_combination::(alpha_powers, &expr_array) + }); + self.constraint_index += N; + } + *) + Definition assert_zeros (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [ N ], [ _ as I ], [ self; array ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let array := M.alloc (| array |) in + M.read (| + let~ expr_array : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ N ] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + M.get_associated_function (| + Ty.apply (Ty.path "array") [ N ] [ I ], + "map", + [], + [ + Ty.function + [ I ] + (Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"); + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] + |), + [ + M.read (| array |); + M.get_trait_method (| + "core::convert::Into", + I, + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + "into", + [], + [] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking", + [], + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking" + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "accumulator" + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking", + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking", + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + "from_basis_coefficients_fn", + [], + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.read (| + let~ alpha_powers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "decomposed_alpha_powers" + |) + |) + |), + M.read (| i |) + |) + |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "constraint_index" + |) + |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| self |) + |), + "p3_uni_stark::folder::ProverConstraintFolder", + "constraint_index" + |) + |); + N + ] + |)) + ] + ] + |) + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing", + M.get_trait_method (| + "p3_field::packed::PackedField", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing", + [], + [], + "packed_linear_combination", + [ N ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| alpha_powers |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, expr_array |) + |) + |)) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "constraint_index" + |) in + M.write (| + β, + M.call_closure (| Ty.path "usize", BinOp.Wrap.add, [ M.read (| β |); N ] |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (SC : Ty.t), + M.IsTraitInstance + "p3_air::air::AirBuilder" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self SC) + (* Instance *) + [ + ("F", InstanceField.Ty (_F SC)); + ("Expr", InstanceField.Ty (_Expr SC)); + ("Var", InstanceField.Ty (_Var SC)); + ("M_", InstanceField.Ty (_M_ SC)); + ("main", InstanceField.Method (main SC)); + ("is_first_row", InstanceField.Method (is_first_row SC)); + ("is_last_row", InstanceField.Method (is_last_row SC)); + ("is_transition_window", InstanceField.Method (is_transition_window SC)); + ("assert_zero", InstanceField.Method (assert_zero SC)); + ("assert_zeros", InstanceField.Method (assert_zeros SC)) + ]. + End Impl_p3_air_air_AirBuilder_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_folder_ProverConstraintFolder_SC. + + Module Impl_p3_air_air_AirBuilderWithPublicValues_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_folder_ProverConstraintFolder_SC. + Definition Self (SC : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::folder::ProverConstraintFolder") [] [ SC ]. + + (* type PublicVar = Self::F; *) + Definition _PublicVar (SC : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + (Ty.apply (Ty.path "p3_uni_stark::folder::ProverConstraintFolder") [] [ SC ]) + "F". + + (* + fn public_values(&self) -> &[Self::F] { + self.public_values + } + *) + Definition public_values + (SC : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::ProverConstraintFolder", + "public_values" + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (SC : Ty.t), + M.IsTraitInstance + "p3_air::air::AirBuilderWithPublicValues" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self SC) + (* Instance *) + [ + ("PublicVar", InstanceField.Ty (_PublicVar SC)); + ("public_values", InstanceField.Method (public_values SC)) + ]. + End Impl_p3_air_air_AirBuilderWithPublicValues_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_folder_ProverConstraintFolder_SC. + + Module Impl_p3_air_air_AirBuilder_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_folder_VerifierConstraintFolder_SC. + Definition Self (SC : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::folder::VerifierConstraintFolder") [] [ SC ]. + + (* type F = Val; *) + Definition _F (SC : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"; + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Domain") + "Val". + + (* type Expr = SC::Challenge; *) + Definition _Expr (SC : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge". + + (* type Var = SC::Challenge; *) + Definition _Var (SC : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge". + + (* type M = ViewPair<'a, SC::Challenge>; *) + Definition _M_ (SC : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + ]. + + (* + fn main(&self) -> Self::M { + self.main + } + *) + Definition main (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "main" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_first_row(&self) -> Self::Expr { + self.is_first_row + } + *) + Definition is_first_row (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "is_first_row" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_last_row(&self) -> Self::Expr { + self.is_last_row + } + *) + Definition is_last_row (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "is_last_row" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_transition_window(&self, size: usize) -> Self::Expr { + if size == 2 { + self.is_transition + } else { + panic!("uni-stark only supports a window size of 2") + } + } + *) + Definition is_transition_window + (SC : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self; size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let size := M.alloc (| size |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| size |); Value.Integer IntegerKind.Usize 2 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "is_transition" + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "uni-stark only supports a window size of 2" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn assert_zero>(&mut self, x: I) { + let x: SC::Challenge = x.into(); + self.accumulator *= self.alpha; + self.accumulator += x; + } + *) + Definition assert_zero (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [ _ as I ], [ self; x ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x := M.alloc (| x |) in + M.read (| + let~ x : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "core::convert::Into", + I, + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "into", + [], + [] + |), + [ M.read (| x |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "accumulator" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "alpha" + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::AddAssign", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "add_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "accumulator" + |) + |); + M.read (| x |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (SC : Ty.t), + M.IsTraitInstance + "p3_air::air::AirBuilder" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self SC) + (* Instance *) + [ + ("F", InstanceField.Ty (_F SC)); + ("Expr", InstanceField.Ty (_Expr SC)); + ("Var", InstanceField.Ty (_Var SC)); + ("M_", InstanceField.Ty (_M_ SC)); + ("main", InstanceField.Method (main SC)); + ("is_first_row", InstanceField.Method (is_first_row SC)); + ("is_last_row", InstanceField.Method (is_last_row SC)); + ("is_transition_window", InstanceField.Method (is_transition_window SC)); + ("assert_zero", InstanceField.Method (assert_zero SC)) + ]. + End Impl_p3_air_air_AirBuilder_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_folder_VerifierConstraintFolder_SC. + + Module Impl_p3_air_air_AirBuilderWithPublicValues_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_folder_VerifierConstraintFolder_SC. + Definition Self (SC : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::folder::VerifierConstraintFolder") [] [ SC ]. + + (* type PublicVar = Self::F; *) + Definition _PublicVar (SC : Ty.t) : Ty.t := + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + (Ty.apply (Ty.path "p3_uni_stark::folder::VerifierConstraintFolder") [] [ SC ]) + "F". + + (* + fn public_values(&self) -> &[Self::F] { + self.public_values + } + *) + Definition public_values + (SC : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::folder::VerifierConstraintFolder", + "public_values" + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (SC : Ty.t), + M.IsTraitInstance + "p3_air::air::AirBuilderWithPublicValues" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self SC) + (* Instance *) + [ + ("PublicVar", InstanceField.Ty (_PublicVar SC)); + ("public_values", InstanceField.Method (public_values SC)) + ]. + End Impl_p3_air_air_AirBuilderWithPublicValues_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_folder_VerifierConstraintFolder_SC. +End folder. diff --git a/CoqOfRust/plonky3/uni-stark/src/lib.rs b/CoqOfRust/plonky3/uni-stark/src/lib.rs new file mode 100644 index 000000000..d462eaf0b --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/lib.rs @@ -0,0 +1,26 @@ +//! A minimal univariate STARK framework. + +#![no_std] + +extern crate alloc; + +mod config; +mod folder; +mod proof; +mod prover; +mod symbolic_builder; +mod symbolic_expression; +mod symbolic_variable; +mod verifier; + +mod check_constraints; + +pub use check_constraints::*; +pub use config::*; +pub use folder::*; +pub use proof::*; +pub use prover::*; +pub use symbolic_builder::*; +pub use symbolic_expression::*; +pub use symbolic_variable::*; +pub use verifier::*; diff --git a/CoqOfRust/plonky3/uni-stark/src/proof.rs b/CoqOfRust/plonky3/uni-stark/src/proof.rs new file mode 100644 index 000000000..ef969cf72 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/proof.rs @@ -0,0 +1,37 @@ +use alloc::vec::Vec; + +use p3_commit::Pcs; +use serde::{Deserialize, Serialize}; + +use crate::StarkGenericConfig; + +type Com = <::Pcs as Pcs< + ::Challenge, + ::Challenger, +>>::Commitment; +type PcsProof = <::Pcs as Pcs< + ::Challenge, + ::Challenger, +>>::Proof; + +#[derive(Serialize, Deserialize)] +#[serde(bound = "")] +pub struct Proof { + pub(crate) commitments: Commitments>, + pub(crate) opened_values: OpenedValues, + pub(crate) opening_proof: PcsProof, + pub(crate) degree_bits: usize, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Commitments { + pub(crate) trace: Com, + pub(crate) quotient_chunks: Com, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct OpenedValues { + pub(crate) trace_local: Vec, + pub(crate) trace_next: Vec, + pub(crate) quotient_chunks: Vec>, +} diff --git a/CoqOfRust/plonky3/uni-stark/src/proof.v b/CoqOfRust/plonky3/uni-stark/src/proof.v new file mode 100644 index 000000000..49c682f70 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/proof.v @@ -0,0 +1,2953 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module proof. + Axiom Com : + forall (SC : Ty.t), + (Ty.apply (Ty.path "p3_uni_stark::proof::Com") [] [ SC ]) = + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"; + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Commitment"). + + Axiom PcsProof : + forall (SC : Ty.t), + (Ty.apply (Ty.path "p3_uni_stark::proof::PcsProof") [] [ SC ]) = + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenge"; + Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Proof"). + + (* StructRecord + { + name := "Proof"; + const_params := []; + ty_params := [ "SC" ]; + fields := + [ + ("commitments", + Ty.apply + (Ty.path "p3_uni_stark::proof::Commitments") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Commitment" + ]); + ("opened_values", + Ty.apply + (Ty.path "p3_uni_stark::proof::OpenedValues") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ]); + ("opening_proof", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait "p3_uni_stark::config::StarkGenericConfig" [] [] SC "Pcs") + "Proof"); + ("degree_bits", Ty.path "usize") + ]; + } *) + + Module underscore. + Module Impl_serde_ser_Serialize_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_proof_Proof_SC. + Definition Self (SC : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::proof::Proof") [] [ SC ]. + + (* Serialize *) + Definition serialize (SC : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "Proof" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::proof::Commitments") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "commitments" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::Proof", + "commitments" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::proof::OpenedValues") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "opened_values" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::Proof", + "opened_values" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Proof" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "opening_proof" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::Proof", + "opening_proof" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "degree_bits" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::Proof", + "degree_bits" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (SC : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self SC) + (* Instance *) [ ("serialize", InstanceField.Method (serialize SC)) ]. + End Impl_serde_ser_Serialize_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_proof_Proof_SC. + Module Impl_serde_de_Deserialize_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_proof_Proof_SC. + Definition Self (SC : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::proof::Proof") [] [ SC ]. + + (* Deserialize *) + Definition deserialize + (SC : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self SC in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::proof::Proof") [] [ SC ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ Ty.apply (Ty.path "p3_uni_stark::proof::_'1::deserialize::__Visitor") [] [ SC ] ] + |), + [ + M.read (| __deserializer |); + mk_str (| "Proof" |); + M.read (| + get_constant (| + "p3_uni_stark::proof::_'1::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_uni_stark::proof::_'1::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (SC : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self SC) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize SC)) ]. + End Impl_serde_de_Deserialize_where_p3_uni_stark_config_StarkGenericConfig_SC_for_p3_uni_stark_proof_Proof_SC. + Module Impl_serde_ser_Serialize_where_serde_ser_Serialize_Com_for_p3_uni_stark_proof_Commitments_Com. + Definition Self (Com : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::proof::Commitments") [] [ Com ]. + + (* Serialize *) + Definition serialize (Com : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Com in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "Commitments" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Com ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "trace" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::Commitments", + "trace" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ Com ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "quotient_chunks" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::Commitments", + "quotient_chunks" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Com : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Com) + (* Instance *) [ ("serialize", InstanceField.Method (serialize Com)) ]. + End Impl_serde_ser_Serialize_where_serde_ser_Serialize_Com_for_p3_uni_stark_proof_Commitments_Com. + Module Impl_serde_de_Deserialize_where_serde_de_Deserialize_Com_for_p3_uni_stark_proof_Commitments_Com. + Definition Self (Com : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::proof::Commitments") [] [ Com ]. + + (* Deserialize *) + Definition deserialize + (Com : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Com in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::proof::Commitments") [] [ Com ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ Ty.apply (Ty.path "p3_uni_stark::proof::_'3::deserialize::__Visitor") [] [ Com ] ] + |), + [ + M.read (| __deserializer |); + mk_str (| "Commitments" |); + M.read (| + get_constant (| + "p3_uni_stark::proof::_'3::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_uni_stark::proof::_'3::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Com : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Com) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize Com)) ]. + End Impl_serde_de_Deserialize_where_serde_de_Deserialize_Com_for_p3_uni_stark_proof_Commitments_Com. + Module Impl_serde_ser_Serialize_where_serde_ser_Serialize_Challenge_for_p3_uni_stark_proof_OpenedValues_Challenge. + Definition Self (Challenge : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::proof::OpenedValues") [] [ Challenge ]. + + (* Serialize *) + Definition serialize + (Challenge : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Challenge in + match ε, τ, α with + | [], [ __S ], [ self; __serializer ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __serializer := M.alloc (| __serializer |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ __serde_state : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ]; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + __S, + [], + [], + "serialize_struct", + [], + [] + |), + [ + M.read (| __serializer |); + mk_str (| "OpenedValues" |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.cast (Ty.path "usize") (Value.Bool false); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "trace_local" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::OpenedValues", + "trace_local" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "trace_next" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::OpenedValues", + "trace_next" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "SerializeStruct", + [], + [], + "serialize_field", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, __serde_state |) |) + |); + mk_str (| "quotient_chunks" |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::OpenedValues", + "quotient_chunks" + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + __S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeStruct", + Ty.associated_in_trait "serde::ser::Serializer" [] [] __S "SerializeStruct", + [], + [], + "end", + [], + [] + |), + [ M.read (| __serde_state |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Challenge : Ty.t), + M.IsTraitInstance + "serde::ser::Serialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Challenge) + (* Instance *) [ ("serialize", InstanceField.Method (serialize Challenge)) ]. + End Impl_serde_ser_Serialize_where_serde_ser_Serialize_Challenge_for_p3_uni_stark_proof_OpenedValues_Challenge. + Module Impl_serde_de_Deserialize_where_serde_de_Deserialize_Challenge_for_p3_uni_stark_proof_OpenedValues_Challenge. + Definition Self (Challenge : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::proof::OpenedValues") [] [ Challenge ]. + + (* Deserialize *) + Definition deserialize + (Challenge : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self Challenge in + match ε, τ, α with + | [], [ __D ], [ __deserializer ] => + ltac:(M.monadic + (let __deserializer := M.alloc (| __deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::proof::OpenedValues") [] [ Challenge ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] __D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + __D, + [], + [], + "deserialize_struct", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::proof::_'5::deserialize::__Visitor") + [] + [ Challenge ] + ] + |), + [ + M.read (| __deserializer |); + mk_str (| "OpenedValues" |); + M.read (| + get_constant (| + "p3_uni_stark::proof::_'5::deserialize::FIELDS", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + ] + |) + |); + Value.StructRecord + "p3_uni_stark::proof::_'5::deserialize::__Visitor" + [ + ("marker", Value.StructTuple "core::marker::PhantomData" []); + ("lifetime", Value.StructTuple "core::marker::PhantomData" []) + ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Challenge : Ty.t), + M.IsTraitInstance + "serde::de::Deserialize" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Challenge) + (* Instance *) [ ("deserialize", InstanceField.Method (deserialize Challenge)) ]. + End Impl_serde_de_Deserialize_where_serde_de_Deserialize_Challenge_for_p3_uni_stark_proof_OpenedValues_Challenge. + End underscore. + + + (* StructRecord + { + name := "Commitments"; + const_params := []; + ty_params := [ "Com" ]; + fields := [ ("trace", Com); ("quotient_chunks", Com) ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Com_for_p3_uni_stark_proof_Commitments_Com. + Definition Self (Com : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::proof::Commitments") [] [ Com ]. + + (* Debug *) + Definition fmt (Com : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Com in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Commitments" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "trace" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::Commitments", + "trace" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "quotient_chunks" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::Commitments", + "quotient_chunks" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Com : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Com) + (* Instance *) [ ("fmt", InstanceField.Method (fmt Com)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Com_for_p3_uni_stark_proof_Commitments_Com. + + + + (* StructRecord + { + name := "OpenedValues"; + const_params := []; + ty_params := [ "Challenge" ]; + fields := + [ + ("trace_local", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Challenge; Ty.path "alloc::alloc::Global" ]); + ("trace_next", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Challenge; Ty.path "alloc::alloc::Global" ]); + ("quotient_chunks", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Challenge; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::alloc::Global" + ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_Challenge_for_p3_uni_stark_proof_OpenedValues_Challenge. + Definition Self (Challenge : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::proof::OpenedValues") [] [ Challenge ]. + + (* Debug *) + Definition fmt (Challenge : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self Challenge in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "OpenedValues" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "trace_local" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::OpenedValues", + "trace_local" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "trace_next" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::OpenedValues", + "trace_next" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "quotient_chunks" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::proof::OpenedValues", + "quotient_chunks" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (Challenge : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self Challenge) + (* Instance *) [ ("fmt", InstanceField.Method (fmt Challenge)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_Challenge_for_p3_uni_stark_proof_OpenedValues_Challenge. + + +End proof. diff --git a/CoqOfRust/plonky3/uni-stark/src/prover.rs b/CoqOfRust/plonky3/uni-stark/src/prover.rs new file mode 100644 index 000000000..74f047029 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/prover.rs @@ -0,0 +1,213 @@ +use alloc::vec; +use alloc::vec::Vec; + +use itertools::{Itertools, izip}; +use p3_air::Air; +use p3_challenger::{CanObserve, CanSample, FieldChallenger}; +use p3_commit::{Pcs, PolynomialSpace}; +use p3_field::{BasedVectorSpace, PackedValue, PrimeCharacteristicRing}; +use p3_matrix::Matrix; +use p3_matrix::dense::RowMajorMatrix; +use p3_maybe_rayon::prelude::*; +use p3_util::{log2_ceil_usize, log2_strict_usize}; +use tracing::{debug_span, info_span, instrument}; + +use crate::{ + Commitments, Domain, OpenedValues, PackedChallenge, PackedVal, Proof, ProverConstraintFolder, + StarkGenericConfig, SymbolicAirBuilder, SymbolicExpression, Val, get_symbolic_constraints, +}; + +#[instrument(skip_all)] +#[allow(clippy::multiple_bound_locations)] // cfg not supported in where clauses? +pub fn prove< + SC, + #[cfg(debug_assertions)] A: for<'a> Air>>, + #[cfg(not(debug_assertions))] A, +>( + config: &SC, + air: &A, + trace: RowMajorMatrix>, + public_values: &Vec>, +) -> Proof +where + SC: StarkGenericConfig, + A: Air>> + for<'a> Air>, +{ + #[cfg(debug_assertions)] + crate::check_constraints::check_constraints(air, &trace, public_values); + + let degree = trace.height(); + let log_degree = log2_strict_usize(degree); + + let symbolic_constraints = get_symbolic_constraints::, A>(air, 0, public_values.len()); + let constraint_count = symbolic_constraints.len(); + let constraint_degree = symbolic_constraints + .iter() + .map(SymbolicExpression::degree_multiple) + .max() + .unwrap_or(0); + let log_quotient_degree = log2_ceil_usize(constraint_degree - 1); + let quotient_degree = 1 << log_quotient_degree; + + let mut challenger = config.initialise_challenger(); + let pcs = config.pcs(); + let trace_domain = pcs.natural_domain_for_degree(degree); + + let (trace_commit, trace_data) = + info_span!("commit to trace data").in_scope(|| pcs.commit(vec![(trace_domain, trace)])); + + // Observe the instance. + // degree < 2^255 so we can safely cast log_degree to a u8. + challenger.observe(Val::::from_u8(log_degree as u8)); + // TODO: Might be best practice to include other instance data here; see verifier comment. + + challenger.observe(trace_commit.clone()); + challenger.observe_slice(public_values); + let alpha: SC::Challenge = challenger.sample_algebra_element(); + + let quotient_domain = + trace_domain.create_disjoint_domain(1 << (log_degree + log_quotient_degree)); + + let trace_on_quotient_domain = pcs.get_evaluations_on_domain(&trace_data, 0, quotient_domain); + + let quotient_values = quotient_values( + air, + public_values, + trace_domain, + quotient_domain, + trace_on_quotient_domain, + alpha, + constraint_count, + ); + let quotient_flat = RowMajorMatrix::new_col(quotient_values).flatten_to_base(); + let quotient_chunks = quotient_domain.split_evals(quotient_degree, quotient_flat); + let qc_domains = quotient_domain.split_domains(quotient_degree); + + let (quotient_commit, quotient_data) = info_span!("commit to quotient poly chunks") + .in_scope(|| pcs.commit(izip!(qc_domains, quotient_chunks).collect_vec())); + challenger.observe(quotient_commit.clone()); + + let commitments = Commitments { + trace: trace_commit, + quotient_chunks: quotient_commit, + }; + + let zeta: SC::Challenge = challenger.sample(); + let zeta_next = trace_domain.next_point(zeta).unwrap(); + + let (opened_values, opening_proof) = info_span!("open").in_scope(|| { + pcs.open( + vec![ + (&trace_data, vec![vec![zeta, zeta_next]]), + ( + "ient_data, + // open every chunk at zeta + (0..quotient_degree).map(|_| vec![zeta]).collect_vec(), + ), + ], + &mut challenger, + ) + }); + let trace_local = opened_values[0][0][0].clone(); + let trace_next = opened_values[0][0][1].clone(); + let quotient_chunks = opened_values[1].iter().map(|v| v[0].clone()).collect_vec(); + let opened_values = OpenedValues { + trace_local, + trace_next, + quotient_chunks, + }; + Proof { + commitments, + opened_values, + opening_proof, + degree_bits: log_degree, + } +} + +#[instrument(name = "compute quotient polynomial", skip_all)] +fn quotient_values( + air: &A, + public_values: &Vec>, + trace_domain: Domain, + quotient_domain: Domain, + trace_on_quotient_domain: Mat, + alpha: SC::Challenge, + constraint_count: usize, +) -> Vec +where + SC: StarkGenericConfig, + A: for<'a> Air>, + Mat: Matrix> + Sync, +{ + let quotient_size = quotient_domain.size(); + let width = trace_on_quotient_domain.width(); + let mut sels = debug_span!("Compute Selectors") + .in_scope(|| trace_domain.selectors_on_coset(quotient_domain)); + + let qdb = log2_strict_usize(quotient_domain.size()) - log2_strict_usize(trace_domain.size()); + let next_step = 1 << qdb; + + // We take PackedVal::::WIDTH worth of values at a time from a quotient_size slice, so we need to + // pad with default values in the case where quotient_size is smaller than PackedVal::::WIDTH. + for _ in quotient_size..PackedVal::::WIDTH { + sels.is_first_row.push(Val::::default()); + sels.is_last_row.push(Val::::default()); + sels.is_transition.push(Val::::default()); + sels.inv_vanishing.push(Val::::default()); + } + + let mut alpha_powers = alpha.powers().take(constraint_count).collect_vec(); + alpha_powers.reverse(); + // alpha powers looks like Vec ~ Vec<[F; D]> + // It's useful to also have access to the the transpose of this of form [Vec; D]. + let decomposed_alpha_powers: Vec<_> = (0..SC::Challenge::DIMENSION) + .map(|i| { + alpha_powers + .iter() + .map(|x| x.as_basis_coefficients_slice()[i]) + .collect() + }) + .collect(); + + (0..quotient_size) + .into_par_iter() + .step_by(PackedVal::::WIDTH) + .flat_map_iter(|i_start| { + let i_range = i_start..i_start + PackedVal::::WIDTH; + + let is_first_row = *PackedVal::::from_slice(&sels.is_first_row[i_range.clone()]); + let is_last_row = *PackedVal::::from_slice(&sels.is_last_row[i_range.clone()]); + let is_transition = *PackedVal::::from_slice(&sels.is_transition[i_range.clone()]); + let inv_vanishing = *PackedVal::::from_slice(&sels.inv_vanishing[i_range]); + + let main = RowMajorMatrix::new( + trace_on_quotient_domain.vertically_packed_row_pair(i_start, next_step), + width, + ); + + let accumulator = PackedChallenge::::ZERO; + let mut folder = ProverConstraintFolder { + main: main.as_view(), + public_values, + is_first_row, + is_last_row, + is_transition, + alpha_powers: &alpha_powers, + decomposed_alpha_powers: &decomposed_alpha_powers, + accumulator, + constraint_index: 0, + }; + air.eval(&mut folder); + + // quotient(x) = constraints(x) / Z_H(x) + let quotient = folder.accumulator * inv_vanishing; + + // "Transpose" D packed base coefficients into WIDTH scalar extension coefficients. + (0..core::cmp::min(quotient_size, PackedVal::::WIDTH)).map(move |idx_in_packing| { + SC::Challenge::from_basis_coefficients_fn(|coeff_idx| { + quotient.as_basis_coefficients_slice()[coeff_idx].as_slice()[idx_in_packing] + }) + }) + }) + .collect() +} diff --git a/CoqOfRust/plonky3/uni-stark/src/prover.v b/CoqOfRust/plonky3/uni-stark/src/prover.v new file mode 100644 index 000000000..0fd254a6c --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/prover.v @@ -0,0 +1,15094 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module prover. + (* #[instrument(skip_all)] *) + Definition prove (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ SC; A ], [ config; air; trace; public_values ] => + ltac:(M.monadic + (let config := M.alloc (| config |) in + let air := M.alloc (| air |) in + let trace := M.alloc (| trace |) in + let public_values := M.alloc (| public_values |) in + M.catch_return (Ty.apply (Ty.path "p3_uni_stark::proof::Proof") [] [ SC ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_uni_stark::proof::Proof") [] [ SC ] ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_uni_stark::check_constraints::check_constraints", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + A + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| air |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trace |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| public_values |) |) |) + ] + |) + |) in + let~ degree : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "height", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, trace |) ] + |) + |) in + let~ log_degree : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| degree |) ] + |) + |) in + let~ symbolic_constraints : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_uni_stark::symbolic_builder::get_symbolic_constraints", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + A + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| air |) |) |); + Value.Integer IntegerKind.Usize 0; + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| public_values |) |) |) + ] + |) + ] + |) + |) in + let~ constraint_count : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, symbolic_constraints |) ] + |) + |) in + let~ constraint_degree : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ]; + Ty.function + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ] + ] + (Ty.path "usize") + ], + [], + [], + "max", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ]; + Ty.function + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ] + ] + (Ty.path "usize") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + [], + [], + "map", + [], + [ + Ty.path "usize"; + Ty.function + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ] + ] + (Ty.path "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, symbolic_constraints |) ] + |) + |) + |) + ] + |); + M.get_associated_function (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "degree_multiple", + [], + [] + |) + ] + |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) in + let~ log_quotient_degree : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_ceil_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| constraint_degree |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + |) in + let~ quotient_degree : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_quotient_degree |) ] + |) + |) in + let~ challenger : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + M.get_trait_method (| + "p3_uni_stark::config::StarkGenericConfig", + SC, + [], + [], + "initialise_challenger", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| config |) |) |) ] + |) + |) in + let~ pcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs" + ], + M.get_trait_method (| + "p3_uni_stark::config::StarkGenericConfig", + SC, + [], + [], + "pcs", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| config |) |) |) ] + |) + |) in + let~ trace_domain : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ], + "natural_domain_for_degree", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| pcs |) |) |); + M.read (| degree |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_uni_stark::proof::Proof") [] [ SC ] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ]); + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ], + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ], + "commit", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| pcs |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.read (| trace_domain |); + M.read (| trace |) + ] + ] + |) + ] + |) + |)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let trace_commit := M.copy (| γ0_0 |) in + let trace_data := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "observe", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, challenger |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + [], + [], + "from_u8", + [], + [] + |), + [ M.cast (Ty.path "u8") (M.read (| log_degree |)) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment" + ], + "observe", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, challenger |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, trace_commit |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "observe_slice", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, challenger |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| public_values |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ alpha : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "sample_algebra_element", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, challenger |) ] + |) + |) in + let~ quotient_domain : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "create_disjoint_domain", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, trace_domain |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| log_degree |); M.read (| log_quotient_degree |) ] + |) + ] + |) + ] + |) + |) in + let~ trace_on_quotient_domain : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "EvaluationsOnDomain" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "EvaluationsOnDomain", + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ], + "get_evaluations_on_domain", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| pcs |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, trace_data |) |) + |); + Value.Integer IntegerKind.Usize 0; + M.read (| quotient_domain |) + ] + |) + |) in + let~ quotient_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_uni_stark::prover::quotient_values", + [], + [ + SC; + A; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "EvaluationsOnDomain" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| air |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| public_values |) |) + |); + M.read (| trace_domain |); + M.read (| quotient_domain |); + M.read (| trace_on_quotient_domain |); + M.read (| alpha |); + M.read (| constraint_count |) + ] + |) + |) in + let~ quotient_flat : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + "flatten_to_base", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + "new_col", + [], + [] + |), + [ M.read (| quotient_values |) ] + |) + |) + |) + ] + |) + |) in + let~ quotient_chunks : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "split_evals", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, quotient_domain |); + M.read (| quotient_degree |); + M.read (| quotient_flat |) + ] + |) + |) in + let~ qc_domains : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "split_domains", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, quotient_domain |); + M.read (| quotient_degree |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_uni_stark::proof::Proof") [] [ SC ] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ]); + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'2", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ], + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ], + "commit", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| pcs |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path "alloc::alloc::Global" + ]; + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "zip", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::into_iter::IntoIter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| qc_domains |) ] + |); + M.read (| quotient_chunks |) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let quotient_commit := M.copy (| γ0_0 |) in + let quotient_data := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment" + ], + "observe", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, challenger |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, quotient_commit |) ] + |) + ] + |) + |) in + let~ commitments : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::proof::Commitments") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment" + ] + ] := + M.alloc (| + Value.StructRecord + "p3_uni_stark::proof::Commitments" + [ + ("trace", M.read (| trace_commit |)); + ("quotient_chunks", M.read (| quotient_commit |)) + ] + |) in + let~ zeta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "p3_challenger::CanSample", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "sample", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, challenger |) ] + |) + |) in + let~ zeta_next : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "next_point", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, trace_domain |); + M.read (| zeta |) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_uni_stark::proof::Proof") [] [ SC ] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Proof" + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Proof" + ]); + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Proof" + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path + "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path + "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 0 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| meta |) + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::prove::__CALLSITE'3", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Proof" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Proof" + ], + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ], + "open", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| pcs |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "ProverData" + ]; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + trace_data + |) + |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ], + "into_vec", + [], + [ + Ty.path + "alloc::alloc::Global" + ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "into_vec", + [], + [ + Ty.path + "alloc::alloc::Global" + ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ]; + Ty.path + "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + M.read (| + zeta + |); + M.read (| + zeta_next + |) + ] + |) + ] + |) + |)) + ] + |) + ] + |) + ] + |) + |)) + ] + |) + ]; + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + quotient_data + |) + |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ + Ty.path + "usize" + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + Value.Integer + IntegerKind.Usize + 0); + ("end_", + M.read (| + quotient_degree + |)) + ]; + M.closure + (fun + γ => + ltac:(M.monadic + match + γ + with + | [ + α0 + ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path + "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| + α0 + |), + [ + fun + γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "into_vec", + [], + [ + Ty.path + "alloc::alloc::Global" + ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ]; + Ty.path + "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + M.read (| + zeta + |) + ] + |) + ] + |) + |)) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + ] + |) + ] + |) + |)) + ] + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + challenger + |) + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let opened_values := M.copy (| γ0_0 |) in + let opening_proof := M.copy (| γ0_1 |) in + let~ trace_local : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + opened_values + |); + Value.Integer + IntegerKind.Usize + 0 + ] + |) + |) + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |) + ] + |) + |) in + let~ trace_next : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + opened_values + |); + Value.Integer + IntegerKind.Usize + 0 + ] + |) + |) + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |); + Value.Integer IntegerKind.Usize 1 + ] + |) + |) + |) + ] + |) + |) in + let~ quotient_chunks : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + opened_values + |); + Value.Integer + IntegerKind.Usize + 1 + ] + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let v := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| v |) + |) + |); + Value.Integer + IntegerKind.Usize + 0 + ] + |) + |) + |) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ opened_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::proof::OpenedValues") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] := + M.alloc (| + Value.StructRecord + "p3_uni_stark::proof::OpenedValues" + [ + ("trace_local", M.read (| trace_local |)); + ("trace_next", M.read (| trace_next |)); + ("quotient_chunks", M.read (| quotient_chunks |)) + ] + |) in + M.alloc (| + Value.StructRecord + "p3_uni_stark::proof::Proof" + [ + ("commitments", M.read (| commitments |)); + ("opened_values", M.read (| opened_values |)); + ("opening_proof", M.read (| opening_proof |)); + ("degree_bits", M.read (| log_degree |)) + ] + |))) + ] + |))) + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_prove : M.IsFunction.C "p3_uni_stark::prover::prove" prove. + Admitted. + Global Typeclasses Opaque prove. + + (* #[instrument(name = "compute quotient polynomial", skip_all)] *) + Definition quotient_values (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], + [ SC; A; Mat ], + [ + air; + public_values; + trace_domain; + quotient_domain; + trace_on_quotient_domain; + alpha; + constraint_count + ] => + ltac:(M.monadic + (let air := M.alloc (| air |) in + let public_values := M.alloc (| public_values |) in + let trace_domain := M.alloc (| trace_domain |) in + let quotient_domain := M.alloc (| quotient_domain |) in + let trace_on_quotient_domain := M.alloc (| trace_on_quotient_domain |) in + let alpha := M.alloc (| alpha |) in + let constraint_count := M.alloc (| constraint_count |) in + M.catch_return + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::quotient_values::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::quotient_values::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::quotient_values::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::quotient_values::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ quotient_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, quotient_domain |) ] + |) + |) in + let~ width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_matrix::Matrix", + Mat, + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, trace_on_quotient_domain |) ] + |) + |) in + let~ sels : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.path "tracing::span::Span", + "in_scope", + [], + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ]); + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::quotient_values::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, interest |) ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::quotient_values::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::quotient_values::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::prover::quotient_values::__CALLSITE'1", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [] ] + (Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "selectors_on_coset", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, trace_domain |); + M.read (| quotient_domain |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + let~ qdb : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, quotient_domain |) ] + |) + ] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "size", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, trace_domain |) ] + |) + ] + |) + ] + |) + |) in + let~ next_step : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| qdb |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| quotient_size |)); + ("end_", + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "is_first_row" + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + M.get_trait_method (| + "core::default::Default", + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + [], + [], + "default", + [], + [] + |), + [] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "is_last_row" + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + M.get_trait_method (| + "core::default::Default", + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + [], + [], + "default", + [], + [] + |), + [] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "is_transition" + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + M.get_trait_method (| + "core::default::Default", + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + [], + [], + "default", + [], + [] + |), + [] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "inv_vanishing" + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + M.get_trait_method (| + "core::default::Default", + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + [], + [], + "default", + [], + [] + |), + [] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ alpha_powers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::take::Take") + [] + [ + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + [], + [], + "take", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_field::field::Powers") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [], + "powers", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, alpha |) ] + |); + M.read (| constraint_count |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "reverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, alpha_powers |) ] + |) + |) + |) + ] + |) + |) in + let~ decomposed_alpha_powers : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + [], + [], + "map", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + alpha_powers + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "as_basis_coefficients_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| x |) + |) + |) + ] + |) + |), + M.read (| i |) + |) + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ]) + ], + M.get_trait_method (| + "p3_maybe_rayon::serial::ParIterExt", + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + [], + [], + "flat_map_iter", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::step_by::StepBy") + [] + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "step_by", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "p3_maybe_rayon::serial::IntoParallelIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_par_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| quotient_size |)) + ] + ] + |); + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let i_start := M.copy (| γ |) in + M.read (| + let~ i_range : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ] := + M.alloc (| + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| i_start |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i_start |); + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |)) + ] + |) in + let~ is_first_row : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing", + [], + [], + "from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "is_first_row" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + i_range + |) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) in + let~ is_last_row : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing", + [], + [], + "from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "is_last_row" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + i_range + |) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) in + let~ is_transition : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing", + [], + [], + "from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "is_transition" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + i_range + |) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) in + let~ inv_vanishing : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] := + M.copy (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing", + [], + [], + "from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "inv_vanishing" + |) + |); + M.read (| i_range |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) in + let~ main : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.path "alloc::alloc::Global" + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_matrix::Matrix", + Mat, + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "vertically_packed_row_pair", + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + trace_on_quotient_domain + |); + M.read (| i_start |); + M.read (| next_step |) + ] + |); + M.read (| width |) + ] + |) + |) in + let~ accumulator : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking" + ] := + M.copy (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking" + |) + |) in + let~ folder : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::folder::ProverConstraintFolder") + [] + [ SC ] + ] := + M.alloc (| + Value.StructRecord + "p3_uni_stark::folder::ProverConstraintFolder" + [ + ("main", + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing"; + Ty.path "alloc::alloc::Global" + ] + ], + "as_view", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, main |) ] + |)); + ("public_values", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| public_values |) |) + |)); + ("is_first_row", M.read (| is_first_row |)); + ("is_last_row", M.read (| is_last_row |)); + ("is_transition", M.read (| is_transition |)); + ("alpha_powers", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + alpha_powers + |) + |) + |) + ] + |) + |) + |)); + ("decomposed_alpha_powers", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + decomposed_alpha_powers + |) + |) + |) + ] + |) + |) + |)); + ("accumulator", M.read (| accumulator |)); + ("constraint_index", + Value.Integer IntegerKind.Usize 0) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::Air", + A, + [], + [ + Ty.apply + (Ty.path + "p3_uni_stark::folder::ProverConstraintFolder") + [] + [ SC ] + ], + "eval", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| air |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, folder |) + |) + |) + ] + |) + |) in + let~ quotient : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking", + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + "mul", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + folder, + "p3_uni_stark::folder::ProverConstraintFolder", + "accumulator" + |) + |); + M.read (| inv_vanishing |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::cmp::min", + [], + [ Ty.path "usize" ] + |), + [ + M.read (| quotient_size |); + M.read (| + get_constant (| + "p3_field::packed::PackedValue::WIDTH", + Ty.path "usize" + |) + |) + ] + |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let idx_in_packing := + M.copy (| γ |) in + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "from_basis_coefficients_fn", + [], + [ + Ty.function + [ + Ty.tuple + [ Ty.path "usize" ] + ] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + ] + |), + [ + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.path + "usize" + ] + ] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + ], + M.alloc (| + α0 + |), + [ + fun γ => + ltac:(M.monadic + (let + coeff_idx := + M.copy (| + γ + |) in + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "p3_field::packed::PackedValue", + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing", + [], + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ] + ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + Ty.associated_in_trait + "p3_field::field::ExtensionField" + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + "ExtensionPacking", + [], + [ + Ty.associated_in_trait + "p3_field::field::Field" + [] + [] + (Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val") + "Packing" + ], + "as_basis_coefficients_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + quotient + |) + ] + |) + |), + M.read (| + coeff_idx + |) + |) + |) + ] + |) + |), + M.read (| + idx_in_packing + |) + |) + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => + M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_quotient_values : + M.IsFunction.C "p3_uni_stark::prover::quotient_values" quotient_values. + Admitted. + Global Typeclasses Opaque quotient_values. +End prover. diff --git a/CoqOfRust/plonky3/uni-stark/src/symbolic_builder.rs b/CoqOfRust/plonky3/uni-stark/src/symbolic_builder.rs new file mode 100644 index 000000000..cd6d9293c --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/symbolic_builder.rs @@ -0,0 +1,330 @@ +use alloc::vec; +use alloc::vec::Vec; + +use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, PairBuilder}; +use p3_field::Field; +use p3_matrix::dense::RowMajorMatrix; +use p3_util::log2_ceil_usize; +use tracing::instrument; + +use crate::Entry; +use crate::symbolic_expression::SymbolicExpression; +use crate::symbolic_variable::SymbolicVariable; + +#[instrument(name = "infer log of constraint degree", skip_all)] +pub fn get_log_quotient_degree( + air: &A, + preprocessed_width: usize, + num_public_values: usize, +) -> usize +where + F: Field, + A: Air>, +{ + // We pad to at least degree 2, since a quotient argument doesn't make sense with smaller degrees. + let constraint_degree = + get_max_constraint_degree(air, preprocessed_width, num_public_values).max(2); + + // The quotient's actual degree is approximately (max_constraint_degree - 1) n, + // where subtracting 1 comes from division by the vanishing polynomial. + // But we pad it to a power of two so that we can efficiently decompose the quotient. + log2_ceil_usize(constraint_degree - 1) +} + +#[instrument(name = "infer constraint degree", skip_all, level = "debug")] +pub fn get_max_constraint_degree( + air: &A, + preprocessed_width: usize, + num_public_values: usize, +) -> usize +where + F: Field, + A: Air>, +{ + get_symbolic_constraints(air, preprocessed_width, num_public_values) + .iter() + .map(|c| c.degree_multiple()) + .max() + .unwrap_or(0) +} + +#[instrument(name = "evaluate constraints symbolically", skip_all, level = "debug")] +pub fn get_symbolic_constraints( + air: &A, + preprocessed_width: usize, + num_public_values: usize, +) -> Vec> +where + F: Field, + A: Air>, +{ + let mut builder = SymbolicAirBuilder::new(preprocessed_width, air.width(), num_public_values); + air.eval(&mut builder); + builder.constraints() +} + +/// An `AirBuilder` for evaluating constraints symbolically, and recording them for later use. +#[derive(Debug)] +pub struct SymbolicAirBuilder { + preprocessed: RowMajorMatrix>, + main: RowMajorMatrix>, + public_values: Vec>, + constraints: Vec>, +} + +impl SymbolicAirBuilder { + pub(crate) fn new(preprocessed_width: usize, width: usize, num_public_values: usize) -> Self { + let prep_values = [0, 1] + .into_iter() + .flat_map(|offset| { + (0..preprocessed_width) + .map(move |index| SymbolicVariable::new(Entry::Preprocessed { offset }, index)) + }) + .collect(); + let main_values = [0, 1] + .into_iter() + .flat_map(|offset| { + (0..width).map(move |index| SymbolicVariable::new(Entry::Main { offset }, index)) + }) + .collect(); + let public_values = (0..num_public_values) + .map(move |index| SymbolicVariable::new(Entry::Public, index)) + .collect(); + Self { + preprocessed: RowMajorMatrix::new(prep_values, preprocessed_width), + main: RowMajorMatrix::new(main_values, width), + public_values, + constraints: vec![], + } + } + + pub(crate) fn constraints(self) -> Vec> { + self.constraints + } +} + +impl AirBuilder for SymbolicAirBuilder { + type F = F; + type Expr = SymbolicExpression; + type Var = SymbolicVariable; + type M = RowMajorMatrix; + + fn main(&self) -> Self::M { + self.main.clone() + } + + fn is_first_row(&self) -> Self::Expr { + SymbolicExpression::IsFirstRow + } + + fn is_last_row(&self) -> Self::Expr { + SymbolicExpression::IsLastRow + } + + /// # Panics + /// This function panics if `size` is not `2`. + fn is_transition_window(&self, size: usize) -> Self::Expr { + if size == 2 { + SymbolicExpression::IsTransition + } else { + panic!("uni-stark only supports a window size of 2") + } + } + + fn assert_zero>(&mut self, x: I) { + self.constraints.push(x.into()); + } +} + +impl AirBuilderWithPublicValues for SymbolicAirBuilder { + type PublicVar = SymbolicVariable; + fn public_values(&self) -> &[Self::PublicVar] { + &self.public_values + } +} + +impl PairBuilder for SymbolicAirBuilder { + fn preprocessed(&self) -> Self::M { + self.preprocessed.clone() + } +} + +#[cfg(test)] +mod tests { + use alloc::vec; + use alloc::vec::Vec; + + use p3_air::BaseAir; + use p3_baby_bear::BabyBear; + + use super::*; + + #[derive(Debug)] + struct MockAir { + constraints: Vec>, + width: usize, + } + + impl BaseAir for MockAir { + fn width(&self) -> usize { + self.width + } + } + + impl Air> for MockAir { + fn eval(&self, builder: &mut SymbolicAirBuilder) { + for constraint in &self.constraints { + builder.assert_zero(*constraint); + } + } + } + + #[test] + fn test_get_log_quotient_degree_no_constraints() { + let air = MockAir { + constraints: vec![], + width: 4, + }; + let log_degree = get_log_quotient_degree(&air, 3, 2); + assert_eq!(log_degree, 0); + } + + #[test] + fn test_get_log_quotient_degree_single_constraint() { + let air = MockAir { + constraints: vec![SymbolicVariable::new(Entry::Main { offset: 0 }, 0)], + width: 4, + }; + let log_degree = get_log_quotient_degree(&air, 3, 2); + assert_eq!(log_degree, log2_ceil_usize(1)); + } + + #[test] + fn test_get_log_quotient_degree_multiple_constraints() { + let air = MockAir { + constraints: vec![ + SymbolicVariable::new(Entry::Main { offset: 0 }, 0), + SymbolicVariable::new(Entry::Main { offset: 1 }, 1), + SymbolicVariable::new(Entry::Main { offset: 2 }, 2), + ], + width: 4, + }; + let log_degree = get_log_quotient_degree(&air, 3, 2); + assert_eq!(log_degree, log2_ceil_usize(1)); + } + + #[test] + fn test_get_max_constraint_degree_no_constraints() { + let air = MockAir { + constraints: vec![], + width: 4, + }; + let max_degree = get_max_constraint_degree(&air, 3, 2); + assert_eq!( + max_degree, 0, + "No constraints should result in a degree of 0" + ); + } + + #[test] + fn test_get_max_constraint_degree_multiple_constraints() { + let air = MockAir { + constraints: vec![ + SymbolicVariable::new(Entry::Main { offset: 0 }, 0), + SymbolicVariable::new(Entry::Main { offset: 1 }, 1), + SymbolicVariable::new(Entry::Main { offset: 2 }, 2), + ], + width: 4, + }; + let max_degree = get_max_constraint_degree(&air, 3, 2); + assert_eq!(max_degree, 1, "Max constraint degree should be 1"); + } + + #[test] + fn test_get_symbolic_constraints() { + let c1 = SymbolicVariable::new(Entry::Main { offset: 0 }, 0); + let c2 = SymbolicVariable::new(Entry::Main { offset: 1 }, 1); + + let air = MockAir { + constraints: vec![c1, c2], + width: 4, + }; + + let constraints = get_symbolic_constraints(&air, 3, 2); + + assert_eq!(constraints.len(), 2, "Should return exactly 2 constraints"); + + assert!( + constraints.iter().any(|x| matches!(x, SymbolicExpression::Variable(v) if v.index == c1.index && v.entry == c1.entry)), + "Expected constraint {:?} was not found", + c1 + ); + + assert!( + constraints.iter().any(|x| matches!(x, SymbolicExpression::Variable(v) if v.index == c2.index && v.entry == c2.entry)), + "Expected constraint {:?} was not found", + c2 + ); + } + + #[test] + fn test_symbolic_air_builder_initialization() { + let builder = SymbolicAirBuilder::::new(2, 4, 3); + + let expected_main = [ + SymbolicVariable::::new(Entry::Main { offset: 0 }, 0), + SymbolicVariable::::new(Entry::Main { offset: 0 }, 1), + SymbolicVariable::::new(Entry::Main { offset: 0 }, 2), + SymbolicVariable::::new(Entry::Main { offset: 0 }, 3), + SymbolicVariable::::new(Entry::Main { offset: 1 }, 0), + SymbolicVariable::::new(Entry::Main { offset: 1 }, 1), + SymbolicVariable::::new(Entry::Main { offset: 1 }, 2), + SymbolicVariable::::new(Entry::Main { offset: 1 }, 3), + ]; + + let builder_main = builder.main.values; + + assert_eq!( + builder_main.len(), + expected_main.len(), + "Main matrix should have the expected length" + ); + + for (expected, actual) in expected_main.iter().zip(builder_main.iter()) { + assert_eq!(expected.index, actual.index, "Index mismatch"); + assert_eq!(expected.entry, actual.entry, "Entry mismatch"); + } + } + + #[test] + fn test_symbolic_air_builder_is_first_last_row() { + let builder = SymbolicAirBuilder::::new(2, 4, 3); + + assert!( + matches!(builder.is_first_row(), SymbolicExpression::IsFirstRow), + "First row condition did not match" + ); + + assert!( + matches!(builder.is_last_row(), SymbolicExpression::IsLastRow), + "Last row condition did not match" + ); + } + + #[test] + fn test_symbolic_air_builder_assert_zero() { + let mut builder = SymbolicAirBuilder::::new(2, 4, 3); + let expr = SymbolicExpression::Constant(BabyBear::new(5)); + builder.assert_zero(expr.clone()); + + let constraints = builder.constraints(); + assert_eq!(constraints.len(), 1, "One constraint should be recorded"); + + assert!( + constraints.iter().any( + |x| matches!(x, SymbolicExpression::Constant(val) if *val == BabyBear::new(5)) + ), + "Constraint should match the asserted one" + ); + } +} diff --git a/CoqOfRust/plonky3/uni-stark/src/symbolic_builder.v b/CoqOfRust/plonky3/uni-stark/src/symbolic_builder.v new file mode 100644 index 000000000..873f34ad7 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/symbolic_builder.v @@ -0,0 +1,3992 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module symbolic_builder. + (* #[instrument(name = "infer log of constraint degree", skip_all)] *) + Definition get_log_quotient_degree (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; A ], [ air; preprocessed_width; num_public_values ] => + ltac:(M.monadic + (let air := M.alloc (| air |) in + let preprocessed_width := M.alloc (| preprocessed_width |) in + let num_public_values := M.alloc (| num_public_values |) in + M.catch_return (Ty.path "usize") (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_log_quotient_degree::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_log_quotient_degree::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_log_quotient_degree::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_log_quotient_degree::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ constraint_degree : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "usize", + [], + [], + "max", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_uni_stark::symbolic_builder::get_max_constraint_degree", + [], + [ F; A ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| air |) |) |); + M.read (| preprocessed_width |); + M.read (| num_public_values |) + ] + |); + Value.Integer IntegerKind.Usize 2 + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_ceil_usize", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| constraint_degree |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_get_log_quotient_degree : + M.IsFunction.C + "p3_uni_stark::symbolic_builder::get_log_quotient_degree" + get_log_quotient_degree. + Admitted. + Global Typeclasses Opaque get_log_quotient_degree. + + (* #[instrument(name = "infer constraint degree", skip_all, level = "debug")] *) + Definition get_max_constraint_degree (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; A ], [ air; preprocessed_width; num_public_values ] => + ltac:(M.monadic + (let air := M.alloc (| air |) in + let preprocessed_width := M.alloc (| preprocessed_width |) in + let num_public_values := M.alloc (| num_public_values |) in + M.catch_return (Ty.path "usize") (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_max_constraint_degree::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_max_constraint_degree::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_max_constraint_degree::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_max_constraint_degree::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ] + ] + (Ty.path "usize") + ], + [], + [], + "max", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ] + ] + (Ty.path "usize") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + [], + [], + "map", + [], + [ + Ty.path "usize"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ] + ] + (Ty.path "usize") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_function (| + "p3_uni_stark::symbolic_builder::get_symbolic_constraints", + [], + [ F; A ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| air |) |) + |); + M.read (| preprocessed_width |); + M.read (| num_public_values |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ] + ] + (Ty.path "usize") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let c := M.copy (| γ |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + "degree_multiple", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| c |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_get_max_constraint_degree : + M.IsFunction.C + "p3_uni_stark::symbolic_builder::get_max_constraint_degree" + get_max_constraint_degree. + Admitted. + Global Typeclasses Opaque get_max_constraint_degree. + + (* #[instrument(name = "evaluate constraints symbolically", skip_all, level = "debug")] *) + Definition get_symbolic_constraints (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F; A ], [ air; preprocessed_width; num_public_values ] => + ltac:(M.monadic + (let air := M.alloc (| air |) in + let preprocessed_width := M.alloc (| preprocessed_width |) in + let num_public_values := M.alloc (| num_public_values |) in + M.catch_return + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]; + Ty.path "alloc::alloc::Global" + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "DEBUG", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "DEBUG", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_symbolic_constraints::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_symbolic_constraints::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_symbolic_constraints::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::symbolic_builder::get_symbolic_constraints::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ builder : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") + [] + [ F ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") + [] + [ F ], + "new", + [], + [] + |), + [ + M.read (| preprocessed_width |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_air::air::BaseAir", + A, + [], + [ F ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| air |) |) |) ] + |); + M.read (| num_public_values |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::Air", + A, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") + [] + [ F ] + ], + "eval", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| air |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, builder |) |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") + [] + [ F ], + "constraints", + [], + [] + |), + [ M.read (| builder |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_get_symbolic_constraints : + M.IsFunction.C + "p3_uni_stark::symbolic_builder::get_symbolic_constraints" + get_symbolic_constraints. + Admitted. + Global Typeclasses Opaque get_symbolic_constraints. + + (* StructRecord + { + name := "SymbolicAirBuilder"; + const_params := []; + ty_params := [ "F" ]; + fields := + [ + ("preprocessed", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ]); + ("main", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ]); + ("public_values", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.path "alloc::alloc::Global" + ]); + ("constraints", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]; + Ty.path "alloc::alloc::Global" + ]) + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_builder_SymbolicAirBuilder_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field4_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "SymbolicAirBuilder" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "preprocessed" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_builder::SymbolicAirBuilder", + "preprocessed" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "main" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_builder::SymbolicAirBuilder", + "main" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "public_values" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_builder::SymbolicAirBuilder", + "public_values" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "constraints" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_builder::SymbolicAirBuilder", + "constraints" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_builder_SymbolicAirBuilder_F. + + Module Impl_p3_uni_stark_symbolic_builder_SymbolicAirBuilder_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") [] [ F ]. + + (* + pub(crate) fn new(preprocessed_width: usize, width: usize, num_public_values: usize) -> Self { + let prep_values = [0, 1] + .into_iter() + .flat_map(|offset| { + (0..preprocessed_width) + .map(move |index| SymbolicVariable::new(Entry::Preprocessed { offset }, index)) + }) + .collect(); + let main_values = [0, 1] + .into_iter() + .flat_map(|offset| { + (0..width).map(move |index| SymbolicVariable::new(Entry::Main { offset }, index)) + }) + .collect(); + let public_values = (0..num_public_values) + .map(move |index| SymbolicVariable::new(Entry::Public, index)) + .collect(); + Self { + preprocessed: RowMajorMatrix::new(prep_values, preprocessed_width), + main: RowMajorMatrix::new(main_values, width), + public_values, + constraints: vec![], + } + } + *) + Definition new (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ preprocessed_width; width; num_public_values ] => + ltac:(M.monadic + (let preprocessed_width := M.alloc (| preprocessed_width |) in + let width := M.alloc (| width |) in + let num_public_values := M.alloc (| num_public_values |) in + M.read (| + let~ prep_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "usize" ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "usize" ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "usize" ], + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.Array + [ Value.Integer IntegerKind.Usize 0; Value.Integer IntegerKind.Usize 1 + ] + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let offset := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| preprocessed_width |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let index := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ], + "new", + [], + [] + |), + [ + Value.StructRecord + "p3_uni_stark::symbolic_variable::Entry::Preprocessed" + [ + ("offset", + M.read (| offset |)) + ]; + M.read (| index |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ main_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "usize" ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::flatten::FlatMap") + [] + [ + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "usize" ]; + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "usize" ], + [], + [], + "flat_map", + [], + [ + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.Array + [ Value.Integer IntegerKind.Usize 0; Value.Integer IntegerKind.Usize 1 + ] + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let offset := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| width |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let index := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ], + "new", + [], + [] + |), + [ + Value.StructRecord + "p3_uni_stark::symbolic_variable::Entry::Main" + [ + ("offset", + M.read (| offset |)) + ]; + M.read (| index |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ public_values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ], + [], + [], + "collect", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", M.read (| num_public_values |)) + ]; + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.path "usize" ] ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let index := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ], + "new", + [], + [] + |), + [ + Value.StructTuple + "p3_uni_stark::symbolic_variable::Entry::Public" + []; + M.read (| index |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + M.alloc (| + Value.StructRecord + "p3_uni_stark::symbolic_builder::SymbolicAirBuilder" + [ + ("preprocessed", + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ M.read (| prep_values |); M.read (| preprocessed_width |) ] + |)); + ("main", + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ M.read (| main_values |); M.read (| width |) ] + |)); + ("public_values", M.read (| public_values |)); + ("constraints", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "new" (new F). + Admitted. + Global Typeclasses Opaque new. + + (* + pub(crate) fn constraints(self) -> Vec> { + self.constraints + } + *) + Definition constraints (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "p3_uni_stark::symbolic_builder::SymbolicAirBuilder", + "constraints" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_constraints : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "constraints" (constraints F). + Admitted. + Global Typeclasses Opaque constraints. + End Impl_p3_uni_stark_symbolic_builder_SymbolicAirBuilder_F. + + Module Impl_p3_air_air_AirBuilder_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_builder_SymbolicAirBuilder_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") [] [ F ]. + + (* type F = F; *) + Definition _F (F : Ty.t) : Ty.t := F. + + (* type Expr = SymbolicExpression; *) + Definition _Expr (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* type Var = SymbolicVariable; *) + Definition _Var (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]. + + (* type M = RowMajorMatrix; *) + Definition _M_ (F : Ty.t) : Ty.t := + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + (Ty.apply (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") [] [ F ]) + "Var"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_air::air::AirBuilder" + [] + [] + (Ty.apply (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") [] [ F ]) + "Var"; + Ty.path "alloc::alloc::Global" + ] + ]. + + (* + fn main(&self) -> Self::M { + self.main.clone() + } + *) + Definition main (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_builder::SymbolicAirBuilder", + "main" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_first_row(&self) -> Self::Expr { + SymbolicExpression::IsFirstRow + } + *) + Definition is_first_row (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_uni_stark::symbolic_expression::SymbolicExpression::IsFirstRow" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_last_row(&self) -> Self::Expr { + SymbolicExpression::IsLastRow + } + *) + Definition is_last_row (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple "p3_uni_stark::symbolic_expression::SymbolicExpression::IsLastRow" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn is_transition_window(&self, size: usize) -> Self::Expr { + if size == 2 { + SymbolicExpression::IsTransition + } else { + panic!("uni-stark only supports a window size of 2") + } + } + *) + Definition is_transition_window + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; size ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let size := M.alloc (| size |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| size |); Value.Integer IntegerKind.Usize 2 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsTransition" + [] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "uni-stark only supports a window size of 2" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn assert_zero>(&mut self, x: I) { + self.constraints.push(x.into()); + } + *) + Definition assert_zero (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [ _ as I ], [ self; x ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let x := M.alloc (| x |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_builder::SymbolicAirBuilder", + "constraints" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::convert::Into", + I, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |), + [ M.read (| x |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_air::air::AirBuilder" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ + ("F", InstanceField.Ty (_F F)); + ("Expr", InstanceField.Ty (_Expr F)); + ("Var", InstanceField.Ty (_Var F)); + ("M_", InstanceField.Ty (_M_ F)); + ("main", InstanceField.Method (main F)); + ("is_first_row", InstanceField.Method (is_first_row F)); + ("is_last_row", InstanceField.Method (is_last_row F)); + ("is_transition_window", InstanceField.Method (is_transition_window F)); + ("assert_zero", InstanceField.Method (assert_zero F)) + ]. + End Impl_p3_air_air_AirBuilder_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_builder_SymbolicAirBuilder_F. + + Module Impl_p3_air_air_AirBuilderWithPublicValues_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_builder_SymbolicAirBuilder_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") [] [ F ]. + + (* type PublicVar = SymbolicVariable; *) + Definition _PublicVar (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]. + + (* + fn public_values(&self) -> &[Self::PublicVar] { + &self.public_values + } + *) + Definition public_values (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_builder::SymbolicAirBuilder", + "public_values" + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_air::air::AirBuilderWithPublicValues" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ + ("PublicVar", InstanceField.Ty (_PublicVar F)); + ("public_values", InstanceField.Method (public_values F)) + ]. + End Impl_p3_air_air_AirBuilderWithPublicValues_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_builder_SymbolicAirBuilder_F. + + Module Impl_p3_air_air_PairBuilder_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_builder_SymbolicAirBuilder_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_builder::SymbolicAirBuilder") [] [ F ]. + + (* + fn preprocessed(&self) -> Self::M { + self.preprocessed.clone() + } + *) + Definition preprocessed (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_builder::SymbolicAirBuilder", + "preprocessed" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_air::air::PairBuilder" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("preprocessed", InstanceField.Method (preprocessed F)) ]. + End Impl_p3_air_air_PairBuilder_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_builder_SymbolicAirBuilder_F. +End symbolic_builder. diff --git a/CoqOfRust/plonky3/uni-stark/src/symbolic_expression.rs b/CoqOfRust/plonky3/uni-stark/src/symbolic_expression.rs new file mode 100644 index 000000000..93814d56d --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/symbolic_expression.rs @@ -0,0 +1,470 @@ +use alloc::rc::Rc; +use core::fmt::Debug; +use core::iter::{Product, Sum}; +use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; + +use p3_field::{Algebra, Field, InjectiveMonomial, PrimeCharacteristicRing}; + +use crate::symbolic_variable::SymbolicVariable; + +/// An expression over `SymbolicVariable`s. +#[derive(Clone, Debug)] +pub enum SymbolicExpression { + Variable(SymbolicVariable), + IsFirstRow, + IsLastRow, + IsTransition, + Constant(F), + Add { + x: Rc, + y: Rc, + degree_multiple: usize, + }, + Sub { + x: Rc, + y: Rc, + degree_multiple: usize, + }, + Neg { + x: Rc, + degree_multiple: usize, + }, + Mul { + x: Rc, + y: Rc, + degree_multiple: usize, + }, +} + +impl SymbolicExpression { + /// Returns the multiple of `n` (the trace length) in this expression's degree. + pub const fn degree_multiple(&self) -> usize { + match self { + Self::Variable(v) => v.degree_multiple(), + Self::IsFirstRow | Self::IsLastRow => 1, + Self::IsTransition | Self::Constant(_) => 0, + Self::Add { + degree_multiple, .. + } + | Self::Sub { + degree_multiple, .. + } + | Self::Neg { + degree_multiple, .. + } + | Self::Mul { + degree_multiple, .. + } => *degree_multiple, + } + } +} + +impl Default for SymbolicExpression { + fn default() -> Self { + Self::Constant(F::ZERO) + } +} + +impl From for SymbolicExpression { + fn from(value: F) -> Self { + Self::Constant(value) + } +} + +impl PrimeCharacteristicRing for SymbolicExpression { + type PrimeSubfield = F::PrimeSubfield; + + const ZERO: Self = Self::Constant(F::ZERO); + const ONE: Self = Self::Constant(F::ONE); + const TWO: Self = Self::Constant(F::TWO); + const NEG_ONE: Self = Self::Constant(F::NEG_ONE); + + #[inline] + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + F::from_prime_subfield(f).into() + } +} + +impl Algebra for SymbolicExpression {} + +impl Algebra> for SymbolicExpression {} + +// Note we cannot implement PermutationMonomial due to the degree_multiple part which makes +// operations non invertible. +impl, const N: u64> InjectiveMonomial for SymbolicExpression {} + +impl Add for SymbolicExpression +where + T: Into, +{ + type Output = Self; + + fn add(self, rhs: T) -> Self { + match (self, rhs.into()) { + (Self::Constant(lhs), Self::Constant(rhs)) => Self::Constant(lhs + rhs), + (lhs, rhs) => Self::Add { + degree_multiple: lhs.degree_multiple().max(rhs.degree_multiple()), + x: Rc::new(lhs), + y: Rc::new(rhs), + }, + } + } +} + +impl AddAssign for SymbolicExpression +where + T: Into, +{ + fn add_assign(&mut self, rhs: T) { + *self = self.clone() + rhs.into(); + } +} + +impl Sum for SymbolicExpression +where + T: Into, +{ + fn sum>(iter: I) -> Self { + iter.map(Into::into) + .reduce(|x, y| x + y) + .unwrap_or(Self::ZERO) + } +} + +impl> Sub for SymbolicExpression { + type Output = Self; + + fn sub(self, rhs: T) -> Self { + match (self, rhs.into()) { + (Self::Constant(lhs), Self::Constant(rhs)) => Self::Constant(lhs - rhs), + (lhs, rhs) => Self::Sub { + degree_multiple: lhs.degree_multiple().max(rhs.degree_multiple()), + x: Rc::new(lhs), + y: Rc::new(rhs), + }, + } + } +} + +impl SubAssign for SymbolicExpression +where + T: Into, +{ + fn sub_assign(&mut self, rhs: T) { + *self = self.clone() - rhs.into(); + } +} + +impl Neg for SymbolicExpression { + type Output = Self; + + fn neg(self) -> Self { + match self { + Self::Constant(c) => Self::Constant(-c), + expr => Self::Neg { + degree_multiple: expr.degree_multiple(), + x: Rc::new(expr), + }, + } + } +} + +impl> Mul for SymbolicExpression { + type Output = Self; + + fn mul(self, rhs: T) -> Self { + match (self, rhs.into()) { + (Self::Constant(lhs), Self::Constant(rhs)) => Self::Constant(lhs * rhs), + (lhs, rhs) => Self::Mul { + degree_multiple: lhs.degree_multiple() + rhs.degree_multiple(), + x: Rc::new(lhs), + y: Rc::new(rhs), + }, + } + } +} + +impl MulAssign for SymbolicExpression +where + T: Into, +{ + fn mul_assign(&mut self, rhs: T) { + *self = self.clone() * rhs.into(); + } +} + +impl> Product for SymbolicExpression { + fn product>(iter: I) -> Self { + iter.map(Into::into) + .reduce(|x, y| x * y) + .unwrap_or(Self::ONE) + } +} + +#[cfg(test)] +mod tests { + use alloc::vec; + + use p3_baby_bear::BabyBear; + + use super::*; + use crate::Entry; + + #[test] + fn test_symbolic_expression_degree_multiple() { + let constant_expr = SymbolicExpression::::Constant(BabyBear::new(5)); + assert_eq!( + constant_expr.degree_multiple(), + 0, + "Constant should have degree 0" + ); + + let variable_expr = + SymbolicExpression::Variable(SymbolicVariable::new(Entry::Main { offset: 0 }, 1)); + assert_eq!( + variable_expr.degree_multiple(), + 1, + "Main variable should have degree 1" + ); + + let preprocessed_var = SymbolicExpression::Variable(SymbolicVariable::new( + Entry::Preprocessed { offset: 0 }, + 2, + )); + assert_eq!( + preprocessed_var.degree_multiple(), + 1, + "Preprocessed variable should have degree 1" + ); + + let permutation_var = SymbolicExpression::Variable(SymbolicVariable::::new( + Entry::Permutation { offset: 0 }, + 3, + )); + assert_eq!( + permutation_var.degree_multiple(), + 1, + "Permutation variable should have degree 1" + ); + + let public_var = + SymbolicExpression::Variable(SymbolicVariable::::new(Entry::Public, 4)); + assert_eq!( + public_var.degree_multiple(), + 0, + "Public variable should have degree 0" + ); + + let challenge_var = + SymbolicExpression::Variable(SymbolicVariable::::new(Entry::Challenge, 5)); + assert_eq!( + challenge_var.degree_multiple(), + 0, + "Challenge variable should have degree 0" + ); + + let is_first_row = SymbolicExpression::::IsFirstRow; + assert_eq!( + is_first_row.degree_multiple(), + 1, + "IsFirstRow should have degree 1" + ); + + let is_last_row = SymbolicExpression::::IsLastRow; + assert_eq!( + is_last_row.degree_multiple(), + 1, + "IsLastRow should have degree 1" + ); + + let is_transition = SymbolicExpression::::IsTransition; + assert_eq!( + is_transition.degree_multiple(), + 0, + "IsTransition should have degree 0" + ); + + let add_expr = SymbolicExpression::::Add { + x: Rc::new(variable_expr.clone()), + y: Rc::new(preprocessed_var.clone()), + degree_multiple: 1, + }; + assert_eq!( + add_expr.degree_multiple(), + 1, + "Addition should take max degree of inputs" + ); + + let sub_expr = SymbolicExpression::::Sub { + x: Rc::new(variable_expr.clone()), + y: Rc::new(preprocessed_var.clone()), + degree_multiple: 1, + }; + assert_eq!( + sub_expr.degree_multiple(), + 1, + "Subtraction should take max degree of inputs" + ); + + let neg_expr = SymbolicExpression::::Neg { + x: Rc::new(variable_expr.clone()), + degree_multiple: 1, + }; + assert_eq!( + neg_expr.degree_multiple(), + 1, + "Negation should keep the degree" + ); + + let mul_expr = SymbolicExpression::::Mul { + x: Rc::new(variable_expr.clone()), + y: Rc::new(preprocessed_var.clone()), + degree_multiple: 2, + }; + assert_eq!( + mul_expr.degree_multiple(), + 2, + "Multiplication should sum degrees" + ); + } + + #[test] + fn test_addition_of_constants() { + let a = SymbolicExpression::Constant(BabyBear::new(3)); + let b = SymbolicExpression::Constant(BabyBear::new(4)); + let result = a + b; + match result { + SymbolicExpression::Constant(val) => assert_eq!(val, BabyBear::new(7)), + _ => panic!("Addition of constants did not simplify correctly"), + } + } + + #[test] + fn test_subtraction_of_constants() { + let a = SymbolicExpression::Constant(BabyBear::new(10)); + let b = SymbolicExpression::Constant(BabyBear::new(4)); + let result = a - b; + match result { + SymbolicExpression::Constant(val) => assert_eq!(val, BabyBear::new(6)), + _ => panic!("Subtraction of constants did not simplify correctly"), + } + } + + #[test] + fn test_negation() { + let a = SymbolicExpression::Constant(BabyBear::new(7)); + let result = -a; + match result { + SymbolicExpression::Constant(val) => { + assert_eq!(val, BabyBear::NEG_ONE * BabyBear::new(7)) + } + _ => panic!("Negation did not work correctly"), + } + } + + #[test] + fn test_multiplication_of_constants() { + let a = SymbolicExpression::Constant(BabyBear::new(3)); + let b = SymbolicExpression::Constant(BabyBear::new(5)); + let result = a * b; + match result { + SymbolicExpression::Constant(val) => assert_eq!(val, BabyBear::new(15)), + _ => panic!("Multiplication of constants did not simplify correctly"), + } + } + + #[test] + fn test_degree_multiple_for_addition() { + let a = SymbolicExpression::Variable::(SymbolicVariable::new( + Entry::Main { offset: 0 }, + 1, + )); + let b = SymbolicExpression::Variable::(SymbolicVariable::new( + Entry::Main { offset: 0 }, + 2, + )); + let result = a.clone() + b.clone(); + match result { + SymbolicExpression::Add { + degree_multiple, + x, + y, + } => { + assert_eq!(degree_multiple, 1); + assert!( + matches!(*x, SymbolicExpression::Variable(ref v) if v.index == 1 && matches!(v.entry, Entry::Main { offset: 0 })) + ); + assert!( + matches!(*y, SymbolicExpression::Variable(ref v) if v.index == 2 && matches!(v.entry, Entry::Main { offset: 0 })) + ); + } + _ => panic!("Addition did not create an Add expression"), + } + } + + #[test] + fn test_degree_multiple_for_multiplication() { + let a = SymbolicExpression::Variable::(SymbolicVariable::new( + Entry::Main { offset: 0 }, + 1, + )); + let b = SymbolicExpression::Variable::(SymbolicVariable::new( + Entry::Main { offset: 0 }, + 2, + )); + let result = a.clone() * b.clone(); + + match result { + SymbolicExpression::Mul { + degree_multiple, + x, + y, + } => { + assert_eq!(degree_multiple, 2, "Multiplication should sum degrees"); + + assert!( + matches!(*x, SymbolicExpression::Variable(ref v) + if v.index == 1 && matches!(v.entry, Entry::Main { offset: 0 }) + ), + "Left operand should match `a`" + ); + + assert!( + matches!(*y, SymbolicExpression::Variable(ref v) + if v.index == 2 && matches!(v.entry, Entry::Main { offset: 0 }) + ), + "Right operand should match `b`" + ); + } + _ => panic!("Multiplication did not create a `Mul` expression"), + } + } + + #[test] + fn test_sum_operator() { + let expressions = vec![ + SymbolicExpression::Constant(BabyBear::new(2)), + SymbolicExpression::Constant(BabyBear::new(3)), + SymbolicExpression::Constant(BabyBear::new(5)), + ]; + let result: SymbolicExpression = expressions.into_iter().sum(); + match result { + SymbolicExpression::Constant(val) => assert_eq!(val, BabyBear::new(10)), + _ => panic!("Sum did not produce correct result"), + } + } + + #[test] + fn test_product_operator() { + let expressions = vec![ + SymbolicExpression::Constant(BabyBear::new(2)), + SymbolicExpression::Constant(BabyBear::new(3)), + SymbolicExpression::Constant(BabyBear::new(4)), + ]; + let result: SymbolicExpression = expressions.into_iter().product(); + match result { + SymbolicExpression::Constant(val) => assert_eq!(val, BabyBear::new(24)), + _ => panic!("Product did not produce correct result"), + } + } +} diff --git a/CoqOfRust/plonky3/uni-stark/src/symbolic_expression.v b/CoqOfRust/plonky3/uni-stark/src/symbolic_expression.v new file mode 100644 index 000000000..49cba7702 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/symbolic_expression.v @@ -0,0 +1,3243 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module symbolic_expression. + (* + Enum SymbolicExpression + { + const_params := []; + ty_params := [ "F" ]; + variants := + [ + { + name := "Variable"; + item := + StructTuple + [ Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ] ]; + }; + { + name := "IsFirstRow"; + item := StructTuple []; + }; + { + name := "IsLastRow"; + item := StructTuple []; + }; + { + name := "IsTransition"; + item := StructTuple []; + }; + { + name := "Constant"; + item := StructTuple [ F ]; + }; + { + name := "Add"; + item := + StructRecord + [ + ("x", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]); + ("y", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]); + ("degree_multiple", Ty.path "usize") + ]; + }; + { + name := "Sub"; + item := + StructRecord + [ + ("x", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]); + ("y", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]); + ("degree_multiple", Ty.path "usize") + ]; + }; + { + name := "Neg"; + item := + StructRecord + [ + ("x", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]); + ("degree_multiple", Ty.path "usize") + ]; + }; + { + name := "Mul"; + item := + StructRecord + [ + ("x", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]); + ("y", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ]); + ("degree_multiple", Ty.path "usize") + ]; + } + ]; + } + *) + + Axiom IsDiscriminant_SymbolicExpression_Variable : + M.IsDiscriminant "p3_uni_stark::symbolic_expression::SymbolicExpression::Variable" 0. + Axiom IsDiscriminant_SymbolicExpression_IsFirstRow : + M.IsDiscriminant "p3_uni_stark::symbolic_expression::SymbolicExpression::IsFirstRow" 1. + Axiom IsDiscriminant_SymbolicExpression_IsLastRow : + M.IsDiscriminant "p3_uni_stark::symbolic_expression::SymbolicExpression::IsLastRow" 2. + Axiom IsDiscriminant_SymbolicExpression_IsTransition : + M.IsDiscriminant "p3_uni_stark::symbolic_expression::SymbolicExpression::IsTransition" 3. + Axiom IsDiscriminant_SymbolicExpression_Constant : + M.IsDiscriminant "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" 4. + Axiom IsDiscriminant_SymbolicExpression_Add : + M.IsDiscriminant "p3_uni_stark::symbolic_expression::SymbolicExpression::Add" 5. + Axiom IsDiscriminant_SymbolicExpression_Sub : + M.IsDiscriminant "p3_uni_stark::symbolic_expression::SymbolicExpression::Sub" 6. + Axiom IsDiscriminant_SymbolicExpression_Neg : + M.IsDiscriminant "p3_uni_stark::symbolic_expression::SymbolicExpression::Neg" 7. + Axiom IsDiscriminant_SymbolicExpression_Mul : + M.IsDiscriminant "p3_uni_stark::symbolic_expression::SymbolicExpression::Mul" 8. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Variable", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Variable" + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsFirstRow" + |) in + M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsFirstRow" + [] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsLastRow" + |) in + M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsLastRow" + [] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsTransition" + |) in + M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsTransition" + [] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::clone::Clone", + F, + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Add", + "x" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Add", + "y" + |) in + let γ1_2 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Add", + "degree_multiple" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + let __self_1 := M.alloc (| γ1_1 |) in + let __self_2 := M.alloc (| γ1_2 |) in + M.alloc (| + Value.StructRecord + "p3_uni_stark::symbolic_expression::SymbolicExpression::Add" + [ + ("x", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |) + ] + |)); + ("y", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_1 |) |) |) + ] + |)); + ("degree_multiple", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_2 |) |) |) + ] + |)) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Sub", + "x" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Sub", + "y" + |) in + let γ1_2 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Sub", + "degree_multiple" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + let __self_1 := M.alloc (| γ1_1 |) in + let __self_2 := M.alloc (| γ1_2 |) in + M.alloc (| + Value.StructRecord + "p3_uni_stark::symbolic_expression::SymbolicExpression::Sub" + [ + ("x", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |) + ] + |)); + ("y", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_1 |) |) |) + ] + |)); + ("degree_multiple", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_2 |) |) |) + ] + |)) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Neg", + "x" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Neg", + "degree_multiple" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + let __self_1 := M.alloc (| γ1_1 |) in + M.alloc (| + Value.StructRecord + "p3_uni_stark::symbolic_expression::SymbolicExpression::Neg" + [ + ("x", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |) + ] + |)); + ("degree_multiple", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_1 |) |) |) + ] + |)) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Mul", + "x" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Mul", + "y" + |) in + let γ1_2 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Mul", + "degree_multiple" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + let __self_1 := M.alloc (| γ1_1 |) in + let __self_2 := M.alloc (| γ1_2 |) in + M.alloc (| + Value.StructRecord + "p3_uni_stark::symbolic_expression::SymbolicExpression::Mul" + [ + ("x", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |) + ] + |)); + ("y", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_1 |) |) |) + ] + |)); + ("degree_multiple", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_2 |) |) |) + ] + |)) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Variable", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Variable" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsFirstRow" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "IsFirstRow" |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsLastRow" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "IsLastRow" |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsTransition" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "IsTransition" |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Constant" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Add", + "x" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Add", + "y" + |) in + let γ1_2 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Add", + "degree_multiple" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + let __self_1 := M.alloc (| γ1_1 |) in + let __self_2 := M.alloc (| γ1_2 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Add" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "x" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "y" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_1 |) |) |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "degree_multiple" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_2 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Sub", + "x" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Sub", + "y" + |) in + let γ1_2 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Sub", + "degree_multiple" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + let __self_1 := M.alloc (| γ1_1 |) in + let __self_2 := M.alloc (| γ1_2 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Sub" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "x" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "y" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_1 |) |) |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "degree_multiple" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_2 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Neg", + "x" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Neg", + "degree_multiple" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + let __self_1 := M.alloc (| γ1_1 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Neg" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "x" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "degree_multiple" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_1 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Mul", + "x" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Mul", + "y" + |) in + let γ1_2 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Mul", + "degree_multiple" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + let __self_1 := M.alloc (| γ1_1 |) in + let __self_2 := M.alloc (| γ1_2 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Mul" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "x" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "y" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_1 |) |) |)); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "degree_multiple" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_2 |) |) + |)) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + pub const fn degree_multiple(&self) -> usize { + match self { + Self::Variable(v) => v.degree_multiple(), + Self::IsFirstRow | Self::IsLastRow => 1, + Self::IsTransition | Self::Constant(_) => 0, + Self::Add { + degree_multiple, .. + } + | Self::Sub { + degree_multiple, .. + } + | Self::Neg { + degree_multiple, .. + } + | Self::Mul { + degree_multiple, .. + } => *degree_multiple, + } + } + *) + Definition degree_multiple + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Variable", + 0 + |) in + let v := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") + [] + [ F ], + "degree_multiple", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| v |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (Ty.tuple []) (| + γ, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsFirstRow" + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsLastRow" + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 1 |))) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (Ty.tuple []) (| + γ, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::IsTransition" + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant", + 0 + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 0 |))) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern + (Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.path "usize" ] ]) (| + γ, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Add", + "degree_multiple" + |) in + let degree_multiple := M.alloc (| γ1_0 |) in + Value.Tuple [ degree_multiple ])); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Sub", + "degree_multiple" + |) in + let degree_multiple := M.alloc (| γ1_0 |) in + Value.Tuple [ degree_multiple ])); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Neg", + "degree_multiple" + |) in + let degree_multiple := M.alloc (| γ1_0 |) in + Value.Tuple [ degree_multiple ])); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Mul", + "degree_multiple" + |) in + let degree_multiple := M.alloc (| γ1_0 |) in + Value.Tuple [ degree_multiple ])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [ degree_multiple ] => + ltac:(M.monadic (M.deref (| M.read (| degree_multiple |) |))) + | _ => M.impossible "wrong number of arguments" + end) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_degree_multiple : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "degree_multiple" (degree_multiple F). + Admitted. + Global Typeclasses Opaque degree_multiple. + End Impl_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_default_Default_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn default() -> Self { + Self::Constant(F::ZERO) + } + *) + Definition default (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("default", InstanceField.Method (default F)) ]. + End Impl_core_default_Default_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_convert_From_where_p3_field_field_Field_F_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn from(value: F) -> Self { + Self::Constant(value) + } + *) + Definition from (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) [ ("from", InstanceField.Method (from F)) ]. + End Impl_core_convert_From_where_p3_field_field_Field_F_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_p3_field_field_PrimeCharacteristicRing_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* type PrimeSubfield = F::PrimeSubfield; *) + Definition _PrimeSubfield (F : Ty.t) : Ty.t := + Ty.associated_in_trait "p3_field::field::PrimeCharacteristicRing" [] [] F "PrimeSubfield". + + (* const ZERO: Self = Self::Constant(F::ZERO); *) + (* Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ] *) + Definition value_ZERO (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ZERO", F |) |) ] + |))). + + (* const ONE: Self = Self::Constant(F::ONE); *) + (* Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ] *) + Definition value_ONE (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::ONE", F |) |) ] + |))). + + (* const TWO: Self = Self::Constant(F::TWO); *) + (* Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ] *) + Definition value_TWO (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::TWO", F |) |) ] + |))). + + (* const NEG_ONE: Self = Self::Constant(F::NEG_ONE); *) + (* Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ] *) + Definition value_NEG_ONE (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ M.read (| get_constant (| "p3_field::field::PrimeCharacteristicRing::NEG_ONE", F |) |) + ] + |))). + + (* + fn from_prime_subfield(f: Self::PrimeSubfield) -> Self { + F::from_prime_subfield(f).into() + } + *) + Definition from_prime_subfield + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ f ] => + ltac:(M.monadic + (let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_trait_method (| + "core::convert::Into", + F, + [], + [ Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ] + ], + "into", + [], + [] + |), + [ + M.call_closure (| + F, + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + F, + [], + [], + "from_prime_subfield", + [], + [] + |), + [ M.read (| f |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_field::field::PrimeCharacteristicRing" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ + ("PrimeSubfield", InstanceField.Ty (_PrimeSubfield F)); + ("value_ZERO", InstanceField.Method (value_ZERO F)); + ("value_ONE", InstanceField.Method (value_ONE F)); + ("value_TWO", InstanceField.Method (value_TWO F)); + ("value_NEG_ONE", InstanceField.Method (value_NEG_ONE F)); + ("from_prime_subfield", InstanceField.Method (from_prime_subfield F)) + ]. + End Impl_p3_field_field_PrimeCharacteristicRing_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_p3_field_field_Algebra_where_p3_field_field_Field_F_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_field::field::Algebra" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ F ] + (Self F) + (* Instance *) []. + End Impl_p3_field_field_Algebra_where_p3_field_field_Field_F_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_p3_field_field_Algebra_where_p3_field_field_Field_F_p3_uni_stark_symbolic_variable_SymbolicVariable_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "p3_field::field::Algebra" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ] ] + (Self F) + (* Instance *) []. + End Impl_p3_field_field_Algebra_where_p3_field_field_Field_F_p3_uni_stark_symbolic_variable_SymbolicVariable_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_p3_field_field_InjectiveMonomial_where_p3_field_field_Field_F_where_p3_field_field_InjectiveMonomial_F_N_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (N : Value.t) (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + Axiom Implements : + forall (N : Value.t) (F : Ty.t), + M.IsTraitInstance + "p3_field::field::InjectiveMonomial" + (* Trait polymorphic consts *) [ N ] + (* Trait polymorphic types *) [] + (Self N F) + (* Instance *) []. + End Impl_p3_field_field_InjectiveMonomial_where_p3_field_field_Field_F_where_p3_field_field_InjectiveMonomial_F_N_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_ops_arith_Add_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* type Output = Self; *) + Definition _Output (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn add(self, rhs: T) -> Self { + match (self, rhs.into()) { + (Self::Constant(lhs), Self::Constant(rhs)) => Self::Constant(lhs + rhs), + (lhs, rhs) => Self::Add { + degree_multiple: lhs.degree_multiple().max(rhs.degree_multiple()), + x: Rc::new(lhs), + y: Rc::new(rhs), + }, + } + } + *) + Definition add (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + M.alloc (| + Value.Tuple + [ + M.read (| self |); + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant", + 0 + |) in + let lhs := M.copy (| γ1_0 |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant", + 0 + |) in + let rhs := M.copy (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Add", + F, + [], + [ F ], + "add", + [], + [] + |), + [ M.read (| lhs |); M.read (| rhs |) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let lhs := M.copy (| γ0_0 |) in + let rhs := M.copy (| γ0_1 |) in + M.alloc (| + Value.StructRecord + "p3_uni_stark::symbolic_expression::SymbolicExpression::Add" + [ + ("degree_multiple", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "usize", + [], + [], + "max", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + "degree_multiple", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, lhs |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + "degree_multiple", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |)); + ("x", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ M.read (| lhs |) ] + |)); + ("y", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ M.read (| rhs |) ] + |)) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F T)); ("add", InstanceField.Method (add F T)) ]. + End Impl_core_ops_arith_Add_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_ops_arith_AddAssign_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn add_assign(&mut self, rhs: T) { + *self = self.clone() + rhs.into(); + } + *) + Definition add_assign (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign F T)) ]. + End Impl_core_ops_arith_AddAssign_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_iter_traits_accum_Sum_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn sum>(iter: I) -> Self { + iter.map(Into::into) + .reduce(|x, y| x + y) + .unwrap_or(Self::ZERO) + } + *) + Definition sum (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + I; + Ty.function + [ T ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ], + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + I; + Ty.function + [ T ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.function + [ T ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ] + |), + [ + M.read (| iter |); + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "add", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Sum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) [ ("sum", InstanceField.Method (sum F T)) ]. + End Impl_core_iter_traits_accum_Sum_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_ops_arith_Sub_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* type Output = Self; *) + Definition _Output (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn sub(self, rhs: T) -> Self { + match (self, rhs.into()) { + (Self::Constant(lhs), Self::Constant(rhs)) => Self::Constant(lhs - rhs), + (lhs, rhs) => Self::Sub { + degree_multiple: lhs.degree_multiple().max(rhs.degree_multiple()), + x: Rc::new(lhs), + y: Rc::new(rhs), + }, + } + } + *) + Definition sub (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + M.alloc (| + Value.Tuple + [ + M.read (| self |); + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant", + 0 + |) in + let lhs := M.copy (| γ1_0 |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant", + 0 + |) in + let rhs := M.copy (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Sub", + F, + [], + [ F ], + "sub", + [], + [] + |), + [ M.read (| lhs |); M.read (| rhs |) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let lhs := M.copy (| γ0_0 |) in + let rhs := M.copy (| γ0_1 |) in + M.alloc (| + Value.StructRecord + "p3_uni_stark::symbolic_expression::SymbolicExpression::Sub" + [ + ("degree_multiple", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "usize", + [], + [], + "max", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + "degree_multiple", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, lhs |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + "degree_multiple", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |)); + ("x", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ M.read (| lhs |) ] + |)); + ("y", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ M.read (| rhs |) ] + |)) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F T)); ("sub", InstanceField.Method (sub F T)) ]. + End Impl_core_ops_arith_Sub_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_ops_arith_SubAssign_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn sub_assign(&mut self, rhs: T) { + *self = self.clone() - rhs.into(); + } + *) + Definition sub_assign (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "sub", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) [ ("sub_assign", InstanceField.Method (sub_assign F T)) ]. + End Impl_core_ops_arith_SubAssign_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_ops_arith_Neg_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* type Output = Self; *) + Definition _Output (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn neg(self) -> Self { + match self { + Self::Constant(c) => Self::Constant(-c), + expr => Self::Neg { + degree_multiple: expr.degree_multiple(), + x: Rc::new(expr), + }, + } + } + *) + Definition neg (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant", + 0 + |) in + let c := M.copy (| γ0_0 |) in + M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Neg", + F, + [], + [], + "neg", + [], + [] + |), + [ M.read (| c |) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let expr := M.copy (| γ |) in + M.alloc (| + Value.StructRecord + "p3_uni_stark::symbolic_expression::SymbolicExpression::Neg" + [ + ("degree_multiple", + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + "degree_multiple", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, expr |) ] + |)); + ("x", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ M.read (| expr |) ] + |)) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F)); ("neg", InstanceField.Method (neg F)) ]. + End Impl_core_ops_arith_Neg_where_p3_field_field_Field_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_ops_arith_Mul_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* type Output = Self; *) + Definition _Output (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn mul(self, rhs: T) -> Self { + match (self, rhs.into()) { + (Self::Constant(lhs), Self::Constant(rhs)) => Self::Constant(lhs * rhs), + (lhs, rhs) => Self::Mul { + degree_multiple: lhs.degree_multiple() + rhs.degree_multiple(), + x: Rc::new(lhs), + y: Rc::new(rhs), + }, + } + } + *) + Definition mul (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + M.alloc (| + Value.Tuple + [ + M.read (| self |); + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant", + 0 + |) in + let lhs := M.copy (| γ1_0 |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant", + 0 + |) in + let rhs := M.copy (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Constant" + [ + M.call_closure (| + F, + M.get_trait_method (| + "core::ops::arith::Mul", + F, + [], + [ F ], + "mul", + [], + [] + |), + [ M.read (| lhs |); M.read (| rhs |) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let lhs := M.copy (| γ0_0 |) in + let rhs := M.copy (| γ0_1 |) in + M.alloc (| + Value.StructRecord + "p3_uni_stark::symbolic_expression::SymbolicExpression::Mul" + [ + ("degree_multiple", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + "degree_multiple", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, lhs |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + "degree_multiple", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |)); + ("x", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ M.read (| lhs |) ] + |)); + ("y", + M.call_closure (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::rc::Rc") + [] + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ M.read (| rhs |) ] + |)) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F T)); ("mul", InstanceField.Method (mul F T)) ]. + End Impl_core_ops_arith_Mul_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_ops_arith_MulAssign_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn mul_assign(&mut self, rhs: T) { + *self = self.clone() * rhs.into(); + } + *) + Definition mul_assign (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) [ ("mul_assign", InstanceField.Method (mul_assign F T)) ]. + End Impl_core_ops_arith_MulAssign_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_iter_traits_accum_Product_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn product>(iter: I) -> Self { + iter.map(Into::into) + .reduce(|x, y| x * y) + .unwrap_or(Self::ONE) + } + *) + Definition product (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + I; + Ty.function + [ T ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ], + [], + [], + "reduce", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + I; + Ty.function + [ T ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "map", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.function + [ T ] + (Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ] + |), + [ + M.read (| iter |); + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]; + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ] + ] + (Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ]) + ], + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let y := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [ + Ty.apply + (Ty.path + "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "mul", + [], + [] + |), + [ M.read (| x |); M.read (| y |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ONE", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Product" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) [ ("product", InstanceField.Method (product F T)) ]. + End Impl_core_iter_traits_accum_Product_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. +End symbolic_expression. diff --git a/CoqOfRust/plonky3/uni-stark/src/symbolic_variable.rs b/CoqOfRust/plonky3/uni-stark/src/symbolic_variable.rs new file mode 100644 index 000000000..a5552107e --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/symbolic_variable.rs @@ -0,0 +1,79 @@ +use core::marker::PhantomData; +use core::ops::{Add, Mul, Sub}; + +use p3_field::Field; + +use crate::symbolic_expression::SymbolicExpression; + +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +pub enum Entry { + Preprocessed { offset: usize }, + Main { offset: usize }, + Permutation { offset: usize }, + Public, + Challenge, +} + +/// A variable within the evaluation window, i.e. a column in either the local or next row. +#[derive(Copy, Clone, Debug)] +pub struct SymbolicVariable { + pub entry: Entry, + pub index: usize, + pub(crate) _phantom: PhantomData, +} + +impl SymbolicVariable { + pub const fn new(entry: Entry, index: usize) -> Self { + Self { + entry, + index, + _phantom: PhantomData, + } + } + + pub const fn degree_multiple(&self) -> usize { + match self.entry { + Entry::Preprocessed { .. } | Entry::Main { .. } | Entry::Permutation { .. } => 1, + Entry::Public | Entry::Challenge => 0, + } + } +} + +impl From> for SymbolicExpression { + fn from(value: SymbolicVariable) -> Self { + Self::Variable(value) + } +} + +impl Add for SymbolicVariable +where + T: Into>, +{ + type Output = SymbolicExpression; + + fn add(self, rhs: T) -> Self::Output { + SymbolicExpression::from(self) + rhs.into() + } +} + +impl Sub for SymbolicVariable +where + T: Into>, +{ + type Output = SymbolicExpression; + + fn sub(self, rhs: T) -> Self::Output { + SymbolicExpression::from(self) - rhs.into() + } +} + +impl Mul for SymbolicVariable +where + T: Into>, +{ + type Output = SymbolicExpression; + + fn mul(self, rhs: T) -> Self::Output { + SymbolicExpression::from(self) * rhs.into() + } +} diff --git a/CoqOfRust/plonky3/uni-stark/src/symbolic_variable.v b/CoqOfRust/plonky3/uni-stark/src/symbolic_variable.v new file mode 100644 index 000000000..1217bd36e --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/symbolic_variable.v @@ -0,0 +1,1316 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module symbolic_variable. + (* + Enum Entry + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "Preprocessed"; + item := StructRecord [ ("offset", Ty.path "usize") ]; + }; + { + name := "Main"; + item := StructRecord [ ("offset", Ty.path "usize") ]; + }; + { + name := "Permutation"; + item := StructRecord [ ("offset", Ty.path "usize") ]; + }; + { + name := "Public"; + item := StructTuple []; + }; + { + name := "Challenge"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_Entry_Preprocessed : + M.IsDiscriminant "p3_uni_stark::symbolic_variable::Entry::Preprocessed" 0. + Axiom IsDiscriminant_Entry_Main : + M.IsDiscriminant "p3_uni_stark::symbolic_variable::Entry::Main" 1. + Axiom IsDiscriminant_Entry_Permutation : + M.IsDiscriminant "p3_uni_stark::symbolic_variable::Entry::Permutation" 2. + Axiom IsDiscriminant_Entry_Public : + M.IsDiscriminant "p3_uni_stark::symbolic_variable::Entry::Public" 3. + Axiom IsDiscriminant_Entry_Challenge : + M.IsDiscriminant "p3_uni_stark::symbolic_variable::Entry::Challenge" 4. + + Module Impl_core_marker_Copy_for_p3_uni_stark_symbolic_variable_Entry. + Definition Self : Ty.t := Ty.path "p3_uni_stark::symbolic_variable::Entry". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_p3_uni_stark_symbolic_variable_Entry. + + Module Impl_core_clone_Clone_for_p3_uni_stark_symbolic_variable_Entry. + Definition Self : Ty.t := Ty.path "p3_uni_stark::symbolic_variable::Entry". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "p3_uni_stark::symbolic_variable::Entry" ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_p3_uni_stark_symbolic_variable_Entry. + + Module Impl_core_fmt_Debug_for_p3_uni_stark_symbolic_variable_Entry. + Definition Self : Ty.t := Ty.path "p3_uni_stark::symbolic_variable::Entry". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Preprocessed", + "offset" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Preprocessed" |) |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "offset" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Main", + "offset" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Main" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "offset" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Permutation", + "offset" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Permutation" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "offset" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| γ, "p3_uni_stark::symbolic_variable::Entry::Public" |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Public" |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Challenge" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Challenge" |) |) |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_p3_uni_stark_symbolic_variable_Entry. + + Module Impl_core_marker_StructuralPartialEq_for_p3_uni_stark_symbolic_variable_Entry. + Definition Self : Ty.t := Ty.path "p3_uni_stark::symbolic_variable::Entry". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_p3_uni_stark_symbolic_variable_Entry. + + Module Impl_core_cmp_PartialEq_p3_uni_stark_symbolic_variable_Entry_for_p3_uni_stark_symbolic_variable_Entry. + Definition Self : Ty.t := Ty.path "p3_uni_stark::symbolic_variable::Entry". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_uni_stark::symbolic_variable::Entry" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_uni_stark::symbolic_variable::Entry" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.alloc (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| __self_discr |); M.read (| __arg1_discr |) ] + |), + ltac:(M.monadic + (M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "bool" ], + M.alloc (| Value.Tuple [ M.read (| self |); M.read (| other |) ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_record_field (| + γ0_0, + "p3_uni_stark::symbolic_variable::Entry::Preprocessed", + "offset" + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_record_field (| + γ0_1, + "p3_uni_stark::symbolic_variable::Entry::Preprocessed", + "offset" + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "usize" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "usize" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, __self_0 |); + M.borrow (| Pointer.Kind.Ref, __arg1_0 |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_record_field (| + γ0_0, + "p3_uni_stark::symbolic_variable::Entry::Main", + "offset" + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_record_field (| + γ0_1, + "p3_uni_stark::symbolic_variable::Entry::Main", + "offset" + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "usize" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "usize" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, __self_0 |); + M.borrow (| Pointer.Kind.Ref, __arg1_0 |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_record_field (| + γ0_0, + "p3_uni_stark::symbolic_variable::Entry::Permutation", + "offset" + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_record_field (| + γ0_1, + "p3_uni_stark::symbolic_variable::Entry::Permutation", + "offset" + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "usize" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "usize" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, __self_0 |); + M.borrow (| Pointer.Kind.Ref, __arg1_0 |) + ] + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool true |))) + ] + |) + |))) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "p3_uni_stark::symbolic_variable::Entry" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_p3_uni_stark_symbolic_variable_Entry_for_p3_uni_stark_symbolic_variable_Entry. + + Module Impl_core_cmp_Eq_for_p3_uni_stark_symbolic_variable_Entry. + Definition Self : Ty.t := Ty.path "p3_uni_stark::symbolic_variable::Entry". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_p3_uni_stark_symbolic_variable_Entry. + + Module Impl_core_hash_Hash_for_p3_uni_stark_symbolic_variable_Entry. + Definition Self : Ty.t := Ty.path "p3_uni_stark::symbolic_variable::Entry". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ __self_discr : Ty.apply (Ty.path "*") [] [ Ty.path "isize" ] := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "p3_uni_stark::symbolic_variable::Entry" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "isize", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_discr |) |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Preprocessed", + "offset" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "usize", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Main", + "offset" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "usize", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Permutation", + "offset" + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "usize", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_p3_uni_stark_symbolic_variable_Entry. + + (* StructRecord + { + name := "SymbolicVariable"; + const_params := []; + ty_params := [ "F" ]; + fields := + [ + ("entry", Ty.path "p3_uni_stark::symbolic_variable::Entry"); + ("index", Ty.path "usize"); + ("_phantom", Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ]) + ]; + } *) + + Module Impl_core_marker_Copy_where_core_marker_Copy_F_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_F_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + + Module Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]. + + (* Clone *) + Definition clone (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "p3_uni_stark::symbolic_variable::SymbolicVariable" + [ + ("entry", + M.call_closure (| + Ty.path "p3_uni_stark::symbolic_variable::Entry", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "p3_uni_stark::symbolic_variable::Entry", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_variable::SymbolicVariable", + "entry" + |) + |) + |) + |) + ] + |)); + ("index", + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "usize", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_variable::SymbolicVariable", + "index" + |) + |) + |) + |) + ] + |)); + ("_phantom", + M.call_closure (| + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply (Ty.path "core::marker::PhantomData") [] [ F ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_variable::SymbolicVariable", + "_phantom" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("clone", InstanceField.Method (clone F)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_F_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]. + + (* Debug *) + Definition fmt (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "SymbolicVariable" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "entry" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_variable::SymbolicVariable", + "entry" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "index" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_variable::SymbolicVariable", + "index" + |) + |) + |) + |)); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "_phantom" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_variable::SymbolicVariable", + "_phantom" + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self F) + (* Instance *) [ ("fmt", InstanceField.Method (fmt F)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_F_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + + Module Impl_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]. + + (* + pub const fn new(entry: Entry, index: usize) -> Self { + Self { + entry, + index, + _phantom: PhantomData, + } + } + *) + Definition new (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ entry; index ] => + ltac:(M.monadic + (let entry := M.alloc (| entry |) in + let index := M.alloc (| index |) in + Value.StructRecord + "p3_uni_stark::symbolic_variable::SymbolicVariable" + [ + ("entry", M.read (| entry |)); + ("index", M.read (| index |)); + ("_phantom", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "new" (new F). + Admitted. + Global Typeclasses Opaque new. + + (* + pub const fn degree_multiple(&self) -> usize { + match self.entry { + Entry::Preprocessed { .. } | Entry::Main { .. } | Entry::Permutation { .. } => 1, + Entry::Public | Entry::Challenge => 0, + } + } + *) + Definition degree_multiple + (F : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ], + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_uni_stark::symbolic_variable::SymbolicVariable", + "entry" + |), + [ + fun γ => + ltac:(M.monadic + (M.find_or_pattern (Ty.tuple []) (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Preprocessed" + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Main" + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Permutation" + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 1 |))) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (Ty.tuple []) (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Public" + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::symbolic_variable::Entry::Challenge" + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 0 |))) + | _ => M.impossible "wrong number of arguments" + end) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_degree_multiple : + forall (F : Ty.t), + M.IsAssociatedFunction.C (Self F) "degree_multiple" (degree_multiple F). + Admitted. + Global Typeclasses Opaque degree_multiple. + End Impl_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + + Module Impl_core_convert_From_where_p3_field_field_Field_F_p3_uni_stark_symbolic_variable_SymbolicVariable_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + Definition Self (F : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn from(value: SymbolicVariable) -> Self { + Self::Variable(value) + } + *) + Definition from (F : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "p3_uni_stark::symbolic_expression::SymbolicExpression::Variable" + [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F : Ty.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ] ] + (Self F) + (* Instance *) [ ("from", InstanceField.Method (from F)) ]. + End Impl_core_convert_From_where_p3_field_field_Field_F_p3_uni_stark_symbolic_variable_SymbolicVariable_F_for_p3_uni_stark_symbolic_expression_SymbolicExpression_F. + + Module Impl_core_ops_arith_Add_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]. + + (* type Output = SymbolicExpression; *) + Definition _Output (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn add(self, rhs: T) -> Self::Output { + SymbolicExpression::from(self) + rhs.into() + } + *) + Definition add (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ] + ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_trait_method (| + "core::convert::From", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [ Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ] + ], + "from", + [], + [] + |), + [ M.read (| self |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F T)); ("add", InstanceField.Method (add F T)) ]. + End Impl_core_ops_arith_Add_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + + Module Impl_core_ops_arith_Sub_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]. + + (* type Output = SymbolicExpression; *) + Definition _Output (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn sub(self, rhs: T) -> Self::Output { + SymbolicExpression::from(self) - rhs.into() + } + *) + Definition sub (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ] + ], + "sub", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_trait_method (| + "core::convert::From", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [ Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ] + ], + "from", + [], + [] + |), + [ M.read (| self |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F T)); ("sub", InstanceField.Method (sub F T)) ]. + End Impl_core_ops_arith_Sub_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + + Module Impl_core_ops_arith_Mul_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. + Definition Self (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ]. + + (* type Output = SymbolicExpression; *) + Definition _Output (F T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ]. + + (* + fn mul(self, rhs: T) -> Self::Output { + SymbolicExpression::from(self) * rhs.into() + } + *) + Definition mul (F T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self F T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + [], + [ Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ] + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_trait_method (| + "core::convert::From", + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ], + [], + [ Ty.apply (Ty.path "p3_uni_stark::symbolic_variable::SymbolicVariable") [] [ F ] + ], + "from", + [], + [] + |), + [ M.read (| self |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") [] [ F ], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::symbolic_expression::SymbolicExpression") + [] + [ F ] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (F T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self F T) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output F T)); ("mul", InstanceField.Method (mul F T)) ]. + End Impl_core_ops_arith_Mul_where_p3_field_field_Field_F_where_core_convert_Into_T_p3_uni_stark_symbolic_expression_SymbolicExpression_F_T_for_p3_uni_stark_symbolic_variable_SymbolicVariable_F. +End symbolic_variable. diff --git a/CoqOfRust/plonky3/uni-stark/src/verifier.rs b/CoqOfRust/plonky3/uni-stark/src/verifier.rs new file mode 100644 index 000000000..05e8c1002 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/verifier.rs @@ -0,0 +1,172 @@ +use alloc::vec; +use alloc::vec::Vec; + +use itertools::Itertools; +use p3_air::{Air, BaseAir}; +use p3_challenger::{CanObserve, CanSample, FieldChallenger}; +use p3_commit::{Pcs, PolynomialSpace}; +use p3_field::{BasedVectorSpace, Field, PrimeCharacteristicRing}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_util::zip_eq::zip_eq; +use tracing::instrument; + +use crate::symbolic_builder::{SymbolicAirBuilder, get_log_quotient_degree}; +use crate::{PcsError, Proof, StarkGenericConfig, Val, VerifierConstraintFolder}; + +#[instrument(skip_all)] +pub fn verify( + config: &SC, + air: &A, + proof: &Proof, + public_values: &Vec>, +) -> Result<(), VerificationError>> +where + SC: StarkGenericConfig, + A: Air>> + for<'a> Air>, +{ + let Proof { + commitments, + opened_values, + opening_proof, + degree_bits, + } = proof; + + let degree = 1 << degree_bits; + let log_quotient_degree = get_log_quotient_degree::, A>(air, 0, public_values.len()); + let quotient_degree = 1 << log_quotient_degree; + + let mut challenger = config.initialise_challenger(); + let pcs = config.pcs(); + let trace_domain = pcs.natural_domain_for_degree(degree); + let quotient_domain = + trace_domain.create_disjoint_domain(1 << (degree_bits + log_quotient_degree)); + let quotient_chunks_domains = quotient_domain.split_domains(quotient_degree); + + let air_width = >>::width(air); + let valid_shape = opened_values.trace_local.len() == air_width + && opened_values.trace_next.len() == air_width + && opened_values.quotient_chunks.len() == quotient_degree + && opened_values + .quotient_chunks + .iter() + .all(|qc| qc.len() == >>::DIMENSION); + if !valid_shape { + return Err(VerificationError::InvalidProofShape); + } + + // Observe the instance. + challenger.observe(Val::::from_usize(proof.degree_bits)); + // TODO: Might be best practice to include other instance data here in the transcript, like some + // encoding of the AIR. This protects against transcript collisions between distinct instances. + // Practically speaking though, the only related known attack is from failing to include public + // values. It's not clear if failing to include other instance data could enable a transcript + // collision, since most such changes would completely change the set of satisfying witnesses. + + challenger.observe(commitments.trace.clone()); + challenger.observe_slice(public_values); + let alpha: SC::Challenge = challenger.sample_algebra_element(); + challenger.observe(commitments.quotient_chunks.clone()); + + let zeta: SC::Challenge = challenger.sample(); + let zeta_next = trace_domain.next_point(zeta).unwrap(); + + pcs.verify( + vec![ + ( + commitments.trace.clone(), + vec![( + trace_domain, + vec![ + (zeta, opened_values.trace_local.clone()), + (zeta_next, opened_values.trace_next.clone()), + ], + )], + ), + ( + commitments.quotient_chunks.clone(), + zip_eq( + quotient_chunks_domains.iter(), + &opened_values.quotient_chunks, + VerificationError::InvalidProofShape, + )? + .map(|(domain, values)| (*domain, vec![(zeta, values.clone())])) + .collect_vec(), + ), + ], + opening_proof, + &mut challenger, + ) + .map_err(VerificationError::InvalidOpeningArgument)?; + + let zps = quotient_chunks_domains + .iter() + .enumerate() + .map(|(i, domain)| { + quotient_chunks_domains + .iter() + .enumerate() + .filter(|(j, _)| *j != i) + .map(|(_, other_domain)| { + other_domain.vanishing_poly_at_point(zeta) + * other_domain + .vanishing_poly_at_point(domain.first_point()) + .inverse() + }) + .product::() + }) + .collect_vec(); + + let quotient = opened_values + .quotient_chunks + .iter() + .enumerate() + .map(|(ch_i, ch)| { + // We checked in valid_shape the length of "ch" is equal to + // >>::DIMENSION. Hence + // the unwrap() will never panic. + zps[ch_i] + * ch.iter() + .enumerate() + .map(|(e_i, &c)| SC::Challenge::ith_basis_element(e_i).unwrap() * c) + .sum::() + }) + .sum::(); + + let sels = trace_domain.selectors_at_point(zeta); + + let main = VerticalPair::new( + RowMajorMatrixView::new_row(&opened_values.trace_local), + RowMajorMatrixView::new_row(&opened_values.trace_next), + ); + + let mut folder = VerifierConstraintFolder { + main, + public_values, + is_first_row: sels.is_first_row, + is_last_row: sels.is_last_row, + is_transition: sels.is_transition, + alpha, + accumulator: SC::Challenge::ZERO, + }; + air.eval(&mut folder); + let folded_constraints = folder.accumulator; + + // Finally, check that + // folded_constraints(zeta) / Z_H(zeta) = quotient(zeta) + if folded_constraints * sels.inv_vanishing != quotient { + return Err(VerificationError::OodEvaluationMismatch); + } + + Ok(()) +} + +#[derive(Debug)] +pub enum VerificationError { + InvalidProofShape, + /// An error occurred while verifying the claimed openings. + InvalidOpeningArgument(PcsErr), + /// Out-of-domain evaluation mismatch, i.e. `constraints(zeta)` did not match + /// `quotient(zeta) Z_H(zeta)`. + OodEvaluationMismatch, +} diff --git a/CoqOfRust/plonky3/uni-stark/src/verifier.v b/CoqOfRust/plonky3/uni-stark/src/verifier.v new file mode 100644 index 000000000..b76c58119 --- /dev/null +++ b/CoqOfRust/plonky3/uni-stark/src/verifier.v @@ -0,0 +1,9965 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module verifier. + (* #[instrument(skip_all)] *) + Definition verify (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ SC; A ], [ config; air; proof; public_values ] => + ltac:(M.monadic + (let config := M.alloc (| config |) in + let air := M.alloc (| air |) in + let proof := M.alloc (| proof |) in + let public_values := M.alloc (| public_values |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ]) (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := M.alloc (| Value.Tuple [] |) in + let __tracing_attr_span := M.copy (| Value.DeclaredButUndefined |) in + let __tracing_attr_guard := M.copy (| Value.DeclaredButUndefined |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ Ty.path "tracing_core::metadata::LevelFilter" ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic (Value.Bool false)) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_span, + M.read (| + let~ interest : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing_core::subscriber::Interest" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path "tracing_core::subscriber::Interest", + "never", + [], + [] + |), + [] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.path "tracing::span::Span" ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path "tracing_core::metadata::Level", + "INFO", + Ty.path "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + get_constant (| + "tracing::level_filters::STATIC_MAX_LEVEL", + Ty.path + "tracing_core::metadata::LevelFilter" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "tracing_core::metadata::Level", + [], + [ + Ty.path + "tracing_core::metadata::LevelFilter" + ], + "le", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + get_associated_constant (| + Ty.path + "tracing_core::metadata::Level", + "INFO", + Ty.path + "tracing_core::metadata::Level" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path + "tracing_core::metadata::LevelFilter", + M.get_associated_function (| + Ty.path + "tracing_core::metadata::LevelFilter", + "current", + [], + [] + |), + [] + |) + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.read (| + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.write (| + interest, + M.call_closure (| + Ty.path + "tracing_core::subscriber::Interest", + M.get_associated_function (| + Ty.path + "tracing_core::callsite::DefaultCallsite", + "interest", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::verifier::verify::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) in + M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path + "tracing_core::subscriber::Interest", + "is_never", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + interest + |) + ] + |) + |) + |) + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_function (| + "tracing::__macro_support::__is_enabled", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::verifier::verify::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |); + M.read (| interest |) + ] + |))) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ meta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::verifier::verify::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "new", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "tracing_core::field::ValueSet", + M.get_associated_function (| + Ty.path "tracing_core::field::FieldSet", + "value_set", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::Field" + ]; + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.dyn + [ + ("tracing_core::field::Value::Trait", + []) + ] + ] + ] + ] + ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::field::FieldSet" + ], + M.get_associated_function (| + Ty.path + "tracing_core::metadata::Metadata", + "fields", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| meta |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [] |) + |) + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ span : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "tracing::span::Span" ] := + M.alloc (| + M.call_closure (| + Ty.path "tracing::span::Span", + M.get_function (| + "tracing::__macro_support::__disabled_span", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "tracing_core::metadata::Metadata" + ], + M.get_trait_method (| + "tracing_core::callsite::Callsite", + Ty.path + "tracing_core::callsite::DefaultCallsite", + [], + [], + "metadata", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + get_constant (| + "p3_uni_stark::verifier::verify::__CALLSITE", + Ty.apply + (Ty.path "&") + [] + [ + Ty.path + "tracing_core::callsite::DefaultCallsite" + ] + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| Value.Tuple [] |) in + span)) + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + __tracing_attr_guard, + M.call_closure (| + Ty.path "tracing::span::Entered", + M.get_associated_function (| + Ty.path "tracing::span::Span", + "enter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, __tracing_attr_span |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool false |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ __tracing_attr_fake_return : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ] + ] := + M.alloc (| + M.never_to_any (| + M.read (| + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.path "never" ], + ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + |) + |) + |) + |) in + M.return_ (| M.read (| __tracing_attr_fake_return |) |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ] + ], + proof, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::proof::Proof", + "commitments" + |) in + let γ1_1 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::proof::Proof", + "opened_values" + |) in + let γ1_2 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::proof::Proof", + "opening_proof" + |) in + let γ1_3 := + M.SubPointer.get_struct_record_field (| + γ, + "p3_uni_stark::proof::Proof", + "degree_bits" + |) in + let commitments := M.alloc (| γ1_0 |) in + let opened_values := M.alloc (| γ1_1 |) in + let opening_proof := M.alloc (| γ1_2 |) in + let degree_bits := M.alloc (| γ1_3 |) in + let~ degree : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.path "usize", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "usize" ] ], + "shl", + [], + [] + |), + [ Value.Integer IntegerKind.Usize 1; M.read (| degree_bits |) ] + |) + |) in + let~ log_quotient_degree : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "p3_uni_stark::symbolic_builder::get_log_quotient_degree", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + A + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| air |) |) |); + Value.Integer IntegerKind.Usize 0; + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| public_values |) |) + |) + ] + |) + ] + |) + |) in + let~ quotient_degree : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| log_quotient_degree |) ] + |) + |) in + let~ challenger : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + M.get_trait_method (| + "p3_uni_stark::config::StarkGenericConfig", + SC, + [], + [], + "initialise_challenger", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| config |) |) |) ] + |) + |) in + let~ pcs : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs" + ], + M.get_trait_method (| + "p3_uni_stark::config::StarkGenericConfig", + SC, + [], + [], + "pcs", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| config |) |) |) ] + |) + |) in + let~ trace_domain : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ], + "natural_domain_for_degree", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| pcs |) |) |); + M.read (| degree |) + ] + |) + |) in + let~ quotient_domain : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "create_disjoint_domain", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, trace_domain |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply (Ty.path "&") [] [ Ty.path "usize" ], + [], + [ Ty.path "usize" ], + "add", + [], + [] + |), + [ M.read (| degree_bits |); M.read (| log_quotient_degree |) ] + |) + ] + |) + ] + |) + |) in + let~ quotient_chunks_domains : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "split_domains", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, quotient_domain |); + M.read (| quotient_degree |) + ] + |) + |) in + let~ air_width : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "p3_air::air::BaseAir", + A, + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "width", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| air |) |) |) ] + |) + |) in + let~ valid_shape : Ty.apply (Ty.path "*") [] [ Ty.path "bool" ] := + M.alloc (| + LogicalOp.and (| + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| opened_values |) |), + "p3_uni_stark::proof::OpenedValues", + "trace_local" + |) + |) + ] + |); + M.read (| air_width |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| opened_values |) |), + "p3_uni_stark::proof::OpenedValues", + "trace_next" + |) + |) + ] + |); + M.read (| air_width |) + ] + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| opened_values |) |), + "p3_uni_stark::proof::OpenedValues", + "quotient_chunks" + |) + |) + ] + |); + M.read (| quotient_degree |) + ] + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "all", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| opened_values |) |), + "p3_uni_stark::proof::OpenedValues", + "quotient_chunks" + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let qc := M.copy (| γ |) in + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| qc |) |) + |) + ] + |); + M.read (| + get_constant (| + "p3_field::field::BasedVectorSpace::DIMENSION", + Ty.path "usize" + |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use (M.alloc (| UnOp.not (| M.read (| valid_shape |) |) |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_uni_stark::verifier::VerificationError::InvalidProofShape" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "observe", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, challenger |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + M.get_trait_method (| + "p3_field::field::PrimeCharacteristicRing", + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + [], + [], + "from_usize", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| proof |) |), + "p3_uni_stark::proof::Proof", + "degree_bits" + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment" + ], + "observe", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, challenger |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| commitments |) |), + "p3_uni_stark::proof::Commitments", + "trace" + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "observe_slice", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, challenger |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| public_values |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ alpha : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "p3_challenger::FieldChallenger", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "sample_algebra_element", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, challenger |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_challenger::CanObserve", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment" + ], + "observe", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, challenger |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| commitments |) |), + "p3_uni_stark::proof::Commitments", + "quotient_chunks" + |) + |) + ] + |) + ] + |) + |) in + let~ zeta : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "p3_challenger::CanSample", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "sample", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, challenger |) ] + |) + |) in + let~ zeta_next : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "next_point", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + |), + [ M.borrow (| Pointer.Kind.Ref, trace_domain |); M.read (| zeta |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ], + "map_err", + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ]; + Ty.function + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + (Ty.apply + (Ty.path "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ], + M.get_trait_method (| + "p3_commit::pcs::Pcs", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ], + "verify", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| pcs |) |) + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment"; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| commitments |) + |), + "p3_uni_stark::proof::Commitments", + "trace" + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "into_vec", + [], + [ Ty.path "alloc::alloc::Global" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.read (| + trace_domain + |); + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "into_vec", + [], + [ + Ty.path + "alloc::alloc::Global" + ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 2 + ] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.read (| + zeta + |); + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + opened_values + |) + |), + "p3_uni_stark::proof::OpenedValues", + "trace_local" + |) + |) + ] + |) + ]; + Value.Tuple + [ + M.read (| + zeta_next + |); + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + opened_values + |) + |), + "p3_uni_stark::proof::OpenedValues", + "trace_next" + |) + |) + ] + |) + ] + ] + |) + ] + |) + |)) + ] + |) + ] + ] + |) + ] + |) + |)) + ] + |) + ]; + Value.Tuple + [ + M.call_closure (| + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + M.get_trait_method (| + "core::clone::Clone", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Commitment", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| commitments |) + |), + "p3_uni_stark::proof::Commitments", + "quotient_chunks" + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]) + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]) + ] + |), + [ + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ]; + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "p3_util::zip_eq::ZipEq") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.apply + (Ty.path + "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ], + M.get_function (| + "p3_util::zip_eq::zip_eq", + [], + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ]; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.apply + (Ty.path + "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + quotient_chunks_domains + |) + ] + |) + |) + |) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| + M.read (| + opened_values + |) + |), + "p3_uni_stark::proof::OpenedValues", + "quotient_chunks" + |) + |); + Value.StructTuple + "p3_uni_stark::verifier::VerificationError::InvalidProofShape" + [] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := + M.copy (| + γ0_0 + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.tuple + []; + Ty.apply + (Ty.path + "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ + M.read (| + residual + |) + ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := + M.copy (| + γ0_0 + |) in + val)) + ] + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ]; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.tuple + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ] + ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let + domain := + M.copy (| + γ0_0 + |) in + let + values := + M.copy (| + γ0_1 + |) in + Value.Tuple + [ + M.read (| + M.deref (| + M.read (| + domain + |) + |) + |); + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ], + "into_vec", + [], + [ + Ty.path + "alloc::alloc::Global" + ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.read (| + M.call_closure (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path + "array") + [ + Value.Integer + IntegerKind.Usize + 1 + ] + [ + Ty.tuple + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ] + ] + ]; + Ty.path + "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [ + M.alloc (| + Value.Array + [ + Value.Tuple + [ + M.read (| + zeta + |); + M.call_closure (| + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + values + |) + |) + |) + ] + |) + ] + ] + |) + ] + |) + |)) + ] + |) + ])) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + ] + |) + ] + |) + |)) + ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| opening_proof |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| Pointer.Kind.MutRef, challenger |) + |) + |) + ] + |); + M.constructor_as_closure + "p3_uni_stark::verifier::VerificationError::InvalidOpeningArgument" + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.apply + (Ty.path + "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.apply + (Ty.path + "p3_uni_stark::verifier::VerificationError") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Error" + ] + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ zps : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "itertools::Itertools", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + [], + [], + "collect_vec", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ], + [], + [], + "map", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + quotient_chunks_domains + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let i := M.copy (| γ0_0 |) in + let domain := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::filter::Filter") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + ] + (Ty.path "bool") + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + [], + [], + "product", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::filter::Filter") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + ] + (Ty.path "bool") + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::filter::Filter") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + ] + (Ty.path "bool") + ], + [], + [], + "map", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::filter::Filter") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + ] + (Ty.path "bool") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ], + [], + [], + "filter", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + quotient_chunks_domains + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path + "&") + [] + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.read (| + γ + |) in + let γ1_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ1_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let j := + M.alloc (| + γ1_0 + |) in + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ + M.read (| + M.deref (| + M.read (| + j + |) + |) + |); + M.read (| i |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let other_domain := + M.copy (| γ0_1 |) in + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "vanishing_poly_at_point", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + other_domain + |) + |) + |); + M.read (| + zeta + |) + ] + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + M.get_trait_method (| + "p3_field::field::Field", + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + [], + [], + "inverse", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "vanishing_poly_at_point", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + other_domain + |) + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val", + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "first_point", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| + domain + |) + |) + |) + ] + |) + ] + |) + |) + |) + ] + |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ quotient : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + [], + [], + "sum", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + [], + [], + "map", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| opened_values |) |), + "p3_uni_stark::proof::OpenedValues", + "quotient_chunks" + |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ] + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| γ, 1 |) in + let ch_i := M.copy (| γ0_0 |) in + let ch := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "mul", + [], + [] + |), + [ + M.read (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + zps + |); + M.read (| ch_i |) + ] + |) + |) + |); + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + [], + [], + "sum", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::map::Map") + [] + [ + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ]; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ], + [], + [], + "map", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::slice::iter::Iter") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path + "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path + "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| ch |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.path + "usize"; + Ty.apply + (Ty.path + "&") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_tuple_field (| + γ, + 0 + |) in + let γ0_1 := + M.SubPointer.get_tuple_field (| + γ, + 1 + |) in + let e_i := + M.copy (| + γ0_0 + |) in + let γ0_1 := + M.read (| + γ0_1 + |) in + let c := + M.copy (| + γ0_1 + |) in + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_associated_function (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::option::Option") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + M.get_trait_method (| + "p3_field::field::BasedVectorSpace", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_commit::domain::PolynomialSpace" + [] + [] + (Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain") + "Val" + ], + "ith_basis_element", + [], + [] + |), + [ + M.read (| + e_i + |) + ] + |) + ] + |); + M.read (| c |) + ] + |))) + ] + |))) + | _ => + M.impossible + "wrong number of arguments" + end)) + ] + |) + ] + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |) in + let~ sels : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_commit::domain::LagrangeSelectors") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + M.get_trait_method (| + "p3_commit::domain::PolynomialSpace", + Ty.associated_in_trait + "p3_commit::pcs::Pcs" + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenger" + ] + (Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Pcs") + "Domain", + [], + [], + "selectors_at_point", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + |), + [ M.borrow (| Pointer.Kind.Ref, trace_domain |); M.read (| zeta |) ] + |) + |) in + let~ main : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::stack::VerticalPair") + [] + [ + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ]; + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ] + ], + "new", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ], + "new_row", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| opened_values |) |), + "p3_uni_stark::proof::OpenedValues", + "trace_local" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_matrix::dense::DenseMatrix") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ] + ], + "new_row", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge"; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| opened_values |) |), + "p3_uni_stark::proof::OpenedValues", + "trace_next" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ folder : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "p3_uni_stark::folder::VerifierConstraintFolder") + [] + [ SC ] + ] := + M.alloc (| + Value.StructRecord + "p3_uni_stark::folder::VerifierConstraintFolder" + [ + ("main", M.read (| main |)); + ("public_values", + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| public_values |) |) + |)); + ("is_first_row", + M.read (| + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "is_first_row" + |) + |)); + ("is_last_row", + M.read (| + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "is_last_row" + |) + |)); + ("is_transition", + M.read (| + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "is_transition" + |) + |)); + ("alpha", M.read (| alpha |)); + ("accumulator", + M.read (| + get_constant (| + "p3_field::field::PrimeCharacteristicRing::ZERO", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + |) + |)) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "p3_air::air::Air", + A, + [], + [ + Ty.apply + (Ty.path "p3_uni_stark::folder::VerifierConstraintFolder") + [] + [ SC ] + ], + "eval", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| air |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, folder |) |) + |) + ] + |) + |) in + let~ folded_constraints : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ] := + M.copy (| + M.SubPointer.get_struct_record_field (| + folder, + "p3_uni_stark::folder::VerifierConstraintFolder", + "accumulator" + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "ne", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge", + [], + [ + Ty.associated_in_trait + "p3_uni_stark::config::StarkGenericConfig" + [] + [] + SC + "Challenge" + ], + "mul", + [], + [] + |), + [ + M.read (| folded_constraints |); + M.read (| + M.SubPointer.get_struct_record_field (| + sels, + "p3_commit::domain::LagrangeSelectors", + "inv_vanishing" + |) + |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, quotient |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "p3_uni_stark::verifier::VerificationError::OodEvaluationMismatch" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple "core::result::Result::Ok" [ Value.Tuple [] ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_verify : + M.IsFunction.C "p3_uni_stark::verifier::verify" verify. + Admitted. + Global Typeclasses Opaque verify. + + (* + Enum VerificationError + { + const_params := []; + ty_params := [ "PcsErr" ]; + variants := + [ + { + name := "InvalidProofShape"; + item := StructTuple []; + }; + { + name := "InvalidOpeningArgument"; + item := StructTuple [ PcsErr ]; + }; + { + name := "OodEvaluationMismatch"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_VerificationError_InvalidProofShape : + M.IsDiscriminant "p3_uni_stark::verifier::VerificationError::InvalidProofShape" 0. + Axiom IsDiscriminant_VerificationError_InvalidOpeningArgument : + M.IsDiscriminant "p3_uni_stark::verifier::VerificationError::InvalidOpeningArgument" 1. + Axiom IsDiscriminant_VerificationError_OodEvaluationMismatch : + M.IsDiscriminant "p3_uni_stark::verifier::VerificationError::OodEvaluationMismatch" 2. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_PcsErr_for_p3_uni_stark_verifier_VerificationError_PcsErr. + Definition Self (PcsErr : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_uni_stark::verifier::VerificationError") [] [ PcsErr ]. + + (* Debug *) + Definition fmt (PcsErr : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self PcsErr in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ] + ], + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::verifier::VerificationError::InvalidProofShape" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "InvalidProofShape" |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "p3_uni_stark::verifier::VerificationError::InvalidOpeningArgument", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "InvalidOpeningArgument" |) |) + |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |)) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "p3_uni_stark::verifier::VerificationError::OodEvaluationMismatch" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "OodEvaluationMismatch" |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (PcsErr : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self PcsErr) + (* Instance *) [ ("fmt", InstanceField.Method (fmt PcsErr)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_PcsErr_for_p3_uni_stark_verifier_VerificationError_PcsErr. +End verifier. diff --git a/CoqOfRust/plonky3/util/src/array_serialization.rs b/CoqOfRust/plonky3/util/src/array_serialization.rs new file mode 100644 index 000000000..027eb5665 --- /dev/null +++ b/CoqOfRust/plonky3/util/src/array_serialization.rs @@ -0,0 +1,55 @@ +use alloc::vec::Vec; +use core::marker::PhantomData; + +use serde::de::{SeqAccess, Visitor}; +use serde::ser::SerializeTuple; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +pub fn serialize( + data: &[T; N], + ser: S, +) -> Result { + let mut s = ser.serialize_tuple(N)?; + for item in data { + s.serialize_element(item)?; + } + s.end() +} + +struct ArrayVisitor(PhantomData); + +impl<'de, T, const N: usize> Visitor<'de> for ArrayVisitor +where + T: Deserialize<'de>, +{ + type Value = [T; N]; + + fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + formatter.write_fmt(format_args!("an array of length {}", N)) + } + + #[inline] + fn visit_seq(self, mut seq: A) -> Result + where + A: SeqAccess<'de>, + { + let mut data = Vec::with_capacity(N); + for _ in 0..N { + match seq.next_element()? { + Some(val) => data.push(val), + None => return Err(serde::de::Error::invalid_length(N, &self)), + } + } + match data.try_into() { + Ok(arr) => Ok(arr), + Err(_) => unreachable!(), + } + } +} +pub fn deserialize<'de, D, T, const N: usize>(deserializer: D) -> Result<[T; N], D::Error> +where + D: Deserializer<'de>, + T: Deserialize<'de>, +{ + deserializer.deserialize_tuple(N, ArrayVisitor::(PhantomData)) +} diff --git a/CoqOfRust/plonky3/util/src/array_serialization.v b/CoqOfRust/plonky3/util/src/array_serialization.v new file mode 100644 index 000000000..f0f6c58a4 --- /dev/null +++ b/CoqOfRust/plonky3/util/src/array_serialization.v @@ -0,0 +1,1116 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module array_serialization. + (* + pub fn serialize( + data: &[T; N], + ser: S, + ) -> Result { + let mut s = ser.serialize_tuple(N)?; + for item in data { + s.serialize_element(item)?; + } + s.end() + } + *) + Definition serialize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ _ as S; T ], [ data; ser ] => + ltac:(M.monadic + (let data := M.alloc (| data |) in + let ser := M.alloc (| ser |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ s : + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "serde::ser::Serializer" [] [] S "SerializeTuple" ] := + M.copy (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.associated_in_trait "serde::ser::Serializer" [] [] S "SerializeTuple" ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Error" + ]; + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "SerializeTuple" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "SerializeTuple"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "SerializeTuple"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Error" + ], + M.get_trait_method (| + "serde::ser::Serializer", + S, + [], + [], + "serialize_tuple", + [], + [] + |), + [ M.read (| ser |); N ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ T ] ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| data |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ T ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let item := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.tuple []; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeTuple", + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "SerializeTuple", + [], + [], + "serialize_element", + [], + [ T ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, s |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| item |) |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Ok"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.associated_in_trait + "serde::ser::Serializer" + [] + [] + S + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Ok"; + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "Error" + ], + M.get_trait_method (| + "serde::ser::SerializeTuple", + Ty.associated_in_trait "serde::ser::Serializer" [] [] S "SerializeTuple", + [], + [], + "end", + [], + [] + |), + [ M.read (| s |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_serialize : + M.IsFunction.C "p3_util::array_serialization::serialize" serialize. + Admitted. + Global Typeclasses Opaque serialize. + + (* StructTuple + { + name := "ArrayVisitor"; + const_params := [ "N" ]; + ty_params := [ "T" ]; + fields := [ Ty.apply (Ty.path "core::marker::PhantomData") [] [ T ] ]; + } *) + + Module Impl_serde_de_Visitor_where_serde_de_Deserialize_T_for_p3_util_array_serialization_ArrayVisitor_N_T. + Definition Self (N : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_util::array_serialization::ArrayVisitor") [ N ] [ T ]. + + (* type Value = [T; N]; *) + Definition _Value (N : Value.t) (T : Ty.t) : Ty.t := Ty.apply (Ty.path "array") [ N ] [ T ]. + + (* + fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + formatter.write_fmt(format_args!("an array of length {}", N)) + } + *) + Definition expecting + (N : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N T in + match ε, τ, α with + | [], [], [ self; formatter ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let formatter := M.alloc (| formatter |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_fmt", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| formatter |) |) |); + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ Value.Integer IntegerKind.Usize 1; Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ mk_str (| "an array of length " |) ] |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, M.alloc (| N |) |) |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn visit_seq(self, mut seq: A) -> Result + where + A: SeqAccess<'de>, + { + let mut data = Vec::with_capacity(N); + for _ in 0..N { + match seq.next_element()? { + Some(val) => data.push(val), + None => return Err(serde::de::Error::invalid_length(N, &self)), + } + } + match data.try_into() { + Ok(arr) => Ok(arr), + Err(_) => unreachable!(), + } + } + *) + Definition visit_seq + (N : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N T in + match ε, τ, α with + | [], [ A ], [ self; seq ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let seq := M.alloc (| seq |) in + M.catch_return + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.associated_in_trait + "serde::de::Visitor" + [] + [] + (Ty.apply (Ty.path "p3_util::array_serialization::ArrayVisitor") [ N ] [ T ]) + "Value"; + Ty.associated_in_trait "serde::de::SeqAccess" [] [] A "Error" + ]) (| + ltac:(M.monadic + (M.read (| + let~ data : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + "with_capacity", + [], + [] + |), + [ N ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", Value.Integer IntegerKind.Usize 0); ("end_", N) ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::option::Option") [] [ T ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.associated_in_trait + "serde::de::SeqAccess" + [] + [] + A + "Error" + ]; + Ty.apply + (Ty.path "core::option::Option") + [] + [ T ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ T ]; + Ty.associated_in_trait + "serde::de::SeqAccess" + [] + [] + A + "Error" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ T ]; + Ty.associated_in_trait + "serde::de::SeqAccess" + [] + [] + A + "Error" + ], + M.get_trait_method (| + "serde::de::SeqAccess", + A, + [], + [], + "next_element", + [], + [ T ] + |), + [ M.borrow (| Pointer.Kind.MutRef, seq |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ T ]; + Ty.associated_in_trait + "serde::de::SeqAccess" + [] + [] + A + "Error" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ N ] + [ T ]; + Ty.associated_in_trait + "serde::de::SeqAccess" + [] + [] + A + "Error" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.associated_in_trait + "serde::de::SeqAccess" + [] + [] + A + "Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let val := M.copy (| γ0_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + "push", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, data |); + M.read (| val |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + M.call_closure (| + Ty.associated_in_trait + "serde::de::SeqAccess" + [] + [] + A + "Error", + M.get_trait_method (| + "serde::de::Error", + Ty.associated_in_trait + "serde::de::SeqAccess" + [] + [] + A + "Error", + [], + [], + "invalid_length", + [], + [] + |), + [ + N; + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + self + |) + |) + |)) + ] + |) + ] + |) + |) + |) + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ T ]; + Ty.associated_in_trait "serde::de::SeqAccess" [] [] A "Error" + ] + ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ T ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ T ] ], + "try_into", + [], + [] + |), + [ M.read (| data |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Ok", + 0 + |) in + let arr := M.copy (| γ0_0 |) in + M.alloc (| + Value.StructTuple "core::result::Result::Ok" [ M.read (| arr |) ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Err", + 0 + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "internal error: entered unreachable code" |) ] + |) + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (T : Ty.t), + M.IsTraitInstance + "serde::de::Visitor" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N T) + (* Instance *) + [ + ("Value", InstanceField.Ty (_Value N T)); + ("expecting", InstanceField.Method (expecting N T)); + ("visit_seq", InstanceField.Method (visit_seq N T)) + ]. + End Impl_serde_de_Visitor_where_serde_de_Deserialize_T_for_p3_util_array_serialization_ArrayVisitor_N_T. + + (* + pub fn deserialize<'de, D, T, const N: usize>(deserializer: D) -> Result<[T; N], D::Error> + where + D: Deserializer<'de>, + T: Deserialize<'de>, + { + deserializer.deserialize_tuple(N, ArrayVisitor::(PhantomData)) + } + *) + Definition deserialize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [ D; T ], [ deserializer ] => + ltac:(M.monadic + (let deserializer := M.alloc (| deserializer |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ T ]; + Ty.associated_in_trait "serde::de::Deserializer" [] [] D "Error" + ], + M.get_trait_method (| + "serde::de::Deserializer", + D, + [], + [], + "deserialize_tuple", + [], + [ Ty.apply (Ty.path "p3_util::array_serialization::ArrayVisitor") [ N ] [ T ] ] + |), + [ + M.read (| deserializer |); + N; + Value.StructTuple + "p3_util::array_serialization::ArrayVisitor" + [ Value.StructTuple "core::marker::PhantomData" [] ] + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_deserialize : + M.IsFunction.C "p3_util::array_serialization::deserialize" deserialize. + Admitted. + Global Typeclasses Opaque deserialize. +End array_serialization. diff --git a/CoqOfRust/plonky3/util/src/lib.rs b/CoqOfRust/plonky3/util/src/lib.rs new file mode 100644 index 000000000..eedab6565 --- /dev/null +++ b/CoqOfRust/plonky3/util/src/lib.rs @@ -0,0 +1,802 @@ +//! Various simple utilities. + +#![no_std] +#![feature(const_swap)] //gy@NOTE: to be added in workflow manually + +extern crate alloc; + +use alloc::slice; +use alloc::string::String; +use alloc::vec::Vec; +use core::any::type_name; +use core::hint::unreachable_unchecked; +use core::mem::{ManuallyDrop, MaybeUninit}; + +use crate::transpose::transpose_in_place_square; + +pub mod array_serialization; +pub mod linear_map; +pub mod transpose; +pub mod zip_eq; + +/// Computes `ceil(log_2(n))`. +#[must_use] +pub const fn log2_ceil_usize(n: usize) -> usize { + (usize::BITS - n.saturating_sub(1).leading_zeros()) as usize +} + +#[must_use] +pub fn log2_ceil_u64(n: u64) -> u64 { + (u64::BITS - n.saturating_sub(1).leading_zeros()).into() +} + +/// Computes `log_2(n)` +/// +/// # Panics +/// Panics if `n` is not a power of two. +#[must_use] +#[inline] +pub fn log2_strict_usize(n: usize) -> usize { + let res = n.trailing_zeros(); + assert_eq!(n.wrapping_shr(res), 1, "Not a power of two: {n}"); + // Tell the optimizer about the semantics of `log2_strict`. i.e. it can replace `n` with + // `1 << res` and vice versa. + assume(n == 1 << res); + res as usize +} + +/// Returns `[0, ..., N - 1]`. +#[must_use] +pub const fn indices_arr() -> [usize; N] { + let mut indices_arr = [0; N]; + let mut i = 0; + while i < N { + indices_arr[i] = i; + i += 1; + } + indices_arr +} + +#[inline] +pub const fn reverse_bits(x: usize, n: usize) -> usize { + // Assert that n is a power of 2 + debug_assert!(n.is_power_of_two()); + reverse_bits_len(x, n.trailing_zeros() as usize) +} + +#[inline] +pub const fn reverse_bits_len(x: usize, bit_len: usize) -> usize { + // NB: The only reason we need overflowing_shr() here as opposed + // to plain '>>' is to accommodate the case n == num_bits == 0, + // which would become `0 >> 64`. Rust thinks that any shift of 64 + // bits causes overflow, even when the argument is zero. + x.reverse_bits() + .overflowing_shr(usize::BITS - bit_len as u32) + .0 +} + +// Lookup table of 6-bit reverses. +// NB: 2^6=64 bytes is a cache line. A smaller table wastes cache space. +#[cfg(not(target_arch = "aarch64"))] +#[rustfmt::skip] +const BIT_REVERSE_6BIT: &[u8] = &[ + 0o00, 0o40, 0o20, 0o60, 0o10, 0o50, 0o30, 0o70, + 0o04, 0o44, 0o24, 0o64, 0o14, 0o54, 0o34, 0o74, + 0o02, 0o42, 0o22, 0o62, 0o12, 0o52, 0o32, 0o72, + 0o06, 0o46, 0o26, 0o66, 0o16, 0o56, 0o36, 0o76, + 0o01, 0o41, 0o21, 0o61, 0o11, 0o51, 0o31, 0o71, + 0o05, 0o45, 0o25, 0o65, 0o15, 0o55, 0o35, 0o75, + 0o03, 0o43, 0o23, 0o63, 0o13, 0o53, 0o33, 0o73, + 0o07, 0o47, 0o27, 0o67, 0o17, 0o57, 0o37, 0o77, +]; + +// Ensure that SMALL_ARR_SIZE >= 4 * BIG_T_SIZE. +const BIG_T_SIZE: usize = 1 << 14; +const SMALL_ARR_SIZE: usize = 1 << 16; + +/// Permutes `arr` such that each index is mapped to its reverse in binary. +/// +/// If the whole array fits in fast cache, then the trivial algorithm is cache friendly. Also, if +/// `T` is really big, then the trivial algorithm is cache-friendly, no matter the size of the array. +pub fn reverse_slice_index_bits(vals: &mut [F]) { + let n = vals.len(); + if n == 0 { + return; + } + let log_n = log2_strict_usize(n); + + // If the whole array fits in fast cache, then the trivial algorithm is cache friendly. Also, if + // `T` is really big, then the trivial algorithm is cache-friendly, no matter the size of the array. + if core::mem::size_of::() << log_n <= SMALL_ARR_SIZE + || core::mem::size_of::() >= BIG_T_SIZE + { + reverse_slice_index_bits_small(vals, log_n); + } else { + debug_assert!(n >= 4); // By our choice of `BIG_T_SIZE` and `SMALL_ARR_SIZE`. + + // Algorithm: + // + // Treat `arr` as a `sqrt(n)` by `sqrt(n)` row-major matrix. (Assume for now that `lb_n` is + // even, i.e., `n` is a square number.) To perform bit-order reversal we: + // 1. Bit-reverse the order of the rows. (They are contiguous in memory, so this is + // basically a series of large `memcpy`s.) + // 2. Transpose the matrix. + // 3. Bit-reverse the order of the rows. + // + // This is equivalent to, for every index `0 <= i < n`: + // 1. bit-reversing `i[lb_n / 2..lb_n]`, + // 2. swapping `i[0..lb_n / 2]` and `i[lb_n / 2..lb_n]`, + // 3. bit-reversing `i[lb_n / 2..lb_n]`. + // + // If `lb_n` is odd, i.e., `n` is not a square number, then the above procedure requires + // slight modification. At steps 1 and 3 we bit-reverse bits `ceil(lb_n / 2)..lb_n`, of the + // index (shuffling `floor(lb_n / 2)` chunks of length `ceil(lb_n / 2)`). At step 2, we + // perform _two_ transposes. We treat `arr` as two matrices, one where the middle bit of the + // index is `0` and another, where the middle bit is `1`; we transpose each individually. + + let lb_num_chunks = log_n >> 1; + let lb_chunk_size = log_n - lb_num_chunks; + unsafe { + reverse_slice_index_bits_chunks(vals, lb_num_chunks, lb_chunk_size); + transpose_in_place_square(vals, lb_chunk_size, lb_num_chunks, 0); + if lb_num_chunks != lb_chunk_size { + // `arr` cannot be interpreted as a square matrix. We instead interpret it as a + // `1 << lb_num_chunks` by `2` by `1 << lb_num_chunks` tensor, in row-major order. + // The above transpose acted on `tensor[..., 0, ...]` (all indices with middle bit + // `0`). We still need to transpose `tensor[..., 1, ...]`. To do so, we advance + // arr by `1 << lb_num_chunks` effectively, adding that to every index. + let vals_with_offset = &mut vals[1 << lb_num_chunks..]; + transpose_in_place_square(vals_with_offset, lb_chunk_size, lb_num_chunks, 0); + } + reverse_slice_index_bits_chunks(vals, lb_num_chunks, lb_chunk_size); + } + } +} + +// Both functions below are semantically equivalent to: +// for i in 0..n { +// result.push(arr[reverse_bits(i, n_power)]); +// } +// where reverse_bits(i, n_power) computes the n_power-bit reverse. The complications are there +// to guide the compiler to generate optimal assembly. + +#[cfg(not(target_arch = "aarch64"))] +fn reverse_slice_index_bits_small(vals: &mut [F], lb_n: usize) { + if lb_n <= 6 { + // BIT_REVERSE_6BIT holds 6-bit reverses. This shift makes them lb_n-bit reverses. + let dst_shr_amt = 6 - lb_n as u32; + #[allow(clippy::needless_range_loop)] + for src in 0..vals.len() { + let dst = (BIT_REVERSE_6BIT[src] as usize).wrapping_shr(dst_shr_amt); + if src < dst { + vals.swap(src, dst); + } + } + } else { + // LLVM does not know that it does not need to reverse src at each iteration (which is + // expensive on x86). We take advantage of the fact that the low bits of dst change rarely and the high + // bits of dst are dependent only on the low bits of src. + let dst_lo_shr_amt = usize::BITS - (lb_n - 6) as u32; + let dst_hi_shl_amt = lb_n - 6; + for src_chunk in 0..(vals.len() >> 6) { + let src_hi = src_chunk << 6; + let dst_lo = src_chunk.reverse_bits().wrapping_shr(dst_lo_shr_amt); + #[allow(clippy::needless_range_loop)] + for src_lo in 0..(1 << 6) { + let dst_hi = (BIT_REVERSE_6BIT[src_lo] as usize) << dst_hi_shl_amt; + let src = src_hi + src_lo; + let dst = dst_hi + dst_lo; + if src < dst { + vals.swap(src, dst); + } + } + } + } +} + +#[cfg(target_arch = "aarch64")] +fn reverse_slice_index_bits_small(vals: &mut [F], lb_n: usize) { + // Aarch64 can reverse bits in one instruction, so the trivial version works best. + for src in 0..vals.len() { + let dst = src.reverse_bits().wrapping_shr(usize::BITS - lb_n as u32); + if src < dst { + vals.swap(src, dst); + } + } +} + +/// Split `arr` chunks and bit-reverse the order of the chunks. There are `1 << lb_num_chunks` +/// chunks, each of length `1 << lb_chunk_size`. +/// SAFETY: ensure that `arr.len() == 1 << lb_num_chunks + lb_chunk_size`. +unsafe fn reverse_slice_index_bits_chunks( + vals: &mut [F], + lb_num_chunks: usize, + lb_chunk_size: usize, +) { + for i in 0..1usize << lb_num_chunks { + // `wrapping_shr` handles the silly case when `lb_num_chunks == 0`. + let j = i + .reverse_bits() + .wrapping_shr(usize::BITS - lb_num_chunks as u32); + if i < j { + unsafe { + core::ptr::swap_nonoverlapping( + vals.get_unchecked_mut(i << lb_chunk_size), + vals.get_unchecked_mut(j << lb_chunk_size), + 1 << lb_chunk_size, + ); + } + } + } +} + +#[inline(always)] +pub fn assume(p: bool) { + debug_assert!(p); + if !p { + unsafe { + unreachable_unchecked(); + } + } +} + +/// Try to force Rust to emit a branch. Example: +/// +/// ```no_run +/// let x = 100; +/// if x > 20 { +/// println!("x is big!"); +/// p3_util::branch_hint(); +/// } else { +/// println!("x is small!"); +/// } +/// ``` +/// +/// This function has no semantics. It is a hint only. +#[inline(always)] +pub fn branch_hint() { + // NOTE: These are the currently supported assembly architectures. See the + // [nightly reference](https://doc.rust-lang.org/nightly/reference/inline-assembly.html) for + // the most up-to-date list. + #[cfg(any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "riscv32", + target_arch = "riscv64", + target_arch = "x86", + target_arch = "x86_64", + ))] + unsafe { + core::arch::asm!("", options(nomem, nostack, preserves_flags)); + } +} + +/// Return a String containing the name of T but with all the crate +/// and module prefixes removed. +pub fn pretty_name() -> String { + let name = type_name::(); + let mut result = String::new(); + for qual in name.split_inclusive(&['<', '>', ',']) { + result.push_str(qual.split("::").last().unwrap()); + } + result +} + +/// A C-style buffered input reader, similar to +/// `core::iter::Iterator::next_chunk()` from nightly. +/// +/// Unsafe because the returned array may contain uninitialised +/// elements. +#[inline] +unsafe fn iter_next_chunk( + iter: &mut I, +) -> ([I::Item; BUFLEN], usize) +where + I::Item: Copy, +{ + let mut buf = unsafe { + let t = [const { MaybeUninit::::uninit() }; BUFLEN]; + // We are forced to use `transmute_copy` here instead of + // `transmute` because `BUFLEN` is a const generic parameter. + // The compiler *should* be smart enough not to emit a copy though. + core::mem::transmute_copy::<_, [I::Item; BUFLEN]>(&t) + }; + let mut i = 0; + + // Read BUFLEN values from `iter` into `buf` at a time. + for c in iter { + // Copy the next Item into `buf`. + unsafe { + *buf.get_unchecked_mut(i) = c; + i = i.unchecked_add(1); + } + // If `buf` is full + if i == BUFLEN { + break; + } + } + (buf, i) +} + +/// Split an iterator into small arrays and apply `func` to each. +/// +/// Repeatedly read `BUFLEN` elements from `input` into an array and +/// pass the array to `func` as a slice. If less than `BUFLEN` +/// elements are remaining, that smaller slice is passed to `func` (if +/// it is non-empty) and the function returns. +#[inline] +pub fn apply_to_chunks(input: I, mut func: H) +where + I: IntoIterator, + H: FnMut(&[I::Item]), +{ + let mut iter = input.into_iter(); + loop { + let (buf, n) = unsafe { iter_next_chunk::(&mut iter) }; + if n == 0 { + break; + } + func(unsafe { buf.get_unchecked(..n) }); + } +} + +/// Convert a vector of `BaseArray` elements to a vector of `Base` elements without any +/// reallocations. +/// +/// This is useful to convert `Vec<[F; N]>` to `Vec` or `Vec` to `Vec` where +/// `A` has the same size, alignment and memory layout as `[F; N]` for some `N`. It can also, +/// be used to safely convert `Vec` to `Vec` if `F` is a `32` bit field +/// or `Vec` to `Vec` if `F` is a `64` bit field. +/// +/// # Safety +/// +/// This is assumes that `BaseArray` has the same alignment and memory layout as `[Base; N]`. +/// As Rust guarantees that arrays elements are contiguous in memory and the alignment of +/// the array is the same as the alignment of its elements, this means that `BaseArray` +/// must have the same alignment as `Base`. +/// +/// # Panics +/// +/// This panics if the size of `BaseArray` is not a multiple of the size of `Base`. +#[inline] +pub unsafe fn flatten_to_base(vec: Vec) -> Vec { + debug_assert_eq!(align_of::(), align_of::()); + + assert!( + size_of::() % size_of::() == 0, + "Size of BaseArray (got {}) must be a multiple of the size of Base ({}).", + size_of::(), + size_of::() + ); + + let d = size_of::() / size_of::(); + // Prevent running `vec`'s destructor so we are in complete control + // of the allocation. + let mut values = ManuallyDrop::new(vec); + + // Each `Self` is an array of `d` elements, so the length and capacity of + // the new vector will be multiplied by `d`. + let new_len = values.len() * d; + let new_cap = values.capacity() * d; + + // Safe as BaseArray and Base have the same alignment. + let ptr = values.as_mut_ptr() as *mut Base; + + unsafe { + // Safety: + // - BaseArray and Base have the same alignment. + // - As size_of::() == size_of::() * d: + // -- The capacity of the new vector is equal to the capacity of the old vector. + // -- The first new_len elements of the new vector correspond to the first + // len elements of the old vector and so are properly initialized. + Vec::from_raw_parts(ptr, new_len, new_cap) + } +} + +/// Convert a vector of `Base` elements to a vector of `BaseArray` elements ideally without any +/// reallocations. +/// +/// This is an inverse of `flatten_to_base`. Unfortunately, unlike `flatten_to_base`, it may not be +/// possible to avoid allocations. This issue is that there is not way to guarantee that the capacity +/// of the vector is a multiple of `d`. +/// +/// # Safety +/// +/// This is assumes that `BaseArray` has the same alignment and memory layout as `[Base; N]`. +/// As Rust guarantees that arrays elements are contiguous in memory and the alignment of +/// the array is the same as the alignment of its elements, this means that `BaseArray` +/// must have the same alignment as `Base`. +/// +/// # Panics +/// +/// This panics if the size of `BaseArray` is not a multiple of the size of `Base`. +/// This panics if the length of the vector is not a multiple of the ratio of the sizes. +#[inline] +pub unsafe fn reconstitute_from_base(mut vec: Vec) -> Vec { + assert!( + size_of::() % size_of::() == 0, + "Size of BaseArray (got {}) must be a multiple of the size of Base ({}).", + size_of::(), + size_of::() + ); + + let d = size_of::() / size_of::(); + + assert!( + vec.len() % d == 0, + "Vector length (got {}) must be a multiple of the extension field dimension ({}).", + vec.len(), + d + ); + + let new_len = vec.len() / d; + + // We could call vec.shrink_to_fit() here to try and increase the probability that + // the capacity is a multiple of d. That might cause a reallocation though which + // would defeat the whole purpose. + let cap = vec.capacity(); + + // The assumption is that basically all callers of `reconstitute_from_base_vec` will be calling it + // with a vector constructed from `flatten_to_base` and so the capacity should be a multiple of `d`. + // But capacities can do strange things so we need to support both possibilities. + // Note that the `else` branch would also work if the capacity is a multiple of `d` but it is slower. + if cap % d == 0 { + // Prevent running `vec`'s destructor so we are in complete control + // of the allocation. + let mut values = ManuallyDrop::new(vec); + + // If we are on this branch then the capacity is a multiple of `d`. + let new_cap = cap / d; + + // Safe as BaseArray and Base have the same alignment. + let ptr = values.as_mut_ptr() as *mut BaseArray; + + unsafe { + // Safety: + // - BaseArray and Base have the same alignment. + // - As size_of::() == size_of::() / d: + // -- If we have reached this point, the length and capacity are both divisible by `d`. + // -- The capacity of the new vector is equal to the capacity of the old vector. + // -- The first new_len elements of the new vector correspond to the first + // len elements of the old vector and so are properly initialized. + Vec::from_raw_parts(ptr, new_len, new_cap) + } + } else { + // If the capacity is not a multiple of `D`, we go via slices. + + let buf_ptr = vec.as_mut_ptr().cast::(); + let slice = unsafe { + // Safety: + // - BaseArray and Base have the same alignment. + // - As size_of::() == size_of::() / D: + // -- If we have reached this point, the length is divisible by `D`. + // -- The first new_len elements of the slice correspond to the first + // len elements of the old slice and so are properly initialized. + slice::from_raw_parts(buf_ptr, new_len) + }; + + // Ideally the compiler could optimize this away to avoid the copy but it appears not to. + slice.to_vec() + } +} + +#[inline(always)] +pub const fn relatively_prime_u64(mut u: u64, mut v: u64) -> bool { + // Check that neither input is 0. + if u == 0 || v == 0 { + return false; + } + + // Check divisibility by 2. + if (u | v) & 1 == 0 { + return false; + } + + // Remove factors of 2 from `u` and `v` + u >>= u.trailing_zeros(); + if u == 1 { + return true; + } + + while v != 0 { + v >>= v.trailing_zeros(); + if v == 1 { + return true; + } + + // Ensure u <= v + if u > v { + core::mem::swap(&mut u, &mut v); + } + + // This looks inefficient for v >> u but thanks to the fact that we remove + // trailing_zeros of v in every iteration, it ends up much more performative + // than first glance implies. + v -= u + } + // If we made it through the loop, at no point is u or v equal to 1 and so the gcd + // must be greater than 1. + false +} + +#[cfg(test)] +mod tests { + use alloc::vec; + use alloc::vec::Vec; + + use rand::rngs::SmallRng; + use rand::{Rng, SeedableRng}; + + use super::*; + + #[test] + fn test_reverse_bits_len() { + assert_eq!(reverse_bits_len(0b0000000000, 10), 0b0000000000); + assert_eq!(reverse_bits_len(0b0000000001, 10), 0b1000000000); + assert_eq!(reverse_bits_len(0b1000000000, 10), 0b0000000001); + assert_eq!(reverse_bits_len(0b00000, 5), 0b00000); + assert_eq!(reverse_bits_len(0b01011, 5), 0b11010); + } + + #[test] + fn test_reverse_index_bits() { + let mut arg = vec![10, 20, 30, 40]; + reverse_slice_index_bits(&mut arg); + assert_eq!(arg, vec![10, 30, 20, 40]); + + let mut input256: Vec = (0..256).collect(); + #[rustfmt::skip] + let output256: Vec = vec![ + 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, + 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, + 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, + 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, + 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, + 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, + 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, + 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, + 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, + 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, + 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, + 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, + 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, + 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, + 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, + 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, + ]; + reverse_slice_index_bits(&mut input256[..]); + assert_eq!(input256, output256); + } + + #[test] + fn test_apply_to_chunks_exact_fit() { + const CHUNK_SIZE: usize = 4; + let input: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; + let mut results: Vec> = Vec::new(); + + apply_to_chunks::(input, |chunk| { + results.push(chunk.to_vec()); + }); + + assert_eq!(results, vec![vec![1, 2, 3, 4], vec![5, 6, 7, 8]]); + } + + #[test] + fn test_apply_to_chunks_with_remainder() { + const CHUNK_SIZE: usize = 3; + let input: Vec = vec![1, 2, 3, 4, 5, 6, 7]; + let mut results: Vec> = Vec::new(); + + apply_to_chunks::(input, |chunk| { + results.push(chunk.to_vec()); + }); + + assert_eq!(results, vec![vec![1, 2, 3], vec![4, 5, 6], vec![7]]); + } + + #[test] + fn test_apply_to_chunks_empty_input() { + const CHUNK_SIZE: usize = 4; + let input: Vec = vec![]; + let mut results: Vec> = Vec::new(); + + apply_to_chunks::(input, |chunk| { + results.push(chunk.to_vec()); + }); + + assert!(results.is_empty()); + } + + #[test] + fn test_apply_to_chunks_single_chunk() { + const CHUNK_SIZE: usize = 10; + let input: Vec = vec![1, 2, 3, 4, 5]; + let mut results: Vec> = Vec::new(); + + apply_to_chunks::(input, |chunk| { + results.push(chunk.to_vec()); + }); + + assert_eq!(results, vec![vec![1, 2, 3, 4, 5]]); + } + + #[test] + fn test_apply_to_chunks_large_chunk_size() { + const CHUNK_SIZE: usize = 100; + let input: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; + let mut results: Vec> = Vec::new(); + + apply_to_chunks::(input, |chunk| { + results.push(chunk.to_vec()); + }); + + assert_eq!(results, vec![vec![1, 2, 3, 4, 5, 6, 7, 8]]); + } + + #[test] + fn test_apply_to_chunks_large_input() { + const CHUNK_SIZE: usize = 5; + let input: Vec = (1..=20).collect(); + let mut results: Vec> = Vec::new(); + + apply_to_chunks::(input, |chunk| { + results.push(chunk.to_vec()); + }); + + assert_eq!( + results, + vec![ + vec![1, 2, 3, 4, 5], + vec![6, 7, 8, 9, 10], + vec![11, 12, 13, 14, 15], + vec![16, 17, 18, 19, 20] + ] + ); + } + + #[test] + fn test_reverse_slice_index_bits_random() { + let lengths = [32, 128, 1 << 16]; + let mut rng = SmallRng::seed_from_u64(1); + for _ in 0..32 { + for &length in &lengths { + let mut rand_list: Vec = Vec::with_capacity(length); + rand_list.resize_with(length, || rng.random()); + let expect = reverse_index_bits_naive(&rand_list); + + let mut actual = rand_list.clone(); + reverse_slice_index_bits(&mut actual); + + assert_eq!(actual, expect); + } + } + } + + #[test] + fn test_log2_strict_usize_edge_cases() { + assert_eq!(log2_strict_usize(1), 0); + assert_eq!(log2_strict_usize(2), 1); + assert_eq!(log2_strict_usize(1 << 18), 18); + assert_eq!(log2_strict_usize(1 << 31), 31); + assert_eq!( + log2_strict_usize(1 << (usize::BITS - 1)), + usize::BITS as usize - 1 + ); + } + + #[test] + #[should_panic] + fn test_log2_strict_usize_zero() { + let _ = log2_strict_usize(0); + } + + #[test] + #[should_panic] + fn test_log2_strict_usize_nonpower_2() { + let _ = log2_strict_usize(0x78c341c65ae6d262); + } + + #[test] + #[should_panic] + fn test_log2_strict_usize_max() { + let _ = log2_strict_usize(usize::MAX); + } + + #[test] + fn test_log2_ceil_usize_comprehensive() { + // Powers of 2 + assert_eq!(log2_ceil_usize(0), 0); + assert_eq!(log2_ceil_usize(1), 0); + assert_eq!(log2_ceil_usize(2), 1); + assert_eq!(log2_ceil_usize(1 << 18), 18); + assert_eq!(log2_ceil_usize(1 << 31), 31); + assert_eq!( + log2_ceil_usize(1 << (usize::BITS - 1)), + usize::BITS as usize - 1 + ); + + // Nonpowers; want to round up + assert_eq!(log2_ceil_usize(3), 2); + assert_eq!(log2_ceil_usize(0x14fe901b), 29); + assert_eq!( + log2_ceil_usize((1 << (usize::BITS - 1)) + 1), + usize::BITS as usize + ); + assert_eq!(log2_ceil_usize(usize::MAX - 1), usize::BITS as usize); + assert_eq!(log2_ceil_usize(usize::MAX), usize::BITS as usize); + } + + fn reverse_index_bits_naive(arr: &[T]) -> Vec { + let n = arr.len(); + let n_power = log2_strict_usize(n); + + let mut out = vec![None; n]; + for (i, v) in arr.iter().enumerate() { + let dst = i.reverse_bits() >> (usize::BITS - n_power as u32); + out[dst] = Some(*v); + } + + out.into_iter().map(|x| x.unwrap()).collect() + } + + #[test] + fn test_relatively_prime_u64() { + // Zero cases (should always return false) + assert!(!relatively_prime_u64(0, 0)); + assert!(!relatively_prime_u64(10, 0)); + assert!(!relatively_prime_u64(0, 10)); + assert!(!relatively_prime_u64(0, 123456789)); + + // Number with itself (if greater than 1, not relatively prime) + assert!(relatively_prime_u64(1, 1)); + assert!(!relatively_prime_u64(10, 10)); + assert!(!relatively_prime_u64(99999, 99999)); + + // Powers of 2 (always false since they share factor 2) + assert!(!relatively_prime_u64(2, 4)); + assert!(!relatively_prime_u64(16, 32)); + assert!(!relatively_prime_u64(64, 128)); + assert!(!relatively_prime_u64(1024, 4096)); + assert!(!relatively_prime_u64(u64::MAX, u64::MAX)); + + // One number is a multiple of the other (always false) + assert!(!relatively_prime_u64(5, 10)); + assert!(!relatively_prime_u64(12, 36)); + assert!(!relatively_prime_u64(15, 45)); + assert!(!relatively_prime_u64(100, 500)); + + // Co-prime numbers (should be true) + assert!(relatively_prime_u64(17, 31)); + assert!(relatively_prime_u64(97, 43)); + assert!(relatively_prime_u64(7919, 65537)); + assert!(relatively_prime_u64(15485863, 32452843)); + + // Small prime numbers (should be true) + assert!(relatively_prime_u64(13, 17)); + assert!(relatively_prime_u64(101, 103)); + assert!(relatively_prime_u64(1009, 1013)); + + // Large numbers (some cases where they are relatively prime or not) + assert!(!relatively_prime_u64( + 190266297176832000, + 10430732356495263744 + )); + assert!(!relatively_prime_u64( + 2040134905096275968, + 5701159354248194048 + )); + assert!(!relatively_prime_u64( + 16611311494648745984, + 7514969329383038976 + )); + assert!(!relatively_prime_u64( + 14863931409971066880, + 7911906750992527360 + )); + + // Max values + assert!(relatively_prime_u64(u64::MAX, 1)); + assert!(relatively_prime_u64(u64::MAX, u64::MAX - 1)); + assert!(!relatively_prime_u64(u64::MAX, u64::MAX)); + } +} diff --git a/CoqOfRust/plonky3/util/src/lib.v b/CoqOfRust/plonky3/util/src/lib.v new file mode 100644 index 000000000..0a0dd0da9 --- /dev/null +++ b/CoqOfRust/plonky3/util/src/lib.v @@ -0,0 +1,4412 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +(* +pub const fn log2_ceil_usize(n: usize) -> usize { + (usize::BITS - n.saturating_sub(1).leading_zeros()) as usize +} +*) +Definition log2_ceil_usize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ n ] => + ltac:(M.monadic + (let n := M.alloc (| n |) in + M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| get_associated_constant (| Ty.path "usize", "BITS", Ty.path "u32" |) |); + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "usize", "leading_zeros", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "saturating_sub", [], [] |), + [ M.read (| n |); Value.Integer IntegerKind.Usize 1 ] + |) + ] + |) + ] + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_log2_ceil_usize : + M.IsFunction.C "p3_util::log2_ceil_usize" log2_ceil_usize. +Admitted. +Global Typeclasses Opaque log2_ceil_usize. + +(* +pub fn log2_ceil_u64(n: u64) -> u64 { + (u64::BITS - n.saturating_sub(1).leading_zeros()).into() +} +*) +Definition log2_ceil_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ n ] => + ltac:(M.monadic + (let n := M.alloc (| n |) in + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::convert::Into", + Ty.path "u32", + [], + [ Ty.path "u64" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| get_associated_constant (| Ty.path "u64", "BITS", Ty.path "u32" |) |); + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u64", "leading_zeros", [], [] |), + [ + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| Ty.path "u64", "saturating_sub", [], [] |), + [ M.read (| n |); Value.Integer IntegerKind.U64 1 ] + |) + ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_log2_ceil_u64 : + M.IsFunction.C "p3_util::log2_ceil_u64" log2_ceil_u64. +Admitted. +Global Typeclasses Opaque log2_ceil_u64. + +(* +pub fn log2_strict_usize(n: usize) -> usize { + let res = n.trailing_zeros(); + assert_eq!(n.wrapping_shr(res), 1, "Not a power of two: {n}"); + // Tell the optimizer about the semantics of `log2_strict`. i.e. it can replace `n` with + // `1 << res` and vice versa. + assume(n == 1 << res); + res as usize +} +*) +Definition log2_strict_usize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ n ] => + ltac:(M.monadic + (let n := M.alloc (| n |) in + M.read (| + let~ res : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "usize", "trailing_zeros", [], [] |), + [ M.read (| n |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "wrapping_shr", [], [] |), + [ M.read (| n |); M.read (| res |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.alloc (| Value.Integer IntegerKind.Usize 1 |) |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 1; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "Not a power of two: " |) ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, n |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::assume", [], [] |), + [ + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| n |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| res |) ] + |) + ] + |) + ] + |) + |) in + M.alloc (| M.cast (Ty.path "usize") (M.read (| res |)) |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_log2_strict_usize : + M.IsFunction.C "p3_util::log2_strict_usize" log2_strict_usize. +Admitted. +Global Typeclasses Opaque log2_strict_usize. + +(* +pub const fn indices_arr() -> [usize; N] { + let mut indices_arr = [0; N]; + let mut i = 0; + while i < N { + indices_arr[i] = i; + i += 1; + } + indices_arr +} +*) +Definition indices_arr (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ N ], [], [] => + ltac:(M.monadic + (M.read (| + let~ indices_arr : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "usize" ] ] := + M.alloc (| repeat (| Value.Integer IntegerKind.Usize 0, N |) |) in + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| Ty.path "bool", BinOp.lt, [ M.read (| i |); N ] |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| indices_arr, M.read (| i |) |), + M.read (| i |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := i in + M.write (| + β, + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| β |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + indices_arr + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_indices_arr : M.IsFunction.C "p3_util::indices_arr" indices_arr. +Admitted. +Global Typeclasses Opaque indices_arr. + +(* +pub const fn reverse_bits(x: usize, n: usize) -> usize { + // Assert that n is a power of 2 + debug_assert!(n.is_power_of_two()); + reverse_bits_len(x, n.trailing_zeros() as usize) +} +*) +Definition reverse_bits (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x; n ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let n := M.alloc (| n |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "usize", + "is_power_of_two", + [], + [] + |), + [ M.read (| n |) ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: n.is_power_of_two()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::reverse_bits_len", [], [] |), + [ + M.read (| x |); + M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "usize", "trailing_zeros", [], [] |), + [ M.read (| n |) ] + |)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_reverse_bits : + M.IsFunction.C "p3_util::reverse_bits" reverse_bits. +Admitted. +Global Typeclasses Opaque reverse_bits. + +(* +pub const fn reverse_bits_len(x: usize, bit_len: usize) -> usize { + // NB: The only reason we need overflowing_shr() here as opposed + // to plain '>>' is to accommodate the case n == num_bits == 0, + // which would become `0 >> 64`. Rust thinks that any shift of 64 + // bits causes overflow, even when the argument is zero. + x.reverse_bits() + .overflowing_shr(usize::BITS - bit_len as u32) + .0 +} +*) +Definition reverse_bits_len (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x; bit_len ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + let bit_len := M.alloc (| bit_len |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple [ Ty.path "usize"; Ty.path "bool" ], + M.get_associated_function (| Ty.path "usize", "overflowing_shr", [], [] |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "reverse_bits", [], [] |), + [ M.read (| x |) ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_associated_constant (| Ty.path "usize", "BITS", Ty.path "u32" |) + |); + M.cast (Ty.path "u32") (M.read (| bit_len |)) + ] + |) + ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_reverse_bits_len : + M.IsFunction.C "p3_util::reverse_bits_len" reverse_bits_len. +Admitted. +Global Typeclasses Opaque reverse_bits_len. + +Definition value_BIT_REVERSE_6BIT (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + Value.Integer IntegerKind.U8 0; + Value.Integer IntegerKind.U8 32; + Value.Integer IntegerKind.U8 16; + Value.Integer IntegerKind.U8 48; + Value.Integer IntegerKind.U8 8; + Value.Integer IntegerKind.U8 40; + Value.Integer IntegerKind.U8 24; + Value.Integer IntegerKind.U8 56; + Value.Integer IntegerKind.U8 4; + Value.Integer IntegerKind.U8 36; + Value.Integer IntegerKind.U8 20; + Value.Integer IntegerKind.U8 52; + Value.Integer IntegerKind.U8 12; + Value.Integer IntegerKind.U8 44; + Value.Integer IntegerKind.U8 28; + Value.Integer IntegerKind.U8 60; + Value.Integer IntegerKind.U8 2; + Value.Integer IntegerKind.U8 34; + Value.Integer IntegerKind.U8 18; + Value.Integer IntegerKind.U8 50; + Value.Integer IntegerKind.U8 10; + Value.Integer IntegerKind.U8 42; + Value.Integer IntegerKind.U8 26; + Value.Integer IntegerKind.U8 58; + Value.Integer IntegerKind.U8 6; + Value.Integer IntegerKind.U8 38; + Value.Integer IntegerKind.U8 22; + Value.Integer IntegerKind.U8 54; + Value.Integer IntegerKind.U8 14; + Value.Integer IntegerKind.U8 46; + Value.Integer IntegerKind.U8 30; + Value.Integer IntegerKind.U8 62; + Value.Integer IntegerKind.U8 1; + Value.Integer IntegerKind.U8 33; + Value.Integer IntegerKind.U8 17; + Value.Integer IntegerKind.U8 49; + Value.Integer IntegerKind.U8 9; + Value.Integer IntegerKind.U8 41; + Value.Integer IntegerKind.U8 25; + Value.Integer IntegerKind.U8 57; + Value.Integer IntegerKind.U8 5; + Value.Integer IntegerKind.U8 37; + Value.Integer IntegerKind.U8 21; + Value.Integer IntegerKind.U8 53; + Value.Integer IntegerKind.U8 13; + Value.Integer IntegerKind.U8 45; + Value.Integer IntegerKind.U8 29; + Value.Integer IntegerKind.U8 61; + Value.Integer IntegerKind.U8 3; + Value.Integer IntegerKind.U8 35; + Value.Integer IntegerKind.U8 19; + Value.Integer IntegerKind.U8 51; + Value.Integer IntegerKind.U8 11; + Value.Integer IntegerKind.U8 43; + Value.Integer IntegerKind.U8 27; + Value.Integer IntegerKind.U8 59; + Value.Integer IntegerKind.U8 7; + Value.Integer IntegerKind.U8 39; + Value.Integer IntegerKind.U8 23; + Value.Integer IntegerKind.U8 55; + Value.Integer IntegerKind.U8 15; + Value.Integer IntegerKind.U8 47; + Value.Integer IntegerKind.U8 31; + Value.Integer IntegerKind.U8 63 + ] + |) + |) + |) + |)) + |))). + +Global Instance Instance_IsConstant_value_BIT_REVERSE_6BIT : + M.IsFunction.C "p3_util::BIT_REVERSE_6BIT" value_BIT_REVERSE_6BIT. +Admitted. +Global Typeclasses Opaque value_BIT_REVERSE_6BIT. + +Definition value_BIG_T_SIZE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; Value.Integer IntegerKind.I32 14 ] + |) + |))). + +Global Instance Instance_IsConstant_value_BIG_T_SIZE : + M.IsFunction.C "p3_util::BIG_T_SIZE" value_BIG_T_SIZE. +Admitted. +Global Typeclasses Opaque value_BIG_T_SIZE. + +Definition value_SMALL_ARR_SIZE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; Value.Integer IntegerKind.I32 16 ] + |) + |))). + +Global Instance Instance_IsConstant_value_SMALL_ARR_SIZE : + M.IsFunction.C "p3_util::SMALL_ARR_SIZE" value_SMALL_ARR_SIZE. +Admitted. +Global Typeclasses Opaque value_SMALL_ARR_SIZE. + +(* +pub fn reverse_slice_index_bits(vals: &mut [F]) { + let n = vals.len(); + if n == 0 { + return; + } + let log_n = log2_strict_usize(n); + + // If the whole array fits in fast cache, then the trivial algorithm is cache friendly. Also, if + // `T` is really big, then the trivial algorithm is cache-friendly, no matter the size of the array. + if core::mem::size_of::() << log_n <= SMALL_ARR_SIZE + || core::mem::size_of::() >= BIG_T_SIZE + { + reverse_slice_index_bits_small(vals, log_n); + } else { + debug_assert!(n >= 4); // By our choice of `BIG_T_SIZE` and `SMALL_ARR_SIZE`. + + // Algorithm: + // + // Treat `arr` as a `sqrt(n)` by `sqrt(n)` row-major matrix. (Assume for now that `lb_n` is + // even, i.e., `n` is a square number.) To perform bit-order reversal we: + // 1. Bit-reverse the order of the rows. (They are contiguous in memory, so this is + // basically a series of large `memcpy`s.) + // 2. Transpose the matrix. + // 3. Bit-reverse the order of the rows. + // + // This is equivalent to, for every index `0 <= i < n`: + // 1. bit-reversing `i[lb_n / 2..lb_n]`, + // 2. swapping `i[0..lb_n / 2]` and `i[lb_n / 2..lb_n]`, + // 3. bit-reversing `i[lb_n / 2..lb_n]`. + // + // If `lb_n` is odd, i.e., `n` is not a square number, then the above procedure requires + // slight modification. At steps 1 and 3 we bit-reverse bits `ceil(lb_n / 2)..lb_n`, of the + // index (shuffling `floor(lb_n / 2)` chunks of length `ceil(lb_n / 2)`). At step 2, we + // perform _two_ transposes. We treat `arr` as two matrices, one where the middle bit of the + // index is `0` and another, where the middle bit is `1`; we transpose each individually. + + let lb_num_chunks = log_n >> 1; + let lb_chunk_size = log_n - lb_num_chunks; + unsafe { + reverse_slice_index_bits_chunks(vals, lb_num_chunks, lb_chunk_size); + transpose_in_place_square(vals, lb_chunk_size, lb_num_chunks, 0); + if lb_num_chunks != lb_chunk_size { + // `arr` cannot be interpreted as a square matrix. We instead interpret it as a + // `1 << lb_num_chunks` by `2` by `1 << lb_num_chunks` tensor, in row-major order. + // The above transpose acted on `tensor[..., 0, ...]` (all indices with middle bit + // `0`). We still need to transpose `tensor[..., 1, ...]`. To do so, we advance + // arr by `1 << lb_num_chunks` effectively, adding that to every index. + let vals_with_offset = &mut vals[1 << lb_num_chunks..]; + transpose_in_place_square(vals_with_offset, lb_chunk_size, lb_num_chunks, 0); + } + reverse_slice_index_bits_chunks(vals, lb_num_chunks, lb_chunk_size); + } + } +} +*) +Definition reverse_slice_index_bits (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ F ], [ vals ] => + ltac:(M.monadic + (let vals := M.alloc (| vals |) in + M.catch_return (Ty.tuple []) (| + ltac:(M.monadic + (M.read (| + let~ n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| vals |) |) |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| n |); Value.Integer IntegerKind.Usize 0 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| Value.Tuple [] |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ log_n : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "p3_util::log2_strict_usize", [], [] |), + [ M.read (| n |) ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ F ] |), + [] + |); + M.read (| log_n |) + ] + |); + M.read (| + get_constant (| "p3_util::SMALL_ARR_SIZE", Ty.path "usize" |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ F ] |), + [] + |); + M.read (| + get_constant (| "p3_util::BIG_T_SIZE", Ty.path "usize" |) + |) + ] + |))) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::reverse_slice_index_bits_small", [], [ F ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| vals |) |) |); + M.read (| log_n |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.ge, + [ + M.read (| n |); + Value.Integer IntegerKind.Usize 4 + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: n >= 4" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ lb_num_chunks : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ M.read (| log_n |); Value.Integer IntegerKind.I32 1 ] + |) + |) in + let~ lb_chunk_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| log_n |); M.read (| lb_num_chunks |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::reverse_slice_index_bits_chunks", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| vals |) |) |); + M.read (| lb_num_chunks |); + M.read (| lb_chunk_size |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::transpose::transpose_in_place_square", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| vals |) |) |); + M.read (| lb_chunk_size |); + M.read (| lb_num_chunks |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ M.read (| lb_num_chunks |); M.read (| lb_chunk_size |) ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ vals_with_offset : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ F ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply (Ty.path "slice") [] [ F ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| vals |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| lb_num_chunks |) + ] + |)) + ] + ] + |) + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::transpose::transpose_in_place_square", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| vals_with_offset |) |) + |); + M.read (| lb_chunk_size |); + M.read (| lb_num_chunks |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::reverse_slice_index_bits_chunks", + [], + [ F ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| vals |) |) |); + M.read (| lb_num_chunks |); + M.read (| lb_chunk_size |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_reverse_slice_index_bits : + M.IsFunction.C "p3_util::reverse_slice_index_bits" reverse_slice_index_bits. +Admitted. +Global Typeclasses Opaque reverse_slice_index_bits. + +(* +fn reverse_slice_index_bits_small(vals: &mut [F], lb_n: usize) { + if lb_n <= 6 { + // BIT_REVERSE_6BIT holds 6-bit reverses. This shift makes them lb_n-bit reverses. + let dst_shr_amt = 6 - lb_n as u32; + #[allow(clippy::needless_range_loop)] + for src in 0..vals.len() { + let dst = (BIT_REVERSE_6BIT[src] as usize).wrapping_shr(dst_shr_amt); + if src < dst { + vals.swap(src, dst); + } + } + } else { + // LLVM does not know that it does not need to reverse src at each iteration (which is + // expensive on x86). We take advantage of the fact that the low bits of dst change rarely and the high + // bits of dst are dependent only on the low bits of src. + let dst_lo_shr_amt = usize::BITS - (lb_n - 6) as u32; + let dst_hi_shl_amt = lb_n - 6; + for src_chunk in 0..(vals.len() >> 6) { + let src_hi = src_chunk << 6; + let dst_lo = src_chunk.reverse_bits().wrapping_shr(dst_lo_shr_amt); + #[allow(clippy::needless_range_loop)] + for src_lo in 0..(1 << 6) { + let dst_hi = (BIT_REVERSE_6BIT[src_lo] as usize) << dst_hi_shl_amt; + let src = src_hi + src_lo; + let dst = dst_hi + dst_lo; + if src < dst { + vals.swap(src, dst); + } + } + } + } +} +*) +Definition reverse_slice_index_bits_small + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ vals; lb_n ] => + ltac:(M.monadic + (let vals := M.alloc (| vals |) in + let lb_n := M.alloc (| lb_n |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ M.read (| lb_n |); Value.Integer IntegerKind.Usize 6 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ dst_shr_amt : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ Value.Integer IntegerKind.U32 6; M.cast (Ty.path "u32") (M.read (| lb_n |)) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| vals |) |) |) + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let src := M.copy (| γ0_0 |) in + let~ dst : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "wrapping_shr", + [], + [] + |), + [ + M.cast + (Ty.path "usize") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + get_constant (| + "p3_util::BIT_REVERSE_6BIT", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u8" ] + ] + |) + |) + |), + M.read (| src |) + |) + |)); + M.read (| dst_shr_amt |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| src |); M.read (| dst |) ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "swap", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| vals |) |) + |); + M.read (| src |); + M.read (| dst |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))); + fun γ => + ltac:(M.monadic + (let~ dst_lo_shr_amt : Ty.apply (Ty.path "*") [] [ Ty.path "u32" ] := + M.alloc (| + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_associated_constant (| Ty.path "usize", "BITS", Ty.path "u32" |) + |); + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| lb_n |); Value.Integer IntegerKind.Usize 6 ] + |)) + ] + |) + |) in + let~ dst_hi_shl_amt : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| lb_n |); Value.Integer IntegerKind.Usize 6 ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shr, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| vals |) |) + |) + ] + |); + Value.Integer IntegerKind.I32 6 + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let src_chunk := M.copy (| γ0_0 |) in + let~ src_hi : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.read (| src_chunk |); + Value.Integer IntegerKind.I32 6 + ] + |) + |) in + let~ dst_lo : + Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "wrapping_shr", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "reverse_bits", + [], + [] + |), + [ M.read (| src_chunk |) ] + |); + M.read (| dst_lo_shr_amt |) + ] + |) + |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + Value.Integer IntegerKind.I32 6 + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let src_lo := M.copy (| γ0_0 |) in + let~ dst_hi : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.cast + (Ty.path "usize") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.read (| + get_constant (| + "p3_util::BIT_REVERSE_6BIT", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "slice") + [] + [ + Ty.path + "u8" + ] + ] + |) + |) + |), + M.read (| src_lo |) + |) + |)); + M.read (| dst_hi_shl_amt |) + ] + |) + |) in + let~ src : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| src_hi |); + M.read (| src_lo |) + ] + |) + |) in + let~ dst : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| dst_hi |); + M.read (| dst_lo |) + ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ + M.read (| src |); + M.read (| dst |) + ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ F ], + "swap", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + vals + |) + |) + |); + M.read (| src |); + M.read (| dst |) + ] + |) + |) in + M.alloc (| + Value.Tuple [] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple [] + |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_reverse_slice_index_bits_small : + M.IsFunction.C "p3_util::reverse_slice_index_bits_small" reverse_slice_index_bits_small. +Admitted. +Global Typeclasses Opaque reverse_slice_index_bits_small. + +(* +unsafe fn reverse_slice_index_bits_chunks( + vals: &mut [F], + lb_num_chunks: usize, + lb_chunk_size: usize, +) { + for i in 0..1usize << lb_num_chunks { + // `wrapping_shr` handles the silly case when `lb_num_chunks == 0`. + let j = i + .reverse_bits() + .wrapping_shr(usize::BITS - lb_num_chunks as u32); + if i < j { + unsafe { + core::ptr::swap_nonoverlapping( + vals.get_unchecked_mut(i << lb_chunk_size), + vals.get_unchecked_mut(j << lb_chunk_size), + 1 << lb_chunk_size, + ); + } + } + } +} +*) +Definition reverse_slice_index_bits_chunks + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ F ], [ vals; lb_num_chunks; lb_chunk_size ] => + ltac:(M.monadic + (let vals := M.alloc (| vals |) in + let lb_num_chunks := M.alloc (| lb_num_chunks |) in + let lb_chunk_size := M.alloc (| lb_chunk_size |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| lb_num_chunks |) ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ j : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "wrapping_shr", + [], + [] + |), + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "reverse_bits", + [], + [] + |), + [ M.read (| i |) ] + |); + M.call_closure (| + Ty.path "u32", + BinOp.Wrap.sub, + [ + M.read (| + get_associated_constant (| + Ty.path "usize", + "BITS", + Ty.path "u32" + |) + |); + M.cast (Ty.path "u32") (M.read (| lb_num_chunks |)) + ] + |) + ] + |) + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.lt, + [ M.read (| i |); M.read (| j |) ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "core::ptr::swap_nonoverlapping", + [], + [ F ] + |), + [ + M.borrow (| + Pointer.Kind.MutPointer, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "get_unchecked_mut", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| vals |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.read (| i |); + M.read (| lb_chunk_size |) + ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutPointer, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ F ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ F ], + "get_unchecked_mut", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| vals |) |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.read (| j |); + M.read (| lb_chunk_size |) + ] + |) + ] + |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| lb_chunk_size |) + ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_reverse_slice_index_bits_chunks : + M.IsFunction.C "p3_util::reverse_slice_index_bits_chunks" reverse_slice_index_bits_chunks. +Admitted. +Global Typeclasses Opaque reverse_slice_index_bits_chunks. + +(* +pub fn assume(p: bool) { + debug_assert!(p); + if !p { + unsafe { + unreachable_unchecked(); + } + } +} +*) +Definition assume (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ p ] => + ltac:(M.monadic + (let p := M.alloc (| p |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| UnOp.not (| M.read (| p |) |) |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: p" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| UnOp.not (| M.read (| p |) |) |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::hint::unreachable_unchecked", [], [] |), + [] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_assume : M.IsFunction.C "p3_util::assume" assume. +Admitted. +Global Typeclasses Opaque assume. + +(* +pub fn branch_hint() { + // NOTE: These are the currently supported assembly architectures. See the + // [nightly reference](https://doc.rust-lang.org/nightly/reference/inline-assembly.html) for + // the most up-to-date list. + #[cfg(any( + target_arch = "aarch64", + target_arch = "arm", + target_arch = "riscv32", + target_arch = "riscv64", + target_arch = "x86", + target_arch = "x86_64", + ))] + unsafe { + core::arch::asm!("", options(nomem, nostack, preserves_flags)); + } +} +*) +Definition branch_hint (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := InlineAssembly in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_branch_hint : M.IsFunction.C "p3_util::branch_hint" branch_hint. +Admitted. +Global Typeclasses Opaque branch_hint. + +(* +pub fn pretty_name() -> String { + let name = type_name::(); + let mut result = String::new(); + for qual in name.split_inclusive(&['<', '>', ',']) { + result.push_str(qual.split("::").last().unwrap()); + } + result +} +*) +Definition pretty_name (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [] => + ltac:(M.monadic + (M.read (| + let~ name : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_function (| "core::any::type_name", [], [ T ] |), + [] + |) + |) in + let~ result : Ty.apply (Ty.path "*") [] [ Ty.path "alloc::string::String" ] := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_associated_function (| Ty.path "alloc::string::String", "new", [], [] |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::str::iter::SplitInclusive") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ Ty.path "char" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::str::iter::SplitInclusive") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ Ty.path "char" ] + ] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::str::iter::SplitInclusive") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ Ty.path "char" ] + ] + ], + M.get_associated_function (| + Ty.path "str", + "split_inclusive", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ Ty.path "char" ] + ] + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| name |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ Value.UnicodeChar 60; Value.UnicodeChar 62; Value.UnicodeChar 44 ] + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::str::iter::SplitInclusive") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ Ty.path "char" ] + ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let qual := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloc::string::String", + "push_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, result |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::str::iter::Split") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ], + [], + [], + "last", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::str::iter::Split") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ], + M.get_associated_function (| + Ty.path "str", + "split", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| qual |) |) + |); + mk_str (| "::" |) + ] + |) + ] + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + result + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_pretty_name : M.IsFunction.C "p3_util::pretty_name" pretty_name. +Admitted. +Global Typeclasses Opaque pretty_name. + +(* +unsafe fn iter_next_chunk( + iter: &mut I, +) -> ([I::Item; BUFLEN], usize) +where + I::Item: Copy, +{ + let mut buf = unsafe { + let t = [const { MaybeUninit::::uninit() }; BUFLEN]; + // We are forced to use `transmute_copy` here instead of + // `transmute` because `BUFLEN` is a const generic parameter. + // The compiler *should* be smart enough not to emit a copy though. + core::mem::transmute_copy::<_, [I::Item; BUFLEN]>(&t) + }; + let mut i = 0; + + // Read BUFLEN values from `iter` into `buf` at a time. + for c in iter { + // Copy the next Item into `buf`. + unsafe { + *buf.get_unchecked_mut(i) = c; + i = i.unchecked_add(1); + } + // If `buf` is full + if i == BUFLEN { + break; + } + } + (buf, i) +} +*) +Definition iter_next_chunk (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ BUFLEN ], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.read (| + let~ buf : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ BUFLEN ] + [ Ty.associated_in_trait "core::iter::traits::iterator::Iterator" [] [] I "Item" ] + ] := + M.copy (| + let~ t : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "array") + [ BUFLEN ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + I + "Item" + ] + ] + ] := + M.alloc (| + repeat (| + M.read (| + get_constant (| + "p3_util::iter_next_chunk_discriminant", + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + I + "Item" + ] + |) + |), + BUFLEN + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ BUFLEN ] + [ Ty.associated_in_trait "core::iter::traits::iterator::Iterator" [] [] I "Item" + ], + M.get_function (| + "core::mem::transmute_copy", + [], + [ + Ty.apply + (Ty.path "array") + [ BUFLEN ] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + I + "Item" + ] + ]; + Ty.apply + (Ty.path "array") + [ BUFLEN ] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + I + "Item" + ] + ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.borrow (| Pointer.Kind.Ref, t |) |) |) + ] + |) + |) + |) in + let~ i : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ I ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&mut") [] [ I ], + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| iter |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + I + "Item" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "&mut") [] [ I ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let c := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + I + "Item" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + I + "Item" + ], + "get_unchecked_mut", + [], + [ Ty.path "usize" ] + |), + [ + (* Unsize *) + M.pointer_coercion + (M.borrow (| Pointer.Kind.MutRef, buf |)); + M.read (| i |) + ] + |) + |), + M.read (| c |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.write (| + i, + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "unchecked_add", + [], + [] + |), + [ M.read (| i |); Value.Integer IntegerKind.Usize 1 ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| i |); BUFLEN ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + M.alloc (| Value.Tuple [ M.read (| buf |); M.read (| i |) ] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_iter_next_chunk : + M.IsFunction.C "p3_util::iter_next_chunk" iter_next_chunk. +Admitted. +Global Typeclasses Opaque iter_next_chunk. + +(* +pub fn apply_to_chunks(input: I, mut func: H) +where + I: IntoIterator, + H: FnMut(&[I::Item]), +{ + let mut iter = input.into_iter(); + loop { + let (buf, n) = unsafe { iter_next_chunk::(&mut iter) }; + if n == 0 { + break; + } + func(unsafe { buf.get_unchecked(..n) }); + } +} +*) +Definition apply_to_chunks (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ BUFLEN ], [ _ as I; H ], [ input; func ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + let func := M.alloc (| func |) in + M.read (| + let~ iter : + Ty.apply + (Ty.path "*") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] := + M.alloc (| + M.call_closure (| + Ty.associated_in_trait "core::iter::traits::collect::IntoIterator" [] [] I "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + I, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| input |) ] + |) + |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.tuple + [ Ty.apply (Ty.path "array") [ BUFLEN ] [ Ty.path "u8" ]; Ty.path "usize" ], + M.get_function (| + "p3_util::iter_next_chunk", + [ BUFLEN ], + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + I + "IntoIter" + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let buf := M.copy (| γ0_0 |) in + let n := M.copy (| γ0_1 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| n |); Value.Integer IntegerKind.Usize 0 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::function::FnMut", + H, + [], + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ], + "call_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, func |); + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "get_unchecked", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ] + |), + [ + (* Unsize *) + M.pointer_coercion (M.borrow (| Pointer.Kind.Ref, buf |)); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", M.read (| n |)) ] + ] + |) + |) + |) + ] + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |))) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_apply_to_chunks : + M.IsFunction.C "p3_util::apply_to_chunks" apply_to_chunks. +Admitted. +Global Typeclasses Opaque apply_to_chunks. + +(* +pub unsafe fn flatten_to_base(vec: Vec) -> Vec { + debug_assert_eq!(align_of::(), align_of::()); + + assert!( + size_of::() % size_of::() == 0, + "Size of BaseArray (got {}) must be a multiple of the size of Base ({}).", + size_of::(), + size_of::() + ); + + let d = size_of::() / size_of::(); + // Prevent running `vec`'s destructor so we are in complete control + // of the allocation. + let mut values = ManuallyDrop::new(vec); + + // Each `Self` is an array of `d` elements, so the length and capacity of + // the new vector will be multiplied by `d`. + let new_len = values.len() * d; + let new_cap = values.capacity() * d; + + // Safe as BaseArray and Base have the same alignment. + let ptr = values.as_mut_ptr() as *mut Base; + + unsafe { + // Safety: + // - BaseArray and Base have the same alignment. + // - As size_of::() == size_of::() * d: + // -- The capacity of the new vector is equal to the capacity of the old vector. + // -- The first new_len elements of the new vector correspond to the first + // len elements of the old vector and so are properly initialized. + Vec::from_raw_parts(ptr, new_len, new_cap) + } +} +*) +Definition flatten_to_base (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ Base; BaseArray ], [ vec ] => + ltac:(M.monadic + (let vec := M.alloc (| vec |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::align_of", [], [ Base ] |), + [] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::align_of", [], [ BaseArray ] |), + [] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.read (| M.deref (| M.read (| left_val |) |) |); + M.read (| M.deref (| M.read (| right_val |) |) |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ BaseArray ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Base ] |), + [] + |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ Value.Integer IntegerKind.Usize 3; Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "Size of BaseArray (got " |); + mk_str (| ") must be a multiple of the size of Base (" |); + mk_str (| ")." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ BaseArray ] + |), + [] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Base ] + |), + [] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ d : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ BaseArray ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Base ] |), + [] + |) + ] + |) + |) in + let~ values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |) ] + |) + |) in + let~ new_len : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, values |) ] + |) + |) + |) + ] + |); + M.read (| d |) + ] + |) + |) in + let~ new_cap : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.mul, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ], + "capacity", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, values |) ] + |) + |) + |) + ] + |); + M.read (| d |) + ] + |) + |) in + let~ ptr : Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "*mut") [] [ Base ] ] := + M.alloc (| + M.cast + (Ty.apply (Ty.path "*mut") [] [ Base ]) + (M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ BaseArray ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ], + "as_mut_ptr", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, values |) ] + |) + |) + |) + ] + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Base; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Base; Ty.path "alloc::alloc::Global" ], + "from_raw_parts", + [], + [] + |), + [ M.read (| ptr |); M.read (| new_len |); M.read (| new_cap |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_flatten_to_base : + M.IsFunction.C "p3_util::flatten_to_base" flatten_to_base. +Admitted. +Global Typeclasses Opaque flatten_to_base. + +(* +pub unsafe fn reconstitute_from_base(mut vec: Vec) -> Vec { + assert!( + size_of::() % size_of::() == 0, + "Size of BaseArray (got {}) must be a multiple of the size of Base ({}).", + size_of::(), + size_of::() + ); + + let d = size_of::() / size_of::(); + + assert!( + vec.len() % d == 0, + "Vector length (got {}) must be a multiple of the extension field dimension ({}).", + vec.len(), + d + ); + + let new_len = vec.len() / d; + + // We could call vec.shrink_to_fit() here to try and increase the probability that + // the capacity is a multiple of d. That might cause a reallocation though which + // would defeat the whole purpose. + let cap = vec.capacity(); + + // The assumption is that basically all callers of `reconstitute_from_base_vec` will be calling it + // with a vector constructed from `flatten_to_base` and so the capacity should be a multiple of `d`. + // But capacities can do strange things so we need to support both possibilities. + // Note that the `else` branch would also work if the capacity is a multiple of `d` but it is slower. + if cap % d == 0 { + // Prevent running `vec`'s destructor so we are in complete control + // of the allocation. + let mut values = ManuallyDrop::new(vec); + + // If we are on this branch then the capacity is a multiple of `d`. + let new_cap = cap / d; + + // Safe as BaseArray and Base have the same alignment. + let ptr = values.as_mut_ptr() as *mut BaseArray; + + unsafe { + // Safety: + // - BaseArray and Base have the same alignment. + // - As size_of::() == size_of::() / d: + // -- If we have reached this point, the length and capacity are both divisible by `d`. + // -- The capacity of the new vector is equal to the capacity of the old vector. + // -- The first new_len elements of the new vector correspond to the first + // len elements of the old vector and so are properly initialized. + Vec::from_raw_parts(ptr, new_len, new_cap) + } + } else { + // If the capacity is not a multiple of `D`, we go via slices. + + let buf_ptr = vec.as_mut_ptr().cast::(); + let slice = unsafe { + // Safety: + // - BaseArray and Base have the same alignment. + // - As size_of::() == size_of::() / D: + // -- If we have reached this point, the length is divisible by `D`. + // -- The first new_len elements of the slice correspond to the first + // len elements of the old slice and so are properly initialized. + slice::from_raw_parts(buf_ptr, new_len) + }; + + // Ideally the compiler could optimize this away to avoid the copy but it appears not to. + slice.to_vec() + } +} +*) +Definition reconstitute_from_base (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ Base; BaseArray ], [ vec ] => + ltac:(M.monadic + (let vec := M.alloc (| vec |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ BaseArray ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Base ] |), + [] + |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ Value.Integer IntegerKind.Usize 3; Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "Size of BaseArray (got " |); + mk_str (| ") must be a multiple of the size of Base (" |); + mk_str (| ")." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ BaseArray ] + |), + [] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Base ] + |), + [] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ d : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ BaseArray ] |), + [] + |); + M.call_closure (| + Ty.path "usize", + M.get_function (| "core::mem::size_of", [], [ Base ] |), + [] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Base; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec |) ] + |); + M.read (| d |) + ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ Value.Integer IntegerKind.Usize 3; Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "Vector length (got " |); + mk_str (| + ") must be a multiple of the extension field dimension (" + |); + mk_str (| ")." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Base; Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec |) ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, d |) |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ new_len : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Base; Ty.path "alloc::alloc::Global" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec |) ] + |); + M.read (| d |) + ] + |) + |) in + let~ cap : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Base; Ty.path "alloc::alloc::Global" ], + "capacity", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, vec |) ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ BaseArray; Ty.path "alloc::alloc::Global" ] + ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.rem, + [ M.read (| cap |); M.read (| d |) ] + |); + Value.Integer IntegerKind.Usize 0 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ values : + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Base; Ty.path "alloc::alloc::Global" ] + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Base; Ty.path "alloc::alloc::Global" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Base; Ty.path "alloc::alloc::Global" ] + ], + "new", + [], + [] + |), + [ M.read (| vec |) ] + |) + |) in + let~ new_cap : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.div, + [ M.read (| cap |); M.read (| d |) ] + |) + |) in + let~ ptr : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "*mut") [] [ BaseArray ] ] := + M.alloc (| + M.cast + (Ty.apply (Ty.path "*mut") [] [ BaseArray ]) + (M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ Base ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Base; Ty.path "alloc::alloc::Global" ], + "as_mut_ptr", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Base; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Base; Ty.path "alloc::alloc::Global" ] + ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, values |) ] + |) + |) + |) + ] + |)) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ], + "from_raw_parts", + [], + [] + |), + [ M.read (| ptr |); M.read (| new_len |); M.read (| new_cap |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let~ buf_ptr : + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "*mut") [] [ BaseArray ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ BaseArray ], + M.get_associated_function (| + Ty.apply (Ty.path "*mut") [] [ Base ], + "cast", + [], + [ BaseArray ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ Base ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Base; Ty.path "alloc::alloc::Global" ], + "as_mut_ptr", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, vec |) ] + |) + ] + |) + |) in + let~ slice : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ BaseArray ] ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ BaseArray ] ], + M.get_function (| "core::slice::raw::from_raw_parts", [], [ BaseArray ] |), + [ + (* MutToConstPointer *) M.pointer_coercion (M.read (| buf_ptr |)); + M.read (| new_len |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ BaseArray; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ BaseArray ], + "to_vec", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_reconstitute_from_base : + M.IsFunction.C "p3_util::reconstitute_from_base" reconstitute_from_base. +Admitted. +Global Typeclasses Opaque reconstitute_from_base. + +(* +pub const fn relatively_prime_u64(mut u: u64, mut v: u64) -> bool { + // Check that neither input is 0. + if u == 0 || v == 0 { + return false; + } + + // Check divisibility by 2. + if (u | v) & 1 == 0 { + return false; + } + + // Remove factors of 2 from `u` and `v` + u >>= u.trailing_zeros(); + if u == 1 { + return true; + } + + while v != 0 { + v >>= v.trailing_zeros(); + if v == 1 { + return true; + } + + // Ensure u <= v + if u > v { + core::mem::swap(&mut u, &mut v); + } + + // This looks inefficient for v >> u but thanks to the fact that we remove + // trailing_zeros of v in every iteration, it ends up much more performative + // than first glance implies. + v -= u + } + // If we made it through the loop, at no point is u or v equal to 1 and so the gcd + // must be greater than 1. + false +} +*) +Definition relatively_prime_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ u; v ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + let v := M.alloc (| v |) in + M.catch_return (Ty.path "bool") (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| u |); Value.Integer IntegerKind.U64 0 ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| v |); Value.Integer IntegerKind.U64 0 ] + |))) + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| Value.Bool false |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_and, + [ + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.bit_or, + [ M.read (| u |); M.read (| v |) ] + |); + Value.Integer IntegerKind.U64 1 + ] + |); + Value.Integer IntegerKind.U64 0 + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| Value.Bool false |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := u in + M.write (| + β, + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shr, + [ + M.read (| β |); + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u64", "trailing_zeros", [], [] |), + [ M.read (| u |) ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| u |); Value.Integer IntegerKind.U64 1 ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| Value.Bool true |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.ne, + [ M.read (| v |); Value.Integer IntegerKind.U64 0 ] + |) + |)) in + let _ := + is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + let β := v in + M.write (| + β, + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.shr, + [ + M.read (| β |); + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.path "u64", + "trailing_zeros", + [], + [] + |), + [ M.read (| v |) ] + |) + ] + |) + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ M.read (| v |); Value.Integer IntegerKind.U64 1 ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Bool true |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.gt, + [ M.read (| u |); M.read (| v |) ] + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "core::mem::swap", + [], + [ Ty.path "u64" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, u |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, v |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + let β := v in + M.write (| + β, + M.call_closure (| + Ty.path "u64", + BinOp.Wrap.sub, + [ M.read (| β |); M.read (| u |) ] + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + M.alloc (| Value.Bool false |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + +Global Instance Instance_IsFunction_relatively_prime_u64 : + M.IsFunction.C "p3_util::relatively_prime_u64" relatively_prime_u64. +Admitted. +Global Typeclasses Opaque relatively_prime_u64. diff --git a/CoqOfRust/plonky3/util/src/linear_map.rs b/CoqOfRust/plonky3/util/src/linear_map.rs new file mode 100644 index 000000000..b8acb40a9 --- /dev/null +++ b/CoqOfRust/plonky3/util/src/linear_map.rs @@ -0,0 +1,68 @@ +use alloc::vec::Vec; +use core::mem; + +/// O(n) Vec-backed map for keys that only implement Eq. +/// Only use this for a very small number of keys, operations +/// on it can easily become O(n^2). +#[derive(Debug)] +pub struct LinearMap(Vec<(K, V)>); + +impl Default for LinearMap { + fn default() -> Self { + Self(Default::default()) + } +} + +impl LinearMap { + pub fn new() -> Self { + Default::default() + } + pub fn get(&self, k: &K) -> Option<&V> { + self.0.iter().find(|(kk, _)| kk == k).map(|(_, v)| v) + } + pub fn get_mut(&mut self, k: &K) -> Option<&mut V> { + self.0.iter_mut().find(|(kk, _)| kk == k).map(|(_, v)| v) + } + /// This is O(n), because we check for an existing entry. + pub fn insert(&mut self, k: K, mut v: V) -> Option { + if let Some(vv) = self.get_mut(&k) { + mem::swap(&mut v, vv); + Some(v) + } else { + self.0.push((k, v)); + None + } + } + pub fn get_or_insert_with(&mut self, k: K, f: impl FnOnce() -> V) -> &mut V { + let existing = self.0.iter().position(|(kk, _)| kk == &k); + if let Some(idx) = existing { + &mut self.0[idx].1 + } else { + self.0.push((k, f())); + let slot = self.0.last_mut().unwrap(); + &mut slot.1 + } + } + pub fn values(&self) -> impl Iterator { + self.0.iter().map(|(_, v)| v) + } +} + +impl FromIterator<(K, V)> for LinearMap { + /// This calls `insert` in a loop, so is O(n^2)!! + fn from_iter>(iter: T) -> Self { + let mut me = Self::default(); + for (k, v) in iter { + me.insert(k, v); + } + me + } +} + +impl IntoIterator for LinearMap { + type Item = (K, V); + type IntoIter = as IntoIterator>::IntoIter; + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} diff --git a/CoqOfRust/plonky3/util/src/linear_map.v b/CoqOfRust/plonky3/util/src/linear_map.v new file mode 100644 index 000000000..d77a983e9 --- /dev/null +++ b/CoqOfRust/plonky3/util/src/linear_map.v @@ -0,0 +1,1409 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module linear_map. + (* StructTuple + { + name := "LinearMap"; + const_params := []; + ty_params := [ "K"; "V" ]; + fields := + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ] + ]; + } *) + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_K_where_core_fmt_Debug_V_for_p3_util_linear_map_LinearMap_K_V. + Definition Self (K V : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ]. + + (* Debug *) + Definition fmt (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self K V in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "LinearMap" |) |) |); + (* Unsize *) + M.pointer_coercion + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_util::linear_map::LinearMap", + 0 + |) + |) + |) + |) + |) + |)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (K V : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self K V) + (* Instance *) [ ("fmt", InstanceField.Method (fmt K V)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_K_where_core_fmt_Debug_V_for_p3_util_linear_map_LinearMap_K_V. + + Module Impl_core_default_Default_for_p3_util_linear_map_LinearMap_K_V. + Definition Self (K V : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ]. + + (* + fn default() -> Self { + Self(Default::default()) + } + *) + Definition default (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self K V in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "p3_util::linear_map::LinearMap" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "default", + [], + [] + |), + [] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (K V : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self K V) + (* Instance *) [ ("default", InstanceField.Method (default K V)) ]. + End Impl_core_default_Default_for_p3_util_linear_map_LinearMap_K_V. + + Module Impl_p3_util_linear_map_LinearMap_K_V. + Definition Self (K V : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ]. + + (* + pub fn new() -> Self { + Default::default() + } + *) + Definition new (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self K V in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ], + M.get_trait_method (| + "core::default::Default", + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ], + [], + [], + "default", + [], + [] + |), + [] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (K V : Ty.t), + M.IsAssociatedFunction.C (Self K V) "new" (new K V). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn get(&self, k: &K) -> Option<&V> { + self.0.iter().find(|(kk, _)| kk == k).map(|(_, v)| v) + } + *) + Definition get (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self K V in + match ε, τ, α with + | [], [], [ self; k ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let k := M.alloc (| k |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.apply (Ty.path "&") [] [ V ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ], + "map", + [], + [ + Ty.apply (Ty.path "&") [] [ V ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ] ] + (Ty.apply (Ty.path "&") [] [ V ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.tuple [ K; V ] ], + [], + [], + "find", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.tuple [ K; V ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.tuple [ K; V ] ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.tuple [ K; V ] ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_util::linear_map::LinearMap", + 0 + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ := M.read (| γ |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let kk := M.alloc (| γ2_0 |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ K ], + [], + [ Ty.apply (Ty.path "&") [] [ K ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, kk |); + M.borrow (| Pointer.Kind.Ref, k |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ] ] + (Ty.apply (Ty.path "&") [] [ V ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let v := M.alloc (| γ1_1 |) in + M.read (| v |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_get : + forall (K V : Ty.t), + M.IsAssociatedFunction.C (Self K V) "get" (get K V). + Admitted. + Global Typeclasses Opaque get. + + (* + pub fn get_mut(&mut self, k: &K) -> Option<&mut V> { + self.0.iter_mut().find(|(kk, _)| kk == k).map(|(_, v)| v) + } + *) + Definition get_mut (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self K V in + match ε, τ, α with + | [], [], [ self; k ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let k := M.alloc (| k |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.apply (Ty.path "&mut") [] [ V ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&mut") [] [ Ty.tuple [ K; V ] ] ], + "map", + [], + [ + Ty.apply (Ty.path "&mut") [] [ V ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Ty.tuple [ K; V ] ] ] ] + (Ty.apply (Ty.path "&mut") [] [ V ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&mut") [] [ Ty.tuple [ K; V ] ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.tuple [ K; V ] ], + [], + [], + "find", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&mut") [] [ Ty.tuple [ K; V ] ] ] + ] + ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.tuple [ K; V ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.tuple [ K; V ] ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.tuple [ K; V ] ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_util::linear_map::LinearMap", + 0 + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "&mut") [] [ Ty.tuple [ K; V ] ] ] + ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ := M.read (| γ |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let kk := M.alloc (| γ2_0 |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ K ], + [], + [ Ty.apply (Ty.path "&") [] [ K ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, kk |); + M.borrow (| Pointer.Kind.Ref, k |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Ty.tuple [ K; V ] ] ] ] + (Ty.apply (Ty.path "&mut") [] [ V ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let v := M.alloc (| γ1_1 |) in + M.read (| v |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_get_mut : + forall (K V : Ty.t), + M.IsAssociatedFunction.C (Self K V) "get_mut" (get_mut K V). + Admitted. + Global Typeclasses Opaque get_mut. + + (* + pub fn insert(&mut self, k: K, mut v: V) -> Option { + if let Some(vv) = self.get_mut(&k) { + mem::swap(&mut v, vv); + Some(v) + } else { + self.0.push((k, v)); + None + } + } + *) + Definition insert (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self K V in + match ε, τ, α with + | [], [], [ self; k; v ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let k := M.alloc (| k |) in + let v := M.alloc (| v |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "core::option::Option") [] [ V ] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&mut") [] [ V ] ], + M.get_associated_function (| + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ], + "get_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, k |) |) + |) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let vv := M.copy (| γ0_0 |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "core::mem::swap", [], [ V ] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, v |) |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| vv |) |) |) + ] + |) + |) in + M.alloc (| + Value.StructTuple "core::option::Option::Some" [ M.read (| v |) ] + |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_util::linear_map::LinearMap", + 0 + |) + |); + Value.Tuple [ M.read (| k |); M.read (| v |) ] + ] + |) + |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_insert : + forall (K V : Ty.t), + M.IsAssociatedFunction.C (Self K V) "insert" (insert K V). + Admitted. + Global Typeclasses Opaque insert. + + (* + pub fn get_or_insert_with(&mut self, k: K, f: impl FnOnce() -> V) -> &mut V { + let existing = self.0.iter().position(|(kk, _)| kk == &k); + if let Some(idx) = existing { + &mut self.0[idx].1 + } else { + self.0.push((k, f())); + let slot = self.0.last_mut().unwrap(); + &mut slot.1 + } + } + *) + Definition get_or_insert_with + (K V : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self K V in + match ε, τ, α with + | [], [ impl_FnOnce___arrow_V ], [ self; k; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let k := M.alloc (| k |) in + let f := M.alloc (| f |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + let~ existing : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.tuple [ K; V ] ], + [], + [], + "position", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ] ] + (Ty.path "bool") + ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.tuple [ K; V ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.tuple [ K; V ] ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.tuple [ K; V ] ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_util::linear_map::LinearMap", + 0 + |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ + Ty.tuple + [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ] + ] + (Ty.path "bool") + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let kk := M.alloc (| γ1_0 |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ K ], + [], + [ Ty.apply (Ty.path "&") [] [ K ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, kk |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| M.borrow (| Pointer.Kind.Ref, k |) |) + |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.apply (Ty.path "&mut") [] [ V ] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := existing in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let idx := M.copy (| γ0_0 |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_tuple_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.tuple [ K; V ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ K; V ]; + Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_util::linear_map::LinearMap", + 0 + |) + |); + M.read (| idx |) + ] + |) + |), + 1 + |) + |) + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ], + "push", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_util::linear_map::LinearMap", + 0 + |) + |); + Value.Tuple + [ + M.read (| k |); + M.call_closure (| + V, + M.get_trait_method (| + "core::ops::function::FnOnce", + impl_FnOnce___arrow_V, + [], + [ Ty.tuple [] ], + "call_once", + [], + [] + |), + [ M.read (| f |); Value.Tuple [] ] + |) + ] + ] + |) + |) in + let~ slot : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "&mut") [] [ Ty.tuple [ K; V ] ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.tuple [ K; V ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&mut") [] [ Ty.tuple [ K; V ] ] ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&mut") [] [ Ty.tuple [ K; V ] ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.tuple [ K; V ] ], + "last_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.tuple [ K; V ] ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.tuple [ K; V ]; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_util::linear_map::LinearMap", + 0 + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_tuple_field (| + M.deref (| M.read (| slot |) |), + 1 + |) + |) + |) + |) + |))) + ] + |) + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_get_or_insert_with : + forall (K V : Ty.t), + M.IsAssociatedFunction.C (Self K V) "get_or_insert_with" (get_or_insert_with K V). + Admitted. + Global Typeclasses Opaque get_or_insert_with. + + (* + pub fn values(&self) -> impl Iterator { + self.0.iter().map(|(_, v)| v) + } + *) + Definition values (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self K V in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::map::Map") + [] + [ + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.tuple [ K; V ] ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ] ] + (Ty.apply (Ty.path "&") [] [ V ]) + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.tuple [ K; V ] ], + [], + [], + "map", + [], + [ + Ty.apply (Ty.path "&") [] [ V ]; + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ] ] + (Ty.apply (Ty.path "&") [] [ V ]) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.tuple [ K; V ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.tuple [ K; V ] ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.tuple [ K; V ] ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "p3_util::linear_map::LinearMap", + 0 + |) + |) + ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ Ty.tuple [ K; V ] ] ] ] + (Ty.apply (Ty.path "&") [] [ V ]) + ], + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let v := M.alloc (| γ1_1 |) in + M.read (| v |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_values : + forall (K V : Ty.t), + M.IsAssociatedFunction.C (Self K V) "values" (values K V). + Admitted. + Global Typeclasses Opaque values. + End Impl_p3_util_linear_map_LinearMap_K_V. + + Module Impl_core_iter_traits_collect_FromIterator_where_core_cmp_Eq_K_Tuple_K_V__for_p3_util_linear_map_LinearMap_K_V. + Definition Self (K V : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ]. + + (* + fn from_iter>(iter: T) -> Self { + let mut me = Self::default(); + for (k, v) in iter { + me.insert(k, v); + } + me + } + *) + Definition from_iter (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self K V in + match ε, τ, α with + | [], [ T ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.read (| + let~ me : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ] ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ], + M.get_trait_method (| + "core::default::Default", + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ], + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + T, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| iter |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.tuple [ K; V ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let k := M.copy (| γ1_0 |) in + let v := M.copy (| γ1_1 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.apply (Ty.path "core::option::Option") [] [ V ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ V ], + M.get_associated_function (| + Ty.apply + (Ty.path "p3_util::linear_map::LinearMap") + [] + [ K; V ], + "insert", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, me |); + M.read (| k |); + M.read (| v |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + me + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (K V : Ty.t), + M.IsTraitInstance + "core::iter::traits::collect::FromIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.tuple [ K; V ] ] + (Self K V) + (* Instance *) [ ("from_iter", InstanceField.Method (from_iter K V)) ]. + End Impl_core_iter_traits_collect_FromIterator_where_core_cmp_Eq_K_Tuple_K_V__for_p3_util_linear_map_LinearMap_K_V. + + Module Impl_core_iter_traits_collect_IntoIterator_for_p3_util_linear_map_LinearMap_K_V. + Definition Self (K V : Ty.t) : Ty.t := + Ty.apply (Ty.path "p3_util::linear_map::LinearMap") [] [ K; V ]. + + (* type Item = (K, V); *) + Definition _Item (K V : Ty.t) : Ty.t := Ty.tuple [ K; V ]. + + (* type IntoIter = as IntoIterator>::IntoIter; *) + Definition _IntoIter (K V : Ty.t) : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ]) + "IntoIter". + + (* + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } + *) + Definition into_iter (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self K V in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::into_iter::IntoIter") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.tuple [ K; V ]; Ty.path "alloc::alloc::Global" ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| self, "p3_util::linear_map::LinearMap", 0 |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (K V : Ty.t), + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self K V) + (* Instance *) + [ + ("Item", InstanceField.Ty (_Item K V)); + ("IntoIter", InstanceField.Ty (_IntoIter K V)); + ("into_iter", InstanceField.Method (into_iter K V)) + ]. + End Impl_core_iter_traits_collect_IntoIterator_for_p3_util_linear_map_LinearMap_K_V. +End linear_map. diff --git a/CoqOfRust/plonky3/util/src/transpose.rs b/CoqOfRust/plonky3/util/src/transpose.rs new file mode 100644 index 000000000..a7843b9d7 --- /dev/null +++ b/CoqOfRust/plonky3/util/src/transpose.rs @@ -0,0 +1,189 @@ +use core::ptr::swap; + +const LB_BLOCK_SIZE: usize = 3; + +/// Transpose square matrix in-place +/// The matrix is of size `1 << lb_size` by `1 << lb_size`. It occupies +/// `M[i, j] == arr[(i + x << lb_stride) + j + x]` for `0 <= i, j < 1 << lb_size`. The transposition +/// swaps `M[i, j]` and `M[j, i]`. +/// +/// SAFETY: +/// Make sure that `(i + x << lb_stride) + j + x` is a valid index in `arr` for all +/// `0 <= i, j < 1 << lb_size`. Ensure also that `lb_size <= lb_stride` to prevent overlap. +unsafe fn transpose_in_place_square_small( + arr: &mut [T], + lb_stride: usize, + lb_size: usize, + x: usize, +) { + unsafe { + for i in x + 1..x + (1 << lb_size) { + for j in x..i { + swap( + arr.get_unchecked_mut(i + (j << lb_stride)), + arr.get_unchecked_mut((i << lb_stride) + j), + ); + } + } + } +} + +/// Transpose square matrices and swap +/// The matrices are of size `1 << lb_size` by `1 << lb_size`. They occupy +/// `M0[i, j] == arr[(i + x << lb_stride) + j + y]`, `M1[i, j] == arr[i + x + (j + y << lb_stride)]` +/// for `0 <= i, j < 1 << lb_size. The transposition swaps `M0[i, j]` and `M1[j, i]`. +/// +/// SAFETY: +/// Make sure that `(i + x << lb_stride) + j + y` and `i + x + (j + y << lb_stride)` are valid +/// indices in `arr` for all `0 <= i, j < 1 << lb_size`. Ensure also that `lb_size <= lb_stride` to +/// prevent overlap. +unsafe fn transpose_swap_square_small( + arr: &mut [T], + lb_stride: usize, + lb_size: usize, + x: usize, + y: usize, +) { + unsafe { + for i in x..x + (1 << lb_size) { + for j in y..y + (1 << lb_size) { + swap( + arr.get_unchecked_mut(i + (j << lb_stride)), + arr.get_unchecked_mut((i << lb_stride) + j), + ); + } + } + } +} + +/// Transpose square matrices and swap +/// The matrices are of size `1 << lb_size` by `1 << lb_size`. They occupy +/// `M0[i, j] == arr[(i + x << lb_stride) + j + y]`, `M1[i, j] == arr[i + x + (j + y << lb_stride)]` +/// for `0 <= i, j < 1 << lb_size. The transposition swaps `M0[i, j]` and `M1[j, i]`. +/// +/// SAFETY: +/// Make sure that `(i + x << lb_stride) + j + y` and `i + x + (j + y << lb_stride)` are valid +/// indices in `arr` for all `0 <= i, j < 1 << lb_size`. Ensure also that `lb_size <= lb_stride` to +/// prevent overlap. +unsafe fn transpose_swap_square( + arr: &mut [T], + lb_stride: usize, + lb_size: usize, + x: usize, + y: usize, +) { + unsafe { + if lb_size <= LB_BLOCK_SIZE { + transpose_swap_square_small(arr, lb_stride, lb_size, x, y); + } else { + let lb_block_size = lb_size - 1; + let block_size = 1 << lb_block_size; + transpose_swap_square(arr, lb_stride, lb_block_size, x, y); + transpose_swap_square(arr, lb_stride, lb_block_size, x + block_size, y); + transpose_swap_square(arr, lb_stride, lb_block_size, x, y + block_size); + transpose_swap_square( + arr, + lb_stride, + lb_block_size, + x + block_size, + y + block_size, + ); + } + } +} + +/// Transpose square matrix in-place +/// The matrix is of size `1 << lb_size` by `1 << lb_size`. It occupies +/// `M[i, j] == arr[(i + x << lb_stride) + j + x]` for `0 <= i, j < 1 << lb_size`. The transposition +/// swaps `M[i, j]` and `M[j, i]`. +/// +/// SAFETY: +/// Make sure that `(i + x << lb_stride) + j + x` is a valid index in `arr` for all +/// `0 <= i, j < 1 << lb_size`. Ensure also that `lb_size <= lb_stride` to prevent overlap. +pub(crate) unsafe fn transpose_in_place_square( + arr: &mut [T], + lb_stride: usize, + lb_size: usize, + x: usize, +) { + unsafe { + if lb_size <= LB_BLOCK_SIZE { + transpose_in_place_square_small(arr, lb_stride, lb_size, x); + } else { + let lb_block_size = lb_size - 1; + let block_size = 1 << lb_block_size; + transpose_in_place_square(arr, lb_stride, lb_block_size, x); + transpose_swap_square(arr, lb_stride, lb_block_size, x, x + block_size); + transpose_in_place_square(arr, lb_stride, lb_block_size, x + block_size); + } + } +} + +#[cfg(test)] +mod tests { + use alloc::vec; + use alloc::vec::Vec; + + use super::*; + + /// Helper to create a square matrix of size `2^log_size` with elements `0..n^2` + fn generate_matrix(log_size: usize) -> Vec { + let size = 1 << log_size; + (0..size * size).collect() + } + + /// Reference transpose that returns a new vector (row-major layout) + fn transpose_reference(input: &[u32], log_size: usize) -> Vec { + let size = 1 << log_size; + let mut transposed = vec![0; size * size]; + for i in 0..size { + for j in 0..size { + transposed[j * size + i] = input[i * size + j]; + } + } + transposed + } + + /// Helper to test the full transpose and assert equality with reference + fn test_transpose(log_size: usize) { + let size = 1 << log_size; + let mut mat = generate_matrix(log_size); + + let expected = transpose_reference(&mat, log_size); + + unsafe { + transpose_in_place_square(&mut mat, log_size, log_size, 0); + } + + assert_eq!( + mat, expected, + "Transpose failed for {}x{} matrix", + size, size + ); + } + + #[test] + fn test_transpose_2x2() { + test_transpose(1); + } + + #[test] + fn test_transpose_4x4() { + test_transpose(2); + } + + #[test] + fn test_transpose_8x8() { + test_transpose(3); + } + + #[test] + fn test_transpose_16x16() { + test_transpose(4); + } + + #[test] + fn test_transpose_32x32() { + test_transpose(5); + } +} diff --git a/CoqOfRust/plonky3/util/src/transpose.v b/CoqOfRust/plonky3/util/src/transpose.v new file mode 100644 index 000000000..cc253fd5f --- /dev/null +++ b/CoqOfRust/plonky3/util/src/transpose.v @@ -0,0 +1,1056 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module transpose. + Definition value_LB_BLOCK_SIZE (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 3 |))). + + Global Instance Instance_IsConstant_value_LB_BLOCK_SIZE : + M.IsFunction.C "p3_util::transpose::LB_BLOCK_SIZE" value_LB_BLOCK_SIZE. + Admitted. + Global Typeclasses Opaque value_LB_BLOCK_SIZE. + + (* + unsafe fn transpose_in_place_square_small( + arr: &mut [T], + lb_stride: usize, + lb_size: usize, + x: usize, + ) { + unsafe { + for i in x + 1..x + (1 << lb_size) { + for j in x..i { + swap( + arr.get_unchecked_mut(i + (j << lb_stride)), + arr.get_unchecked_mut((i << lb_stride) + j), + ); + } + } + } + } + *) + Definition transpose_in_place_square_small + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ T ], [ arr; lb_stride; lb_size; x ] => + ltac:(M.monadic + (let arr := M.alloc (| arr |) in + let lb_stride := M.alloc (| lb_stride |) in + let lb_size := M.alloc (| lb_size |) in + let x := M.alloc (| x |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| x |); Value.Integer IntegerKind.Usize 1 ] + |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| x |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| lb_size |) ] + |) + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ ("start", M.read (| x |)); ("end_", M.read (| i |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let j := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "core::ptr::swap", + [], + [ T ] + |), + [ + M.borrow (| + Pointer.Kind.MutPointer, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ T ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ T ], + "get_unchecked_mut", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| arr |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.read (| j |); + M.read (| + lb_stride + |) + ] + |) + ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutPointer, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ T ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ T ], + "get_unchecked_mut", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| arr |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.read (| i |); + M.read (| + lb_stride + |) + ] + |); + M.read (| j |) + ] + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_transpose_in_place_square_small : + M.IsFunction.C + "p3_util::transpose::transpose_in_place_square_small" + transpose_in_place_square_small. + Admitted. + Global Typeclasses Opaque transpose_in_place_square_small. + + (* + unsafe fn transpose_swap_square_small( + arr: &mut [T], + lb_stride: usize, + lb_size: usize, + x: usize, + y: usize, + ) { + unsafe { + for i in x..x + (1 << lb_size) { + for j in y..y + (1 << lb_size) { + swap( + arr.get_unchecked_mut(i + (j << lb_stride)), + arr.get_unchecked_mut((i << lb_stride) + j), + ); + } + } + } + } + *) + Definition transpose_swap_square_small + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ T ], [ arr; lb_stride; lb_size; x; y ] => + ltac:(M.monadic + (let arr := M.alloc (| arr |) in + let lb_stride := M.alloc (| lb_stride |) in + let lb_size := M.alloc (| lb_size |) in + let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + M.read (| + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| x |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| x |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| lb_size |) ] + |) + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + M.use + (M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", M.read (| y |)); + ("end_", + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| y |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + Value.Integer IntegerKind.Usize 1; + M.read (| lb_size |) + ] + |) + ] + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + ltac:(M.monadic + (let~ _ : + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let j := M.copy (| γ0_0 |) in + let~ _ : + Ty.apply + (Ty.path "*") + [] + [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "core::ptr::swap", + [], + [ T ] + |), + [ + M.borrow (| + Pointer.Kind.MutPointer, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ T ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ T ], + "get_unchecked_mut", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| arr |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.read (| i |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.read (| j |); + M.read (| + lb_stride + |) + ] + |) + ] + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutPointer, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ T ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ T ], + "get_unchecked_mut", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| arr |) + |) + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ + M.read (| i |); + M.read (| + lb_stride + |) + ] + |); + M.read (| j |) + ] + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_transpose_swap_square_small : + M.IsFunction.C "p3_util::transpose::transpose_swap_square_small" transpose_swap_square_small. + Admitted. + Global Typeclasses Opaque transpose_swap_square_small. + + (* + unsafe fn transpose_swap_square( + arr: &mut [T], + lb_stride: usize, + lb_size: usize, + x: usize, + y: usize, + ) { + unsafe { + if lb_size <= LB_BLOCK_SIZE { + transpose_swap_square_small(arr, lb_stride, lb_size, x, y); + } else { + let lb_block_size = lb_size - 1; + let block_size = 1 << lb_block_size; + transpose_swap_square(arr, lb_stride, lb_block_size, x, y); + transpose_swap_square(arr, lb_stride, lb_block_size, x + block_size, y); + transpose_swap_square(arr, lb_stride, lb_block_size, x, y + block_size); + transpose_swap_square( + arr, + lb_stride, + lb_block_size, + x + block_size, + y + block_size, + ); + } + } + } + *) + Definition transpose_swap_square (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ arr; lb_stride; lb_size; x; y ] => + ltac:(M.monadic + (let arr := M.alloc (| arr |) in + let lb_stride := M.alloc (| lb_stride |) in + let lb_size := M.alloc (| lb_size |) in + let x := M.alloc (| x |) in + let y := M.alloc (| y |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| lb_size |); + M.read (| + get_constant (| + "p3_util::transpose::LB_BLOCK_SIZE", + Ty.path "usize" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::transpose::transpose_swap_square_small", + [], + [ T ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| arr |) |) |); + M.read (| lb_stride |); + M.read (| lb_size |); + M.read (| x |); + M.read (| y |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ lb_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| lb_size |); Value.Integer IntegerKind.Usize 1 ] + |) + |) in + let~ block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| lb_block_size |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::transpose::transpose_swap_square", [], [ T ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| arr |) |) |); + M.read (| lb_stride |); + M.read (| lb_block_size |); + M.read (| x |); + M.read (| y |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::transpose::transpose_swap_square", [], [ T ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| arr |) |) |); + M.read (| lb_stride |); + M.read (| lb_block_size |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| x |); M.read (| block_size |) ] + |); + M.read (| y |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::transpose::transpose_swap_square", [], [ T ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| arr |) |) |); + M.read (| lb_stride |); + M.read (| lb_block_size |); + M.read (| x |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| y |); M.read (| block_size |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::transpose::transpose_swap_square", [], [ T ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| arr |) |) |); + M.read (| lb_stride |); + M.read (| lb_block_size |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| x |); M.read (| block_size |) ] + |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| y |); M.read (| block_size |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_transpose_swap_square : + M.IsFunction.C "p3_util::transpose::transpose_swap_square" transpose_swap_square. + Admitted. + Global Typeclasses Opaque transpose_swap_square. + + (* + pub(crate) unsafe fn transpose_in_place_square( + arr: &mut [T], + lb_stride: usize, + lb_size: usize, + x: usize, + ) { + unsafe { + if lb_size <= LB_BLOCK_SIZE { + transpose_in_place_square_small(arr, lb_stride, lb_size, x); + } else { + let lb_block_size = lb_size - 1; + let block_size = 1 << lb_block_size; + transpose_in_place_square(arr, lb_stride, lb_block_size, x); + transpose_swap_square(arr, lb_stride, lb_block_size, x, x + block_size); + transpose_in_place_square(arr, lb_stride, lb_block_size, x + block_size); + } + } + } + *) + Definition transpose_in_place_square (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ arr; lb_stride; lb_size; x ] => + ltac:(M.monadic + (let arr := M.alloc (| arr |) in + let lb_stride := M.alloc (| lb_stride |) in + let lb_size := M.alloc (| lb_size |) in + let x := M.alloc (| x |) in + M.read (| + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.le, + [ + M.read (| lb_size |); + M.read (| + get_constant (| + "p3_util::transpose::LB_BLOCK_SIZE", + Ty.path "usize" + |) + |) + ] + |) + |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::transpose::transpose_in_place_square_small", + [], + [ T ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| arr |) |) |); + M.read (| lb_stride |); + M.read (| lb_size |); + M.read (| x |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ lb_block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.sub, + [ M.read (| lb_size |); Value.Integer IntegerKind.Usize 1 ] + |) + |) in + let~ block_size : Ty.apply (Ty.path "*") [] [ Ty.path "usize" ] := + M.alloc (| + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.shl, + [ Value.Integer IntegerKind.Usize 1; M.read (| lb_block_size |) ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::transpose::transpose_in_place_square", + [], + [ T ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| arr |) |) |); + M.read (| lb_stride |); + M.read (| lb_block_size |); + M.read (| x |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| "p3_util::transpose::transpose_swap_square", [], [ T ] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| arr |) |) |); + M.read (| lb_stride |); + M.read (| lb_block_size |); + M.read (| x |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| x |); M.read (| block_size |) ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "p3_util::transpose::transpose_in_place_square", + [], + [ T ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| arr |) |) |); + M.read (| lb_stride |); + M.read (| lb_block_size |); + M.call_closure (| + Ty.path "usize", + BinOp.Wrap.add, + [ M.read (| x |); M.read (| block_size |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_transpose_in_place_square : + M.IsFunction.C "p3_util::transpose::transpose_in_place_square" transpose_in_place_square. + Admitted. + Global Typeclasses Opaque transpose_in_place_square. +End transpose. diff --git a/CoqOfRust/plonky3/util/src/zip_eq.rs b/CoqOfRust/plonky3/util/src/zip_eq.rs new file mode 100644 index 000000000..42c0c06be --- /dev/null +++ b/CoqOfRust/plonky3/util/src/zip_eq.rs @@ -0,0 +1,63 @@ +/// An iterator which iterates two other iterators of the same length simultaneously. +/// +/// Equality of the lengths of `a` abd `b` are at construction time. +#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] +pub struct ZipEq { + a: A, + b: B, +} + +/// Zips two iterators but **panics** if they are not of the same length. +/// +/// Similar to `itertools::zip_eq`, but we check the lengths at construction time. +pub fn zip_eq( + a: A, + b: B, + err: Error, +) -> Result, Error> +where + A: IntoIterator, + AIter: ExactSizeIterator, + B: IntoIterator, + BIter: ExactSizeIterator, +{ + let a_iter = a.into_iter(); + let b_iter = b.into_iter(); + match a_iter.len() == b_iter.len() { + true => Ok(ZipEq { + a: a_iter, + b: b_iter, + }), + false => Err(err), + } +} + +impl Iterator for ZipEq +where + A: ExactSizeIterator, // We need to use ExactSizeIterator here otherwise the size_hint() methods could differ. + B: ExactSizeIterator, +{ + type Item = (A::Item, B::Item); + + fn next(&mut self) -> Option { + match (self.a.next(), self.b.next()) { + (Some(a), Some(b)) => Some((a, b)), + (None, None) => None, + _ => unreachable!("The iterators must have the same length."), + } + } + + fn size_hint(&self) -> (usize, Option) { + // self.a.size_hint() = self.b.size_hint() as a and b are ExactSizeIterators + // and we checked that they are the same length at construction time. + debug_assert_eq!(self.a.size_hint(), self.b.size_hint()); + self.a.size_hint() + } +} + +impl ExactSizeIterator for ZipEq +where + A: ExactSizeIterator, + B: ExactSizeIterator, +{ +} diff --git a/CoqOfRust/plonky3/util/src/zip_eq.v b/CoqOfRust/plonky3/util/src/zip_eq.v new file mode 100644 index 000000000..2bfe6df40 --- /dev/null +++ b/CoqOfRust/plonky3/util/src/zip_eq.v @@ -0,0 +1,668 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module zip_eq. + (* StructRecord + { + name := "ZipEq"; + const_params := []; + ty_params := [ "A"; "B" ]; + fields := [ ("a", A); ("b", B) ]; + } *) + + (* + pub fn zip_eq( + a: A, + b: B, + err: Error, + ) -> Result, Error> + where + A: IntoIterator, + AIter: ExactSizeIterator, + B: IntoIterator, + BIter: ExactSizeIterator, + { + let a_iter = a.into_iter(); + let b_iter = b.into_iter(); + match a_iter.len() == b_iter.len() { + true => Ok(ZipEq { + a: a_iter, + b: b_iter, + }), + false => Err(err), + } + } + *) + Definition zip_eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ A; AIter; B; BIter; Error ], [ a; b; err ] => + ltac:(M.monadic + (let a := M.alloc (| a |) in + let b := M.alloc (| b |) in + let err := M.alloc (| err |) in + M.read (| + let~ a_iter : Ty.apply (Ty.path "*") [] [ AIter ] := + M.alloc (| + M.call_closure (| + AIter, + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + A, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| a |) ] + |) + |) in + let~ b_iter : Ty.apply (Ty.path "*") [] [ BIter ] := + M.alloc (| + M.call_closure (| + BIter, + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + B, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| b |) ] + |) + |) in + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.apply (Ty.path "p3_util::zip_eq::ZipEq") [] [ AIter; BIter ]; Error ] + ], + M.alloc (| + M.call_closure (| + Ty.path "bool", + BinOp.eq, + [ + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::iter::traits::exact_size::ExactSizeIterator", + AIter, + [], + [], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, a_iter |) ] + |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::iter::traits::exact_size::ExactSizeIterator", + BIter, + [], + [], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, b_iter |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructRecord + "p3_util::zip_eq::ZipEq" + [ ("a", M.read (| a_iter |)); ("b", M.read (| b_iter |)) ] + ] + |))); + fun γ => + ltac:(M.monadic + (let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool false |) in + M.alloc (| Value.StructTuple "core::result::Result::Err" [ M.read (| err |) ] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_zip_eq : M.IsFunction.C "p3_util::zip_eq::zip_eq" zip_eq. + Admitted. + Global Typeclasses Opaque zip_eq. + + Module Impl_core_iter_traits_iterator_Iterator_where_core_iter_traits_exact_size_ExactSizeIterator_A_where_core_iter_traits_exact_size_ExactSizeIterator_B_for_p3_util_zip_eq_ZipEq_A_B. + Definition Self (A B : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_util::zip_eq::ZipEq") [] [ A; B ]. + + (* type Item = (A::Item, B::Item); *) + Definition _Item (A B : Ty.t) : Ty.t := + Ty.tuple + [ + Ty.associated_in_trait "core::iter::traits::iterator::Iterator" [] [] A "Item"; + Ty.associated_in_trait "core::iter::traits::iterator::Iterator" [] [] B "Item" + ]. + + (* + fn next(&mut self) -> Option { + match (self.a.next(), self.b.next()) { + (Some(a), Some(b)) => Some((a, b)), + (None, None) => None, + _ => unreachable!("The iterators must have the same length."), + } + } + *) + Definition next (A B : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self A B in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Ty.apply + (Ty.path "*") + [] + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + A + "Item"; + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + B + "Item" + ] + ] + ], + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + A + "Item" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + A, + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_util::zip_eq::ZipEq", + "a" + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.associated_in_trait + "core::iter::traits::iterator::Iterator" + [] + [] + B + "Item" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + B, + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_util::zip_eq::ZipEq", + "b" + |) + |) + ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "core::option::Option::Some", + 0 + |) in + let a := M.copy (| γ1_0 |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "core::option::Option::Some", + 0 + |) in + let b := M.copy (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ Value.Tuple [ M.read (| a |); M.read (| b |) ] ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := M.is_struct_tuple (| γ0_0, "core::option::Option::None" |) in + let _ := M.is_struct_tuple (| γ0_1, "core::option::Option::None" |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 1; + Value.Integer IntegerKind.Usize 0 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "internal error: entered unreachable code: The iterators must have the same length." + |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 0 ] + [ Ty.path "core::fmt::rt::Argument" ], + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "none", + [], + [] + |), + [] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn size_hint(&self) -> (usize, Option) { + // self.a.size_hint() = self.b.size_hint() as a and b are ExactSizeIterators + // and we checked that they are the same length at construction time. + debug_assert_eq!(self.a.size_hint(), self.b.size_hint()); + self.a.size_hint() + } + *) + Definition size_hint (A B : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self A B in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.apply (Ty.path "*") [] [ Ty.tuple [] ] := + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + A, + [], + [], + "size_hint", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_util::zip_eq::ZipEq", + "a" + |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + B, + [], + [], + "size_hint", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_util::zip_eq::ZipEq", + "b" + |) + |) + ] + |) + |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Ty.apply (Ty.path "*") [] [ Ty.tuple [] ], + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ] + ], + [], + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + ] + |) + |) + |)) in + let _ := + is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : + Ty.apply + (Ty.path "*") + [] + [ Ty.path "core::panicking::AssertKind" ] := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ] + ]; + Ty.tuple + [ + Ty.path "usize"; + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ] + ] + ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + A, + [], + [], + "size_hint", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "p3_util::zip_eq::ZipEq", + "a" + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (A B : Ty.t), + M.IsTraitInstance + "core::iter::traits::iterator::Iterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self A B) + (* Instance *) + [ + ("Item", InstanceField.Ty (_Item A B)); + ("next", InstanceField.Method (next A B)); + ("size_hint", InstanceField.Method (size_hint A B)) + ]. + End Impl_core_iter_traits_iterator_Iterator_where_core_iter_traits_exact_size_ExactSizeIterator_A_where_core_iter_traits_exact_size_ExactSizeIterator_B_for_p3_util_zip_eq_ZipEq_A_B. + + Module Impl_core_iter_traits_exact_size_ExactSizeIterator_where_core_iter_traits_exact_size_ExactSizeIterator_A_where_core_iter_traits_exact_size_ExactSizeIterator_B_for_p3_util_zip_eq_ZipEq_A_B. + Definition Self (A B : Ty.t) : Ty.t := Ty.apply (Ty.path "p3_util::zip_eq::ZipEq") [] [ A; B ]. + + Axiom Implements : + forall (A B : Ty.t), + M.IsTraitInstance + "core::iter::traits::exact_size::ExactSizeIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self A B) + (* Instance *) []. + End Impl_core_iter_traits_exact_size_ExactSizeIterator_where_core_iter_traits_exact_size_ExactSizeIterator_A_where_core_iter_traits_exact_size_ExactSizeIterator_B_for_p3_util_zip_eq_ZipEq_A_B. +End zip_eq.